UICompany.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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. namespace DataManager
  19. {
  20. public partial class UICompany : Form
  21. {
  22. private string companyId;
  23. private int userId;
  24. private DataTable companyInfo;
  25. private DataTable fundList;
  26. private DataTable contactList;
  27. private List<DataRowView> old_selected_contactor = new List<DataRowView>();
  28. private List<DataRowView> old_selected_collector = new List<DataRowView>();
  29. private string saveFilePath;
  30. public UICompany(string companyId, int userId)
  31. {
  32. this.companyId = companyId.Trim().ToUpper();
  33. this.userId = userId;
  34. this.saveFilePath = ".\\Contracts\\" + companyId + "\\";
  35. InitializeComponent();
  36. InitializedData();
  37. }
  38. public string CompanyId { get { return companyId; } }
  39. public int UserId { get { return userId; } }
  40. private void InitializedData()
  41. {
  42. #region Basic Info Tab
  43. companyInfo = DataAccess.Get_dm_company_information(CompanyId);
  44. if(companyInfo == null || companyInfo.Rows.Count == 0 ) { return; }
  45. txtCompanyName.Text = companyInfo.Rows[0]["company_name"].ToString();
  46. txtRegisterCode.Text = companyInfo.Rows[0]["register_number"].ToString();
  47. txtCompanyId.Text = companyInfo.Rows[0]["company_id"].ToString();
  48. txtIncoporationDate.Text = DateTime.Parse(companyInfo.Rows[0]["establish_date"].ToString()).ToShortDateString();
  49. txtRegisterAddress.Text = companyInfo.Rows[0]["register_number_address"].ToString();
  50. txtOrgCode.Text = companyInfo.Rows[0]["credit_code"].ToString();
  51. txtBusinessAddress.Text = companyInfo.Rows[0]["company_address"].ToString();
  52. if (companyInfo.Rows[0]["nature_business_type"].ToString() != "")
  53. txtOrgType.Text = UIConstants.CompanyOwnerType[int.Parse(companyInfo.Rows[0]["nature_business_type"].ToString())];
  54. else
  55. txtOrgType.Text = "未知";
  56. if (companyInfo.Rows[0]["company_type"].ToString() != "")
  57. txtCompanyType.Text = UIConstants.CompanyType[int.Parse(companyInfo.Rows[0]["company_type"].ToString())];
  58. else
  59. txtCompanyType.Text = "未知";
  60. txtBusinessType.Text = companyInfo.Rows[0]["business_type"].ToString();
  61. if (companyInfo.Rows[0]["company_asset_size"].ToString() != "")
  62. txtAssetSize.Text = UIConstants.CompanyAssetSize[int.Parse(companyInfo.Rows[0]["company_asset_size"].ToString())];
  63. else
  64. txtAssetSize.Text = "未知";
  65. txtIsQualifiedAdvisor.Text = companyInfo.Rows[0]["has_consulting_qualification"].ToString() == "1" ? "是" : "否";
  66. //txtOwner.Text = companyInfo.Rows[0]["establish_date"].ToString();
  67. //txtAmacUpdateDate.Text = companyInfo.Rows[0]["zjx_last_info_update_time"].ToString();
  68. //lklAmacURL.Links.Add(Link )companyInfo.Rows[0]["amac_link"].ToString();
  69. txtCompanyShortName.Text = companyInfo.Rows[0]["company_short_name"].ToString();
  70. #endregion
  71. LoadContactsGrid();
  72. #region Fund List Tab
  73. Dictionary<int, string> d = new Dictionary<int, string>(UIConstants.HedgeFundStrategy);
  74. d.Add(DataAccess.DM_NULL, "全部");
  75. BindingSource bs = new BindingSource();
  76. bs.DataSource = d;
  77. cmbStrategy.DataSource = bs;
  78. cmbStrategy.DisplayMember = "Value";
  79. cmbStrategy.ValueMember = "Key";
  80. cmbStrategy.SelectedValue = (int)DataAccess.DM_NULL;
  81. LoadFundGrid();
  82. #endregion
  83. #region Contracts Tab
  84. sbyte jobType = Convert.ToSByte(UIConstants.JobType.Contact);
  85. DataTable dt_dm_user_1 = DataAccess.Get_dm_user(null, jobType);
  86. clbContactor.DataSource = dt_dm_user_1;
  87. clbContactor.DisplayMember = "username";
  88. clbContactor.ValueMember = "userid";
  89. // 给覆盖此公司的user打上勾
  90. DataTable dt_company_cover_1 = DataAccess.Get_dm_company_cover(CompanyId, jobType, null);
  91. for(int i = 0; i < clbContactor.Items.Count; i++)
  92. {
  93. string itemUserId = ((DataRowView)clbContactor.Items[i]).Row["userid"].ToString();
  94. if (dt_company_cover_1.Select("userid = " + itemUserId).Length > 0)
  95. clbContactor.SetItemChecked(i, true);
  96. }
  97. // 记录一下初始的勾选
  98. foreach(DataRowView item in clbContactor.CheckedItems)
  99. {
  100. old_selected_contactor.Add(item);
  101. }
  102. jobType = Convert.ToSByte(UIConstants.JobType.Collection);
  103. DataTable dt_dm_user_2 = DataAccess.Get_dm_user(null, jobType);
  104. clbCollector.DataSource = dt_dm_user_2;
  105. clbCollector.DisplayMember = "username";
  106. clbCollector.ValueMember = "userid";
  107. // 给覆盖此公司的user打上勾
  108. DataTable dt_company_cover_2 = DataAccess.Get_dm_company_cover(CompanyId, jobType, null);
  109. for (int i = 0; i < clbCollector.Items.Count; i++)
  110. {
  111. string itemUserId = ((DataRowView)clbCollector.Items[i]).Row["userid"].ToString();
  112. if (dt_company_cover_2.Select("userid = " + itemUserId).Length > 0)
  113. clbCollector.SetItemChecked(i, true);
  114. }
  115. // 记录一下初始的勾选
  116. foreach(DataRowView item in clbCollector.CheckedItems)
  117. {
  118. old_selected_collector.Add(item);
  119. }
  120. LoadContractFiles();
  121. #endregion
  122. }
  123. #region Basic Info
  124. private void btnSaveBasicInfo_Click(object sender, EventArgs e)
  125. {
  126. MessageBox.Show("暂时不支持存数据");
  127. }
  128. #endregion
  129. #region Contact List
  130. private void LoadContactsGrid()
  131. {
  132. contactList = DataAccess.Get_dm_contacts(CompanyId);
  133. grdContacts.DataSource = contactList;
  134. grdContacts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  135. grdContacts.Columns["id"].Visible = false;
  136. grdContacts.Columns["company_id"].Visible = false;
  137. grdContacts.Columns["name"].HeaderText = "姓名";
  138. grdContacts.Columns["role"].HeaderText = "职务";
  139. grdContacts.Columns["phone"].HeaderText = "电话";
  140. grdContacts.Columns["wechat"].HeaderText = "微信";
  141. grdContacts.Columns["email"].HeaderText = "邮箱";
  142. grdContacts.Columns["isvalid"].Visible = false;
  143. grdContacts.Columns["creatorid"].Visible = false;
  144. grdContacts.Columns["createtime"].Visible = false;
  145. grdContacts.Columns["updaterid"].Visible = false;
  146. grdContacts.Columns["updatetime"].Visible = false;
  147. lblContactsCount.Text = contactList.Rows.Count.ToString();
  148. }
  149. private void btnSaveContact_Click(object sender, EventArgs e)
  150. {
  151. if(contactList == null ) return;
  152. int updatedCnt = DataAccess.Set_dm_contacts(contactList, CompanyId, UserId);
  153. contactList.AcceptChanges();
  154. MessageBox.Show("成功更新了" + updatedCnt.ToString() + "个联系人");
  155. }
  156. #endregion
  157. #region Fund List
  158. private void LoadFundGrid()
  159. {
  160. fundList = DataAccess.Get_dm_fund_information(null, CompanyId);
  161. BindingSource bs = new BindingSource();
  162. bs.DataSource = fundList;
  163. grdFund.DataSource = bs;
  164. grdFund.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  165. grdFund.Columns["fund_id"].Visible = false;
  166. grdFund.Columns["raise_type"].Visible = false;
  167. grdFund.Columns["fund_name"].Visible = false;
  168. grdFund.Columns["fund_short_name"].HeaderText = "基金简称";
  169. grdFund.Columns["fund_structure"].Visible = false;
  170. grdFund.Columns["fund_type"].Visible = false;
  171. grdFund.Columns["strategy"].Visible = false;
  172. grdFund.Columns["substrategy"].Visible = false;
  173. grdFund.Columns["fund_status"].Visible = false;
  174. grdFund.Columns["base_currency"].Visible = false;
  175. grdFund.Columns["inception_date"].HeaderText = "成立日";
  176. grdFund.Columns["initial_unit_value"].Visible = false;
  177. grdFund.Columns["p_fund_id"].Visible = false;
  178. grdFund.Columns["p_fund_name"].Visible = false;
  179. grdFund.Columns["advisor_id"].Visible = false;
  180. grdFund.Columns["company_name"].Visible = false;
  181. grdFund.Columns["custodian_id"].Visible = false;
  182. grdFund.Columns["custodian_name"].HeaderText = "托管";
  183. grdFund.Columns["trust_id"].Visible = false;
  184. grdFund.Columns["nav_frequency"].HeaderText = "净值频率";
  185. grdFund.Columns["manager_type"].Visible = false;
  186. grdFund.Columns["zjx_last_info_update_time"].Visible = false;
  187. grdFund.Columns["amac_url"].Visible = false;
  188. grdFund.Columns["register_number"].HeaderText = "备案编码";
  189. grdFund.Columns["register_date"].Visible = false;
  190. grdFund.Columns["main_code"].Visible = false;
  191. grdFund.Columns["isVisible"].Visible = false;
  192. grdFund.Columns["is_ranking"].HeaderText = "是否排名";
  193. grdFund.Columns["is_rating"].HeaderText = "是否评级";
  194. grdFund.Columns["is_authorized"].HeaderText = "是否授权";
  195. grdFund.Columns["trust_register_number"].Visible = false;
  196. grdFund.Columns["isvalid"].Visible = false;
  197. grdFund.Columns["creatorid"].Visible = false;
  198. grdFund.Columns["createtime"].Visible = false;
  199. grdFund.Columns["updaterid"].Visible = false;
  200. grdFund.Columns["updatetime"].Visible = false;
  201. grdFund.Columns["fund_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
  202. SetStatusStrip(fundList.Rows.Count);
  203. }
  204. private void grdFund_CellContentClick(object sender, DataGridViewCellEventArgs e)
  205. {
  206. int rowIndex = e.RowIndex;
  207. int columnIndex = e.ColumnIndex;
  208. if (columnIndex < 0 || rowIndex < 0) return;
  209. DataGridViewRow row = grdFund.Rows[rowIndex];
  210. string fundId = row.Cells["fund_id"].Value.ToString();
  211. UIFund frm = new UIFund(fundId);
  212. frm.ShowDialog();
  213. }
  214. private void cmbStrategy_SelectedIndexChanged(object sender, EventArgs e)
  215. {
  216. FilterFund();
  217. }
  218. private void dtpInceptionDate_ValueChanged(object sender, EventArgs e)
  219. {
  220. FilterFund();
  221. }
  222. private void FilterFund()
  223. {
  224. string strategy = cmbStrategy.SelectedValue.ToString();
  225. string inception = dtpInceptionDate.Value.ToString();
  226. string filter = null;
  227. int cnt = 0;
  228. if (strategy == DataAccess.DM_NULL.ToString())
  229. filter = string.Format("inception_date <= #{0}#", inception);
  230. else
  231. filter = string.Format("strategy = {0} and inception_date <= #{1}#", strategy, inception);
  232. if (fundList != null && fundList.Rows.Count > 0)
  233. {
  234. BindingSource bs = (BindingSource)grdFund.DataSource;
  235. bs.Filter = filter;
  236. cnt = bs.Count;
  237. }
  238. SetStatusStrip(cnt);
  239. }
  240. private void SetStatusStrip(int cnt)
  241. {
  242. ToolStripStatusLabel label = new ToolStripStatusLabel();
  243. label.Text = "记录条数:" + cnt.ToString();
  244. sstCompany.Items.Clear();
  245. sstCompany.Items.Add(label);
  246. }
  247. #endregion
  248. #region Contract
  249. private void btnSaveContactor_Click(object sender, EventArgs e)
  250. {
  251. List<CompanyCoverUser> coverage = new List<CompanyCoverUser>();
  252. List<DataRowView> new_selected_contactor = new List<DataRowView>();
  253. foreach(DataRowView item in clbContactor.CheckedItems)
  254. new_selected_contactor.Add(item);
  255. CompanyCoverUser cov1 = CompareCoverage(CompanyId, 1, old_selected_contactor, new_selected_contactor);
  256. if(cov1 != null )
  257. coverage.Add(cov1);
  258. List<DataRowView> new_selected_collector = new List<DataRowView>();
  259. foreach (DataRowView item in clbCollector.CheckedItems)
  260. new_selected_collector.Add(item);
  261. CompanyCoverUser cov2 = CompareCoverage(CompanyId, 2, old_selected_collector, new_selected_collector);
  262. if(cov2 != null )
  263. coverage.Add(cov2);
  264. string query = JsonSerializer.Serialize(coverage);
  265. int ret = DataAccess.Set_dm_company_cover(query, UserId);
  266. string message = ret < 0 ? "Oops... 变更存数据库时出了错" : "人员覆盖变更已经成功存盘~";
  267. MessageBox.Show(message);
  268. }
  269. /// <summary>
  270. /// 前后人员覆盖对比
  271. /// </summary>
  272. /// <param name="companyId"></param>
  273. /// <param name="coverType"></param>
  274. /// <param name="oldList"></param>
  275. /// <param name="newList"></param>
  276. /// <returns></returns>
  277. private CompanyCoverUser CompareCoverage(string companyId, sbyte coverType, List<DataRowView> oldList, List<DataRowView> newList)
  278. {
  279. CompanyCoverUser companyCoverUser = new CompanyCoverUser();
  280. companyCoverUser.CompanyId = companyId;
  281. companyCoverUser.CoverType = coverType;
  282. if (oldList == null || newList == null) return companyCoverUser;
  283. // 在旧名单里,但不在新名单里的要删掉
  284. List<DataRowView> itemDeleted = oldList.Except(newList).ToList();
  285. // 在新名单里,但不在旧名单里的要增加
  286. List<DataRowView> itemAdded = newList.Except(oldList).ToList();
  287. int i = 0;
  288. CompanyCoverUser.Coverage[] covers = null;
  289. if (itemDeleted.Count > 0 || itemAdded.Count > 0)
  290. covers = new CompanyCoverUser.Coverage[itemDeleted.Count+itemAdded.Count];
  291. foreach (DataRowView item in itemDeleted)
  292. {
  293. CompanyCoverUser.Coverage cov = new CompanyCoverUser.Coverage();
  294. cov.IsValid = 0;
  295. cov.UserId = int.Parse(item.Row["userid"].ToString());
  296. covers[i] = cov;
  297. i++;
  298. }
  299. foreach (DataRowView item in itemAdded)
  300. {
  301. CompanyCoverUser.Coverage cov = new CompanyCoverUser.Coverage();
  302. cov.IsValid = 1;
  303. cov.UserId = int.Parse(item.Row["userid"].ToString());
  304. covers[i] = cov;
  305. i++;
  306. }
  307. companyCoverUser.Coverages = covers;
  308. //ret = JsonSerializer.Serialize(companyCoverUser);
  309. return companyCoverUser;
  310. }
  311. /// <summary>
  312. /// 上传文件 TODO: 文件先写到本地
  313. /// </summary>
  314. /// <param name="sender"></param>
  315. /// <param name="e"></param>
  316. private void btnUploadFile_Click(object sender, EventArgs e)
  317. {
  318. ofdUploadFile.Title = "文件上传 ... 还没做完呢";
  319. //ofdUploadFile.DefaultExt = "doc";
  320. //ofdUploadFile.Filter = "所有Word文件(*.doc)|所有pdf文件(*.pdf)|所有文件(*.*)|*.*";
  321. if(ofdUploadFile.ShowDialog() == DialogResult.OK)
  322. {
  323. // TODO: upload files to server. let's fake it for now
  324. string filePath = ofdUploadFile.FileName;
  325. string fileName = Path.GetFileName(filePath);
  326. string saveFileName = this.saveFilePath + fileName;
  327. try
  328. {
  329. if (!Directory.Exists(saveFilePath)) { Directory.CreateDirectory(saveFilePath); }
  330. File.Copy(filePath, saveFileName, true);
  331. CreateFileButton(Path.GetFileName(saveFileName));
  332. }
  333. catch (Exception ex)
  334. {
  335. MessageBox.Show("文件上传失败:" + ex.Message);
  336. }
  337. }
  338. }
  339. /// <summary>
  340. /// 显示已上传文件,每个文件一个按钮
  341. /// </summary>
  342. private void LoadContractFiles()
  343. {
  344. if (Directory.Exists(this.saveFilePath))
  345. {
  346. string[] fileNames = Directory.GetFiles(saveFilePath);
  347. if(fileNames.Length > 0)
  348. {
  349. foreach (string fileName in fileNames)
  350. {
  351. CreateFileButton(Path.GetFileName(fileName));
  352. }
  353. }
  354. }
  355. }
  356. /// <summary>
  357. /// 为每个上传的文件产生一个按钮来显示
  358. /// </summary>
  359. /// <param name="fileName"></param>
  360. private void CreateFileButton(string fileName)
  361. {
  362. Panel panFile = new Panel();
  363. panFile.BorderStyle = BorderStyle.FixedSingle;
  364. panFile.Size = btnUploadFile.Size;
  365. panFile.Text = fileName;
  366. panFile.Font = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134)));
  367. panFile.Click += PanFile_Click;
  368. panFile.MouseEnter += PanFile_Enter;
  369. panFile.MouseLeave += PanFile_MouseLeave;
  370. Label lblFileName = new Label();
  371. lblFileName.Text = fileName;
  372. lblFileName.ForeColor = Color.Navy;
  373. lblFileName.Size = new Size(panFile.Width, panFile.Height/2);
  374. lblFileName.Location = new Point(panFile.Location.X, panFile.Location.Y + panFile.Size.Height/2);
  375. lblFileName.TextAlign = ContentAlignment.MiddleCenter;
  376. lblFileName.Click += LblFileName_Click;
  377. panFile.Controls.Add(lblFileName);
  378. CircleDeleteControl delIcon = new CircleDeleteControl();
  379. delIcon.Size = new Size(panFile.Width/8, panFile.Height/8);
  380. delIcon.Location = new Point(panFile.Width * 3/4, panFile.Width * 1/8);
  381. delIcon.Visible = true;
  382. delIcon.Click += DelIcon_Click;
  383. panFile.Controls.Add(delIcon);
  384. flowLayoutPanel1.Controls.Add(panFile);
  385. }
  386. private void LblFileName_Click(object sender, EventArgs e)
  387. {
  388. Control pan = ((Control)sender).Parent;
  389. PanFile_Click(pan, e);
  390. }
  391. private void PanFile_Click(object sender, EventArgs e)
  392. {
  393. OpenFile(saveFilePath + ((Panel)sender).Text);
  394. }
  395. private void PanFile_Enter(object sender, EventArgs e)
  396. {
  397. ((Control)sender).BackColor = Color.LightGray;
  398. }
  399. private void PanFile_MouseLeave(object sender, EventArgs e)
  400. {
  401. ((Control)sender).BackColor = Color.White;
  402. }
  403. private void DelIcon_Click(object sender, EventArgs e)
  404. {
  405. DialogResult result = MessageBox.Show("确认要删除此文件么?", "删除文件确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  406. if (result == DialogResult.Yes)
  407. {
  408. Panel pan = (Panel)((Control)sender).Parent;
  409. File.Delete(saveFilePath + pan.Text);
  410. pan.Parent.Controls.Remove(pan);
  411. }
  412. }
  413. private void OpenFile(string fileName)
  414. {
  415. ProcessStartInfo startInfo = new ProcessStartInfo
  416. {
  417. FileName = fileName,
  418. UseShellExecute = true
  419. };
  420. Process.Start(startInfo);
  421. }
  422. #endregion
  423. }
  424. public class CompanyCoverUser
  425. {
  426. public string CompanyId { get; set; }
  427. public sbyte CoverType { get; set; }
  428. public Coverage[] Coverages { get; set; }
  429. public class Coverage
  430. {
  431. public sbyte IsValid { get; set; }
  432. public int UserId { get; set; }
  433. }
  434. }
  435. public class CircleDeleteControl : Control
  436. {
  437. protected override void OnPaint(PaintEventArgs e)
  438. {
  439. base.OnPaint(e);
  440. Graphics g = e.Graphics;
  441. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
  442. Point center = new Point(this.Width/2, this.Height/2);
  443. // 圆形删除符号的直径可以是控件的最小边长
  444. int diameter = Math.Min(this.Width, this.Height);
  445. // 圆形删除符号的内半径
  446. int innerRadius = diameter / 2;
  447. using (Pen deletePen = new Pen(Color.Red, 1))
  448. {
  449. // 绘制圆形删除符号的背景
  450. g.DrawEllipse(deletePen, center.X - innerRadius, center.Y - innerRadius, diameter, diameter);
  451. // 绘制两条相交的对角线
  452. g.DrawLine(deletePen, center.X - innerRadius, center.Y + innerRadius, center.X + innerRadius, center.Y - innerRadius);
  453. g.DrawLine(deletePen, center.X - innerRadius, center.Y - innerRadius, center.X + innerRadius, center.Y + innerRadius);
  454. }
  455. }
  456. protected override void OnMouseEnter(EventArgs e)
  457. {
  458. base.OnMouseEnter(e);
  459. this.Cursor = Cursors.Hand;
  460. }
  461. protected override void OnMouseLeave(EventArgs e)
  462. {
  463. base.OnMouseLeave(e);
  464. this.Cursor = Cursors.Arrow;
  465. }
  466. }
  467. }