| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411 |
- 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;
- using System.Drawing.Text;
- using System.IO;
- namespace ddq
- {
- public partial class FundQ : Form
- {
- private string fundId;
- private string companyId;
- private int userId;
- private DataTable fundInfoTable;
- public FundQ(string fundId, string companyId, int userId)
- {
- InitializeComponent();
- this.fundId = fundId;
- this.companyId = companyId;
- this.userId = userId;
- 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<string>("fund_short_name");
- //this.lblMainCode.Text = "Code: " + dt.Rows[0].Field<string>("register_number");
- this.lblMainCode.Text = "Code: " + fundId;
- this.lblCategory.Text = "Category: " + dt.Rows[0].Field<string>("strategy");
- this.lblInceptionDate.Text = "Launched: " + dt.Rows[0].Field<DateTime?>("inception_date")?.ToString("yyyy-MM-dd");
- this.lblDomicile.Text = "Domicile: ";
- fundInfoTable = DataAccess.Get_dd_fund_info(fundId, null, 1);
- bool hasPM = false;
- DataTable dtPM;
- bool hasTER = false;
- DataTable dtTER;
- if (fundInfoTable != null && fundInfoTable.Rows.Count > 0)
- {
- string jsonString = fundInfoTable.Rows[0].Field<string>("info").Trim();
- JsonDocument document = JsonDocument.Parse(jsonString);
- JsonElement root = document.RootElement;
- if (root.ValueKind != JsonValueKind.Undefined)
- {
- //
- // General Info
- //
- this.txtInvestmentObjective.Text = Utility.Json2Text(root, "investmentObjective");
- this.txtBenchmark.Text = Utility.Json2Text(root, "benchmark");
- this.txtInvestmentPhilosophy.Text = Utility.Json2Text(root, "investmentPhilosophy");
- this.txtManagementFee.Text = Utility.Json2Text(root, "managementFee");
- this.txtSubscriptionFee.Text = Utility.Json2Text(root, "subscriptionFee");
- this.txtRedemptionFee.Text = Utility.Json2Text(root, "redemptionFee");
- this.txtAdministrationFee.Text = Utility.Json2Text(root, "administrationFee");
- this.txtSwitchingFee.Text = Utility.Json2Text(root, "switchingFee");
- this.txtTrusteeFee.Text = Utility.Json2Text(root, "trusteeFee");
- this.txtPerformanceFee.Text = Utility.Json2Text(root, "performanceFee");
- this.txtPolicyOfClosingFund.Text = Utility.Json2Text(root, "policyOfClosingFund");
- JsonElement elmPM;
- hasPM = root.TryGetProperty("portfolioManagers", out elmPM);
-
- if (hasPM == true)
- {
- dtPM = Utility.Json2Table(elmPM);
- InitPortfolioManagerGrid(dtPM);
- }
- JsonElement elmTER;
- hasTER = root.TryGetProperty("ter", out elmTER);
- if (hasTER == true)
- {
- dtTER = Utility.Json2Table(elmTER);
- InitTERGrid(dtTER);
- }
- //
- // Process
- //
- this.chkAllowDerivatives.Checked = Utility.Json2Text(root, "allowDerivatives").ToLower() == "true" ? true : false;
- this.chkUseDerivatives.Checked = Utility.Json2Text(root, "useDerivatives").ToLower() == "true" ? true : false;
- this.chkDerivativesForEfficent.Checked = this.chkUseDerivatives.Checked == true ? Utility.Json2Text(root, "drvForEffPM").ToLower() == "true" ? true : false : false;
- if (this.chkUseDerivatives.Checked == true)
- {
- this.chkDerivativesForEfficent.Checked = Utility.Json2Text(root, "drvForEffPM").ToLower() == "true" ? true : false;
- this.chkDerivatesForHedging.Checked = Utility.Json2Text(root, "drvForHedging").ToLower() == "true" ? true : false;
- this.chkDerivativesForMarket.Checked = Utility.Json2Text(root, "drvForMktAcs").ToLower() == "true" ? true : false;
- this.chkDerivatesForLeverage.Checked = Utility.Json2Text(root, "drvForLeverage").ToLower() == "true" ? true : false;
- }
- this.chkPriceTarget.Checked = Utility.Json2Text(root, "priceTarget").ToLower() == "true" ? true : false;
- if (this.chkPriceTarget.Checked == true)
- {
- this.txtOverrunPriceTarget.Text = Utility.Json2Text(root, "overrunPriceTarget");
- }
- }
- }
- if (hasPM == false)
- {
- dtPM = new DataTable();
- // 没有基金经理数据时,初始化表
- dtPM.Columns.Add("personnel_id", typeof(string));
- dtPM.Columns.Add("name", typeof(string));
- dtPM.Columns.Add("startDate", typeof(DateTime));
- dtPM.Columns.Add("endDate", typeof(DateTime));
- InitPortfolioManagerGrid(dtPM);
- }
- if (hasTER == false)
- {
- dtTER = new DataTable();
- dtTER.Columns.Add("year", typeof(int));
- dtTER.Columns.Add("ter", typeof(decimal));
- int year = DateTime.Today.Year - 1;
- for (int i = 0; i < 5; i++)
- {
- DataRow row = dtTER.NewRow();
- row["year"] = year - i;
- dtTER.Rows.Add(row);
- }
- InitTERGrid(dtTER);
- }
- }
- private void InitPortfolioManagerGrid(DataTable dt)
- {
- this.grdPortfolioManager.DataSource = dt;
- this.grdPortfolioManager.Columns["personnel_id"].Visible = false;
- this.grdPortfolioManager.Columns["name"].HeaderText = "Manager Name";
- this.grdPortfolioManager.Columns["name"].DisplayIndex = 0;
- this.grdPortfolioManager.Columns["startDate"].HeaderText = "Start Date";
- this.grdPortfolioManager.Columns["startDate"].DefaultCellStyle.Format = "d";
- this.grdPortfolioManager.Columns["startDate"].DisplayIndex = 1;
- this.grdPortfolioManager.Columns["endDate"].HeaderText = "End Date";
- this.grdPortfolioManager.Columns["endDate"].DefaultCellStyle.Format = "yyyy-MM-dd";
- this.grdPortfolioManager.Columns["endDate"].DisplayIndex = 2;
- }
- private void InitTERGrid(DataTable dt)
- {
- this.grdTER.DataSource = dt;
- this.grdTER.Columns["year"].HeaderText = "Year";
- this.grdTER.Columns["year"].ReadOnly = true;
- this.grdTER.Columns["year"].DisplayIndex = 0;
- this.grdTER.Columns["ter"].HeaderText = "Total Expense Ratio %";
- this.grdTER.Columns["ter"].ValueType = typeof(decimal);
- this.grdTER.Columns["ter"].DefaultCellStyle.Format = "N3";
- this.grdTER.Columns["ter"].DisplayIndex = 1;
- }
- private void FundQ_Load(object sender, EventArgs e)
- {
- }
- private void btnSaveGeneralInfo_Click(object sender, EventArgs e)
- {
- try
- {
- // 数据对象
- var textData = new
- {
- fundId = this.fundId,
- // -- General Info --
- investmentObjective = this.txtInvestmentObjective.Text,
- benchmark = this.txtBenchmark.Text,
- investmentPhilosophy = this.txtInvestmentPhilosophy.Text,
- portfolioManagers = Utility.DataTable2List((DataTable)this.grdPortfolioManager.DataSource),
- ter = Utility.DataTable2List((DataTable)this.grdTER.DataSource),
- managementFee = this.txtManagementFee.Text,
- subscriptionFee = this.txtSubscriptionFee.Text,
- redemptionFee = this.txtRedemptionFee.Text,
- administrationFee = this.txtAdministrationFee.Text,
- switchingFee = this.txtSwitchingFee.Text,
- trusteeFee = this.txtTrusteeFee.Text,
- performanceFee = this.txtPerformanceFee.Text,
- policyOfClosingFund = this.txtPolicyOfClosingFund.Text,
- // -- Process --
- allowDerivatives = this.chkAllowDerivatives.Checked,
- useDerivatives = this.chkUseDerivatives.Checked,
- drvForEffPM = this.chkDerivativesForEfficent.Checked,
- drvForHedging = this.chkDerivatesForHedging.Checked,
- drvForMktAcs = this.chkDerivativesForMarket.Checked,
- drvForLeverage = this.chkDerivatesForLeverage.Checked,
- priceTarget = this.chkPriceTarget.Checked,
- overrunPriceTarget = this.txtOverrunPriceTarget.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");
- }
- }
- private void grdTER_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
- {
- string errMsg = "Please enter a number between 0 and 100, with up to 3 decimal digits";
- if (grdTER.Columns[e.ColumnIndex].Name == "ter" && e.RowIndex >= 0)
- {
- // 先清除可能存在的旧错误提示
- grdTER.Rows[e.RowIndex].ErrorText = "";
- if (e.FormattedValue.ToString().Trim() == "") return;
- // 尝试将输入的值转换为小数
- if (!decimal.TryParse(e.FormattedValue.ToString(), out decimal newValue))
- {
- // 如果转换失败,说明输入的不是有效数字
- e.Cancel = true;
- grdTER.Rows[e.RowIndex].ErrorText = errMsg;
- return;
- }
- // 验证数值范围(例如限制在0到100之间)
- if (newValue < 0 || newValue > 100)
- {
- e.Cancel = true;
- grdTER.Rows[e.RowIndex].ErrorText = errMsg;
- return;
- }
- // (可选) 自定义验证小数位数
- string[] parts = e.FormattedValue.ToString().Split('.');
- if (parts.Length > 1 && parts[1].Length > 3) // 检查小数点后的位数
- {
- e.Cancel = true;
- grdTER.Rows[e.RowIndex].ErrorText = errMsg;
- }
- }
- }
- private void btnSaveFundProcess_Click(object sender, EventArgs e)
- {
-
- }
- private void chkUseDerivatives_CheckedChanged(object sender, EventArgs e)
- {
- bool isChecked = chkUseDerivatives.Checked;
- this.chkDerivativesForEfficent.Enabled = isChecked;
- this.chkDerivatesForHedging.Enabled = isChecked;
- this.chkDerivativesForMarket.Enabled = isChecked;
- this.chkDerivatesForLeverage.Enabled = isChecked;
- if (isChecked == false)
- {
- this.chkDerivativesForEfficent.Checked = false;
- this.chkDerivatesForHedging.Checked = false;
- this.chkDerivativesForMarket.Checked = false;
- this.chkDerivatesForLeverage.Checked = false;
- }
- }
- private void chkPriceTarget_CheckedChanged(object sender, EventArgs e)
- {
- bool isChecked = chkPriceTarget.Checked;
- if (!isChecked) { this.txtOverrunPriceTarget.Text = ""; }
- }
- private void btnUploadProcessDiagram_Click(object sender, EventArgs e)
- {
- this.ofdProcessDiagram.Title = "Upload Diagram File -- FAKE";
- if (this.ofdProcessDiagram.ShowDialog() == DialogResult.OK)
- {
- // TODO: upload files to server. let's fake it for now
- string filePath = ofdProcessDiagram.FileName;
- string fileName = Path.GetFileName(filePath);
- try
- {
- }
- catch (Exception ex)
- {
- MessageBox.Show("File was not able to be uploaded:" + ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- private void btnAddManager_Click(object sender, EventArgs e)
- {
- using (PersonSelectionDialog dialog = new PersonSelectionDialog(companyId))
- {
- dialog.StartPosition = FormStartPosition.CenterParent;
- DialogResult result = dialog.ShowDialog(this);
- if (result == DialogResult.OK && dialog.PersonnelId != "")
- {
- DataTable dt = (DataTable)this.grdPortfolioManager.DataSource;
-
- DataRow row = dt.NewRow();
- row["personnel_id"] = dialog.PersonnelId;
- row["name"] = dialog.PersonnelName;
- row["startDate"] = dialog.StartDate.Date;
- dt.Rows.Add(row);
- }
-
- }
- }
- private void grdPortfolioManager_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
- {
- int rowIndex = e.RowIndex;
- int columnIndex = e.ColumnIndex;
- if (rowIndex < 0 || columnIndex < 0) { return; }
- // 先清除可能存在的旧错误提示
- grdPortfolioManager.Rows[rowIndex].ErrorText = "";
- // 如果转换失败,说明输入的不是有效日期
- bool isPass = DateTime.TryParse(grdPortfolioManager.Rows[rowIndex].Cells["startDate"].Value.ToString(), out DateTime newDate);
- if (!isPass || newDate < new DateTime(1900, 1, 1) || newDate > DateTime.Today)
- {
- e.Cancel = true;
- grdPortfolioManager.Rows[columnIndex].ErrorText = "Please enter a proper start date";
- return;
- }
- if (grdPortfolioManager.Rows[rowIndex].Cells["endDate"].Value.ToString() == "") return;
- isPass = DateTime.TryParse(grdPortfolioManager.Rows[rowIndex].Cells["endDate"].Value.ToString(), out newDate);
- if (!isPass || newDate < new DateTime(1900, 1, 1) || newDate > DateTime.Today)
- {
- e.Cancel = true;
- grdPortfolioManager.Rows[columnIndex].ErrorText = "Please enter a proper end date"; ;
- return;
- }
- }
- private void grdPortfolioManager_Validating(object sender, CancelEventArgs e)
- {
- }
- }
- }
|