DataManager.cs 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  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;
  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. dt = orphanFundTable.Select("provider_name LIKE '%" + providerName + "%'", "id DESC").CopyToDataTable();
  466. else
  467. dt = orphanFundTable;
  468. grdOrphanFund.DataSource = dt;
  469. grdOrphanFund.Columns["id"].Visible = false;
  470. grdOrphanFund.Columns["fund_id"].HeaderText = "基金ID";
  471. grdOrphanFund.Columns["provider_id"].Visible = false;
  472. grdOrphanFund.Columns["provider_name"].HeaderText = "数据源";
  473. grdOrphanFund.Columns["external_id"].HeaderText = "外部ID";
  474. grdOrphanFund.Columns["isvalid"].HeaderText = "状态";
  475. grdOrphanFund.Columns["creatorid"].Visible = false;
  476. grdOrphanFund.Columns["creator_name"].HeaderText = "创建";
  477. grdOrphanFund.Columns["createtime"].HeaderText = "创建时间";
  478. grdOrphanFund.Columns["updaterid"].Visible = false;
  479. grdOrphanFund.Columns["updater_name"].HeaderText = "更新";
  480. grdOrphanFund.Columns["updatetime"].HeaderText = "更新时间";
  481. grdOrphanFund.Columns["provider_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  482. grdOrphanFund.Columns["external_id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  483. }
  484. private void btnOrphanFundSearch_Click(object sender, EventArgs e)
  485. {
  486. LoadOrphanFund();
  487. }
  488. private void grdOrphanFund_CellClick(object sender, DataGridViewCellEventArgs e)
  489. {
  490. int rowIndex = e.RowIndex;
  491. if (rowIndex < 0) return;
  492. DataGridViewRow row = grdOrphanFund.Rows[rowIndex];
  493. // 弹出基金页面
  494. string provider_id = row.Cells["provider_id"].Value.ToString();
  495. string external_id = row.Cells["external_id"].Value.ToString();
  496. string fund_id = row.Cells["fund_id"].Value.ToString();
  497. UIFund frmFund = new UIFund(provider_id, external_id, fund_id, UserId);
  498. frmFund.ShowDialog();
  499. if (frmFund.DialogResult == DialogResult.OK)
  500. {
  501. LoadOrphanFund();
  502. }
  503. }
  504. private void txtOrphanProvider_KeyPress(object sender, KeyPressEventArgs e)
  505. {
  506. if (e.KeyChar == 13)
  507. {
  508. btnOrphanFundSearch_Click(sender, e);
  509. }
  510. }
  511. #endregion
  512. #region Authorization Coverage
  513. private void LoadCompanyCoverageChart()
  514. {
  515. int coveredCnt = 0;
  516. int totalCnt = 0;
  517. DataRow[] rows = companyCoverageTable.Select(CompanySizeFilter());
  518. for (int i = 0; i < rows.Length; i ++)
  519. {
  520. coveredCnt += int.Parse(rows[i]["covered_cnt"].ToString());
  521. totalCnt += int.Parse(rows[i]["total_cnt"].ToString());
  522. }
  523. string[] pieX = { "合作#", "未合作#" };
  524. int[] pieY = { coveredCnt, totalCnt - coveredCnt };
  525. chtEntityCoverage.Series.Clear();
  526. Series series = new Series();
  527. series.ChartType = SeriesChartType.Pie;
  528. series.Points.DataBindXY(pieX, pieY);
  529. series.Points[0].Label = $"{series.Points[0].AxisLabel}: {coveredCnt:N0}";
  530. series.Points[0].ToolTip = $"{series.Points[0].AxisLabel}: {(100.0 * coveredCnt / totalCnt):F2}%";
  531. series.Points[1].Label = $"{series.Points[1].AxisLabel}: {(totalCnt - coveredCnt):N0}";
  532. series.Points[1].ToolTip = $"{series.Points[1].AxisLabel}: {(100.0 * ( 1.0 - coveredCnt / totalCnt)):F2}%";
  533. series.Points[1].Color = Color.LightGray;
  534. chtEntityCoverage.Series.Add(series);
  535. }
  536. private void LoadFundCoverageChart()
  537. {
  538. chtEntityCoverage.Series.Clear();
  539. Series series = new Series();
  540. series.Name = "合作%";
  541. series.ChartType = SeriesChartType.StackedColumn100;
  542. Series series2 = new Series();
  543. series2.Name = "未合作%";
  544. series2.ChartType = SeriesChartType.StackedColumn100;
  545. series2.Color = Color.LightGray;
  546. int coveredCnt = 0;
  547. int totalCnt = 0;
  548. DataRow[] rows = fundCoverageTable.Select(CompanySizeFilter());
  549. for (int i = 0; i < rows.Length; i++)
  550. {
  551. coveredCnt += int.Parse(rows[i]["covered_cnt"].ToString());
  552. totalCnt += int.Parse(rows[i]["total_cnt"].ToString());
  553. series.Points.AddXY(rows[i]["company_asset_size_name"].ToString(), coveredCnt);
  554. series2.Points.AddXY(rows[i]["company_asset_size_name"].ToString(), totalCnt - coveredCnt);
  555. }
  556. chtEntityCoverage.Series.Add(series);
  557. chtEntityCoverage.Series.Add(series2);
  558. chtEntityCoverage.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray;
  559. chtEntityCoverage.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.LightGray;
  560. }
  561. private string CompanySizeFilter()
  562. {
  563. string selectExp = "company_asset_size in (";
  564. if (chk100.Checked) selectExp += "6,";
  565. if (chk50.Checked) selectExp += "5,";
  566. if (chk20.Checked) selectExp += "4,";
  567. if (chk10.Checked) selectExp += "3,";
  568. if (chk5.Checked) selectExp += "2,";
  569. if (chk0.Checked) selectExp += "1,";
  570. // 没有checkbox背选中时表示规模未知
  571. if (selectExp.Substring(selectExp.Length - 1) == "(") selectExp = selectExp + " -1)";
  572. // 去掉最后一个逗号
  573. if (selectExp.Substring(selectExp.Length - 1) == ",") selectExp = selectExp.Substring(0, selectExp.Length - 1) + ")";
  574. return selectExp;
  575. }
  576. private void LoadEntityCoverageGrid()
  577. {
  578. // 这个sp有点慢
  579. this.Cursor = Cursors.WaitCursor;
  580. if (rdbCompany.Checked)
  581. {
  582. companyCoverageTable = DataAccess.Report_company_coverage(null);
  583. grdEntityCoverage.DataSource = companyCoverageTable;
  584. }
  585. else
  586. {
  587. fundCoverageTable = DataAccess.Report_fund_coverage(null);
  588. grdEntityCoverage.DataSource = fundCoverageTable;
  589. }
  590. this.Cursor = Cursors.Default;
  591. grdEntityCoverage.Columns["company_asset_size"].Visible = false;
  592. grdEntityCoverage.Columns["company_asset_size_name"].HeaderText = "规模";
  593. grdEntityCoverage.Columns["covered_cnt"].HeaderText = "覆盖数";
  594. grdEntityCoverage.Columns["covered_cnt"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
  595. grdEntityCoverage.Columns["covered_cnt"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
  596. grdEntityCoverage.Columns["total_cnt"].HeaderText = "总数";
  597. grdEntityCoverage.Columns["total_cnt"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
  598. grdEntityCoverage.Columns["total_cnt"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
  599. grdEntityCoverage.Columns["cover_pct"].HeaderText = "覆盖率%";
  600. grdEntityCoverage.Columns["cover_pct"].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
  601. grdEntityCoverage.Columns["cover_pct"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
  602. grdEntityCoverage.Columns["company_asset_size_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  603. grdEntityCoverage.Columns["cover_pct"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  604. }
  605. private void LoadAuthrizedCompanyList()
  606. {
  607. authorizedCompanyTable = DataAccess.Get_dm_company_authorization(null, null);
  608. }
  609. private void LoadAuthrizedFundList()
  610. {
  611. authorizedFundTable = DataAccess.Get_dm_fund_authorization(null);
  612. }
  613. private void LoadAuthorizedCompanyGrid()
  614. {
  615. if (authorizedCompanyTable != null)
  616. {
  617. DataTable dt = null;
  618. string selectExp = CompanySizeFilter();
  619. string nameExp = txtLocateEntity.Text.Trim();
  620. if (nameExp.Length > 0) selectExp += " and company_short_name LIKE '%" + nameExp + "%'";
  621. DataRow[] dr = authorizedCompanyTable.Select(selectExp, "company_asset_size DESC");
  622. if (dr != null && dr.Length > 0) dt = dr.CopyToDataTable();
  623. grdAuthorizedEntity.DataSource = dt;
  624. if (dt != null)
  625. {
  626. grdAuthorizedEntity.Columns["company_id"].Visible = false;
  627. grdAuthorizedEntity.Columns["company_name"].Visible = false;
  628. grdAuthorizedEntity.Columns["company_short_name"].HeaderText = "公司简称";
  629. grdAuthorizedEntity.Columns["company_asset_size"].Visible = false;
  630. grdAuthorizedEntity.Columns["company_asset_size_name"].HeaderText = "规模";
  631. grdAuthorizedEntity.Columns["register_number"].HeaderText = "协会编号";
  632. grdAuthorizedEntity.Columns["establish_date"].HeaderText = "成立日";
  633. grdAuthorizedEntity.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  634. grdAuthorizedEntity.Columns["company_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  635. }
  636. }
  637. }
  638. private void LoadAuthorizedFundGrid()
  639. {
  640. if (authorizedFundTable != null)
  641. {
  642. DataTable dt = null;
  643. string selectExp = CompanySizeFilter();
  644. string nameExp = txtLocateEntity.Text.Trim();
  645. if (nameExp.Length > 0) selectExp += " and fund_short_name LIKE '%" + nameExp + "%'";
  646. DataRow[] dr = authorizedFundTable.Select(selectExp, "company_asset_size DESC");
  647. if (dr != null && dr.Length > 0) dt = dr.CopyToDataTable();
  648. grdAuthorizedEntity.DataSource = dt;
  649. if (dt != null)
  650. {
  651. grdAuthorizedEntity.Columns["fund_id"].Visible = false;
  652. grdAuthorizedEntity.Columns["fund_name"].Visible = false;
  653. grdAuthorizedEntity.Columns["fund_short_name"].HeaderText = "基金简称";
  654. grdAuthorizedEntity.Columns["company_asset_size"].Visible = false;
  655. grdAuthorizedEntity.Columns["strategy"].Visible = false;
  656. grdAuthorizedEntity.Columns["substrategy"].HeaderText = "二级分类";
  657. grdAuthorizedEntity.Columns["inception_date"].HeaderText = "成立日";
  658. grdAuthorizedEntity.Columns["register_number"].HeaderText = "备案编码";
  659. grdAuthorizedEntity.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  660. grdAuthorizedEntity.Columns["fund_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  661. }
  662. }
  663. }
  664. private void btnEntityCoverage_Click(object sender, EventArgs e)
  665. {
  666. // 左下角的固定格式覆盖率表
  667. LoadEntityCoverageGrid();
  668. if (rdbCompany.Checked)
  669. {
  670. // 授权公司数据
  671. LoadAuthrizedCompanyList();
  672. // 对公司覆盖率表进行可视化 (PIE)
  673. LoadCompanyCoverageChart();
  674. // 授权公司列表
  675. LoadAuthorizedCompanyGrid();
  676. }
  677. else
  678. {
  679. // 授权基金数据
  680. LoadAuthrizedFundList();
  681. // 对基金覆盖率表进行可视化(BAR)
  682. LoadFundCoverageChart();
  683. // 授权基金列表
  684. LoadAuthorizedFundGrid();
  685. }
  686. }
  687. private void rdbCompany_CheckedChanged(object sender, EventArgs e)
  688. {
  689. btnEntityCoverage_Click(sender, e);
  690. }
  691. private void chk100_CheckedChanged(object sender, EventArgs e)
  692. {
  693. if (((Control)sender).Focus())
  694. {
  695. if (rdbCompany.Checked)
  696. {
  697. // 重新画图
  698. LoadCompanyCoverageChart();
  699. // 刷新公司列表
  700. LoadAuthorizedCompanyGrid();
  701. }
  702. else
  703. {
  704. // 重新画图
  705. LoadFundCoverageChart();
  706. // 刷新基金列表
  707. LoadAuthorizedFundGrid();
  708. }
  709. }
  710. }
  711. private void chk50_CheckedChanged(object sender, EventArgs e)
  712. {
  713. chk100_CheckedChanged(sender, e);
  714. }
  715. private void chk20_CheckedChanged(object sender, EventArgs e)
  716. {
  717. chk100_CheckedChanged(sender, e);
  718. }
  719. private void chk10_CheckedChanged(object sender, EventArgs e)
  720. {
  721. chk100_CheckedChanged(sender, e);
  722. }
  723. private void chk5_CheckedChanged(object sender, EventArgs e)
  724. {
  725. chk100_CheckedChanged(sender, e);
  726. }
  727. private void chk0_CheckedChanged(object sender, EventArgs e)
  728. {
  729. chk100_CheckedChanged(sender, e);
  730. }
  731. private void txtLocateEntity_TextChanged(object sender, EventArgs e)
  732. {
  733. if (rdbCompany.Checked) LoadAuthorizedCompanyGrid();
  734. else LoadAuthorizedFundGrid();
  735. }
  736. private void grdAuthorizedEntity_CellClick(object sender, DataGridViewCellEventArgs e)
  737. {
  738. int rowIndex = e.RowIndex;
  739. int columnIndex = e.ColumnIndex;
  740. if (columnIndex < 0 || rowIndex < 0) return;
  741. DataGridViewRow row = grdAuthorizedEntity.Rows[rowIndex];
  742. if (rdbCompany.Checked)
  743. {
  744. string entityId = row.Cells["company_id"].Value.ToString().ToUpper();
  745. if (entityId.Length == 10 && Regex.Match(entityId, "^CO").Success)
  746. {
  747. UICompany frm = new UICompany(entityId, UserId);
  748. frm.Show();
  749. }
  750. }
  751. else
  752. {
  753. string entityId = row.Cells["fund_id"].Value.ToString().ToUpper();
  754. if (entityId.Length == 10 && Regex.Match(entityId, "^[H|M]F").Success)
  755. {
  756. UIFund frm = new UIFund(entityId, UserId);
  757. frm.Show();
  758. }
  759. }
  760. }
  761. private void rdbFund_CheckedChanged(object sender, EventArgs e)
  762. {
  763. // DO NOTHING, because same actions were triggered by rdbCompany_CheckedChanged anyway
  764. }
  765. #endregion
  766. #endregion
  767. }
  768. }