UICompany.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. using Mysqlx.Crud;
  2. using MySqlX.Serialization;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Runtime.InteropServices.ComTypes;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. using System.Text.Json;
  16. using System.IO;
  17. using System.Diagnostics;
  18. using System.Text.RegularExpressions;
  19. namespace DataManager
  20. {
  21. public partial class UICompany : Form
  22. {
  23. private string companyId;
  24. private int userId;
  25. private DataTable companyInfo;
  26. private DataTable fundList;
  27. private DataTable contactList;
  28. private List<DataRowView> old_selected_contactor = new List<DataRowView>();
  29. private List<DataRowView> old_selected_collector = new List<DataRowView>();
  30. private string saveFilePath;
  31. private DataTable taskList;
  32. public UICompany(string companyId, int userId)
  33. {
  34. this.companyId = companyId.Trim().ToUpper();
  35. this.userId = userId;
  36. this.saveFilePath = ".\\Contracts\\" + companyId + "\\";
  37. InitializeComponent();
  38. InitializedData();
  39. }
  40. public string CompanyId { get { return companyId; } }
  41. public int UserId { get { return userId; } }
  42. private void InitializedData()
  43. {
  44. #region Basic Info Tab
  45. companyInfo = DataAccess.Get_dm_company_information(CompanyId);
  46. if(companyInfo == null || companyInfo.Rows.Count == 0 ) { return; }
  47. txtCompanyName.Text = companyInfo.Rows[0]["company_name"].ToString();
  48. txtRegisterCode.Text = companyInfo.Rows[0]["register_number"].ToString();
  49. txtCompanyId.Text = companyInfo.Rows[0]["company_id"].ToString();
  50. txtIncoporationDate.Text = DateTime.Parse(companyInfo.Rows[0]["establish_date"].ToString()).ToShortDateString();
  51. txtRegisterAddress.Text = companyInfo.Rows[0]["register_number_address"].ToString();
  52. txtOrgCode.Text = companyInfo.Rows[0]["credit_code"].ToString();
  53. txtBusinessAddress.Text = companyInfo.Rows[0]["company_address"].ToString();
  54. if (companyInfo.Rows[0]["nature_business_type"].ToString() != "")
  55. txtOrgType.Text = UIConstants.CompanyOwnerType[int.Parse(companyInfo.Rows[0]["nature_business_type"].ToString())];
  56. else
  57. txtOrgType.Text = "未知";
  58. if (companyInfo.Rows[0]["company_type"].ToString() != "")
  59. txtCompanyType.Text = UIConstants.CompanyType[int.Parse(companyInfo.Rows[0]["company_type"].ToString())];
  60. else
  61. txtCompanyType.Text = "未知";
  62. txtBusinessType.Text = companyInfo.Rows[0]["business_type"].ToString();
  63. if (companyInfo.Rows[0]["company_asset_size"].ToString() != "")
  64. txtAssetSize.Text = UIConstants.CompanyAssetSize[int.Parse(companyInfo.Rows[0]["company_asset_size"].ToString())];
  65. else
  66. txtAssetSize.Text = "未知";
  67. txtIsQualifiedAdvisor.Text = companyInfo.Rows[0]["has_consulting_qualification"].ToString() == "1" ? "是" : "否";
  68. //txtOwner.Text = companyInfo.Rows[0]["establish_date"].ToString();
  69. //txtAmacUpdateDate.Text = companyInfo.Rows[0]["zjx_last_info_update_time"].ToString();
  70. //lklAmacURL.Links.Add(Link )companyInfo.Rows[0]["amac_link"].ToString();
  71. txtCompanyShortName.Text = companyInfo.Rows[0]["company_short_name"].ToString();
  72. #endregion
  73. LoadContactsGrid();
  74. #region Fund List Tab
  75. Dictionary<int, string> d = new Dictionary<int, string>(UIConstants.HedgeFundStrategy);
  76. d.Add(DataAccess.DM_NULL, "全部");
  77. BindingSource bs = new BindingSource();
  78. bs.DataSource = d;
  79. cmbStrategy.DataSource = bs;
  80. cmbStrategy.DisplayMember = "Value";
  81. cmbStrategy.ValueMember = "Key";
  82. cmbStrategy.SelectedValue = (int)DataAccess.DM_NULL;
  83. LoadFundGrid();
  84. #endregion
  85. #region Contracts Tab
  86. sbyte jobType = Convert.ToSByte(UIConstants.JobType.联络);
  87. DataTable dt_dm_user_1 = DataAccess.Get_dm_user(null, jobType);
  88. clbContactor.DataSource = dt_dm_user_1;
  89. clbContactor.DisplayMember = "username";
  90. clbContactor.ValueMember = "userid";
  91. // 给覆盖此公司的user打上勾
  92. DataTable dt_company_cover_1 = DataAccess.Get_dm_company_cover(CompanyId, jobType, null);
  93. for(int i = 0; i < clbContactor.Items.Count; i++)
  94. {
  95. string itemUserId = ((DataRowView)clbContactor.Items[i]).Row["userid"].ToString();
  96. if (dt_company_cover_1.Select("userid = " + itemUserId).Length > 0)
  97. clbContactor.SetItemChecked(i, true);
  98. }
  99. // 记录一下初始的勾选
  100. foreach(DataRowView item in clbContactor.CheckedItems)
  101. {
  102. old_selected_contactor.Add(item);
  103. }
  104. jobType = Convert.ToSByte(UIConstants.JobType.采集);
  105. DataTable dt_dm_user_2 = DataAccess.Get_dm_user(null, jobType);
  106. clbCollector.DataSource = dt_dm_user_2;
  107. clbCollector.DisplayMember = "username";
  108. clbCollector.ValueMember = "userid";
  109. // 给覆盖此公司的user打上勾
  110. DataTable dt_company_cover_2 = DataAccess.Get_dm_company_cover(CompanyId, jobType, null);
  111. for (int i = 0; i < clbCollector.Items.Count; i++)
  112. {
  113. string itemUserId = ((DataRowView)clbCollector.Items[i]).Row["userid"].ToString();
  114. if (dt_company_cover_2.Select("userid = " + itemUserId).Length > 0)
  115. clbCollector.SetItemChecked(i, true);
  116. }
  117. // 记录一下初始的勾选
  118. foreach(DataRowView item in clbCollector.CheckedItems)
  119. {
  120. old_selected_collector.Add(item);
  121. }
  122. DataTable dt = DataAccess.Get_dm_company_authorization(CompanyId, null);
  123. if (dt != null && dt.Rows.Count > 0) chkIsAuthorized.Checked = true;
  124. LoadContractFiles();
  125. #endregion
  126. #region Task Tab
  127. cmbTaskType.Items.Add(UIConstants.JobType.联络.ToString());
  128. cmbTaskType.Items.Add(UIConstants.JobType.采集.ToString());
  129. cmbTaskType.SelectedIndex = 0;
  130. LoadTaskList(UIConstants.JobType.联络);
  131. #endregion
  132. }
  133. #region Basic Info
  134. private void btnSaveBasicInfo_Click(object sender, EventArgs e)
  135. {
  136. if (companyInfo == null || companyInfo.Rows.Count == 0) return;
  137. string originalShortName = companyInfo.Rows[0]["company_short_name"].ToString();
  138. string currentShortName = txtCompanyShortName.Text.Trim();
  139. if (originalShortName == currentShortName) return;
  140. if (currentShortName.Length > 0)
  141. {
  142. int ret = DataAccess.Set_dm_company_information(CompanyId, currentShortName, UserId);
  143. MessageBox.Show(ret < 0 ? "Oops... 变更存数据库时出了错" : "数据变更已经成功存盘~", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  144. }
  145. else
  146. {
  147. MessageBox.Show("公司简称不能空着,把意义不大又重复的词去掉试试?", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  148. txtCompanyShortName.Focus();
  149. }
  150. }
  151. #endregion
  152. #region Contact List
  153. private void LoadContactsGrid()
  154. {
  155. contactList = DataAccess.Get_dm_contacts(CompanyId);
  156. grdContacts.DataSource = contactList;
  157. grdContacts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  158. grdContacts.Columns["id"].Visible = false;
  159. grdContacts.Columns["company_id"].Visible = false;
  160. grdContacts.Columns["name"].HeaderText = "姓名";
  161. grdContacts.Columns["role"].HeaderText = "职务";
  162. grdContacts.Columns["phone"].HeaderText = "电话";
  163. grdContacts.Columns["wechat"].HeaderText = "微信";
  164. grdContacts.Columns["email"].HeaderText = "邮箱";
  165. grdContacts.Columns["isvalid"].Visible = false;
  166. grdContacts.Columns["creatorid"].Visible = false;
  167. grdContacts.Columns["createtime"].Visible = false;
  168. grdContacts.Columns["updaterid"].Visible = false;
  169. grdContacts.Columns["updatetime"].Visible = false;
  170. lblContactsCount.Text = contactList.Rows.Count.ToString();
  171. }
  172. private void btnSaveContact_Click(object sender, EventArgs e)
  173. {
  174. if(contactList == null ) return;
  175. int updatedCnt = DataAccess.Set_dm_contacts(contactList, CompanyId, UserId);
  176. contactList.AcceptChanges();
  177. MessageBox.Show("成功更新了" + updatedCnt.ToString() + "个联系人", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  178. }
  179. #endregion
  180. #region Fund List
  181. private void LoadFundGrid()
  182. {
  183. fundList = DataAccess.Get_dm_fund_information(null, CompanyId);
  184. BindingSource bs = new BindingSource();
  185. bs.DataSource = fundList;
  186. grdFund.DataSource = bs;
  187. grdFund.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  188. grdFund.Columns["fund_id"].Visible = false;
  189. grdFund.Columns["raise_type"].Visible = false;
  190. grdFund.Columns["fund_name"].Visible = false;
  191. grdFund.Columns["fund_short_name"].HeaderText = "基金简称";
  192. grdFund.Columns["fund_structure"].Visible = false;
  193. grdFund.Columns["fund_type"].Visible = false;
  194. grdFund.Columns["strategy"].Visible = false;
  195. grdFund.Columns["substrategy"].Visible = false;
  196. grdFund.Columns["fund_status"].Visible = false;
  197. grdFund.Columns["base_currency"].Visible = false;
  198. grdFund.Columns["inception_date"].HeaderText = "成立日";
  199. grdFund.Columns["initial_unit_value"].Visible = false;
  200. grdFund.Columns["p_fund_id"].Visible = false;
  201. grdFund.Columns["p_fund_name"].Visible = false;
  202. grdFund.Columns["advisor_id"].Visible = false;
  203. grdFund.Columns["company_name"].Visible = false;
  204. grdFund.Columns["custodian_id"].Visible = false;
  205. grdFund.Columns["custodian_name"].HeaderText = "托管";
  206. grdFund.Columns["trust_id"].Visible = false;
  207. grdFund.Columns["nav_frequency"].HeaderText = "净值频率";
  208. grdFund.Columns["manager_type"].Visible = false;
  209. grdFund.Columns["zjx_last_info_update_time"].Visible = false;
  210. grdFund.Columns["amac_url"].Visible = false;
  211. grdFund.Columns["register_number"].HeaderText = "备案编码";
  212. grdFund.Columns["register_date"].Visible = false;
  213. grdFund.Columns["main_code"].Visible = false;
  214. grdFund.Columns["isVisible"].Visible = false;
  215. grdFund.Columns["is_ranking"].HeaderText = "是否排名";
  216. grdFund.Columns["is_rating"].HeaderText = "是否评级";
  217. grdFund.Columns["is_authorized"].HeaderText = "是否授权";
  218. grdFund.Columns["trust_register_number"].Visible = false;
  219. grdFund.Columns["isvalid"].Visible = false;
  220. grdFund.Columns["creatorid"].Visible = false;
  221. grdFund.Columns["createtime"].Visible = false;
  222. grdFund.Columns["updaterid"].Visible = false;
  223. grdFund.Columns["updatetime"].Visible = false;
  224. grdFund.Columns["max_price_date"].HeaderText = "最新净值日";
  225. grdFund.Columns["fund_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
  226. SetStatusStrip(fundList.Rows.Count);
  227. }
  228. private void grdFund_CellClick(object sender, DataGridViewCellEventArgs e)
  229. {
  230. int rowIndex = e.RowIndex;
  231. int columnIndex = e.ColumnIndex;
  232. if (columnIndex < 0 || rowIndex < 0) return;
  233. DataGridViewRow row = grdFund.Rows[rowIndex];
  234. string fundId = row.Cells["fund_id"].Value.ToString();
  235. UIFund frm = new UIFund(fundId, UserId);
  236. frm.ShowDialog();
  237. }
  238. private void cmbStrategy_SelectedIndexChanged(object sender, EventArgs e)
  239. {
  240. FilterFund();
  241. }
  242. private void dtpInceptionDate_ValueChanged(object sender, EventArgs e)
  243. {
  244. FilterFund();
  245. }
  246. private void FilterFund()
  247. {
  248. string strategy = cmbStrategy.SelectedValue.ToString();
  249. string inception = dtpInceptionDate.Value.ToString();
  250. string filter = null;
  251. int cnt = 0;
  252. if (strategy == DataAccess.DM_NULL.ToString())
  253. filter = string.Format("inception_date <= #{0}#", inception);
  254. else
  255. filter = string.Format("strategy = {0} and inception_date <= #{1}#", strategy, inception);
  256. if (fundList != null && fundList.Rows.Count > 0)
  257. {
  258. BindingSource bs = (BindingSource)grdFund.DataSource;
  259. bs.Filter = filter;
  260. cnt = bs.Count;
  261. }
  262. SetStatusStrip(cnt);
  263. }
  264. private void SetStatusStrip(int cnt)
  265. {
  266. ToolStripStatusLabel label = new ToolStripStatusLabel();
  267. label.Text = "记录条数:" + cnt.ToString();
  268. sstCompany.Items.Clear();
  269. sstCompany.Items.Add(label);
  270. }
  271. #endregion
  272. #region Contract
  273. private void btnSaveContactor_Click(object sender, EventArgs e)
  274. {
  275. List<CompanyCoverUser> coverage = new List<CompanyCoverUser>();
  276. List<DataRowView> new_selected_contactor = new List<DataRowView>();
  277. foreach(DataRowView item in clbContactor.CheckedItems)
  278. new_selected_contactor.Add(item);
  279. CompanyCoverUser cov1 = CompareCoverage(CompanyId, 1, old_selected_contactor, new_selected_contactor);
  280. if(cov1 != null )
  281. coverage.Add(cov1);
  282. List<DataRowView> new_selected_collector = new List<DataRowView>();
  283. foreach (DataRowView item in clbCollector.CheckedItems)
  284. new_selected_collector.Add(item);
  285. CompanyCoverUser cov2 = CompareCoverage(CompanyId, 2, old_selected_collector, new_selected_collector);
  286. if(cov2 != null )
  287. coverage.Add(cov2);
  288. string query = JsonSerializer.Serialize(coverage);
  289. int ret = DataAccess.Set_dm_company_cover(query, UserId);
  290. int ret2 = DataAccess.Set_dm_company_authorization(CompanyId, chkIsAuthorized.Checked ? 1 : 0, UserId);
  291. string message = (ret * ret2) < 0 ? "Oops... 变更存数据库时出了错" : "数据变更已经成功存盘~";
  292. MessageBox.Show(message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  293. }
  294. /// <summary>
  295. /// 前后人员覆盖对比
  296. /// </summary>
  297. /// <param name="companyId"></param>
  298. /// <param name="coverType"></param>
  299. /// <param name="oldList"></param>
  300. /// <param name="newList"></param>
  301. /// <returns></returns>
  302. private CompanyCoverUser CompareCoverage(string companyId, sbyte coverType, List<DataRowView> oldList, List<DataRowView> newList)
  303. {
  304. CompanyCoverUser companyCoverUser = new CompanyCoverUser();
  305. companyCoverUser.CompanyId = companyId;
  306. companyCoverUser.CoverType = coverType;
  307. if (oldList == null || newList == null) return companyCoverUser;
  308. // 在旧名单里,但不在新名单里的要删掉
  309. List<DataRowView> itemDeleted = oldList.Except(newList).ToList();
  310. // 在新名单里,但不在旧名单里的要增加
  311. List<DataRowView> itemAdded = newList.Except(oldList).ToList();
  312. int i = 0;
  313. CompanyCoverUser.Coverage[] covers = null;
  314. if (itemDeleted.Count > 0 || itemAdded.Count > 0)
  315. covers = new CompanyCoverUser.Coverage[itemDeleted.Count+itemAdded.Count];
  316. foreach (DataRowView item in itemDeleted)
  317. {
  318. CompanyCoverUser.Coverage cov = new CompanyCoverUser.Coverage();
  319. cov.IsValid = 0;
  320. cov.UserId = int.Parse(item.Row["userid"].ToString());
  321. covers[i] = cov;
  322. i++;
  323. }
  324. foreach (DataRowView item in itemAdded)
  325. {
  326. CompanyCoverUser.Coverage cov = new CompanyCoverUser.Coverage();
  327. cov.IsValid = 1;
  328. cov.UserId = int.Parse(item.Row["userid"].ToString());
  329. covers[i] = cov;
  330. i++;
  331. }
  332. companyCoverUser.Coverages = covers;
  333. //ret = JsonSerializer.Serialize(companyCoverUser);
  334. return companyCoverUser;
  335. }
  336. private void btnAuthorizeFunds_Click(object sender, EventArgs e)
  337. {
  338. UIBuckAuthorizeFund frm = new UIBuckAuthorizeFund(UserId);
  339. frm.Show();
  340. }
  341. /// <summary>
  342. /// 上传文件 TODO: 文件先写到本地
  343. /// </summary>
  344. /// <param name="sender"></param>
  345. /// <param name="e"></param>
  346. private void btnUploadFile_Click(object sender, EventArgs e)
  347. {
  348. ofdUploadFile.Title = "文件上传 ... 还没做完呢";
  349. //ofdUploadFile.DefaultExt = "doc";
  350. //ofdUploadFile.Filter = "所有Word文件(*.doc)|所有pdf文件(*.pdf)|所有文件(*.*)|*.*";
  351. if(ofdUploadFile.ShowDialog() == DialogResult.OK)
  352. {
  353. // TODO: upload files to server. let's fake it for now
  354. string filePath = ofdUploadFile.FileName;
  355. string fileName = Path.GetFileName(filePath);
  356. string saveFileName = this.saveFilePath + fileName;
  357. try
  358. {
  359. if (!Directory.Exists(saveFilePath)) { Directory.CreateDirectory(saveFilePath); }
  360. File.Copy(filePath, saveFileName, true);
  361. CreateFileButton(Path.GetFileName(saveFileName));
  362. }
  363. catch (Exception ex)
  364. {
  365. MessageBox.Show("文件上传失败:" + ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
  366. }
  367. }
  368. }
  369. /// <summary>
  370. /// 显示已上传文件,每个文件一个按钮
  371. /// </summary>
  372. private void LoadContractFiles()
  373. {
  374. if (Directory.Exists(this.saveFilePath))
  375. {
  376. string[] fileNames = Directory.GetFiles(saveFilePath);
  377. if(fileNames.Length > 0)
  378. {
  379. foreach (string fileName in fileNames)
  380. {
  381. CreateFileButton(Path.GetFileName(fileName));
  382. }
  383. }
  384. }
  385. }
  386. /// <summary>
  387. /// 为每个上传的文件产生一个按钮来显示
  388. /// </summary>
  389. /// <param name="fileName"></param>
  390. private void CreateFileButton(string fileName)
  391. {
  392. Panel panFile = new Panel();
  393. panFile.BorderStyle = BorderStyle.FixedSingle;
  394. panFile.Size = btnUploadFile.Size;
  395. panFile.Text = fileName;
  396. panFile.Font = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
  397. panFile.Click += PanFile_Click;
  398. panFile.MouseEnter += PanFile_Enter;
  399. panFile.MouseLeave += PanFile_MouseLeave;
  400. Label lblFileName = new Label();
  401. lblFileName.Text = fileName;
  402. lblFileName.ForeColor = Color.DodgerBlue;
  403. lblFileName.Size = new Size(panFile.Width, panFile.Height/2);
  404. lblFileName.Location = new Point(panFile.Location.X, panFile.Location.Y + panFile.Size.Height/2);
  405. lblFileName.TextAlign = ContentAlignment.MiddleCenter;
  406. lblFileName.Click += LblFileName_Click;
  407. panFile.Controls.Add(lblFileName);
  408. CircleDeleteControl delIcon = new CircleDeleteControl();
  409. delIcon.Size = new Size(panFile.Width/8, panFile.Height/8);
  410. delIcon.Location = new Point(panFile.Width * 3/4, panFile.Width * 1/8);
  411. delIcon.Visible = true;
  412. delIcon.Click += DelIcon_Click;
  413. panFile.Controls.Add(delIcon);
  414. flowLayoutPanel1.Controls.Add(panFile);
  415. }
  416. private void LblFileName_Click(object sender, EventArgs e)
  417. {
  418. Control pan = ((Control)sender).Parent;
  419. PanFile_Click(pan, e);
  420. }
  421. private void PanFile_Click(object sender, EventArgs e)
  422. {
  423. OpenFile(saveFilePath + ((Panel)sender).Text);
  424. }
  425. private void PanFile_Enter(object sender, EventArgs e)
  426. {
  427. ((Control)sender).BackColor = Color.LightGray;
  428. }
  429. private void PanFile_MouseLeave(object sender, EventArgs e)
  430. {
  431. ((Control)sender).BackColor = Color.White;
  432. }
  433. private void DelIcon_Click(object sender, EventArgs e)
  434. {
  435. DialogResult result = MessageBox.Show("确认要删除此文件么?", "删除文件确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  436. if (result == DialogResult.Yes)
  437. {
  438. Panel pan = (Panel)((Control)sender).Parent;
  439. File.Delete(saveFilePath + pan.Text);
  440. pan.Parent.Controls.Remove(pan);
  441. }
  442. }
  443. private void OpenFile(string fileName)
  444. {
  445. ProcessStartInfo startInfo = new ProcessStartInfo
  446. {
  447. FileName = fileName,
  448. UseShellExecute = true
  449. };
  450. Process.Start(startInfo);
  451. }
  452. #endregion
  453. #region Task List
  454. private void LoadTaskList(UIConstants.JobType jobType)
  455. {
  456. if (jobType == UIConstants.JobType.联络)
  457. {
  458. taskList = DataAccess.Get_dm_contact_task(null, null, CompanyId, null, null, null, null, null, null, null);
  459. grdTaskList.DataSource = taskList;
  460. grdTaskList.Columns["task_id"].HeaderText = "ID";
  461. grdTaskList.Columns["company_short_name"].HeaderText = "公司";
  462. grdTaskList.Columns["task_date"].HeaderText = "日期";
  463. grdTaskList.Columns["task_type_name"].HeaderText = "任务";
  464. grdTaskList.Columns["isvalid_name"].HeaderText = "状态";
  465. grdTaskList.Columns["priority_name"].HeaderText = "优先级";
  466. grdTaskList.Columns["follow_up_date"].HeaderText = "跟进日";
  467. grdTaskList.Columns["company_asset_size_name"].HeaderText = "规模";
  468. grdTaskList.Columns["creator_name"].HeaderText = "创建";
  469. grdTaskList.Columns["updater_name"].HeaderText = "更新";
  470. grdTaskList.Columns["updatetime"].HeaderText = "更新时间";
  471. grdTaskList.Columns["company_id"].Visible = false;
  472. grdTaskList.Columns["task_type"].Visible = false;
  473. grdTaskList.Columns["isvalid"].Visible = false;
  474. grdTaskList.Columns["priority"].Visible = false;
  475. grdTaskList.Columns["company_asset_size"].Visible = false;
  476. grdTaskList.Columns["creatorid"].Visible = false;
  477. grdTaskList.Columns["createtime"].Visible = false;
  478. grdTaskList.Columns["updaterid"].Visible = false;
  479. grdTaskList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  480. }
  481. else
  482. {
  483. taskList = DataAccess.Get_dm_collection_task(null, null, CompanyId, null, null, null, null, null, null);
  484. grdTaskList.DataSource = taskList;
  485. grdTaskList.Columns["task_id"].HeaderText = "ID";
  486. grdTaskList.Columns["provider_name"].HeaderText = "来源";
  487. grdTaskList.Columns["task_date"].HeaderText = "日期";
  488. grdTaskList.Columns["task_type_name"].HeaderText = "任务";
  489. grdTaskList.Columns["entity_name"].HeaderText = "主题";
  490. grdTaskList.Columns["err_message"].HeaderText = "详情";
  491. grdTaskList.Columns["isvalid_name"].HeaderText = "状态";
  492. grdTaskList.Columns["creator_name"].HeaderText = "创建";
  493. grdTaskList.Columns["updater_name"].HeaderText = "更新";
  494. grdTaskList.Columns["updatetime"].HeaderText = "更新时间";
  495. grdTaskList.Columns["provider_id"].Visible = false;
  496. grdTaskList.Columns["task_type"].Visible = false;
  497. grdTaskList.Columns["entity_id"].Visible = false;
  498. grdTaskList.Columns["isvalid"].Visible = false;
  499. grdTaskList.Columns["creatorid"].Visible = false;
  500. grdTaskList.Columns["createtime"].Visible = false;
  501. grdTaskList.Columns["updaterid"].Visible = false;
  502. grdTaskList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  503. }
  504. }
  505. private void btnAddtTask_Click(object sender, EventArgs e)
  506. {
  507. UIConstants.JobType jobType = (UIConstants.JobType)Enum.Parse(typeof(UIConstants.JobType), cmbTaskType.SelectedItem.ToString());
  508. if (jobType == UIConstants.JobType.联络)
  509. {
  510. frmContactTask ctk = new frmContactTask(UserId, CompanyId, companyInfo.Rows[0]["company_short_name"].ToString());
  511. ctk.ShowDialog();
  512. // 刷新 grid 数据
  513. if (ctk.DialogResult == DialogResult.OK)
  514. {
  515. LoadTaskList(jobType);
  516. }
  517. }
  518. else
  519. {
  520. UICollectionTask ctk = new UICollectionTask(UserId, CompanyId, companyInfo.Rows[0]["company_short_name"].ToString());
  521. ctk.ShowDialog();
  522. // 刷新 grid 数据
  523. if (ctk.DialogResult == DialogResult.OK)
  524. {
  525. LoadTaskList(jobType);
  526. }
  527. }
  528. }
  529. private void cmbTaskType_SelectedIndexChanged(object sender, EventArgs e)
  530. {
  531. if (cmbTaskType.Focus())
  532. {
  533. UIConstants.JobType jobType = (UIConstants.JobType)Enum.Parse(typeof(UIConstants.JobType), cmbTaskType.SelectedItem.ToString());
  534. LoadTaskList(jobType);
  535. }
  536. }
  537. #endregion
  538. private void grdTaskList_CellClick(object sender, DataGridViewCellEventArgs e)
  539. {
  540. int rowIndex = e.RowIndex;
  541. int columnIndex = e.ColumnIndex;
  542. if (columnIndex < 0 || rowIndex < 0) return;
  543. DataRow row = taskList.Rows[rowIndex];
  544. UIConstants.JobType jobType = (UIConstants.JobType)Enum.Parse(typeof(UIConstants.JobType), cmbTaskType.SelectedItem.ToString());
  545. if (jobType == UIConstants.JobType.联络)
  546. {
  547. ContactTask task = new ContactTask(UserId, row.Field<int>("task_id"), row.Field<string>("company_id"), row.Field<string>("company_short_name"),
  548. row.Field<DateTime>("task_date"), row.Field<short>("task_type"), row.Field<sbyte>("isvalid"), row.Field<sbyte>("priority"),
  549. row.Field<DateTime?>("follow_up_date"), row.Field<sbyte?>("company_asset_size"),
  550. row.Field<int?>("creatorid"), row.Field<string>("creator_name"), row.Field<DateTime?>("createtime"),
  551. row.Field<int?>("updaterid"), row.Field<string>("updater_name"), row.Field<DateTime?>("updatetime"));
  552. if (task != null)
  553. {
  554. frmContactTask ctk = new frmContactTask(task);
  555. ctk.ShowDialog();
  556. // 刷新 grid 数据
  557. if (ctk.DialogResult == DialogResult.OK)
  558. {
  559. LoadTaskList(jobType);
  560. }
  561. }
  562. }
  563. else
  564. {
  565. CollectionTask task = new CollectionTask(UserId, row.Field<int>("task_id"), row.Field<string>("provider_id"), row.Field<string>("provider_name"),
  566. row.Field<DateTime>("task_date"), row.Field<short>("task_type"),
  567. row.Field<string>("entity_id"), row.Field<string>("entity_name"),
  568. row.Field<string>("err_message"), row.Field<sbyte>("isvalid"),
  569. row.Field<int?>("creatorid"), row.Field<string>("creator_name"), row.Field<DateTime?>("createtime"),
  570. row.Field<int?>("updaterid"), row.Field<string>("updater_name"), row.Field<DateTime?>("updatetime"));
  571. if (task != null)
  572. {
  573. UICollectionTask ctk = new UICollectionTask(task);
  574. ctk.ShowDialog();
  575. // 刷新 grid 数据
  576. if (ctk.DialogResult == DialogResult.OK)
  577. {
  578. LoadTaskList(jobType);
  579. }
  580. }
  581. }
  582. }
  583. }
  584. public class CompanyCoverUser
  585. {
  586. public string CompanyId { get; set; }
  587. public sbyte CoverType { get; set; }
  588. public Coverage[] Coverages { get; set; }
  589. public class Coverage
  590. {
  591. public sbyte IsValid { get; set; }
  592. public int UserId { get; set; }
  593. }
  594. }
  595. public class CircleDeleteControl : Control
  596. {
  597. protected override void OnPaint(PaintEventArgs e)
  598. {
  599. //this.BackColor = Color.White;
  600. base.OnPaint(e);
  601. Graphics g = e.Graphics;
  602. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
  603. Point center = new Point(this.Width/2, this.Height/2);
  604. // 圆形删除符号的直径可以是控件的最小边长
  605. int diameter = Math.Min(this.Width, this.Height);
  606. // 圆形删除符号的内半径
  607. int innerRadius = diameter / 2;
  608. using (Pen deletePen = new Pen(Color.Red, 1))
  609. {
  610. // 绘制圆形删除符号的背景
  611. g.DrawEllipse(deletePen, center.X - innerRadius, center.Y - innerRadius, diameter, diameter);
  612. // 绘制两条相交的对角线
  613. int offset = (int)Math.Floor(innerRadius / 1.4);
  614. g.DrawLine(deletePen, center.X - innerRadius - offset, center.Y + innerRadius + offset, center.X + innerRadius + offset, center.Y - innerRadius - offset);
  615. g.DrawLine(deletePen, center.X - innerRadius - offset, center.Y - innerRadius - offset, center.X + innerRadius + offset, center.Y + innerRadius + offset);
  616. }
  617. }
  618. protected override void OnMouseEnter(EventArgs e)
  619. {
  620. base.OnMouseEnter(e);
  621. this.Cursor = Cursors.Hand;
  622. }
  623. protected override void OnMouseLeave(EventArgs e)
  624. {
  625. base.OnMouseLeave(e);
  626. this.Cursor = Cursors.Arrow;
  627. }
  628. }
  629. }