DataManager.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using System.Windows.Automation.Peers;
  11. using System.Windows.Forms;
  12. using System.Windows.Forms.DataVisualization.Charting;
  13. using static DataManager.DataAccess;
  14. using static DataManager.UIConstants;
  15. namespace DataManager
  16. {
  17. public partial class frmDataManager : Form
  18. {
  19. private DateTime defaultDatetime = DateTime.Now.AddDays(-30);
  20. private DataTable collectionTaskTable = new DataTable();
  21. private DataTable contactTaskTable;
  22. private DataTable orphanFundTable;
  23. private DataTable companyCoverageTable;
  24. private DataTable authorizedCompanyTable;
  25. private DataTable fundCoverageTable;
  26. private DataTable authorizedFundTable;
  27. private static int userId;
  28. public static int UserId { get => userId; set => userId = value; }
  29. public frmDataManager(int userid)
  30. {
  31. UserId = userid;
  32. InitializeComponent();
  33. InitializeData();
  34. }
  35. private void InitializeData()
  36. {
  37. #region Contact Task Tab
  38. DataTable dt_dm_user_1 = DataAccess.Get_dm_user(null, 1);
  39. dt_dm_user_1.Rows.Add(DataAccess.DM_NULL, 1, "全部");
  40. cmbContactor.DataSource = dt_dm_user_1;
  41. cmbContactor.DisplayMember = "username";
  42. cmbContactor.ValueMember = "userid";
  43. cmbContactor.SelectedValue = UserId;
  44. dtpContactTaskDate.Value = defaultDatetime;
  45. BindingSource bs4 = new BindingSource();
  46. Dictionary<int, string> d4 = new Dictionary<int, string>(ContactTaskType);
  47. d4.Add(DM_NULL, "全部");
  48. bs4.DataSource = d4;
  49. cmbContactTaskType.DataSource = bs4;
  50. cmbContactTaskType.DisplayMember = "Value";
  51. cmbContactTaskType.ValueMember = "Key";
  52. cmbContactTaskType.SelectedValue = (int)DM_NULL;
  53. BindingSource bs = new BindingSource();
  54. Dictionary<int, string> d = new Dictionary<int, string>(ContactTaskStatus);
  55. d.Add(DM_NULL, "全部");
  56. bs.DataSource = d;
  57. cmbContactTaskStatus.DataSource = bs;
  58. cmbContactTaskStatus.DisplayMember = "Value";
  59. cmbContactTaskStatus.ValueMember = "Key";
  60. cmbContactTaskStatus.SelectedValue = (int)DM_NULL;
  61. BindingSource bs2 = new BindingSource();
  62. Dictionary<int, string> d2 = new Dictionary<int, string>(TaskPriority);
  63. d2.Add(DM_NULL, "全部");
  64. bs2.DataSource = d2;
  65. cmbContactPriority.DataSource = bs2;
  66. cmbContactPriority.DisplayMember = "Value";
  67. cmbContactPriority.ValueMember = "Key";
  68. cmbContactPriority.SelectedValue = (int)DM_NULL;
  69. BindingSource bs3 = new BindingSource();
  70. Dictionary<int, string> d3 = new Dictionary<int, string>(CompanyAssetSize);
  71. d3.Add(DM_NULL, "全部");
  72. bs3.DataSource = d3;
  73. cmbContactCompanySize.DataSource = bs3;
  74. cmbContactCompanySize.DisplayMember = "Value";
  75. cmbContactCompanySize.ValueMember = "Key";
  76. cmbContactCompanySize.SelectedValue = (int)DM_NULL;
  77. dtpContactFollowUpDate.ShowCheckBox = true;
  78. dtpContactFollowUpDate.Checked = false;
  79. #endregion
  80. #region Collection Task Tab
  81. DataTable dt_dm_user_2 = DataAccess.Get_dm_user(null, 2);
  82. dt_dm_user_2.Rows.Add(DataAccess.DM_NULL, 2, "全部");
  83. cmbCollector.DataSource = dt_dm_user_2;
  84. cmbCollector.DisplayMember = "username";
  85. cmbCollector.ValueMember = "userid";
  86. cmbCollector.SelectedValue = UserId;
  87. dtpCollectionTaskDate.Value = defaultDatetime;
  88. BindingSource bs5 = new BindingSource();
  89. Dictionary<int, string> d5 = new Dictionary<int, string>(CollectionTaskType);
  90. d5.Add(DM_NULL, "全部");
  91. bs5.DataSource = d5;
  92. cmbCollectionTaskType.DataSource = bs5;
  93. cmbCollectionTaskType.DisplayMember = "Value";
  94. cmbCollectionTaskType.ValueMember = "Key";
  95. cmbCollectionTaskType.SelectedValue = (int)DM_NULL;
  96. BindingSource bs6 = new BindingSource();
  97. Dictionary<int, string> d6 = new Dictionary<int, string>(CollectionTaskStatus);
  98. d6.Add(DM_NULL, "全部");
  99. bs6.DataSource = d6;
  100. cmbCollectionTaskStatus.DataSource = bs6;
  101. cmbCollectionTaskStatus.DisplayMember = "Value";
  102. cmbCollectionTaskStatus.ValueMember = "Key";
  103. cmbCollectionTaskStatus.SelectedValue = (int)DM_NULL;
  104. #endregion
  105. }
  106. #region Contact Tab
  107. private void LoadContactTaskGrid()
  108. {
  109. ContactTask task = CreateContactTaskFromUI();
  110. int? userid = task.UserId;
  111. if (userid == DM_NULL) userid = null;
  112. short? taskType = task.TaskType;
  113. if(taskType == DM_NULL) taskType = null;
  114. sbyte? isvalid = task.Isvalid;
  115. if(isvalid == DM_NULL) isvalid = null;
  116. sbyte? priority = task.Priority;
  117. if (priority == DM_NULL) priority = null;
  118. sbyte? companyAssetSize = task.CompanyAssetSize;
  119. if(companyAssetSize == DM_NULL) companyAssetSize = null;
  120. contactTaskTable = DataAccess.Get_dm_contact_task(userid, null, task.CompanyId, task.CompanyShortName,
  121. task.TaskDate, taskType, isvalid, priority,
  122. task.FollowUpDate, companyAssetSize);
  123. grdContactTask.DataSource = contactTaskTable;
  124. grdContactTask.Columns["task_id"].HeaderText = "ID";
  125. grdContactTask.Columns["company_short_name"].HeaderText = "公司";
  126. grdContactTask.Columns["task_date"].HeaderText = "日期";
  127. grdContactTask.Columns["task_type_name"].HeaderText = "任务";
  128. grdContactTask.Columns["isvalid_name"].HeaderText = "状态";
  129. grdContactTask.Columns["priority_name"].HeaderText = "优先级";
  130. grdContactTask.Columns["follow_up_date"].HeaderText = "跟进日";
  131. grdContactTask.Columns["company_asset_size_name"].HeaderText = "规模";
  132. grdContactTask.Columns["creator_name"].HeaderText = "创建";
  133. grdContactTask.Columns["updater_name"].HeaderText = "更新";
  134. grdContactTask.Columns["updatetime"].HeaderText = "更新时间";
  135. grdContactTask.Columns["company_id"].Visible = false;
  136. grdContactTask.Columns["task_type"].Visible = false;
  137. grdContactTask.Columns["isvalid"].Visible = false;
  138. grdContactTask.Columns["priority"].Visible = false;
  139. grdContactTask.Columns["company_asset_size"].Visible = false;
  140. grdContactTask.Columns["creatorid"].Visible = false;
  141. grdContactTask.Columns["createtime"].Visible = false;
  142. grdContactTask.Columns["updaterid"].Visible = false;
  143. grdContactTask.Columns["company_short_name"].DefaultCellStyle.ForeColor = Color.DodgerBlue;
  144. grdContactTask.Columns["company_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
  145. lblContactTaskCount.Text = contactTaskTable.Rows.Count.ToString();
  146. }
  147. private ContactTask CreateContactTaskFromUI()
  148. {
  149. ContactTask task = new ContactTask();
  150. task.UserId = int.Parse(cmbContactor.SelectedValue.ToString());
  151. // 支持输 company_id或简称关键字的搜索
  152. string keywrod = txtContactCompany.Text.Trim();
  153. if (keywrod == String.Empty)
  154. {
  155. task.CompanyId = null;
  156. task.CompanyShortName = null;
  157. } else if (keywrod.Length == 10 && keywrod.ToUpper().Substring(0, 2) == "CO")
  158. {
  159. task.CompanyId = keywrod.ToUpper();
  160. task.CompanyShortName = null;
  161. } else
  162. {
  163. task.CompanyId = null;
  164. task.CompanyShortName = keywrod;
  165. }
  166. task.TaskDate = DateTime.Parse(dtpContactTaskDate.Text.ToString());
  167. task.TaskType = short.Parse(cmbContactTaskType.SelectedValue.ToString());
  168. task.Isvalid = sbyte.Parse(cmbContactTaskStatus.SelectedValue.ToString());
  169. task.Priority = sbyte.Parse(cmbContactPriority.SelectedValue.ToString());
  170. task.CompanyAssetSize = sbyte.Parse(cmbContactCompanySize.SelectedValue.ToString());
  171. if (dtpContactFollowUpDate.Checked == true)
  172. {
  173. task.FollowUpDate = DateTime.Parse(dtpContactFollowUpDate.Text.ToString());
  174. } else {
  175. task.FollowUpDate = null;
  176. };
  177. return task;
  178. }
  179. private void btnContactSearch_Click(object sender, EventArgs e)
  180. {
  181. LoadContactTaskGrid();
  182. }
  183. private void grdContactTask_CellClick(object sender, DataGridViewCellEventArgs e)
  184. {
  185. int rowIndex = e.RowIndex;
  186. int columnIndex = e.ColumnIndex;
  187. if (columnIndex < 0 || rowIndex < 0) return;
  188. DataRow row = contactTaskTable.Rows[rowIndex];
  189. if (columnIndex == grdContactTask.Columns["company_short_name"].Index)
  190. // 弹出公司页面
  191. {
  192. UICompany frmCompany = new UICompany(row.Field<string>("company_id"), UserId);
  193. frmCompany.Show();
  194. }
  195. else
  196. // 弹出联系任务编辑框
  197. {
  198. ContactTask task = new ContactTask(UserId, row.Field<int>("task_id"), row.Field<string>("company_id"), row.Field<string>("company_short_name"),
  199. row.Field<DateTime>("task_date"), row.Field<short>("task_type"), row.Field<sbyte>("isvalid"), row.Field<sbyte>("priority"),
  200. row.Field<DateTime?>("follow_up_date"), row.Field<sbyte?>("company_asset_size"),
  201. row.Field<int?>("creatorid"), row.Field<string>("creator_name"), row.Field<DateTime?>("createtime"),
  202. row.Field<int?>("updaterid"), row.Field<string>("updater_name"), row.Field<DateTime?>("updatetime"));
  203. if (task != null)
  204. {
  205. frmContactTask ctk = new frmContactTask(task);
  206. ctk.ShowDialog();
  207. // 刷新 grid 数据
  208. if (ctk.DialogResult == DialogResult.OK)
  209. {
  210. LoadContactTaskGrid();
  211. }
  212. }
  213. }
  214. }
  215. private void btnAddContactTask_Click(object sender, EventArgs e)
  216. {
  217. frmContactTask ctk = new frmContactTask(UserId);
  218. ctk.ShowDialog();
  219. // 刷新 grid 数据
  220. if (ctk.DialogResult == DialogResult.OK)
  221. {
  222. LoadContactTaskGrid();
  223. }
  224. }
  225. #endregion
  226. #region Collection Tab
  227. private void LoadCollectionTaskGrid()
  228. {
  229. CollectionTask task = CreatecCollectionTaskFromUI();
  230. int? userId = task.UserId;
  231. if (userId == DM_NULL) userId = null;
  232. short? taskType = task.TaskType;
  233. if (taskType == DM_NULL) taskType = null;
  234. sbyte? isvalid = task.Isvalid;
  235. if (isvalid == DM_NULL) isvalid = null;
  236. collectionTaskTable = DataAccess.Get_dm_collection_task(userId, null, task.ProviderId, task.ProviderName,
  237. task.TaskDate, taskType, task.EntityId, task.EntityName,
  238. isvalid);
  239. grdCollectionTask.DataSource = collectionTaskTable;
  240. grdCollectionTask.Columns["task_id"].HeaderText = "ID";
  241. grdCollectionTask.Columns["provider_name"].HeaderText = "来源";
  242. grdCollectionTask.Columns["task_date"].HeaderText = "日期";
  243. grdCollectionTask.Columns["task_type_name"].HeaderText = "任务";
  244. grdCollectionTask.Columns["entity_name"].HeaderText = "主题";
  245. grdCollectionTask.Columns["err_message"].HeaderText = "详情";
  246. grdCollectionTask.Columns["isvalid_name"].HeaderText = "状态";
  247. grdCollectionTask.Columns["creator_name"].HeaderText = "创建";
  248. grdCollectionTask.Columns["updater_name"].HeaderText = "更新";
  249. grdCollectionTask.Columns["updatetime"].HeaderText = "更新时间";
  250. grdCollectionTask.Columns["provider_id"].Visible = false;
  251. grdCollectionTask.Columns["task_type"].Visible = false;
  252. grdCollectionTask.Columns["entity_id"].Visible = false;
  253. grdCollectionTask.Columns["isvalid"].Visible = false;
  254. grdCollectionTask.Columns["creatorid"].Visible = false;
  255. grdCollectionTask.Columns["createtime"].Visible = false;
  256. grdCollectionTask.Columns["updaterid"].Visible = false;
  257. //grdCollectionTask.Columns["provider_name"].DefaultCellStyle.ForeColor = Color.DodgerBlue;
  258. grdCollectionTask.Columns["entity_name"].DefaultCellStyle.ForeColor = Color.DodgerBlue;
  259. grdCollectionTask.Columns["entity_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
  260. lblCollectionTaskCount.Text = collectionTaskTable.Rows.Count.ToString();
  261. }
  262. private CollectionTask CreatecCollectionTaskFromUI()
  263. {
  264. CollectionTask task = new CollectionTask();
  265. task.UserId = int.Parse(cmbCollector.SelectedValue.ToString());
  266. string providerKeyword = txtCollectionProvider.Text.Trim();
  267. if (providerKeyword == string.Empty)
  268. {
  269. task.ProviderId = null;
  270. task.ProviderName = null;
  271. }
  272. else if (providerKeyword.Length == 10 && providerKeyword.Substring(0, 2).ToUpper() == "CO")
  273. {
  274. task.ProviderId = providerKeyword.ToUpper();
  275. task.ProviderName = null;
  276. }
  277. else
  278. {
  279. task.ProviderId = null;
  280. task.ProviderName = providerKeyword;
  281. }
  282. task.TaskDate = DateTime.Parse(dtpCollectionTaskDate.Text.ToString());
  283. task.TaskType = short.Parse(cmbCollectionTaskType.SelectedValue.ToString());
  284. // 支持输入fund_id或简称关键字的搜索
  285. string entityKeyword = txtCollectionEntity.Text.Trim();
  286. if (entityKeyword == string.Empty)
  287. {
  288. task.EntityId = null;
  289. task.EntityName = null;
  290. }
  291. else if (entityKeyword.Length == 10 && Regex.Match(entityKeyword.ToUpper(), "^[M|H]F").Success)
  292. {
  293. task.EntityId = entityKeyword.ToUpper();
  294. task.EntityName = null;
  295. }
  296. else
  297. {
  298. task.EntityId = null;
  299. task.EntityName = entityKeyword;
  300. }
  301. task.Isvalid = sbyte.Parse(cmbCollectionTaskStatus.SelectedValue.ToString());
  302. return task;
  303. }
  304. private void btnCollectionSearch_Click(object sender, EventArgs e)
  305. {
  306. LoadCollectionTaskGrid();
  307. }
  308. private void grdCollectionTask_CellClick(object sender, DataGridViewCellEventArgs e)
  309. {
  310. int rowIndex = e.RowIndex;
  311. int columnIndex = e.ColumnIndex;
  312. if (columnIndex < 0 || rowIndex < 0) return;
  313. DataRow row = collectionTaskTable.Rows[rowIndex];
  314. if (columnIndex == grdCollectionTask.Columns["entity_name"].Index )
  315. // 弹出基金页面
  316. {
  317. string entityId = row["entity_id"].ToString();
  318. if (entityId.Length == 10 && Regex.Match(entityId, "^[HM]F").Success)
  319. {
  320. UIFund frmFund = new UIFund(entityId, UserId);
  321. frmFund.Show();
  322. }
  323. }
  324. else
  325. // 弹出采集任务编辑框
  326. {
  327. CollectionTask task = new CollectionTask(UserId, row.Field<int>("task_id"), row.Field<string>("provider_id"), row.Field<string>("provider_name"),
  328. row.Field<DateTime>("task_date"), row.Field<short>("task_type"),
  329. row.Field<string>("entity_id"), row.Field<string>("entity_name"),
  330. row.Field<string>("err_message"), row.Field<sbyte>("isvalid"),
  331. row.Field<int?>("creatorid"), row.Field<string>("creator_name"), row.Field<DateTime?>("createtime"),
  332. row.Field<int?>("updaterid"), row.Field<string>("updater_name"), row.Field<DateTime?>("updatetime"));
  333. if (task != null)
  334. {
  335. UICollectionTask ctk = new UICollectionTask(task);
  336. ctk.ShowDialog();
  337. // 刷新 grid 数据
  338. if (ctk.DialogResult == DialogResult.OK)
  339. {
  340. LoadCollectionTaskGrid();
  341. }
  342. }
  343. }
  344. }
  345. private void btnAddCollectionTask_Click(object sender, EventArgs e)
  346. {
  347. UICollectionTask ctk = new UICollectionTask(UserId);
  348. ctk.ShowDialog();
  349. // 刷新 grid 数据
  350. if (ctk.DialogResult == DialogResult.OK)
  351. {
  352. LoadCollectionTaskGrid();
  353. }
  354. }
  355. #endregion
  356. #region Data - Fund
  357. private void LoadFundGrid()
  358. {
  359. string keyword = txtFundKeyword.Text.Trim();
  360. if (keyword == string.Empty) { keyword = null; }
  361. // 只搜私募
  362. DataTable dt = DataAccess.Search_dm_fund(RaiseType.FirstOrDefault(x=>x.Value== "私募").Key, keyword);
  363. grdFundList.DataSource = dt;
  364. grdFundList.DefaultCellStyle.ForeColor = Color.DimGray;
  365. grdFundList.Columns["fund_id"].Visible = false;
  366. grdFundList.Columns["fund_name"].HeaderText = "基金全名";
  367. grdFundList.Columns["fund_short_name"].HeaderText = "基金简称";
  368. grdFundList.Columns["company_id"].Visible = false;
  369. grdFundList.Columns["company_short_name"].HeaderText = "公司简称";
  370. grdFundList.Columns["strategy"].HeaderText = "策略分类";
  371. grdFundList.Columns["substrategy"].HeaderText = "二级分类";
  372. grdFundList.Columns["max_price_date"].HeaderText = "最新净值";
  373. grdFundList.Columns["company_short_name"].DefaultCellStyle.ForeColor = Color.DodgerBlue;
  374. grdFundList.Columns["max_price_date"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  375. grdFundList.Columns["fund_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  376. ToolStripStatusLabel label = new ToolStripStatusLabel();
  377. label.Text = "记录条数:" + dt.Rows.Count.ToString();
  378. sstData.Items.Clear();
  379. sstData.Items.Add(label);
  380. }
  381. private void btnSearchFund_Click(object sender, EventArgs e)
  382. {
  383. LoadFundGrid();
  384. }
  385. private void grdFundList_CellClick(object sender, DataGridViewCellEventArgs e)
  386. {
  387. int rowIndex = e.RowIndex;
  388. int columnIndex = e.ColumnIndex;
  389. if (columnIndex < 0 || rowIndex < 0) return;
  390. DataGridViewRow row = grdFundList.Rows[rowIndex];
  391. if (columnIndex == grdFundList.Columns["company_short_name"].Index)
  392. // 弹出公司页面
  393. {
  394. string entityId = row.Cells["company_id"].Value.ToString().ToUpper();
  395. if (entityId.Length == 10 && Regex.Match(entityId, "^CO").Success)
  396. {
  397. UICompany frm = new UICompany(entityId, UserId);
  398. frm.Show();
  399. }
  400. }
  401. else
  402. // 弹出基金页面
  403. {
  404. string entityId = row.Cells["fund_id"].Value.ToString().ToUpper();
  405. if (entityId.Length == 10 && Regex.Match(entityId, "^[M|H]F").Success)
  406. {
  407. UIFund frm = new UIFund(entityId, UserId);
  408. frm.Show();
  409. }
  410. }
  411. }
  412. #endregion
  413. #region Data - Company
  414. private void LoadCompanyGrid()
  415. {
  416. string keyword = txtCompanyKeyword.Text.Trim();
  417. if (keyword == string.Empty) { keyword = null; }
  418. // 只搜私募
  419. DataTable dt = DataAccess.Search_dm_company(1, keyword);
  420. grdCompanyList.DataSource = dt;
  421. grdCompanyList.DefaultCellStyle.ForeColor = Color.DimGray;
  422. grdCompanyList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  423. //grdCompanyList.Columns["company_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
  424. grdCompanyList.Columns["company_id"].Visible = false;
  425. grdCompanyList.Columns["company_name"].HeaderText = "公司全名";
  426. grdCompanyList.Columns["company_short_name"].HeaderText = "公司简称";
  427. grdCompanyList.Columns["company_asset_size"].Visible = false;
  428. grdCompanyList.Columns["company_asset_size_name"].HeaderText = "管理规模";
  429. grdCompanyList.Columns["register_number"].HeaderText = "协会编号";
  430. grdCompanyList.Columns["establish_date"].HeaderText = "成立日";
  431. grdCompanyList.Columns["company_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  432. ToolStripStatusLabel label = new ToolStripStatusLabel();
  433. label.Text = "记录条数:" + dt.Rows.Count.ToString();
  434. sstData.Items.Clear();
  435. sstData.Items.Add(label);
  436. }
  437. private void btnSearchCompany_Click(object sender, EventArgs e)
  438. {
  439. LoadCompanyGrid();
  440. }
  441. private void grdCompanyList_CellClick(object sender, DataGridViewCellEventArgs e)
  442. {
  443. int rowIndex = e.RowIndex;
  444. int columnIndex = e.ColumnIndex;
  445. if (columnIndex < 0 || rowIndex < 0) return;
  446. DataGridViewRow row = grdCompanyList.Rows[rowIndex];
  447. string entityId = row.Cells["company_id"].Value.ToString().ToUpper();
  448. if (entityId.Length == 10 && Regex.Match(entityId, "^CO").Success)
  449. {
  450. UICompany frm = new UICompany(entityId, UserId);
  451. frm.Show();
  452. }
  453. }
  454. #endregion
  455. #region Reports
  456. #region Orphan Fund
  457. private void LoadOrphanFund()
  458. {
  459. DataTable dt = null;
  460. string providerName = txtOrphanProvider.Text.Trim();
  461. sbyte isOrphan = 1;
  462. if (!chkIsOrphan.Checked) isOrphan = 0;
  463. orphanFundTable = DataAccess.Get_dm_external_fund_mapping(isOrphan, UserId);
  464. if (providerName != string.Empty)
  465. {
  466. DataRow[] rows = orphanFundTable.Select("provider_name LIKE '%" + providerName + "%'", "id DESC");
  467. if(rows != null && rows.Length > 0) dt = rows.CopyToDataTable();
  468. }
  469. else
  470. dt = orphanFundTable;
  471. if (dt != null)
  472. {
  473. grdOrphanFund.DataSource = dt;
  474. grdOrphanFund.Columns["id"].Visible = false;
  475. grdOrphanFund.Columns["fund_id"].HeaderText = "基金ID";
  476. grdOrphanFund.Columns["provider_id"].Visible = false;
  477. grdOrphanFund.Columns["provider_name"].HeaderText = "数据源";
  478. grdOrphanFund.Columns["external_id"].HeaderText = "外部ID";
  479. grdOrphanFund.Columns["isvalid"].HeaderText = "状态";
  480. grdOrphanFund.Columns["creatorid"].Visible = false;
  481. grdOrphanFund.Columns["creator_name"].HeaderText = "创建";
  482. grdOrphanFund.Columns["createtime"].HeaderText = "创建时间";
  483. grdOrphanFund.Columns["updaterid"].Visible = false;
  484. grdOrphanFund.Columns["updater_name"].HeaderText = "更新";
  485. grdOrphanFund.Columns["updatetime"].HeaderText = "更新时间";
  486. grdOrphanFund.Columns["provider_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  487. grdOrphanFund.Columns["external_id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  488. }
  489. }
  490. private void btnOrphanFundSearch_Click(object sender, EventArgs e)
  491. {
  492. LoadOrphanFund();
  493. }
  494. private void grdOrphanFund_CellClick(object sender, DataGridViewCellEventArgs e)
  495. {
  496. int rowIndex = e.RowIndex;
  497. if (rowIndex < 0) return;
  498. DataGridViewRow row = grdOrphanFund.Rows[rowIndex];
  499. // 弹出基金页面
  500. string provider_id = row.Cells["provider_id"].Value.ToString();
  501. string external_id = row.Cells["external_id"].Value.ToString();
  502. string fund_id = row.Cells["fund_id"].Value.ToString();
  503. UIFund frmFund = new UIFund(provider_id, external_id, fund_id, UserId);
  504. frmFund.ShowDialog();
  505. if (frmFund.DialogResult == DialogResult.OK)
  506. {
  507. LoadOrphanFund();
  508. }
  509. }
  510. private void txtOrphanProvider_KeyPress(object sender, KeyPressEventArgs e)
  511. {
  512. if (e.KeyChar == 13)
  513. {
  514. btnOrphanFundSearch_Click(sender, e);
  515. }
  516. }
  517. #endregion
  518. #region Authorization Coverage
  519. private void LoadCompanyCoverageChart()
  520. {
  521. int coveredCnt = 0;
  522. int totalCnt = 0;
  523. DataRow[] rows = companyCoverageTable.Select(CompanySizeFilter());
  524. for (int i = 0; i < rows.Length; i ++)
  525. {
  526. coveredCnt += int.Parse(rows[i]["covered_cnt"].ToString());
  527. totalCnt += int.Parse(rows[i]["total_cnt"].ToString());
  528. }
  529. string[] pieX = { "合作#", "未合作#" };
  530. int[] pieY = { coveredCnt, totalCnt - coveredCnt };
  531. chtEntityCoverage.Series.Clear();
  532. Series series = new Series();
  533. series.ChartType = SeriesChartType.Pie;
  534. series.Points.DataBindXY(pieX, pieY);
  535. series.Points[0].Label = $"{series.Points[0].AxisLabel}: {coveredCnt:N0}";
  536. series.Points[0].ToolTip = $"{series.Points[0].AxisLabel}: {(100.0 * coveredCnt / totalCnt):F2}%";
  537. series.Points[1].Label = $"{series.Points[1].AxisLabel}: {(totalCnt - coveredCnt):N0}";
  538. series.Points[1].ToolTip = $"{series.Points[1].AxisLabel}: {(100.0 * ( 1.0 - coveredCnt / totalCnt)):F2}%";
  539. series.Points[1].Color = Color.LightGray;
  540. chtEntityCoverage.Series.Add(series);
  541. }
  542. private void LoadFundCoverageChart()
  543. {
  544. chtEntityCoverage.Series.Clear();
  545. Series series = new Series();
  546. series.Name = "合作%";
  547. series.ChartType = SeriesChartType.StackedColumn100;
  548. Series series2 = new Series();
  549. series2.Name = "未合作%";
  550. series2.ChartType = SeriesChartType.StackedColumn100;
  551. series2.Color = Color.LightGray;
  552. int coveredCnt = 0;
  553. int totalCnt = 0;
  554. DataRow[] rows = fundCoverageTable.Select(CompanySizeFilter());
  555. for (int i = 0; i < rows.Length; i++)
  556. {
  557. coveredCnt += int.Parse(rows[i]["covered_cnt"].ToString());
  558. totalCnt += int.Parse(rows[i]["total_cnt"].ToString());
  559. series.Points.AddXY(rows[i]["company_asset_size_name"].ToString(), coveredCnt);
  560. series2.Points.AddXY(rows[i]["company_asset_size_name"].ToString(), totalCnt - coveredCnt);
  561. }
  562. chtEntityCoverage.Series.Add(series);
  563. chtEntityCoverage.Series.Add(series2);
  564. chtEntityCoverage.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray;
  565. chtEntityCoverage.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.LightGray;
  566. }
  567. private string CompanySizeFilter()
  568. {
  569. string selectExp = "company_asset_size in (";
  570. if (chk100.Checked) selectExp += "6,";
  571. if (chk50.Checked) selectExp += "5,";
  572. if (chk20.Checked) selectExp += "4,";
  573. if (chk10.Checked) selectExp += "3,";
  574. if (chk5.Checked) selectExp += "2,";
  575. if (chk0.Checked) selectExp += "1,";
  576. // 没有checkbox背选中时表示规模未知
  577. if (selectExp.Substring(selectExp.Length - 1) == "(") selectExp = selectExp + " -1)";
  578. // 去掉最后一个逗号
  579. if (selectExp.Substring(selectExp.Length - 1) == ",") selectExp = selectExp.Substring(0, selectExp.Length - 1) + ")";
  580. return selectExp;
  581. }
  582. private void LoadEntityCoverageGrid()
  583. {
  584. // 这个sp有点慢
  585. this.Cursor = Cursors.WaitCursor;
  586. if (rdbCompany.Checked)
  587. {
  588. companyCoverageTable = DataAccess.Report_company_coverage(null);
  589. grdEntityCoverage.DataSource = companyCoverageTable;
  590. }
  591. else
  592. {
  593. fundCoverageTable = DataAccess.Report_fund_coverage(null);
  594. grdEntityCoverage.DataSource = fundCoverageTable;
  595. }
  596. this.Cursor = Cursors.Default;
  597. grdEntityCoverage.Columns["company_asset_size"].Visible = false;
  598. grdEntityCoverage.Columns["company_asset_size_name"].HeaderText = "规模";
  599. grdEntityCoverage.Columns["covered_cnt"].HeaderText = "覆盖数";
  600. grdEntityCoverage.Columns["covered_cnt"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
  601. grdEntityCoverage.Columns["covered_cnt"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
  602. grdEntityCoverage.Columns["total_cnt"].HeaderText = "总数";
  603. grdEntityCoverage.Columns["total_cnt"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
  604. grdEntityCoverage.Columns["total_cnt"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
  605. grdEntityCoverage.Columns["cover_pct"].HeaderText = "覆盖率%";
  606. grdEntityCoverage.Columns["cover_pct"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
  607. grdEntityCoverage.Columns["cover_pct"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
  608. grdEntityCoverage.Columns["company_asset_size_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  609. grdEntityCoverage.Columns["cover_pct"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  610. }
  611. private void LoadAuthrizedCompanyList()
  612. {
  613. authorizedCompanyTable = DataAccess.Get_dm_company_authorization(null, null);
  614. }
  615. private void LoadAuthrizedFundList()
  616. {
  617. authorizedFundTable = DataAccess.Get_dm_fund_authorization(null);
  618. }
  619. private void LoadAuthorizedCompanyGrid()
  620. {
  621. if (authorizedCompanyTable != null)
  622. {
  623. DataTable dt = null;
  624. string selectExp = CompanySizeFilter();
  625. string nameExp = txtLocateEntity.Text.Trim();
  626. if (nameExp.Length > 0) selectExp += " and company_short_name LIKE '%" + nameExp + "%'";
  627. DataRow[] dr = authorizedCompanyTable.Select(selectExp, "company_asset_size DESC");
  628. if (dr != null && dr.Length > 0) dt = dr.CopyToDataTable();
  629. grdAuthorizedEntity.DataSource = dt;
  630. if (dt != null)
  631. {
  632. grdAuthorizedEntity.Columns["company_id"].Visible = false;
  633. grdAuthorizedEntity.Columns["company_name"].Visible = false;
  634. grdAuthorizedEntity.Columns["company_short_name"].HeaderText = "公司简称";
  635. grdAuthorizedEntity.Columns["company_asset_size"].Visible = false;
  636. grdAuthorizedEntity.Columns["company_asset_size_name"].HeaderText = "规模";
  637. grdAuthorizedEntity.Columns["register_number"].HeaderText = "协会编号";
  638. grdAuthorizedEntity.Columns["establish_date"].HeaderText = "成立日";
  639. grdAuthorizedEntity.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  640. grdAuthorizedEntity.Columns["company_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  641. }
  642. }
  643. }
  644. private void LoadAuthorizedFundGrid()
  645. {
  646. if (authorizedFundTable != null)
  647. {
  648. DataTable dt = null;
  649. string selectExp = CompanySizeFilter();
  650. string nameExp = txtLocateEntity.Text.Trim();
  651. if (nameExp.Length > 0) selectExp += " and fund_short_name LIKE '%" + nameExp + "%'";
  652. DataRow[] dr = authorizedFundTable.Select(selectExp, "company_asset_size DESC");
  653. if (dr != null && dr.Length > 0) dt = dr.CopyToDataTable();
  654. grdAuthorizedEntity.DataSource = dt;
  655. if (dt != null)
  656. {
  657. grdAuthorizedEntity.Columns["fund_id"].Visible = false;
  658. grdAuthorizedEntity.Columns["fund_name"].Visible = false;
  659. grdAuthorizedEntity.Columns["fund_short_name"].HeaderText = "基金简称";
  660. grdAuthorizedEntity.Columns["company_asset_size"].Visible = false;
  661. grdAuthorizedEntity.Columns["strategy"].Visible = false;
  662. grdAuthorizedEntity.Columns["substrategy"].HeaderText = "二级分类";
  663. grdAuthorizedEntity.Columns["inception_date"].HeaderText = "成立日";
  664. grdAuthorizedEntity.Columns["register_number"].HeaderText = "备案编码";
  665. grdAuthorizedEntity.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  666. grdAuthorizedEntity.Columns["fund_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  667. }
  668. }
  669. }
  670. private void btnEntityCoverage_Click(object sender, EventArgs e)
  671. {
  672. // 左下角的固定格式覆盖率表
  673. LoadEntityCoverageGrid();
  674. if (rdbCompany.Checked)
  675. {
  676. // 授权公司数据
  677. LoadAuthrizedCompanyList();
  678. // 对公司覆盖率表进行可视化 (PIE)
  679. LoadCompanyCoverageChart();
  680. // 授权公司列表
  681. LoadAuthorizedCompanyGrid();
  682. }
  683. else
  684. {
  685. // 授权基金数据
  686. LoadAuthrizedFundList();
  687. // 对基金覆盖率表进行可视化(BAR)
  688. LoadFundCoverageChart();
  689. // 授权基金列表
  690. LoadAuthorizedFundGrid();
  691. }
  692. }
  693. private void rdbCompany_CheckedChanged(object sender, EventArgs e)
  694. {
  695. btnEntityCoverage_Click(sender, e);
  696. }
  697. private void chk100_CheckedChanged(object sender, EventArgs e)
  698. {
  699. if (((Control)sender).Focus())
  700. {
  701. if (rdbCompany.Checked)
  702. {
  703. // 重新画图
  704. LoadCompanyCoverageChart();
  705. // 刷新公司列表
  706. LoadAuthorizedCompanyGrid();
  707. }
  708. else
  709. {
  710. // 重新画图
  711. LoadFundCoverageChart();
  712. // 刷新基金列表
  713. LoadAuthorizedFundGrid();
  714. }
  715. }
  716. }
  717. private void chk50_CheckedChanged(object sender, EventArgs e)
  718. {
  719. chk100_CheckedChanged(sender, e);
  720. }
  721. private void chk20_CheckedChanged(object sender, EventArgs e)
  722. {
  723. chk100_CheckedChanged(sender, e);
  724. }
  725. private void chk10_CheckedChanged(object sender, EventArgs e)
  726. {
  727. chk100_CheckedChanged(sender, e);
  728. }
  729. private void chk5_CheckedChanged(object sender, EventArgs e)
  730. {
  731. chk100_CheckedChanged(sender, e);
  732. }
  733. private void chk0_CheckedChanged(object sender, EventArgs e)
  734. {
  735. chk100_CheckedChanged(sender, e);
  736. }
  737. private void txtLocateEntity_TextChanged(object sender, EventArgs e)
  738. {
  739. if (rdbCompany.Checked) LoadAuthorizedCompanyGrid();
  740. else LoadAuthorizedFundGrid();
  741. }
  742. private void grdAuthorizedEntity_CellClick(object sender, DataGridViewCellEventArgs e)
  743. {
  744. int rowIndex = e.RowIndex;
  745. int columnIndex = e.ColumnIndex;
  746. if (columnIndex < 0 || rowIndex < 0) return;
  747. DataGridViewRow row = grdAuthorizedEntity.Rows[rowIndex];
  748. if (rdbCompany.Checked)
  749. {
  750. string entityId = row.Cells["company_id"].Value.ToString().ToUpper();
  751. if (entityId.Length == 10 && Regex.Match(entityId, "^CO").Success)
  752. {
  753. UICompany frm = new UICompany(entityId, UserId);
  754. frm.Show();
  755. }
  756. }
  757. else
  758. {
  759. string entityId = row.Cells["fund_id"].Value.ToString().ToUpper();
  760. if (entityId.Length == 10 && Regex.Match(entityId, "^[H|M]F").Success)
  761. {
  762. UIFund frm = new UIFund(entityId, UserId);
  763. frm.Show();
  764. }
  765. }
  766. }
  767. private void rdbFund_CheckedChanged(object sender, EventArgs e)
  768. {
  769. // DO NOTHING, because same actions were triggered by rdbCompany_CheckedChanged anyway
  770. }
  771. #endregion
  772. #endregion
  773. }
  774. }