FundQ.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Text.Json;
  11. using System.Text.Json.Serialization;
  12. namespace ddq
  13. {
  14. public partial class FundQ : Form
  15. {
  16. private string fundId;
  17. private int userId = 123;
  18. private DataTable fundInfoTable;
  19. public FundQ(string fundId)
  20. {
  21. InitializeComponent();
  22. this.fundId = fundId;
  23. InitializeData();
  24. }
  25. private void InitializeData()
  26. {
  27. DataTable dt = DataAccess.Get_fund_info(fundId, null);
  28. if (dt == null || dt.Rows.Count <= 0) return;
  29. this.lblFundName.Text = dt.Rows[0].Field<string>("fund_short_name");
  30. this.lblMainCode.Text = "Code: " + dt.Rows[0].Field<string>("register_number");
  31. this.lblCategory.Text = "Category: " + dt.Rows[0].Field<string>("strategy");
  32. this.lblInceptionDate.Text = "Launched: " + dt.Rows[0].Field<DateTime?>("inception_date")?.ToString("yyyy-MM-dd");
  33. this.lblDomicile.Text = "Domicile: ";
  34. fundInfoTable = DataAccess.Get_dd_fund_info(fundId, null, 1);
  35. if (fundInfoTable == null || fundInfoTable.Rows.Count <= 0) return;
  36. string jsonString = fundInfoTable.Rows[0].Field<string>("info").Trim();
  37. JsonDocument document = JsonDocument.Parse(jsonString);
  38. JsonElement root = document.RootElement;
  39. this.txtInvestmentObjective.Text = root.GetProperty("investmentObjective").ToString();
  40. this.txtBenchmark.Text = root.GetProperty("benchmark").ToString();
  41. this.txtInvestmentPhilosophy.Text = root.GetProperty("investmentPhilosophy").ToString();
  42. }
  43. private void FundQ_Load(object sender, EventArgs e)
  44. {
  45. }
  46. private void btnSaveGeneralInfo_Click(object sender, EventArgs e)
  47. {
  48. try
  49. {
  50. // 数据对象
  51. var textData = new
  52. {
  53. FundId = this.fundId,
  54. InvestmentObjective = this.txtInvestmentObjective.Text,
  55. Benchmark = this.txtBenchmark.Text,
  56. InvestmentPhilosophy = this.txtInvestmentPhilosophy.Text,
  57. UpdateTime = DateTime.Now
  58. };
  59. // 序列化选项
  60. var options = new JsonSerializerOptions
  61. {
  62. WriteIndented = true,
  63. PropertyNamingPolicy = JsonNamingPolicy.CamelCase
  64. };
  65. string jsonString = JsonSerializer.Serialize(textData, options);
  66. //MessageBox.Show($"Save JSON: \n{jsonString}", "Json Result");
  67. int ret = DataAccess.Set_dd_fund_info(this.fundId, DateTime.Today, jsonString, 1, 1, userId);
  68. if (ret == 1)
  69. {
  70. this.Close();
  71. }
  72. }
  73. catch (Exception ex)
  74. {
  75. MessageBox.Show($"Error: {ex.Message}", "Error");
  76. }
  77. }
  78. }
  79. }