DDQ.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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 = "CO0002000E";
  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. BindingSource bs = new BindingSource();
  66. Dictionary<int, string> d = new Dictionary<int, string>(Utility.CategoryGroup);
  67. bs.DataSource = d;
  68. this.cmbCategoryGroup.DataSource = bs;
  69. this.cmbCategoryGroup.DisplayMember = "Value";
  70. this.cmbCategoryGroup.ValueMember = "Key";
  71. this.cmbCategoryGroup.SelectedValue = 0;
  72. if (fundDataTable == null)
  73. {
  74. fundDataTable = DataAccess.Get_fund_list_by_company(companyId);
  75. InitFundListGrid(fundDataTable);
  76. }
  77. }
  78. private void InitFundListGrid(DataTable dt)
  79. {
  80. this.grdFundList.DataSource = dt;
  81. this.grdFundList.Columns["fund_id"].Visible = true;
  82. this.grdFundList.Columns["fund_short_name"].HeaderText = "Fund Name";
  83. this.grdFundList.Columns["inception_date"].HeaderText = "Inception Date";
  84. this.grdFundList.Columns["inception_date"].DefaultCellStyle.Format = "yyyy-MM-dd";
  85. this.grdFundList.Columns["strategy_id"].Visible = false;
  86. this.grdFundList.Columns["strategy"].HeaderText = "Broad Asset Group";
  87. this.grdFundList.Columns["domicile"].HeaderText = "Domicile";
  88. this.grdFundList.Columns["base_currency"].HeaderText = "Currency";
  89. this.grdFundList.Columns["status_id"].Visible = false;
  90. this.grdFundList.Columns["status"].HeaderText = "Operating Status";
  91. }
  92. private void grdFundList_CellContentClick(object sender, DataGridViewCellEventArgs e)
  93. {
  94. int rowIndex = e.RowIndex;
  95. int columnIndex = e.ColumnIndex;
  96. if (columnIndex < 0 || rowIndex < 0) return;
  97. DataRow row = fundDataTable.Rows[rowIndex];
  98. // 弹出基金页面
  99. string entityId = row["fund_id"].ToString();
  100. if (entityId.Length == 10 && Regex.Match(entityId, "^[HM]F").Success)
  101. {
  102. FundQ fundQ = new FundQ(entityId, companyId, userId);
  103. fundQ.Show();
  104. }
  105. }
  106. private void cmbCategoryGroup_SelectedIndexChanged(object sender, EventArgs e)
  107. {
  108. string filter = "";
  109. if (fundDataTable != null && fundDataTable.Rows != null && fundDataTable.Rows.Count > 0)
  110. {
  111. if (cmbCategoryGroup.SelectedIndex > 0)
  112. {
  113. filter = "strategy_id = " + cmbCategoryGroup.SelectedValue;
  114. this.fundDataTable.DefaultView.RowFilter = filter;
  115. } else
  116. {
  117. this.fundDataTable.DefaultView.RowFilter = "";
  118. }
  119. }
  120. }
  121. //
  122. // People
  123. //
  124. private void LoadPeopleList(string companyId)
  125. {
  126. if (peopleDataTable == null)
  127. {
  128. peopleDataTable = DataAccess.Get_dd_personnel_info(null, companyId);
  129. InitPeopleListGrid(peopleDataTable);
  130. }
  131. }
  132. private void InitPeopleListGrid(DataTable dt)
  133. {
  134. this.grdPeopleList.DataSource = dt;
  135. this.grdPeopleList.Columns["personnel_id"].Visible = false;
  136. this.grdPeopleList.Columns["company_id"].Visible = false;
  137. this.grdPeopleList.Columns["role"].Visible = false;
  138. this.grdPeopleList.Columns["name"].HeaderText = "Name";
  139. this.grdPeopleList.Columns["role_desc"].HeaderText = "Role";
  140. this.grdPeopleList.Columns["title"].HeaderText = "Title";
  141. this.grdPeopleList.Columns["industry_start_year"].HeaderText = "Industry Start Year";
  142. this.grdPeopleList.Columns["company_start_year"].HeaderText = "Company Start Year";
  143. this.grdPeopleList.Columns["bio"].HeaderText = "Bio";
  144. }
  145. private void btnAddPersonn_Click(object sender, EventArgs e)
  146. {
  147. LoadPersonnelQ(null);
  148. }
  149. private void grdPeopleList_CellClick(object sender, DataGridViewCellEventArgs e)
  150. {
  151. int rowIndex = e.RowIndex;
  152. if (rowIndex < 0) return;
  153. string personnelId = peopleDataTable.Rows[rowIndex]["personnel_id"].ToString();
  154. LoadPersonnelQ(personnelId);
  155. }
  156. private void LoadPersonnelQ(string personnelId)
  157. {
  158. using (PersonnelQ dialog = new PersonnelQ(personnelId, this.companyId, this.userId))
  159. {
  160. dialog.StartPosition = FormStartPosition.CenterParent;
  161. DialogResult result = dialog.ShowDialog(this);
  162. if (result == DialogResult.OK)
  163. {
  164. peopleDataTable = DataAccess.Get_dd_personnel_info(null, this.companyId);
  165. this.grdPeopleList.DataSource = peopleDataTable;
  166. }
  167. }
  168. }
  169. //
  170. // Company
  171. //
  172. private void InitCompanyData(string companyId)
  173. {
  174. DataTable dt = DataAccess.Get_dd_company_info(companyId, null, 1);
  175. if (dt == null || dt.Rows.Count <= 0) return;
  176. if (dt != null && dt.Rows.Count > 0)
  177. {
  178. string jsonString = dt.Rows[0].Field<string>("info").Trim();
  179. JsonDocument document = JsonDocument.Parse(jsonString);
  180. JsonElement root = document.RootElement;
  181. if (root.ValueKind != JsonValueKind.Undefined)
  182. {
  183. //
  184. // General Info
  185. //
  186. LoadDateDataFromJson(this.dtpIncepionDate, root, "foundingDate", this.tspInceptionDate);
  187. LoadTextDataFromJson(this.txtDetailOfAcquired, root, "detailOfAcquired", this.tspDetailOfAcquired);
  188. LoadTextDataFromJson(this.txtParentCompanyName, root, "parentCompanyName", this.tspParentCompanyName);
  189. LoadAcqusitionGrid(root);
  190. LoadSupportFromParentCompany(root);
  191. LoadFinancialData(root);
  192. LoadCreditRating(root);
  193. LoadCompanyAUM(root);
  194. LoadClientBreakdown(root);
  195. }
  196. }
  197. }
  198. private void LoadAcqusitionGrid(JsonElement jsonElement)
  199. {
  200. bool hasData = jsonElement.TryGetProperty("acqusition", out JsonElement element);
  201. string strUpdateTime = "";
  202. if (hasData == true)
  203. hasData &= element.TryGetProperty("v", out JsonElement elm);
  204. DataTable dt = new DataTable();
  205. if (hasData == true)
  206. {
  207. Utility.DDData dddata = Utility.Json2Table2(element);
  208. if (dddata != null)
  209. {
  210. dt = (DataTable)dddata.Value;
  211. strUpdateTime = dddata.UpdateTime;
  212. }
  213. } else
  214. {
  215. dt.Columns.Add("date", typeof(string));
  216. dt.Columns.Add("action", typeof(string));
  217. }
  218. this.grdAcquisiton.DataSource = dt;
  219. this.grdAcquisiton.Columns["date"].HeaderText = "Date";
  220. this.grdAcquisiton.Columns["date"].DefaultCellStyle.Format = "yyyy-MM-dd";
  221. this.grdAcquisiton.Columns["date"].DisplayIndex = 0;
  222. this.grdAcquisiton.Columns["action"].HeaderText = "Event";
  223. this.grdAcquisiton.Columns["action"].DisplayIndex = 1;
  224. this.tspAcqusition.Text = strUpdateTime;
  225. this.tspAcqusition.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? COLOR_MODIFIED : COLOR_NORMAL;
  226. }
  227. private void LoadSupportFromParentCompany(JsonElement jsonElement)
  228. {
  229. bool hasData = jsonElement.TryGetProperty("supportFromParent", out JsonElement element);
  230. string strUpdateTime = "";
  231. JsonElement elm = new JsonElement();
  232. if (hasData == true)
  233. hasData &= element.TryGetProperty("v", out elm);
  234. if (hasData == true)
  235. {
  236. this.chkSupportFinancial.Checked = Utility.Json2Boolean(elm, "financial");
  237. this.chkSupportSales.Checked = Utility.Json2Boolean(elm, "sales");
  238. this.chkSupportMarketing.Checked = Utility.Json2Boolean(elm, "marketing"); ;
  239. this.chkSupportTechnical.Checked = Utility.Json2Boolean(elm, "technical"); ;
  240. this.chkSupportPersonnel.Checked = Utility.Json2Boolean(elm, "personnel");
  241. hasData = element.TryGetProperty("t", out elm);
  242. if (hasData == true)
  243. strUpdateTime = elm.ToString();
  244. }
  245. this.tspSupportFromParent.Text = strUpdateTime;
  246. this.tspSupportFromParent.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? COLOR_MODIFIED : COLOR_NORMAL;
  247. }
  248. private void LoadFinancialData(JsonElement jsonElement)
  249. {
  250. bool hasData = jsonElement.TryGetProperty("financialData", out JsonElement element);
  251. string strUpdateTime = "";
  252. if (hasData == true)
  253. hasData &= element.TryGetProperty("v", out JsonElement elm);
  254. DataTable dt = new DataTable();
  255. if (hasData == true)
  256. {
  257. Utility.DDData dddata = Utility.Json2Table2(element);
  258. if (dddata != null)
  259. {
  260. dt = (DataTable)dddata.Value;
  261. strUpdateTime = dddata.UpdateTime;
  262. }
  263. }
  264. else
  265. {
  266. dt.Columns.Add("year", typeof(int));
  267. dt.Columns.Add("netIncome", typeof(int));
  268. dt.Columns.Add("operatingCashFlow", typeof(int));
  269. dt.Columns.Add("interestCoverageRatio", typeof(decimal));
  270. for (int i = 1; i <= 5; i++)
  271. {
  272. DataRow row = dt.NewRow();
  273. row.SetField("year", DateTime.Today.Year - i);
  274. dt.Rows.Add(row);
  275. }
  276. }
  277. this.grdFinancialData.DataSource = dt;
  278. this.grdFinancialData.Columns["year"].HeaderText = "Year";
  279. this.grdFinancialData.Columns["year"].DisplayIndex = 0;
  280. this.grdFinancialData.Columns["netIncome"].HeaderText = "Net Income (US$ Mil)";
  281. this.grdFinancialData.Columns["netIncome"].DisplayIndex = 1;
  282. this.grdFinancialData.Columns["operatingCashFlow"].HeaderText = "Operating Cash Flow (US$ Mil)";
  283. this.grdFinancialData.Columns["operatingCashFlow"].DisplayIndex = 2;
  284. this.grdFinancialData.Columns["interestCoverageRatio"].HeaderText = "Interest Coverage Ratio (%)";
  285. this.grdFinancialData.Columns["interestCoverageRatio"].DefaultCellStyle.Format = "N2";
  286. this.grdFinancialData.Columns["interestCoverageRatio"].DisplayIndex = 3;
  287. this.tspFinancialData.Text = strUpdateTime;
  288. this.tspFinancialData.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? COLOR_MODIFIED : COLOR_NORMAL;
  289. }
  290. private void LoadCreditRating(JsonElement jsonElement)
  291. {
  292. bool hasData = jsonElement.TryGetProperty("creditRating", out JsonElement element);
  293. string strUpdateTime = "";
  294. if (hasData == true)
  295. hasData &= element.TryGetProperty("v", out JsonElement elm);
  296. DataTable dt = new DataTable();
  297. if (hasData == true)
  298. {
  299. Utility.DDData dddata = Utility.Json2Table2(element);
  300. if (dddata != null)
  301. {
  302. dt = (DataTable)dddata.Value;
  303. strUpdateTime = dddata.UpdateTime;
  304. }
  305. }
  306. else
  307. {
  308. dt.Columns.Add("agent", typeof(string));
  309. dt.Columns.Add("outlook", typeof(string));
  310. dt.Columns.Add("longTerm", typeof(string));
  311. dt.Columns.Add("shortTerm", typeof(string));
  312. dt.Columns.Add("seniorUnsecured", typeof(string));
  313. dt.Columns.Add("subordinated", typeof(string));
  314. dt.Columns.Add("trustPreferred", typeof(string));
  315. dt.Columns.Add("preferred", typeof(string));
  316. }
  317. this.grdCreditRating.DataSource = dt;
  318. this.grdCreditRating.Columns["agent"].DisplayIndex = 0;
  319. this.grdCreditRating.Columns["outlook"].HeaderText = "Outlook";
  320. this.grdCreditRating.Columns["outlook"].DisplayIndex = 1;
  321. this.grdCreditRating.Columns["longTerm"].HeaderText = "Long-term Issuer Rating";
  322. this.grdCreditRating.Columns["longTerm"].DisplayIndex = 2;
  323. this.grdCreditRating.Columns["shortTerm"].HeaderText = "Short-term Issuer Rating";
  324. this.grdCreditRating.Columns["shortTerm"].DisplayIndex = 3;
  325. this.grdCreditRating.Columns["seniorUnsecured"].HeaderText = "Senior Unsecured";
  326. this.grdCreditRating.Columns["seniorUnsecured"].DisplayIndex = 4;
  327. this.grdCreditRating.Columns["subordinated"].HeaderText = "Sub-ordinated";
  328. this.grdCreditRating.Columns["subordinated"].DisplayIndex = 5;
  329. this.grdCreditRating.Columns["trustPreferred"].HeaderText = "Trust Preferred";
  330. this.grdCreditRating.Columns["trustPreferred"].DisplayIndex = 6;
  331. this.grdCreditRating.Columns["preferred"].HeaderText = "Preferred Stock";
  332. this.grdCreditRating.Columns["preferred"].DisplayIndex = 7;
  333. this.tspCreditRating.Text = strUpdateTime;
  334. this.tspCreditRating.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? COLOR_MODIFIED : COLOR_NORMAL;
  335. }
  336. private void LoadCompanyAUM(JsonElement jsonElement)
  337. {
  338. bool hasData = jsonElement.TryGetProperty("aum", out JsonElement element);
  339. string strUpdateTime = "";
  340. if (hasData == true)
  341. hasData &= element.TryGetProperty("v", out JsonElement elm);
  342. DataTable dt = new DataTable();
  343. if (hasData == true)
  344. {
  345. Utility.DDData dddata = Utility.Json2Table2(element);
  346. if (dddata != null)
  347. {
  348. dt = (DataTable)dddata.Value;
  349. strUpdateTime = dddata.UpdateTime;
  350. }
  351. }
  352. else
  353. {
  354. for (int i = 1; i <= 5; i++)
  355. {
  356. dt.Columns.Add((DateTime.Today.Year - i).ToString(), typeof(int));
  357. }
  358. dt.Rows.Add(dt.NewRow());
  359. }
  360. this.grdAUM.DataSource = dt;
  361. for (int i = 1; i <= 5; i++)
  362. {
  363. this.grdAUM.Columns[(DateTime.Today.Year - i).ToString()].DisplayIndex = i - 1;
  364. }
  365. this.tspAUM.Text = strUpdateTime;
  366. this.tspAUM.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? COLOR_MODIFIED : COLOR_NORMAL;
  367. }
  368. private void LoadClientBreakdown(JsonElement jsonElement)
  369. {
  370. bool hasData = jsonElement.TryGetProperty("clientBreakdown", out JsonElement element);
  371. string strUpdateTime = "";
  372. if (hasData == true)
  373. hasData &= element.TryGetProperty("v", out JsonElement elm);
  374. DataTable dt = new DataTable();
  375. if (hasData == true)
  376. {
  377. Utility.DDData dddata = Utility.Json2Table2(element);
  378. if (dddata != null)
  379. {
  380. dt = (DataTable)dddata.Value;
  381. strUpdateTime = dddata.UpdateTime;
  382. }
  383. }
  384. else
  385. {
  386. for (int i = 1; i <= 5; i++)
  387. {
  388. dt.Columns.Add((DateTime.Today.Year - i).ToString(), typeof(int));
  389. }
  390. dt.Columns.Add("type", typeof(string));
  391. DataRow row = dt.NewRow();
  392. row.SetField("type", "Instituional");
  393. dt.Rows.Add(row);
  394. row = dt.NewRow();
  395. row.SetField("type", "Retail");
  396. dt.Rows.Add(row);
  397. }
  398. this.grdClientBreakdown.DataSource = dt;
  399. this.grdClientBreakdown.Columns["type"].HeaderText = "Client Type";
  400. this.grdClientBreakdown.Columns["type"].DisplayIndex = 0;
  401. for (int i = 1; i <= 5; i++)
  402. {
  403. this.grdClientBreakdown.Columns[(DateTime.Today.Year - i).ToString()].DisplayIndex = i;
  404. }
  405. this.tspClientBreakdown.Text = strUpdateTime;
  406. this.tspClientBreakdown.ForeColor = Utility.IsChangedRecently(strUpdateTime) ? COLOR_MODIFIED : COLOR_NORMAL;
  407. }
  408. private void btnSaveCompany_Click(object sender, EventArgs e)
  409. {
  410. try
  411. {
  412. // 数据对象
  413. var textData = new
  414. {
  415. foundingDate = Utility.AddInfo(this.dtpIncepionDate.Value.Date.ToString("yyyy-MM-dd"), userId),
  416. detailOfAcquired = Utility.AddInfo(this.txtDetailOfAcquired.Text.Trim(), userId),
  417. parentCompanyName = Utility.AddInfo(this.txtParentCompanyName.Text.Trim(), userId),
  418. acqusition = Utility.AddInfo(Utility.DataTable2List((DataTable)this.grdAcquisiton.DataSource), userId),
  419. supportFromParent = Utility.AddInfo(new
  420. {
  421. financial = this.chkSupportFinancial.Checked,
  422. sales = this.chkSupportSales.Checked,
  423. marketing = this.chkSupportMarketing.Checked,
  424. technical = this.chkSupportTechnical.Checked,
  425. personnel = this.chkSupportPersonnel.Checked
  426. }, userId),
  427. financialData = Utility.AddInfo(Utility.DataTable2List((DataTable)this.grdFinancialData.DataSource), userId),
  428. creditRating = Utility.AddInfo(Utility.DataTable2List((DataTable)this.grdCreditRating.DataSource), userId),
  429. aum = Utility.AddInfo(Utility.DataTable2List((DataTable)this.grdAUM.DataSource), userId),
  430. clientBreakdown = Utility.AddInfo(Utility.DataTable2List((DataTable) this.grdClientBreakdown.DataSource), userId)
  431. };
  432. // 序列化选项
  433. var options = new JsonSerializerOptions
  434. {
  435. WriteIndented = true,
  436. PropertyNamingPolicy = JsonNamingPolicy.CamelCase
  437. };
  438. string jsonString = JsonSerializer.Serialize(textData, options);
  439. int ret = DataAccess.Set_dd_company_info(this.companyId, DateTime.Today, jsonString, 1, 1, this.userId);
  440. if (ret == 1)
  441. {
  442. MessageBox.Show("Data is saved successfully", "Information");
  443. }
  444. }
  445. catch (Exception ex)
  446. {
  447. MessageBox.Show($"Error: {ex.Message}", "Error");
  448. }
  449. }
  450. }
  451. }