UICompany.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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. private void pctFundExport_Click(object sender, EventArgs e)
  272. {
  273. frmDataManager.ExportDataTable(fundList);
  274. }
  275. #endregion
  276. #region Contract
  277. private void btnSaveContactor_Click(object sender, EventArgs e)
  278. {
  279. List<CompanyCoverUser> coverage = new List<CompanyCoverUser>();
  280. List<DataRowView> new_selected_contactor = new List<DataRowView>();
  281. foreach(DataRowView item in clbContactor.CheckedItems)
  282. new_selected_contactor.Add(item);
  283. CompanyCoverUser cov1 = CompareCoverage(CompanyId, 1, old_selected_contactor, new_selected_contactor);
  284. if(cov1 != null )
  285. coverage.Add(cov1);
  286. List<DataRowView> new_selected_collector = new List<DataRowView>();
  287. foreach (DataRowView item in clbCollector.CheckedItems)
  288. new_selected_collector.Add(item);
  289. CompanyCoverUser cov2 = CompareCoverage(CompanyId, 2, old_selected_collector, new_selected_collector);
  290. if(cov2 != null )
  291. coverage.Add(cov2);
  292. string query = JsonSerializer.Serialize(coverage);
  293. int ret = DataAccess.Set_dm_company_cover(query, UserId);
  294. int ret2 = DataAccess.Set_dm_company_authorization(CompanyId, chkIsAuthorized.Checked ? 1 : 0, UserId);
  295. string message = (ret * ret2) < 0 ? "Oops... 变更存数据库时出了错" : "数据变更已经成功存盘~";
  296. MessageBox.Show(message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  297. }
  298. /// <summary>
  299. /// 前后人员覆盖对比
  300. /// </summary>
  301. /// <param name="companyId"></param>
  302. /// <param name="coverType"></param>
  303. /// <param name="oldList"></param>
  304. /// <param name="newList"></param>
  305. /// <returns></returns>
  306. private CompanyCoverUser CompareCoverage(string companyId, sbyte coverType, List<DataRowView> oldList, List<DataRowView> newList)
  307. {
  308. CompanyCoverUser companyCoverUser = new CompanyCoverUser();
  309. companyCoverUser.CompanyId = companyId;
  310. companyCoverUser.CoverType = coverType;
  311. if (oldList == null || newList == null) return companyCoverUser;
  312. // 在旧名单里,但不在新名单里的要删掉
  313. List<DataRowView> itemDeleted = oldList.Except(newList).ToList();
  314. // 在新名单里,但不在旧名单里的要增加
  315. List<DataRowView> itemAdded = newList.Except(oldList).ToList();
  316. int i = 0;
  317. CompanyCoverUser.Coverage[] covers = null;
  318. if (itemDeleted.Count > 0 || itemAdded.Count > 0)
  319. covers = new CompanyCoverUser.Coverage[itemDeleted.Count+itemAdded.Count];
  320. foreach (DataRowView item in itemDeleted)
  321. {
  322. CompanyCoverUser.Coverage cov = new CompanyCoverUser.Coverage();
  323. cov.IsValid = 0;
  324. cov.UserId = int.Parse(item.Row["userid"].ToString());
  325. covers[i] = cov;
  326. i++;
  327. }
  328. foreach (DataRowView item in itemAdded)
  329. {
  330. CompanyCoverUser.Coverage cov = new CompanyCoverUser.Coverage();
  331. cov.IsValid = 1;
  332. cov.UserId = int.Parse(item.Row["userid"].ToString());
  333. covers[i] = cov;
  334. i++;
  335. }
  336. companyCoverUser.Coverages = covers;
  337. //ret = JsonSerializer.Serialize(companyCoverUser);
  338. return companyCoverUser;
  339. }
  340. private void btnAuthorizeFunds_Click(object sender, EventArgs e)
  341. {
  342. UIBuckAuthorizeFund frm = new UIBuckAuthorizeFund(UserId);
  343. frm.Show();
  344. }
  345. /// <summary>
  346. /// 上传文件 TODO: 文件先写到本地
  347. /// </summary>
  348. /// <param name="sender"></param>
  349. /// <param name="e"></param>
  350. private void btnUploadFile_Click(object sender, EventArgs e)
  351. {
  352. ofdUploadFile.Title = "文件上传 ... 还没做完呢";
  353. //ofdUploadFile.DefaultExt = "doc";
  354. //ofdUploadFile.Filter = "所有Word文件(*.doc)|所有pdf文件(*.pdf)|所有文件(*.*)|*.*";
  355. if(ofdUploadFile.ShowDialog() == DialogResult.OK)
  356. {
  357. // TODO: upload files to server. let's fake it for now
  358. string filePath = ofdUploadFile.FileName;
  359. string fileName = Path.GetFileName(filePath);
  360. string saveFileName = this.saveFilePath + fileName;
  361. try
  362. {
  363. if (!Directory.Exists(saveFilePath)) { Directory.CreateDirectory(saveFilePath); }
  364. File.Copy(filePath, saveFileName, true);
  365. CreateFileButton(Path.GetFileName(saveFileName));
  366. }
  367. catch (Exception ex)
  368. {
  369. MessageBox.Show("文件上传失败:" + ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
  370. }
  371. }
  372. }
  373. /// <summary>
  374. /// 显示已上传文件,每个文件一个按钮
  375. /// </summary>
  376. private void LoadContractFiles()
  377. {
  378. if (Directory.Exists(this.saveFilePath))
  379. {
  380. string[] fileNames = Directory.GetFiles(saveFilePath);
  381. if(fileNames.Length > 0)
  382. {
  383. foreach (string fileName in fileNames)
  384. {
  385. CreateFileButton(Path.GetFileName(fileName));
  386. }
  387. }
  388. }
  389. }
  390. /// <summary>
  391. /// 为每个上传的文件产生一个按钮来显示
  392. /// </summary>
  393. /// <param name="fileName"></param>
  394. private void CreateFileButton(string fileName)
  395. {
  396. Panel panFile = new Panel();
  397. panFile.BorderStyle = BorderStyle.FixedSingle;
  398. panFile.Size = btnUploadFile.Size;
  399. panFile.Text = fileName;
  400. panFile.Font = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
  401. panFile.Click += PanFile_Click;
  402. panFile.MouseEnter += PanFile_Enter;
  403. panFile.MouseLeave += PanFile_MouseLeave;
  404. Label lblFileName = new Label();
  405. lblFileName.Text = fileName;
  406. lblFileName.ForeColor = Color.DodgerBlue;
  407. lblFileName.Size = new Size(panFile.Width, panFile.Height/2);
  408. lblFileName.Location = new Point(panFile.Location.X, panFile.Location.Y + panFile.Size.Height/2);
  409. lblFileName.TextAlign = ContentAlignment.MiddleCenter;
  410. lblFileName.Click += LblFileName_Click;
  411. panFile.Controls.Add(lblFileName);
  412. CircleDeleteControl delIcon = new CircleDeleteControl();
  413. delIcon.Size = new Size(panFile.Width/8, panFile.Height/8);
  414. delIcon.Location = new Point(panFile.Width * 3/4, panFile.Width * 1/8);
  415. delIcon.Visible = true;
  416. delIcon.Click += DelIcon_Click;
  417. panFile.Controls.Add(delIcon);
  418. flowLayoutPanel1.Controls.Add(panFile);
  419. }
  420. private void LblFileName_Click(object sender, EventArgs e)
  421. {
  422. Control pan = ((Control)sender).Parent;
  423. PanFile_Click(pan, e);
  424. }
  425. private void PanFile_Click(object sender, EventArgs e)
  426. {
  427. OpenFile(saveFilePath + ((Panel)sender).Text);
  428. }
  429. private void PanFile_Enter(object sender, EventArgs e)
  430. {
  431. ((Control)sender).BackColor = Color.LightGray;
  432. }
  433. private void PanFile_MouseLeave(object sender, EventArgs e)
  434. {
  435. ((Control)sender).BackColor = Color.White;
  436. }
  437. private void DelIcon_Click(object sender, EventArgs e)
  438. {
  439. DialogResult result = MessageBox.Show("确认要删除此文件么?", "删除文件确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  440. if (result == DialogResult.Yes)
  441. {
  442. Panel pan = (Panel)((Control)sender).Parent;
  443. File.Delete(saveFilePath + pan.Text);
  444. pan.Parent.Controls.Remove(pan);
  445. }
  446. }
  447. private void OpenFile(string fileName)
  448. {
  449. ProcessStartInfo startInfo = new ProcessStartInfo
  450. {
  451. FileName = fileName,
  452. UseShellExecute = true
  453. };
  454. Process.Start(startInfo);
  455. }
  456. #endregion
  457. #region Task List
  458. private void LoadTaskList(UIConstants.JobType jobType)
  459. {
  460. if (jobType == UIConstants.JobType.联络)
  461. {
  462. taskList = DataAccess.Get_dm_contact_task(null, null, CompanyId, null, null, null, null, null, null, null);
  463. grdTaskList.DataSource = taskList;
  464. grdTaskList.Columns["task_id"].HeaderText = "ID";
  465. grdTaskList.Columns["company_short_name"].HeaderText = "公司";
  466. grdTaskList.Columns["task_date"].HeaderText = "日期";
  467. grdTaskList.Columns["task_type_name"].HeaderText = "任务";
  468. grdTaskList.Columns["isvalid_name"].HeaderText = "状态";
  469. grdTaskList.Columns["priority_name"].HeaderText = "优先级";
  470. grdTaskList.Columns["follow_up_date"].HeaderText = "跟进日";
  471. grdTaskList.Columns["company_asset_size_name"].HeaderText = "规模";
  472. grdTaskList.Columns["creator_name"].HeaderText = "创建";
  473. grdTaskList.Columns["updater_name"].HeaderText = "更新";
  474. grdTaskList.Columns["updatetime"].HeaderText = "更新时间";
  475. grdTaskList.Columns["company_id"].Visible = false;
  476. grdTaskList.Columns["task_type"].Visible = false;
  477. grdTaskList.Columns["isvalid"].Visible = false;
  478. grdTaskList.Columns["priority"].Visible = false;
  479. grdTaskList.Columns["company_asset_size"].Visible = false;
  480. grdTaskList.Columns["creatorid"].Visible = false;
  481. grdTaskList.Columns["createtime"].Visible = false;
  482. grdTaskList.Columns["updaterid"].Visible = false;
  483. grdTaskList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  484. }
  485. else
  486. {
  487. taskList = DataAccess.Get_dm_collection_task(null, null, CompanyId, null, null, null, null, null, null);
  488. grdTaskList.DataSource = taskList;
  489. grdTaskList.Columns["task_id"].HeaderText = "ID";
  490. grdTaskList.Columns["provider_name"].HeaderText = "来源";
  491. grdTaskList.Columns["task_date"].HeaderText = "日期";
  492. grdTaskList.Columns["task_type_name"].HeaderText = "任务";
  493. grdTaskList.Columns["entity_name"].HeaderText = "主题";
  494. grdTaskList.Columns["err_message"].HeaderText = "详情";
  495. grdTaskList.Columns["isvalid_name"].HeaderText = "状态";
  496. grdTaskList.Columns["creator_name"].HeaderText = "创建";
  497. grdTaskList.Columns["updater_name"].HeaderText = "更新";
  498. grdTaskList.Columns["updatetime"].HeaderText = "更新时间";
  499. grdTaskList.Columns["provider_id"].Visible = false;
  500. grdTaskList.Columns["task_type"].Visible = false;
  501. grdTaskList.Columns["entity_id"].Visible = false;
  502. grdTaskList.Columns["isvalid"].Visible = false;
  503. grdTaskList.Columns["creatorid"].Visible = false;
  504. grdTaskList.Columns["createtime"].Visible = false;
  505. grdTaskList.Columns["updaterid"].Visible = false;
  506. grdTaskList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  507. }
  508. }
  509. private void btnAddtTask_Click(object sender, EventArgs e)
  510. {
  511. UIConstants.JobType jobType = (UIConstants.JobType)Enum.Parse(typeof(UIConstants.JobType), cmbTaskType.SelectedItem.ToString());
  512. if (jobType == UIConstants.JobType.联络)
  513. {
  514. frmContactTask ctk = new frmContactTask(UserId, CompanyId, companyInfo.Rows[0]["company_short_name"].ToString());
  515. ctk.ShowDialog();
  516. // 刷新 grid 数据
  517. if (ctk.DialogResult == DialogResult.OK)
  518. {
  519. LoadTaskList(jobType);
  520. }
  521. }
  522. else
  523. {
  524. UICollectionTask ctk = new UICollectionTask(UserId, CompanyId, companyInfo.Rows[0]["company_short_name"].ToString());
  525. ctk.ShowDialog();
  526. // 刷新 grid 数据
  527. if (ctk.DialogResult == DialogResult.OK)
  528. {
  529. LoadTaskList(jobType);
  530. }
  531. }
  532. }
  533. private void cmbTaskType_SelectedIndexChanged(object sender, EventArgs e)
  534. {
  535. if (cmbTaskType.Focus())
  536. {
  537. UIConstants.JobType jobType = (UIConstants.JobType)Enum.Parse(typeof(UIConstants.JobType), cmbTaskType.SelectedItem.ToString());
  538. LoadTaskList(jobType);
  539. }
  540. }
  541. private void grdTaskList_CellClick(object sender, DataGridViewCellEventArgs e)
  542. {
  543. int rowIndex = e.RowIndex;
  544. int columnIndex = e.ColumnIndex;
  545. if (columnIndex < 0 || rowIndex < 0) return;
  546. DataRow row = taskList.Rows[rowIndex];
  547. UIConstants.JobType jobType = (UIConstants.JobType)Enum.Parse(typeof(UIConstants.JobType), cmbTaskType.SelectedItem.ToString());
  548. if (jobType == UIConstants.JobType.联络)
  549. {
  550. ContactTask task = new ContactTask(UserId, row.Field<int>("task_id"), row.Field<string>("company_id"), row.Field<string>("company_short_name"),
  551. row.Field<DateTime>("task_date"), row.Field<short>("task_type"), row.Field<sbyte>("isvalid"), row.Field<sbyte>("priority"),
  552. row.Field<DateTime?>("follow_up_date"), row.Field<sbyte?>("company_asset_size"),
  553. row.Field<int?>("creatorid"), row.Field<string>("creator_name"), row.Field<DateTime?>("createtime"),
  554. row.Field<int?>("updaterid"), row.Field<string>("updater_name"), row.Field<DateTime?>("updatetime"));
  555. if (task != null)
  556. {
  557. frmContactTask ctk = new frmContactTask(task);
  558. ctk.ShowDialog();
  559. // 刷新 grid 数据
  560. if (ctk.DialogResult == DialogResult.OK)
  561. {
  562. LoadTaskList(jobType);
  563. }
  564. }
  565. }
  566. else
  567. {
  568. CollectionTask task = new CollectionTask(UserId, row.Field<int>("task_id"), row.Field<string>("provider_id"), row.Field<string>("provider_name"),
  569. row.Field<DateTime>("task_date"), row.Field<short>("task_type"),
  570. row.Field<string>("entity_id"), row.Field<string>("entity_name"),
  571. row.Field<string>("err_message"), row.Field<sbyte>("isvalid"),
  572. row.Field<int?>("creatorid"), row.Field<string>("creator_name"), row.Field<DateTime?>("createtime"),
  573. row.Field<int?>("updaterid"), row.Field<string>("updater_name"), row.Field<DateTime?>("updatetime"));
  574. if (task != null)
  575. {
  576. UICollectionTask ctk = new UICollectionTask(task);
  577. ctk.ShowDialog();
  578. // 刷新 grid 数据
  579. if (ctk.DialogResult == DialogResult.OK)
  580. {
  581. LoadTaskList(jobType);
  582. }
  583. }
  584. }
  585. }
  586. #endregion
  587. }
  588. public class CompanyCoverUser
  589. {
  590. public string CompanyId { get; set; }
  591. public sbyte CoverType { get; set; }
  592. public Coverage[] Coverages { get; set; }
  593. public class Coverage
  594. {
  595. public sbyte IsValid { get; set; }
  596. public int UserId { get; set; }
  597. }
  598. }
  599. public class CircleDeleteControl : Control
  600. {
  601. protected override void OnPaint(PaintEventArgs e)
  602. {
  603. //this.BackColor = Color.White;
  604. base.OnPaint(e);
  605. Graphics g = e.Graphics;
  606. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
  607. Point center = new Point(this.Width/2, this.Height/2);
  608. // 圆形删除符号的直径可以是控件的最小边长
  609. int diameter = Math.Min(this.Width, this.Height);
  610. // 圆形删除符号的内半径
  611. int innerRadius = diameter / 2;
  612. using (Pen deletePen = new Pen(Color.Red, 1))
  613. {
  614. // 绘制圆形删除符号的背景
  615. g.DrawEllipse(deletePen, center.X - innerRadius, center.Y - innerRadius, diameter, diameter);
  616. // 绘制两条相交的对角线
  617. int offset = (int)Math.Floor(innerRadius / 1.4);
  618. g.DrawLine(deletePen, center.X - innerRadius - offset, center.Y + innerRadius + offset, center.X + innerRadius + offset, center.Y - innerRadius - offset);
  619. g.DrawLine(deletePen, center.X - innerRadius - offset, center.Y - innerRadius - offset, center.X + innerRadius + offset, center.Y + innerRadius + offset);
  620. }
  621. }
  622. protected override void OnMouseEnter(EventArgs e)
  623. {
  624. base.OnMouseEnter(e);
  625. this.Cursor = Cursors.Hand;
  626. }
  627. protected override void OnMouseLeave(EventArgs e)
  628. {
  629. base.OnMouseLeave(e);
  630. this.Cursor = Cursors.Arrow;
  631. }
  632. }
  633. }