DataManager.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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.Forms;
  11. using static DataManager.DataAccess;
  12. using static DataManager.UIConstants;
  13. namespace DataManager
  14. {
  15. public partial class frmDataManager : Form
  16. {
  17. private DateTime defaultDatetime = DateTime.Now.AddDays(-30);
  18. private DataTable collectionTaskTable = new DataTable();
  19. private DataTable contactTaskTable;
  20. private static int userId;
  21. public static int UserId { get => userId; set => userId = value; }
  22. public frmDataManager(int userid)
  23. {
  24. UserId = userid;
  25. InitializeComponent();
  26. InitializeData();
  27. }
  28. private void InitializeData()
  29. {
  30. #region Contact Task Tab
  31. DataTable dt_dm_user_1 = DataAccess.Get_dm_user(null, 1);
  32. dt_dm_user_1.Rows.Add(DataAccess.DM_NULL, 1, "全部");
  33. cmbContactor.DataSource = dt_dm_user_1;
  34. cmbContactor.DisplayMember = "username";
  35. cmbContactor.ValueMember = "userid";
  36. cmbContactor.SelectedValue = UserId;
  37. dtpContactTaskDate.Value = defaultDatetime;
  38. BindingSource bs4 = new BindingSource();
  39. Dictionary<int, string> d4 = new Dictionary<int, string>(ContactTaskType);
  40. d4.Add(DM_NULL, "全部");
  41. bs4.DataSource = d4;
  42. cmbContactTaskType.DataSource = bs4;
  43. cmbContactTaskType.DisplayMember = "Value";
  44. cmbContactTaskType.ValueMember = "Key";
  45. cmbContactTaskType.SelectedValue = (int)DM_NULL;
  46. BindingSource bs = new BindingSource();
  47. Dictionary<int, string> d = new Dictionary<int, string>(ContactTaskStatus);
  48. d.Add(DM_NULL, "全部");
  49. bs.DataSource = d;
  50. cmbContactTaskStatus.DataSource = bs;
  51. cmbContactTaskStatus.DisplayMember = "Value";
  52. cmbContactTaskStatus.ValueMember = "Key";
  53. cmbContactTaskStatus.SelectedValue = (int)DM_NULL;
  54. BindingSource bs2 = new BindingSource();
  55. Dictionary<int, string> d2 = new Dictionary<int, string>(TaskPriority);
  56. d2.Add(DM_NULL, "全部");
  57. bs2.DataSource = d2;
  58. cmbContactPriority.DataSource = bs2;
  59. cmbContactPriority.DisplayMember = "Value";
  60. cmbContactPriority.ValueMember = "Key";
  61. cmbContactPriority.SelectedValue = (int)DM_NULL;
  62. BindingSource bs3 = new BindingSource();
  63. Dictionary<int, string> d3 = new Dictionary<int, string>(CompanyAssetSize);
  64. d3.Add(DM_NULL, "全部");
  65. bs3.DataSource = d3;
  66. cmbContactCompanySize.DataSource = bs3;
  67. cmbContactCompanySize.DisplayMember = "Value";
  68. cmbContactCompanySize.ValueMember = "Key";
  69. cmbContactCompanySize.SelectedValue = (int)DM_NULL;
  70. dtpContactFollowUpDate.ShowCheckBox = true;
  71. dtpContactFollowUpDate.Checked = false;
  72. #endregion
  73. #region Collection Task Tab
  74. DataTable dt_dm_user_2 = DataAccess.Get_dm_user(null, 2);
  75. dt_dm_user_2.Rows.Add(DataAccess.DM_NULL, 2, "全部");
  76. cmbCollector.DataSource = dt_dm_user_2;
  77. cmbCollector.DisplayMember = "username";
  78. cmbCollector.ValueMember = "userid";
  79. cmbCollector.SelectedValue = UserId;
  80. dtpCollectionTaskDate.Value = defaultDatetime;
  81. BindingSource bs5 = new BindingSource();
  82. Dictionary<int, string> d5 = new Dictionary<int, string>(CollectionTaskType);
  83. d5.Add(DM_NULL, "全部");
  84. bs5.DataSource = d5;
  85. cmbCollectionTaskType.DataSource = bs5;
  86. cmbCollectionTaskType.DisplayMember = "Value";
  87. cmbCollectionTaskType.ValueMember = "Key";
  88. cmbCollectionTaskType.SelectedValue = (int)DM_NULL;
  89. BindingSource bs6 = new BindingSource();
  90. Dictionary<int, string> d6 = new Dictionary<int, string>(CollectionTaskStatus);
  91. d6.Add(DM_NULL, "全部");
  92. bs6.DataSource = d6;
  93. cmbCollectionTaskStatus.DataSource = bs6;
  94. cmbCollectionTaskStatus.DisplayMember = "Value";
  95. cmbCollectionTaskStatus.ValueMember = "Key";
  96. cmbCollectionTaskStatus.SelectedValue = (int)DM_NULL;
  97. #endregion
  98. }
  99. #region Contact Tab
  100. private void LoadContactTaskGrid()
  101. {
  102. ContactTask task = CreateContactTaskFromUI();
  103. int? userid = task.UserId;
  104. if (userid == DM_NULL) userid = null;
  105. short? taskType = task.TaskType;
  106. if(taskType == DM_NULL) taskType = null;
  107. sbyte? isvalid = task.Isvalid;
  108. if(isvalid == DM_NULL) isvalid = null;
  109. sbyte? priority = task.Priority;
  110. if (priority == DM_NULL) priority = null;
  111. sbyte? companyAssetSize = task.CompanyAssetSize;
  112. if(companyAssetSize == DM_NULL) companyAssetSize = null;
  113. contactTaskTable = DataAccess.Get_dm_contact_task(userid, null, task.CompanyId, task.CompanyShortName,
  114. task.TaskDate, taskType, isvalid, priority,
  115. task.FollowUpDate, companyAssetSize);
  116. grdContactTask.DataSource = contactTaskTable;
  117. grdContactTask.Columns["task_id"].HeaderText = "ID";
  118. grdContactTask.Columns["company_short_name"].HeaderText = "公司";
  119. grdContactTask.Columns["task_date"].HeaderText = "日期";
  120. grdContactTask.Columns["task_type_name"].HeaderText = "任务";
  121. grdContactTask.Columns["isvalid_name"].HeaderText = "状态";
  122. grdContactTask.Columns["priority_name"].HeaderText = "优先级";
  123. grdContactTask.Columns["follow_up_date"].HeaderText = "跟进日";
  124. grdContactTask.Columns["company_asset_size_name"].HeaderText = "规模";
  125. grdContactTask.Columns["creator_name"].HeaderText = "创建";
  126. grdContactTask.Columns["updater_name"].HeaderText = "更新";
  127. grdContactTask.Columns["updatetime"].HeaderText = "更新时间";
  128. grdContactTask.Columns["company_id"].Visible = false;
  129. grdContactTask.Columns["task_type"].Visible = false;
  130. grdContactTask.Columns["isvalid"].Visible = false;
  131. grdContactTask.Columns["priority"].Visible = false;
  132. grdContactTask.Columns["company_asset_size"].Visible = false;
  133. grdContactTask.Columns["creatorid"].Visible = false;
  134. grdContactTask.Columns["createtime"].Visible = false;
  135. grdContactTask.Columns["updaterid"].Visible = false;
  136. grdContactTask.Columns["company_short_name"].DefaultCellStyle.ForeColor = Color.DodgerBlue;
  137. grdContactTask.Columns["company_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
  138. lblContactTaskCount.Text = contactTaskTable.Rows.Count.ToString();
  139. }
  140. private ContactTask CreateContactTaskFromUI()
  141. {
  142. ContactTask task = new ContactTask();
  143. task.UserId = int.Parse(cmbContactor.SelectedValue.ToString());
  144. // 支持输 company_id或简称关键字的搜索
  145. string keywrod = txtContactCompany.Text.Trim();
  146. if (keywrod == String.Empty)
  147. {
  148. task.CompanyId = null;
  149. task.CompanyShortName = null;
  150. } else if (keywrod.Length == 10 && keywrod.ToUpper().Substring(0, 2) == "CO")
  151. {
  152. task.CompanyId = keywrod.ToUpper();
  153. task.CompanyShortName = null;
  154. } else
  155. {
  156. task.CompanyId = null;
  157. task.CompanyShortName = keywrod;
  158. }
  159. task.TaskDate = DateTime.Parse(dtpContactTaskDate.Text.ToString());
  160. task.TaskType = short.Parse(cmbContactTaskType.SelectedValue.ToString());
  161. task.Isvalid = sbyte.Parse(cmbContactTaskStatus.SelectedValue.ToString());
  162. task.Priority = sbyte.Parse(cmbContactPriority.SelectedValue.ToString());
  163. task.CompanyAssetSize = sbyte.Parse(cmbContactCompanySize.SelectedValue.ToString());
  164. if (dtpContactFollowUpDate.Checked == true)
  165. {
  166. task.FollowUpDate = DateTime.Parse(dtpContactFollowUpDate.Text.ToString());
  167. } else {
  168. task.FollowUpDate = null;
  169. };
  170. return task;
  171. }
  172. private void btnContactSearch_Click(object sender, EventArgs e)
  173. {
  174. LoadContactTaskGrid();
  175. }
  176. private void grdContactTask_CellClick(object sender, DataGridViewCellEventArgs e)
  177. {
  178. int rowIndex = e.RowIndex;
  179. int columnIndex = e.ColumnIndex;
  180. if (columnIndex < 0 || rowIndex < 0) return;
  181. DataRow row = contactTaskTable.Rows[rowIndex];
  182. if (columnIndex == grdContactTask.Columns["company_short_name"].Index)
  183. // 弹出公司页面
  184. {
  185. UICompany frmCompany = new UICompany(row.Field<string>("company_id"), UserId);
  186. frmCompany.Show();
  187. }
  188. else
  189. // 弹出联系任务编辑框
  190. {
  191. ContactTask task = new ContactTask(UserId, row.Field<int>("task_id"), row.Field<string>("company_id"), row.Field<string>("company_short_name"),
  192. row.Field<DateTime>("task_date"), row.Field<short>("task_type"), row.Field<sbyte>("isvalid"), row.Field<sbyte>("priority"),
  193. row.Field<DateTime?>("follow_up_date"), row.Field<sbyte?>("company_asset_size"),
  194. row.Field<int?>("creatorid"), row.Field<string>("creator_name"), row.Field<DateTime?>("createtime"),
  195. row.Field<int?>("updaterid"), row.Field<string>("updater_name"), row.Field<DateTime?>("updatetime"));
  196. if (task != null)
  197. {
  198. frmContactTask ctk = new frmContactTask(task);
  199. ctk.ShowDialog();
  200. // 刷新 grid 数据
  201. if (ctk.DialogResult == DialogResult.OK)
  202. {
  203. LoadContactTaskGrid();
  204. }
  205. }
  206. }
  207. }
  208. private void btnAddContactTask_Click(object sender, EventArgs e)
  209. {
  210. frmContactTask ctk = new frmContactTask(UserId);
  211. ctk.ShowDialog();
  212. // 刷新 grid 数据
  213. if (ctk.DialogResult == DialogResult.OK)
  214. {
  215. LoadContactTaskGrid();
  216. }
  217. }
  218. #endregion
  219. #region Collection Tab
  220. private void LoadCollectionTaskGrid()
  221. {
  222. CollectionTask task = CreatecCollectionTaskFromUI();
  223. int? userId = task.UserId;
  224. if (userId == DM_NULL) userId = null;
  225. short? taskType = task.TaskType;
  226. if (taskType == DM_NULL) taskType = null;
  227. sbyte? isvalid = task.Isvalid;
  228. if (isvalid == DM_NULL) isvalid = null;
  229. collectionTaskTable = DataAccess.Get_dm_collection_task(userId, null, task.ProviderId, task.ProviderName,
  230. task.TaskDate, taskType, task.EntityId, task.EntityName,
  231. isvalid);
  232. grdCollectionTask.DataSource = collectionTaskTable;
  233. grdCollectionTask.Columns["task_id"].HeaderText = "ID";
  234. grdCollectionTask.Columns["provider_name"].HeaderText = "来源";
  235. grdCollectionTask.Columns["task_date"].HeaderText = "日期";
  236. grdCollectionTask.Columns["task_type_name"].HeaderText = "任务";
  237. grdCollectionTask.Columns["entity_name"].HeaderText = "主题";
  238. grdCollectionTask.Columns["err_message"].HeaderText = "详情";
  239. grdCollectionTask.Columns["isvalid_name"].HeaderText = "状态";
  240. grdCollectionTask.Columns["creator_name"].HeaderText = "创建";
  241. grdCollectionTask.Columns["updater_name"].HeaderText = "更新";
  242. grdCollectionTask.Columns["updatetime"].HeaderText = "更新时间";
  243. grdCollectionTask.Columns["provider_id"].Visible = false;
  244. grdCollectionTask.Columns["task_type"].Visible = false;
  245. grdCollectionTask.Columns["entity_id"].Visible = false;
  246. grdCollectionTask.Columns["isvalid"].Visible = false;
  247. grdCollectionTask.Columns["creatorid"].Visible = false;
  248. grdCollectionTask.Columns["createtime"].Visible = false;
  249. grdCollectionTask.Columns["updaterid"].Visible = false;
  250. //grdCollectionTask.Columns["provider_name"].DefaultCellStyle.ForeColor = Color.DodgerBlue;
  251. grdCollectionTask.Columns["entity_name"].DefaultCellStyle.ForeColor = Color.DodgerBlue;
  252. grdCollectionTask.Columns["entity_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
  253. lblCollectionTaskCount.Text = collectionTaskTable.Rows.Count.ToString();
  254. }
  255. private CollectionTask CreatecCollectionTaskFromUI()
  256. {
  257. CollectionTask task = new CollectionTask();
  258. task.UserId = int.Parse(cmbCollector.SelectedValue.ToString());
  259. string providerKeyword = txtCollectionProvider.Text.Trim();
  260. if (providerKeyword == string.Empty)
  261. {
  262. task.ProviderId = null;
  263. task.ProviderName = null;
  264. }
  265. else if (providerKeyword.Length == 10 && providerKeyword.Substring(0, 2).ToUpper() == "CO")
  266. {
  267. task.ProviderId = providerKeyword.ToUpper();
  268. task.ProviderName = null;
  269. }
  270. else
  271. {
  272. task.ProviderId = null;
  273. task.ProviderName = providerKeyword;
  274. }
  275. task.TaskDate = DateTime.Parse(dtpCollectionTaskDate.Text.ToString());
  276. task.TaskType = short.Parse(cmbCollectionTaskType.SelectedValue.ToString());
  277. // 支持输入fund_id或简称关键字的搜索
  278. string entityKeyword = txtCollectionEntity.Text.Trim();
  279. if (entityKeyword == string.Empty)
  280. {
  281. task.EntityId = null;
  282. task.EntityName = null;
  283. }
  284. else if (entityKeyword.Length == 10 && Regex.Match(entityKeyword.ToUpper(), "^[M|H]F").Success)
  285. {
  286. task.EntityId = entityKeyword.ToUpper();
  287. task.EntityName = null;
  288. }
  289. else
  290. {
  291. task.EntityId = null;
  292. task.EntityName = entityKeyword;
  293. }
  294. task.Isvalid = sbyte.Parse(cmbCollectionTaskStatus.SelectedValue.ToString());
  295. return task;
  296. }
  297. private void btnCollectionSearch_Click(object sender, EventArgs e)
  298. {
  299. LoadCollectionTaskGrid();
  300. }
  301. private void grdCollectionTask_CellClick(object sender, DataGridViewCellEventArgs e)
  302. {
  303. int rowIndex = e.RowIndex;
  304. int columnIndex = e.ColumnIndex;
  305. if (columnIndex < 0 || rowIndex < 0) return;
  306. DataRow row = collectionTaskTable.Rows[rowIndex];
  307. if (columnIndex == grdCollectionTask.Columns["entity_name"].Index )
  308. // 弹出基金页面
  309. {
  310. string entityId = row["entity_id"].ToString();
  311. if (entityId.Length == 10 && Regex.Match(entityId, "^[HM]F").Success)
  312. {
  313. UIFund frmFund = new UIFund(entityId, UserId);
  314. frmFund.Show();
  315. }
  316. }
  317. else
  318. // 弹出采集任务编辑框
  319. {
  320. CollectionTask task = new CollectionTask(UserId, row.Field<int>("task_id"), row.Field<string>("provider_id"), row.Field<string>("provider_name"),
  321. row.Field<DateTime>("task_date"), row.Field<short>("task_type"),
  322. row.Field<string>("entity_id"), row.Field<string>("entity_name"),
  323. row.Field<string>("err_message"), row.Field<sbyte>("isvalid"),
  324. row.Field<int?>("creatorid"), row.Field<string>("creator_name"), row.Field<DateTime?>("createtime"),
  325. row.Field<int?>("updaterid"), row.Field<string>("updater_name"), row.Field<DateTime?>("updatetime"));
  326. if (task != null)
  327. {
  328. UICollectionTask ctk = new UICollectionTask(task);
  329. ctk.ShowDialog();
  330. // 刷新 grid 数据
  331. if (ctk.DialogResult == DialogResult.OK)
  332. {
  333. LoadCollectionTaskGrid();
  334. }
  335. }
  336. }
  337. }
  338. private void btnAddCollectionTask_Click(object sender, EventArgs e)
  339. {
  340. UICollectionTask ctk = new UICollectionTask(UserId);
  341. ctk.ShowDialog();
  342. // 刷新 grid 数据
  343. if (ctk.DialogResult == DialogResult.OK)
  344. {
  345. LoadCollectionTaskGrid();
  346. }
  347. }
  348. #endregion
  349. #region Data - Fund
  350. private void LoadFundGrid()
  351. {
  352. string keyword = txtFundKeyword.Text.Trim();
  353. if (keyword == string.Empty) { keyword = null; }
  354. // 只搜私募
  355. DataTable dt = DataAccess.Search_dm_fund(RaiseType.FirstOrDefault(x=>x.Value== "私募").Key, keyword);
  356. grdFundList.DataSource = dt;
  357. grdFundList.DefaultCellStyle.ForeColor = Color.DimGray;
  358. grdFundList.Columns["fund_id"].Visible = false;
  359. grdFundList.Columns["fund_name"].HeaderText = "基金全名";
  360. grdFundList.Columns["fund_short_name"].HeaderText = "基金简称";
  361. grdFundList.Columns["company_id"].Visible = false;
  362. grdFundList.Columns["company_short_name"].HeaderText = "公司简称";
  363. grdFundList.Columns["strategy"].HeaderText = "策略分类";
  364. grdFundList.Columns["substrategy"].HeaderText = "二级分类";
  365. grdFundList.Columns["max_price_date"].HeaderText = "最新净值";
  366. grdFundList.Columns["company_short_name"].DefaultCellStyle.ForeColor = Color.DodgerBlue;
  367. grdFundList.Columns["max_price_date"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  368. grdFundList.Columns["fund_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  369. ToolStripStatusLabel label = new ToolStripStatusLabel();
  370. label.Text = "记录条数:" + dt.Rows.Count.ToString();
  371. sstData.Items.Clear();
  372. sstData.Items.Add(label);
  373. }
  374. private void btnSearchFund_Click(object sender, EventArgs e)
  375. {
  376. LoadFundGrid();
  377. }
  378. private void grdFundList_CellClick(object sender, DataGridViewCellEventArgs e)
  379. {
  380. int rowIndex = e.RowIndex;
  381. int columnIndex = e.ColumnIndex;
  382. if (columnIndex < 0 || rowIndex < 0) return;
  383. DataGridViewRow row = grdFundList.Rows[rowIndex];
  384. if (columnIndex == grdFundList.Columns["company_short_name"].Index)
  385. // 弹出公司页面
  386. {
  387. string entityId = row.Cells["company_id"].Value.ToString().ToUpper();
  388. if (entityId.Length == 10 && Regex.Match(entityId, "^CO").Success)
  389. {
  390. UICompany frm = new UICompany(entityId, UserId);
  391. frm.Show();
  392. }
  393. }
  394. else
  395. // 弹出基金页面
  396. {
  397. string entityId = row.Cells["fund_id"].Value.ToString().ToUpper();
  398. if (entityId.Length == 10 && Regex.Match(entityId, "^[M|H]F").Success)
  399. {
  400. UIFund frm = new UIFund(entityId, UserId);
  401. frm.Show();
  402. }
  403. }
  404. }
  405. #endregion
  406. #region Data - Company
  407. private void LoadCompanyGrid()
  408. {
  409. string keyword = txtCompanyKeyword.Text.Trim();
  410. if (keyword == string.Empty) { keyword = null; }
  411. // 只搜私募
  412. DataTable dt = DataAccess.Search_dm_company(1, keyword);
  413. grdCompanyList.DataSource = dt;
  414. grdCompanyList.DefaultCellStyle.ForeColor = Color.DimGray;
  415. grdCompanyList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  416. //grdCompanyList.Columns["company_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
  417. grdCompanyList.Columns["company_id"].Visible = false;
  418. grdCompanyList.Columns["company_name"].HeaderText = "公司全名";
  419. grdCompanyList.Columns["company_short_name"].HeaderText = "公司简称";
  420. grdCompanyList.Columns["company_asset_size"].Visible = false;
  421. grdCompanyList.Columns["company_asset_size_name"].HeaderText = "管理规模";
  422. grdCompanyList.Columns["company_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  423. ToolStripStatusLabel label = new ToolStripStatusLabel();
  424. label.Text = "记录条数:" + dt.Rows.Count.ToString();
  425. sstData.Items.Clear();
  426. sstData.Items.Add(label);
  427. }
  428. private void btnSearchCompany_Click(object sender, EventArgs e)
  429. {
  430. LoadCompanyGrid();
  431. }
  432. #endregion
  433. private void grdCompanyList_CellClick(object sender, DataGridViewCellEventArgs e)
  434. {
  435. int rowIndex = e.RowIndex;
  436. int columnIndex = e.ColumnIndex;
  437. if (columnIndex < 0 || rowIndex < 0) return;
  438. DataGridViewRow row = grdCompanyList.Rows[rowIndex];
  439. string entityId = row.Cells["company_id"].Value.ToString().ToUpper();
  440. if (entityId.Length == 10 && Regex.Match(entityId, "^CO").Success)
  441. {
  442. UICompany frm = new UICompany(entityId, UserId);
  443. frm.Show();
  444. }
  445. }
  446. }
  447. }