DDQ.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. using Org.BouncyCastle.Asn1.Pkcs;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Security.Policy;
  9. using System.Text;
  10. using System.Text.Json;
  11. using System.Text.RegularExpressions;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using static ddq.DataAccess;
  15. using static ddq.Utility;
  16. namespace ddq
  17. {
  18. public partial class frmMain : Form
  19. {
  20. // 先hard-code公司ID,以后要按照登录用户来判断它的公司归属
  21. private string companyId = "CO000201PR";
  22. private int userId = 123;
  23. private DataTable fundDataTable;
  24. private DataTable peopleDataTable;
  25. public frmMain()
  26. {
  27. InitializeComponent();
  28. InitializeData();
  29. }
  30. private void InitializeData()
  31. {
  32. }
  33. private void tbcMain_SelectedIndexChanged(object sender, EventArgs e)
  34. {
  35. // Request
  36. if (tbcMain.SelectedIndex == 0) { }
  37. // Data
  38. else if (tbcMain.SelectedIndex == 1)
  39. {
  40. LoadFundList(companyId);
  41. }
  42. // Setting
  43. else { };
  44. }
  45. private void tbcData_SelectedIndexChanged(object sender, EventArgs e)
  46. {
  47. if (tbcData.SelectedIndex == 0)
  48. {
  49. LoadFundList(companyId);
  50. }
  51. else if (tbcData.SelectedIndex == 1)
  52. {
  53. LoadPeopleList(companyId);
  54. }
  55. else if (tbcData.SelectedIndex == 2)
  56. {
  57. InitCompanyData(companyId);
  58. }
  59. }
  60. //
  61. // Fund
  62. //
  63. private void LoadFundList(string companyId)
  64. {
  65. if (fundDataTable == null)
  66. {
  67. fundDataTable = DataAccess.Get_fund_list_by_company(companyId, 1, 1000);
  68. InitFundListGrid(fundDataTable);
  69. }
  70. }
  71. private void InitFundListGrid(DataTable dt)
  72. {
  73. this.grdFundList.DataSource = dt;
  74. this.grdFundList.Columns["fund_id"].Visible = true;
  75. this.grdFundList.Columns["company_id"].Visible = false;
  76. this.grdFundList.Columns["fund_short_name"].HeaderText = "Fund Name";
  77. this.grdFundList.Columns["fund_status"].HeaderText = "Operating Status";
  78. this.grdFundList.Columns["management_start_date"].HeaderText = "Inception Date";
  79. this.grdFundList.Columns["management_start_date"].DefaultCellStyle.Format = "yyyy-MM-dd";
  80. this.grdFundList.Columns["management_end_date"].HeaderText = "Liquidate Date";
  81. this.grdFundList.Columns["management_end_date"].DefaultCellStyle.Format = "yyyy-MM-dd";
  82. this.grdFundList.Columns["ret_tenure"].HeaderText = "Return Since Inception";
  83. this.grdFundList.Columns["ret_tenure"].DefaultCellStyle.Format = "P1";
  84. }
  85. private void grdFundList_CellContentClick(object sender, DataGridViewCellEventArgs e)
  86. {
  87. int rowIndex = e.RowIndex;
  88. int columnIndex = e.ColumnIndex;
  89. if (columnIndex < 0 || rowIndex < 0) return;
  90. DataRow row = fundDataTable.Rows[rowIndex];
  91. // 弹出基金页面
  92. string entityId = row["fund_id"].ToString();
  93. if (entityId.Length == 10 && Regex.Match(entityId, "^[HM]F").Success)
  94. {
  95. FundQ fundQ = new FundQ(entityId, companyId, userId);
  96. fundQ.Show();
  97. }
  98. }
  99. //
  100. // People
  101. //
  102. private void LoadPeopleList(string companyId)
  103. {
  104. if (peopleDataTable == null)
  105. {
  106. peopleDataTable = DataAccess.Get_dd_personnel_info(null, companyId);
  107. InitPeopleListGrid(peopleDataTable);
  108. }
  109. }
  110. private void InitPeopleListGrid(DataTable dt)
  111. {
  112. this.grdPeopleList.DataSource = dt;
  113. this.grdPeopleList.Columns["personnel_id"].Visible = false;
  114. this.grdPeopleList.Columns["company_id"].Visible = false;
  115. this.grdPeopleList.Columns["role"].Visible = false;
  116. this.grdPeopleList.Columns["name"].HeaderText = "Name";
  117. this.grdPeopleList.Columns["role_desc"].HeaderText = "Role";
  118. this.grdPeopleList.Columns["title"].HeaderText = "Title";
  119. this.grdPeopleList.Columns["industry_start_year"].HeaderText = "Industry Start Year";
  120. this.grdPeopleList.Columns["company_start_year"].HeaderText = "Company Start Year";
  121. this.grdPeopleList.Columns["bio"].HeaderText = "Bio";
  122. }
  123. private void btnAddPersonn_Click(object sender, EventArgs e)
  124. {
  125. LoadPersonnelQ(null);
  126. }
  127. private void grdPeopleList_CellClick(object sender, DataGridViewCellEventArgs e)
  128. {
  129. int rowIndex = e.RowIndex;
  130. if (rowIndex < 0) return;
  131. string personnelId = peopleDataTable.Rows[rowIndex]["personnel_id"].ToString();
  132. LoadPersonnelQ(personnelId);
  133. }
  134. private void LoadPersonnelQ(string personnelId)
  135. {
  136. using (PersonnelQ dialog = new PersonnelQ(personnelId, this.companyId, this.userId))
  137. {
  138. dialog.StartPosition = FormStartPosition.CenterParent;
  139. DialogResult result = dialog.ShowDialog(this);
  140. if (result == DialogResult.OK)
  141. {
  142. peopleDataTable = DataAccess.Get_dd_personnel_info(null, this.companyId);
  143. this.grdPeopleList.DataSource = peopleDataTable;
  144. }
  145. }
  146. }
  147. //
  148. // Company
  149. //
  150. private void InitCompanyData(string companyId)
  151. {
  152. DataTable dt = DataAccess.Get_dd_company_info(companyId, null, 1);
  153. if (dt == null || dt.Rows.Count <= 0) return;
  154. if (dt != null && dt.Rows.Count > 0)
  155. {
  156. string jsonString = dt.Rows[0].Field<string>("info").Trim();
  157. JsonDocument document = JsonDocument.Parse(jsonString);
  158. JsonElement root = document.RootElement;
  159. if (root.ValueKind != JsonValueKind.Undefined)
  160. {
  161. //
  162. // General Info
  163. //
  164. Utility.DDData dddata = Utility.Json2Text2(root, "foundingDate");
  165. if (dddata != null)
  166. {
  167. bool isDate = DateTime.TryParse(dddata.value.ToString(), out DateTime newDate);
  168. if (isDate)
  169. {
  170. this.dtpIncepionDate.Value = newDate.Date;
  171. this.tspInceptionDate.Text = dddata.updateTime;
  172. this.tspInceptionDate.ForeColor = Utility.IsChangedRecently(dddata.updateTime) ? Color.Red : Color.DarkSlateGray;
  173. }
  174. }
  175. this.txtDetailOfAcquired.Text = Utility.Json2Text2(root, "detailOfAcquired").value.ToString();
  176. this.tspDetailOfAcquired.Text = Utility.Json2Text2(root, "detailOfAcquired").updateTime;
  177. this.tspDetailOfAcquired.ForeColor = Utility.IsChangedRecently(this.tspDetailOfAcquired.Text) ? Color.Red : Color.DarkSlateGray;
  178. this.txtParentCompanyName.Text = Utility.Json2Text2(root, "parentCompanyName").value.ToString();
  179. this.tspParentCompanyName.Text = Utility.Json2Text2(root, "parentCompanyName").updateTime;
  180. this.tspParentCompanyName.ForeColor = Utility.IsChangedRecently(this.tspParentCompanyName.Text) ? Color.Red : Color.DarkSlateGray;
  181. LoadAcqusitionGrid(root);
  182. LoadSupportFromParentCompany(root);
  183. LoadFinancialData(root);
  184. LoadCreditRating(root);
  185. LoadCompanyAUM(root);
  186. LoadClientBreakdown(root);
  187. }
  188. }
  189. }
  190. private void LoadAcqusitionGrid(JsonElement jsonElement)
  191. {
  192. bool hasData = jsonElement.TryGetProperty("acqusition", out JsonElement element);
  193. string strUpdateTime = "";
  194. if (hasData == true)
  195. hasData &= element.TryGetProperty("v", out JsonElement elm);
  196. DataTable dt = new DataTable();
  197. if (hasData == true)
  198. {
  199. Utility.DDData dddata = Utility.Json2Table2(element);
  200. if (dddata != null)
  201. {
  202. dt = (DataTable)dddata.value;
  203. strUpdateTime = dddata.updateTime;
  204. }
  205. } else
  206. {
  207. dt.Columns.Add("date", typeof(string));
  208. dt.Columns.Add("action", typeof(string));
  209. }
  210. this.grdAcquisiton.DataSource = dt;
  211. this.grdAcquisiton.Columns["date"].HeaderText = "Date";
  212. this.grdAcquisiton.Columns["date"].DefaultCellStyle.Format = "yyyy-MM-dd";
  213. this.grdAcquisiton.Columns["date"].DisplayIndex = 0;
  214. this.grdAcquisiton.Columns["action"].HeaderText = "Event";
  215. this.grdAcquisiton.Columns["action"].DisplayIndex = 1;
  216. this.tspAcqusition.Text = strUpdateTime;
  217. this.tspAcqusition.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? Color.Red : Color.DarkSlateGray;
  218. }
  219. private void LoadSupportFromParentCompany(JsonElement jsonElement)
  220. {
  221. bool hasData = jsonElement.TryGetProperty("supportFromParent", out JsonElement element);
  222. string strUpdateTime = "";
  223. JsonElement elm = new JsonElement();
  224. if (hasData == true)
  225. hasData &= element.TryGetProperty("v", out elm);
  226. if (hasData == true)
  227. {
  228. this.chkSupportFinancial.Checked = Utility.Json2Boolean(elm, "financial");
  229. this.chkSupportSales.Checked = Utility.Json2Boolean(elm, "sales");
  230. this.chkSupportMarketing.Checked = Utility.Json2Boolean(elm, "marketing"); ;
  231. this.chkSupportTechnical.Checked = Utility.Json2Boolean(elm, "technical"); ;
  232. this.chkSupportPersonnel.Checked = Utility.Json2Boolean(elm, "personnel");
  233. hasData = element.TryGetProperty("t", out elm);
  234. if (hasData == true)
  235. strUpdateTime = elm.ToString();
  236. }
  237. this.tspSupportFromParent.Text = strUpdateTime;
  238. this.tspSupportFromParent.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? Color.Red : Color.DarkSlateGray;
  239. }
  240. private void LoadFinancialData(JsonElement jsonElement)
  241. {
  242. bool hasData = jsonElement.TryGetProperty("financialData", out JsonElement element);
  243. string strUpdateTime = "";
  244. if (hasData == true)
  245. hasData &= element.TryGetProperty("v", out JsonElement elm);
  246. DataTable dt = new DataTable();
  247. if (hasData == true)
  248. {
  249. Utility.DDData dddata = Utility.Json2Table2(element);
  250. if (dddata != null)
  251. {
  252. dt = (DataTable)dddata.value;
  253. strUpdateTime = dddata.updateTime;
  254. }
  255. }
  256. else
  257. {
  258. dt.Columns.Add("year", typeof(int));
  259. dt.Columns.Add("netIncome", typeof(int));
  260. dt.Columns.Add("operatingCashFlow", typeof(int));
  261. dt.Columns.Add("interestCoverageRatio", typeof(decimal));
  262. for (int i = 1; i <= 5; i++)
  263. {
  264. DataRow row = dt.NewRow();
  265. row.SetField("year", DateTime.Today.Year - i);
  266. dt.Rows.Add(row);
  267. }
  268. }
  269. this.grdFinancialData.DataSource = dt;
  270. this.grdFinancialData.Columns["year"].HeaderText = "Year";
  271. this.grdFinancialData.Columns["year"].DisplayIndex = 0;
  272. this.grdFinancialData.Columns["netIncome"].HeaderText = "Net Income (US$ Mil)";
  273. this.grdFinancialData.Columns["netIncome"].DisplayIndex = 1;
  274. this.grdFinancialData.Columns["operatingCashFlow"].HeaderText = "Operating Cash Flow (US$ Mil)";
  275. this.grdFinancialData.Columns["operatingCashFlow"].DisplayIndex = 2;
  276. this.grdFinancialData.Columns["interestCoverageRatio"].HeaderText = "Interest Coverage Ratio (%)";
  277. this.grdFinancialData.Columns["interestCoverageRatio"].DefaultCellStyle.Format = "N2";
  278. this.grdFinancialData.Columns["interestCoverageRatio"].DisplayIndex = 3;
  279. this.tspFinancialData.Text = strUpdateTime;
  280. this.tspFinancialData.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? Color.Red : Color.DarkSlateGray;
  281. }
  282. private void LoadCreditRating(JsonElement jsonElement)
  283. {
  284. bool hasData = jsonElement.TryGetProperty("creditRating", out JsonElement element);
  285. string strUpdateTime = "";
  286. if (hasData == true)
  287. hasData &= element.TryGetProperty("v", out JsonElement elm);
  288. DataTable dt = new DataTable();
  289. if (hasData == true)
  290. {
  291. Utility.DDData dddata = Utility.Json2Table2(element);
  292. if (dddata != null)
  293. {
  294. dt = (DataTable)dddata.value;
  295. strUpdateTime = dddata.updateTime;
  296. }
  297. }
  298. else
  299. {
  300. dt.Columns.Add("agent", typeof(string));
  301. dt.Columns.Add("outlook", typeof(string));
  302. dt.Columns.Add("longTerm", typeof(string));
  303. dt.Columns.Add("shortTerm", typeof(string));
  304. dt.Columns.Add("seniorUnsecured", typeof(string));
  305. dt.Columns.Add("subordinated", typeof(string));
  306. dt.Columns.Add("trustPreferred", typeof(string));
  307. dt.Columns.Add("preferred", typeof(string));
  308. }
  309. this.grdCreditRating.DataSource = dt;
  310. this.grdCreditRating.Columns["agent"].DisplayIndex = 0;
  311. this.grdCreditRating.Columns["outlook"].HeaderText = "Outlook";
  312. this.grdCreditRating.Columns["outlook"].DisplayIndex = 1;
  313. this.grdCreditRating.Columns["longTerm"].HeaderText = "Long-term Issuer Rating";
  314. this.grdCreditRating.Columns["longTerm"].DisplayIndex = 2;
  315. this.grdCreditRating.Columns["shortTerm"].HeaderText = "Short-term Issuer Rating";
  316. this.grdCreditRating.Columns["shortTerm"].DisplayIndex = 3;
  317. this.grdCreditRating.Columns["seniorUnsecured"].HeaderText = "Senior Unsecured";
  318. this.grdCreditRating.Columns["seniorUnsecured"].DisplayIndex = 4;
  319. this.grdCreditRating.Columns["subordinated"].HeaderText = "Sub-ordinated";
  320. this.grdCreditRating.Columns["subordinated"].DisplayIndex = 5;
  321. this.grdCreditRating.Columns["trustPreferred"].HeaderText = "Trust Preferred";
  322. this.grdCreditRating.Columns["trustPreferred"].DisplayIndex = 6;
  323. this.grdCreditRating.Columns["preferred"].HeaderText = "Preferred Stock";
  324. this.grdCreditRating.Columns["preferred"].DisplayIndex = 7;
  325. this.tspCreditRating.Text = strUpdateTime;
  326. this.tspCreditRating.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? Color.Red : Color.DarkSlateGray;
  327. }
  328. private void LoadCompanyAUM(JsonElement jsonElement)
  329. {
  330. bool hasData = jsonElement.TryGetProperty("aum", out JsonElement element);
  331. string strUpdateTime = "";
  332. if (hasData == true)
  333. hasData &= element.TryGetProperty("v", out JsonElement elm);
  334. DataTable dt = new DataTable();
  335. if (hasData == true)
  336. {
  337. Utility.DDData dddata = Utility.Json2Table2(element);
  338. if (dddata != null)
  339. {
  340. dt = (DataTable)dddata.value;
  341. strUpdateTime = dddata.updateTime;
  342. }
  343. }
  344. else
  345. {
  346. for (int i = 1; i <= 5; i++)
  347. {
  348. dt.Columns.Add((DateTime.Today.Year - i).ToString(), typeof(int));
  349. }
  350. dt.Rows.Add(dt.NewRow());
  351. }
  352. this.grdAUM.DataSource = dt;
  353. for (int i = 1; i <= 5; i++)
  354. {
  355. this.grdAUM.Columns[(DateTime.Today.Year - i).ToString()].DisplayIndex = i - 1;
  356. }
  357. this.tspAUM.Text = strUpdateTime;
  358. this.tspAUM.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? Color.Red : Color.DarkSlateGray;
  359. }
  360. private void LoadClientBreakdown(JsonElement jsonElement)
  361. {
  362. bool hasData = jsonElement.TryGetProperty("clientBreakdown", out JsonElement element);
  363. string strUpdateTime = "";
  364. if (hasData == true)
  365. hasData &= element.TryGetProperty("v", out JsonElement elm);
  366. DataTable dt = new DataTable();
  367. if (hasData == true)
  368. {
  369. Utility.DDData dddata = Utility.Json2Table2(element);
  370. if (dddata != null)
  371. {
  372. dt = (DataTable)dddata.value;
  373. strUpdateTime = dddata.updateTime;
  374. }
  375. }
  376. else
  377. {
  378. for (int i = 1; i <= 5; i++)
  379. {
  380. dt.Columns.Add((DateTime.Today.Year - i).ToString(), typeof(int));
  381. }
  382. dt.Columns.Add("type", typeof(string));
  383. DataRow row = dt.NewRow();
  384. row.SetField("type", "Instituional");
  385. dt.Rows.Add(row);
  386. row = dt.NewRow();
  387. row.SetField("type", "Retail");
  388. dt.Rows.Add(row);
  389. }
  390. this.grdClientBreakdown.DataSource = dt;
  391. this.grdClientBreakdown.Columns["type"].HeaderText = "Client Type";
  392. this.grdClientBreakdown.Columns["type"].DisplayIndex = 0;
  393. for (int i = 1; i <= 5; i++)
  394. {
  395. this.grdClientBreakdown.Columns[(DateTime.Today.Year - i).ToString()].DisplayIndex = i;
  396. }
  397. this.tspClientBreakdown.Text = strUpdateTime;
  398. this.tspClientBreakdown.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? Color.Red : Color.DarkSlateGray;
  399. }
  400. private void btnSaveCompany_Click(object sender, EventArgs e)
  401. {
  402. try
  403. {
  404. // 数据对象
  405. var textData = new
  406. {
  407. foundingDate = Utility.AddInfo(this.dtpIncepionDate.Value.Date.ToString("yyyy-MM-dd"), userId),
  408. detailOfAcquired = Utility.AddInfo(this.txtDetailOfAcquired.Text.Trim(), userId),
  409. parentCompanyName = Utility.AddInfo(this.txtParentCompanyName.Text.Trim(), userId),
  410. acqusition = Utility.AddInfo(Utility.DataTable2List((DataTable)this.grdAcquisiton.DataSource), userId),
  411. supportFromParent = Utility.AddInfo(new
  412. {
  413. financial = this.chkSupportFinancial.Checked,
  414. sales = this.chkSupportSales.Checked,
  415. marketing = this.chkSupportMarketing.Checked,
  416. technical = this.chkSupportTechnical.Checked,
  417. personnel = this.chkSupportPersonnel.Checked
  418. }, userId),
  419. financialData = Utility.AddInfo(Utility.DataTable2List((DataTable)this.grdFinancialData.DataSource), userId),
  420. creditRating = Utility.AddInfo(Utility.DataTable2List((DataTable)this.grdCreditRating.DataSource), userId),
  421. aum = Utility.AddInfo(Utility.DataTable2List((DataTable)this.grdAUM.DataSource), userId),
  422. clientBreakdown = Utility.AddInfo(Utility.DataTable2List((DataTable) this.grdClientBreakdown.DataSource), userId)
  423. };
  424. // 序列化选项
  425. var options = new JsonSerializerOptions
  426. {
  427. WriteIndented = true,
  428. PropertyNamingPolicy = JsonNamingPolicy.CamelCase
  429. };
  430. string jsonString = JsonSerializer.Serialize(textData, options);
  431. int ret = DataAccess.Set_dd_company_info(this.companyId, DateTime.Today, jsonString, 1, 1, this.userId);
  432. if (ret == 1)
  433. {
  434. MessageBox.Show("Data is saved successfully", "Information");
  435. }
  436. }
  437. catch (Exception ex)
  438. {
  439. MessageBox.Show($"Error: {ex.Message}", "Error");
  440. }
  441. }
  442. }
  443. }