DDQ.cs 16 KB

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