123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics.Eventing.Reader;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace DataManager
- {
- public partial class UIFund : Form
- {
- private int userId;
- private string fundId = null;
- private string providerId = null;
- private string externalId = null;
- private string matchedFundId = null;
- private DataTable fundInfo = new DataTable();
- private DataTable tbNav;
- public UIFund(string fundId, int userId)
- {
- this.fundId = fundId;
- this.userId = userId;
-
- InitializeComponent();
- InitializeData();
- }
- public UIFund(string providerId, string externalId, string fundId, int userId)
- {
- this.providerId = providerId;
- this.externalId = externalId;
- this.matchedFundId = fundId;
- this.userId = userId;
- InitializeComponent();
- InitializeData();
- }
- public string FundId { get { return fundId; } }
- public int UserId { get { return userId; } }
- public string ProviderId { get {return providerId; } }
- public string ExternalId { get {return externalId; } }
- private void InitializeData()
- {
- txtFundId.Text = fundId;
- // 正常的基金页面
- if (!string.IsNullOrEmpty(fundId))
- {
- fundInfo = DataAccess.Get_dm_fund_information(fundId, null);
- #region Basic Info
- if (fundInfo == null || fundInfo.Rows.Count <= 0)
- {
- txtFundName.Text = string.Format("基金{0}不存在,得跟管理员说一下", fundId);
- txtFundName.ForeColor = Color.Red;
- return;
- }
- txtFundName.Text = fundInfo.Rows[0]["fund_name"].ToString();
- txtFundId.ReadOnly = true;
- txtRegisterCode.Text = fundInfo.Rows[0]["register_number"].ToString();
- txtRegisterCode.ReadOnly = true;
- lblInceptionDate.Text = fundInfo.Rows[0]["inception_date"].ToString();
- string s = fundInfo.Rows[0]["fund_type"].ToString();
- if (s != string.Empty)
- lblFundType.Text = UIConstants.FundType[int.Parse(s)];
- else
- lblFundType.Text = "";
- lblCompany.Text = fundInfo.Rows[0]["company_name"].ToString();
- lblCompany.ForeColor = Color.DodgerBlue;
- lblRegisteDate.Text = fundInfo.Rows[0]["register_date"].ToString();
-
- s = fundInfo.Rows[0]["manager_type"].ToString();
- if (s != string.Empty)
- lblManagementType.Text = UIConstants.ManagerType[int.Parse(s)];
- else
- lblManagementType.Text = "";
- s = fundInfo.Rows[0]["base_currency"].ToString();
- if (s != string.Empty)
- lblCurrency.Text = UIConstants.Currency[int.Parse(s)];
- else
- lblCurrency.Text = "";
- s = fundInfo.Rows[0]["fund_status"].ToString();
- if (s != String.Empty)
- lblStatus.Text = UIConstants.FundStatus[int.Parse(s)];
- else
- lblStatus.Text = "";
- lblCustodian.Text = fundInfo.Rows[0]["custodian_name"].ToString();
- lblAmacUpdateDate.Text = fundInfo.Rows[0]["zjx_last_info_update_time"].ToString();
-
- txtFundShortName.Text = fundInfo.Rows[0]["fund_short_name"].ToString();
-
-
- cmbStrategy.DataSource = new BindingSource(UIConstants.HedgeFundStrategy, null); ;
- cmbStrategy.DisplayMember = "Value";
- cmbStrategy.ValueMember = "Key";
- s = fundInfo.Rows[0]["strategy"].ToString();
- int strategyId = -1;
- if (s != string.Empty) strategyId = int.Parse(s);
- cmbStrategy.SelectedValue = strategyId;
- cmbSubStrategy.DataSource = new BindingSource(LoadSubStrategy(strategyId), null);
- cmbSubStrategy.DisplayMember = "Value";
- cmbSubStrategy.ValueMember = "Key";
- s = fundInfo.Rows[0]["substrategy"].ToString();
- int substrategyId = -1;
- if (s != string.Empty) substrategyId = int.Parse(s);
- cmbSubStrategy.SelectedValue = substrategyId;
- // 净值频率
- string navFreq = fundInfo.Rows[0]["nav_frequency"].ToString().Trim();
- if (string.IsNullOrEmpty(navFreq)) navFreq = "未知";
- cmbNavFrequency.SelectedIndex = cmbNavFrequency.Items.IndexOf(navFreq);
- chkRating.Checked = fundInfo.Rows[0]["is_rating"].ToString() == "1" ? true : false;
- chkRanking.Checked = fundInfo.Rows[0]["is_ranking"].ToString() == "1" ? true : false;
- chkAuthorized.Checked = fundInfo.Rows[0]["is_authorized"].ToString() == "1" ? true : false;
- lblMatchFund.Visible = false;
- lblMatchInstrunction.Visible = false;
- txtMatchFund.Visible = false;
- #endregion
- #region Nav
- dtpNavStartDate.ShowCheckBox = true;
- dtpNavStartDate.Checked = true;
- dtpNavStartDate.Value = DateTime.Parse(lblInceptionDate.Text);
- dtpNavEndDate.ShowCheckBox = true;
- dtpNavEndDate.Checked = true;
- dtpNavEndDate.Value = DateTime.Today;
- lblNavFrequency.Text = navFreq;
- LoadNavGrid(FundId, null, null, null, null);
- #endregion
- }
- // 用于孤儿基金的页面
- else
- {
- txtFundName.Text = ExternalId;
- txtFundShortName.Enabled = false;
- cmbStrategy.Enabled = false;
- cmbSubStrategy.Enabled = false;
- txtParentFund.Enabled = false;
- cmbNavFrequency.Enabled = false;
- chkAuthorized.Enabled = false;
- chkRanking.Enabled = false;
- chkRating.Enabled = false;
- txtMatchFund.Text = (this.matchedFundId == null ? string.Empty : matchedFundId);
- LoadNavGrid(null, ProviderId, ExternalId, null, null);
- }
- }
- private void btnSave_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(FundId))
- {
- string matchedFundId = txtMatchFund.Text;
- // 暂时只做个简单的ID长度和前两位字母检查
- if (matchedFundId.Length == 10 && matchedFundId.Substring(0, 2) == "HF")
- {
- DataAccess.Set_dm_external_fund_mapping(ProviderId, ExternalId, matchedFundId, UserId);
- this.DialogResult = DialogResult.OK;
- this.Close();
- }
- else
- {
- MessageBox.Show("输入的基金ID应该是HFXXXXXXXXXX", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- txtMatchFund.Focus();
- }
- }
- else
- {
- string fundShortName = txtFundShortName.Text.Trim();
- int? strategyId = int.Parse(cmbStrategy.SelectedValue.ToString());
- int? subStrategyId = int.Parse(cmbSubStrategy.SelectedValue.ToString());
- string parentFundId = txtParentFund.Text.Trim();
- parentFundId = (string.IsNullOrEmpty(parentFundId) ? null : parentFundId);
- string navFrequency = cmbNavFrequency.SelectedText.ToString();
- sbyte isAuthorized = (sbyte)(chkAuthorized.Checked ? 1 : 0);
- sbyte isRanking = (sbyte)(chkRanking.Checked ? 1 : 0);
- sbyte isRating = (sbyte)(chkRating.Checked ? 1 : 0);
- DataAccess.Set_dm_fund_information(FundId, fundShortName, strategyId, subStrategyId, parentFundId, navFrequency, isAuthorized, isRanking, isRating, UserId);
-
- MessageBox.Show("所有更新顺利存盘", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
-
- }
- private Dictionary<int, string> LoadSubStrategy(int strategyId)
- {
- Dictionary<int, string> d;
- int[] keysToSelect = null;
- switch (cmbStrategy.SelectedValue)
- {
- case 1:
- keysToSelect = new int[] { 1010, 1020, 1030, -1 };
- break;
- case 2:
- keysToSelect = new int[] { 2010, -1 };
- break;
- case 3:
- keysToSelect = new int[] { 3010, 3020, 3030, 3040, 3050, -1 };
- break;
- case 4:
- keysToSelect = new int[] { 4010, 4020, 4030, 4040, -1 };
- break;
- case 5:
- keysToSelect = new int[] { 5010, 5020, 5030, -1 };
- break;
- case 6:
- keysToSelect = new int[] { 6010, 6020, 6030, -1 };
- break;
- case 7:
- keysToSelect = new int[] { 7010, 7020, -1 };
- break;
- case 8:
- keysToSelect = new int[] { 8010, 8020, -1 };
- break;
- default:
- keysToSelect = new int[] { -1 };
- break;
- }
- d = UIConstants.HedgeFundSubStrategy.Where(kvp => keysToSelect.Contains(kvp.Key)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
- return d;
- }
- /// <summary>
- /// 二级策略选项跟随改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void cmbStrategy_SelectedIndexChanged(object sender, EventArgs e)
- {
- // 避免初始化绑定数据源时触发
- if (cmbStrategy.ContainsFocus)
- {
- int strategyId = int.Parse(cmbStrategy.SelectedValue.ToString());
- cmbSubStrategy.DataSource = new BindingSource(LoadSubStrategy(strategyId), null);
- cmbSubStrategy.DisplayMember = "Value";
- cmbSubStrategy.ValueMember = "Key";
- }
- }
- private void lblCompany_Click(object sender, EventArgs e)
- {
- string companyId = fundInfo.Rows[0]["advisor_id"].ToString();
- if (companyId.Length == 10)
- {
- UICompany frm = new UICompany(companyId, UserId);
- frm.ShowDialog();
- }
- }
- private void LoadNavGrid(string fundId, string providerId, string externalId, DateTime? startDate, DateTime? endDate)
- {
- tbNav = DataAccess.Get_dm_nav(fundId, providerId, externalId, startDate, endDate);
-
- grdNav.DataSource = tbNav;
- grdNav.Columns["fund_id"].Visible = false;
- grdNav.Columns["provider_id"].Visible = false;
- grdNav.Columns["provider_name"].HeaderText = "数据源";
- grdNav.Columns["external_id"].HeaderText = "外部ID";
- grdNav.Columns["price_date"].HeaderText = "净值日期";
- grdNav.Columns["nav"].HeaderText = "净值";
- grdNav.Columns["cumulative_nav_withdrawal"].HeaderText = "现金分红累计净值";
- grdNav.Columns["cumulative_nav"].HeaderText = "分红再投累计净值";
- grdNav.Columns["cumulative_nav"].DefaultCellStyle.BackColor = Color.AntiqueWhite;
- grdNav.Columns["isvalid"].HeaderText = "状态";
- grdNav.Columns["creatorid"].Visible = false;
- grdNav.Columns["creator_name"].HeaderText = "创建";
- grdNav.Columns["createtime"].HeaderText = "创建日期";
- grdNav.Columns["updaterid"].Visible = false;
- grdNav.Columns["updater_name"].HeaderText = "更新";
- grdNav.Columns["updatetime"].HeaderText = "更新日期";
- grdNav.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
- grdNav.RowHeadersVisible = false;
- }
- private void btnDrawNavLineChart_Click(object sender, EventArgs e)
- {
- NavChart chart = new NavChart(FundId, tbNav);
- chart.Show();
- }
- private void grdNav_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- //int rowIndex = e.RowIndex;
- //int columnIndex = e.ColumnIndex;
- //if (rowIndex < 0 || columnIndex < 0) return;
- //DataGridViewRow row = grdNav.Rows[rowIndex];
- //if(row == null) return;
- }
- private void btnAddNav_Click(object sender, EventArgs e)
- {
- }
- private void dtpNavEndDate_ValueChanged(object sender, EventArgs e)
- {
- DateTime startDate = dtpNavStartDate.Value;
- if (!dtpNavStartDate.Checked) startDate = dtpNavStartDate.MinDate;
-
- DateTime endDate = dtpNavEndDate.Value;
- if (!dtpNavEndDate.Checked) endDate = DateTime.Today;
- DataTable dt = FilterDate(tbNav, startDate, endDate);
- if(dt!=null) grdNav.DataSource = dt;
- }
- private DataTable FilterDate(DataTable data, DateTime startDate, DateTime endDate)
- {
- DataTable dt = null;
- if (startDate > endDate)
- {
- MessageBox.Show("起始日不能大于截止日哦", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return null;
- }
- if (data != null && data.Rows.Count > 0)
- {
- string expression = "price_date <= #" + endDate.ToString() + "# and price_date >= #" + startDate.ToString() + "#";
- DataRow[] rows = data.Select(expression, "price_date DESC");
- if (rows != null && rows.Length > 0)
- dt = rows.CopyToDataTable();
- }
- return dt;
- }
- private void dtpNavStartDate_ValueChanged(object sender, EventArgs e)
- {
- dtpNavEndDate_ValueChanged(sender, e);
- }
- }
- }
|