using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Text.Json; using System.Text.Json.Serialization; namespace ddq { public partial class FundQ : Form { private string fundId; private int userId = 123; private DataTable fundInfoTable; public FundQ(string fundId) { InitializeComponent(); this.fundId = fundId; InitializeData(); } private void InitializeData() { DataTable dt = DataAccess.Get_fund_info(fundId, null); if (dt == null || dt.Rows.Count <= 0) return; this.lblFundName.Text = dt.Rows[0].Field("fund_short_name"); this.lblMainCode.Text = "Code: " + dt.Rows[0].Field("register_number"); this.lblCategory.Text = "Category: " + dt.Rows[0].Field("strategy"); this.lblInceptionDate.Text = "Launched: " + dt.Rows[0].Field("inception_date")?.ToString("yyyy-MM-dd"); this.lblDomicile.Text = "Domicile: "; fundInfoTable = DataAccess.Get_dd_fund_info(fundId, null, 1); if (fundInfoTable == null || fundInfoTable.Rows.Count <= 0) return; string jsonString = fundInfoTable.Rows[0].Field("info").Trim(); JsonDocument document = JsonDocument.Parse(jsonString); JsonElement root = document.RootElement; this.txtInvestmentObjective.Text = root.GetProperty("investmentObjective").ToString(); this.txtBenchmark.Text = root.GetProperty("benchmark").ToString(); this.txtInvestmentPhilosophy.Text = root.GetProperty("investmentPhilosophy").ToString(); } private void FundQ_Load(object sender, EventArgs e) { } private void btnSaveGeneralInfo_Click(object sender, EventArgs e) { try { // 数据对象 var textData = new { FundId = this.fundId, InvestmentObjective = this.txtInvestmentObjective.Text, Benchmark = this.txtBenchmark.Text, InvestmentPhilosophy = this.txtInvestmentPhilosophy.Text, UpdateTime = DateTime.Now }; // 序列化选项 var options = new JsonSerializerOptions { WriteIndented = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; string jsonString = JsonSerializer.Serialize(textData, options); //MessageBox.Show($"Save JSON: \n{jsonString}", "Json Result"); int ret = DataAccess.Set_dd_fund_info(this.fundId, DateTime.Today, jsonString, 1, 1, userId); if (ret == 1) { this.Close(); } } catch (Exception ex) { MessageBox.Show($"Error: {ex.Message}", "Error"); } } } }