UIFund.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Diagnostics.Eventing.Reader;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace DataManager
  13. {
  14. public partial class UIFund : Form
  15. {
  16. private int userId;
  17. private string fundId = null;
  18. private string providerId = null;
  19. private string externalId = null;
  20. private string matchedFundId = null;
  21. private DataTable fundInfo = new DataTable();
  22. private DataTable tbNav;
  23. public UIFund(string fundId, int userId)
  24. {
  25. this.fundId = fundId;
  26. this.userId = userId;
  27. InitializeComponent();
  28. InitializeData();
  29. }
  30. public UIFund(string providerId, string externalId, string fundId, int userId)
  31. {
  32. this.providerId = providerId;
  33. this.externalId = externalId;
  34. this.matchedFundId = fundId;
  35. this.userId = userId;
  36. InitializeComponent();
  37. InitializeData();
  38. }
  39. public string FundId { get { return fundId; } }
  40. public int UserId { get { return userId; } }
  41. public string ProviderId { get {return providerId; } }
  42. public string ExternalId { get {return externalId; } }
  43. private void InitializeData()
  44. {
  45. txtFundId.Text = fundId;
  46. // 正常的基金页面
  47. if (!string.IsNullOrEmpty(fundId))
  48. {
  49. fundInfo = DataAccess.Get_dm_fund_information(fundId, null);
  50. #region Basic Info
  51. if (fundInfo == null || fundInfo.Rows.Count <= 0)
  52. {
  53. txtFundName.Text = string.Format("基金{0}不存在,得跟管理员说一下", fundId);
  54. txtFundName.ForeColor = Color.Red;
  55. return;
  56. }
  57. txtFundName.Text = fundInfo.Rows[0]["fund_name"].ToString();
  58. txtFundId.ReadOnly = true;
  59. txtRegisterCode.Text = fundInfo.Rows[0]["register_number"].ToString();
  60. txtRegisterCode.ReadOnly = true;
  61. lblInceptionDate.Text = fundInfo.Rows[0]["inception_date"].ToString();
  62. string s = fundInfo.Rows[0]["fund_type"].ToString();
  63. if (s != string.Empty)
  64. lblFundType.Text = UIConstants.FundType[int.Parse(s)];
  65. else
  66. lblFundType.Text = "";
  67. lblCompany.Text = fundInfo.Rows[0]["company_name"].ToString();
  68. lblCompany.ForeColor = Color.DodgerBlue;
  69. lblRegisteDate.Text = fundInfo.Rows[0]["register_date"].ToString();
  70. s = fundInfo.Rows[0]["manager_type"].ToString();
  71. if (s != string.Empty)
  72. lblManagementType.Text = UIConstants.ManagerType[int.Parse(s)];
  73. else
  74. lblManagementType.Text = "";
  75. s = fundInfo.Rows[0]["base_currency"].ToString();
  76. if (s != string.Empty)
  77. lblCurrency.Text = UIConstants.Currency[int.Parse(s)];
  78. else
  79. lblCurrency.Text = "";
  80. s = fundInfo.Rows[0]["fund_status"].ToString();
  81. if (s != String.Empty)
  82. lblStatus.Text = UIConstants.FundStatus[int.Parse(s)];
  83. else
  84. lblStatus.Text = "";
  85. lblCustodian.Text = fundInfo.Rows[0]["custodian_name"].ToString();
  86. lblAmacUpdateDate.Text = fundInfo.Rows[0]["zjx_last_info_update_time"].ToString();
  87. txtFundShortName.Text = fundInfo.Rows[0]["fund_short_name"].ToString();
  88. cmbStrategy.DataSource = new BindingSource(UIConstants.HedgeFundStrategy, null); ;
  89. cmbStrategy.DisplayMember = "Value";
  90. cmbStrategy.ValueMember = "Key";
  91. s = fundInfo.Rows[0]["strategy"].ToString();
  92. int strategyId = -1;
  93. if (s != string.Empty) strategyId = int.Parse(s);
  94. cmbStrategy.SelectedValue = strategyId;
  95. cmbSubStrategy.DataSource = new BindingSource(LoadSubStrategy(strategyId), null);
  96. cmbSubStrategy.DisplayMember = "Value";
  97. cmbSubStrategy.ValueMember = "Key";
  98. s = fundInfo.Rows[0]["substrategy"].ToString();
  99. int substrategyId = -1;
  100. if (s != string.Empty) substrategyId = int.Parse(s);
  101. cmbSubStrategy.SelectedValue = substrategyId;
  102. // 净值频率
  103. string navFreq = fundInfo.Rows[0]["nav_frequency"].ToString().Trim();
  104. if (string.IsNullOrEmpty(navFreq)) navFreq = "未知";
  105. cmbNavFrequency.SelectedIndex = cmbNavFrequency.Items.IndexOf(navFreq);
  106. chkRating.Checked = fundInfo.Rows[0]["is_rating"].ToString() == "是" ? true : false;
  107. chkRanking.Checked = fundInfo.Rows[0]["is_ranking"].ToString() == "是" ? true : false;
  108. chkAuthorized.Checked = fundInfo.Rows[0]["is_authorized"].ToString() == "是" ? true : false;
  109. lblMatchFund.Visible = false;
  110. lblMatchInstrunction.Visible = false;
  111. txtMatchFund.Visible = false;
  112. txtFundShortName.Focus();
  113. #endregion
  114. #region Nav
  115. dtpNavStartDate.ShowCheckBox = true;
  116. dtpNavStartDate.Checked = true;
  117. dtpNavStartDate.Value = DateTime.Parse(lblInceptionDate.Text);
  118. dtpNavEndDate.ShowCheckBox = true;
  119. dtpNavEndDate.Checked = true;
  120. dtpNavEndDate.Value = DateTime.Today;
  121. lblNavFrequency.Text = navFreq;
  122. LoadNavGrid(FundId, null, null, null, null);
  123. #endregion
  124. }
  125. // 用于孤儿基金的页面
  126. else
  127. {
  128. txtFundName.Text = ExternalId;
  129. txtFundShortName.Enabled = false;
  130. cmbStrategy.Enabled = false;
  131. cmbSubStrategy.Enabled = false;
  132. txtParentFund.Enabled = false;
  133. cmbNavFrequency.Enabled = false;
  134. chkAuthorized.Enabled = false;
  135. chkRanking.Enabled = false;
  136. chkRating.Enabled = false;
  137. txtMatchFund.Text = (this.matchedFundId == null ? string.Empty : matchedFundId);
  138. LoadNavGrid(null, ProviderId, ExternalId, null, null);
  139. }
  140. }
  141. private void btnSave_Click(object sender, EventArgs e)
  142. {
  143. if (string.IsNullOrEmpty(FundId))
  144. {
  145. string matchedFundId = txtMatchFund.Text;
  146. // 暂时只做个简单的ID长度和前两位字母检查
  147. if (matchedFundId.Length == 10 && matchedFundId.Substring(0, 2) == "HF")
  148. {
  149. DataAccess.Set_dm_external_fund_mapping(ProviderId, ExternalId, matchedFundId, UserId);
  150. this.DialogResult = DialogResult.OK;
  151. this.Close();
  152. }
  153. else
  154. {
  155. MessageBox.Show("输入的基金ID应该是HFXXXXXXXXXX", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  156. txtMatchFund.Focus();
  157. }
  158. }
  159. else
  160. {
  161. string fundShortName = txtFundShortName.Text.Trim();
  162. int? strategyId = int.Parse(cmbStrategy.SelectedValue.ToString());
  163. int? subStrategyId = int.Parse(cmbSubStrategy.SelectedValue.ToString());
  164. string parentFundId = txtParentFund.Text.Trim();
  165. parentFundId = (string.IsNullOrEmpty(parentFundId) ? null : parentFundId);
  166. string navFrequency = cmbNavFrequency.SelectedText.ToString();
  167. sbyte isAuthorized = (sbyte)(chkAuthorized.Checked ? 1 : 0);
  168. sbyte isRanking = (sbyte)(chkRanking.Checked ? 1 : 0);
  169. sbyte isRating = (sbyte)(chkRating.Checked ? 1 : 0);
  170. DataAccess.Set_dm_fund_information(FundId, fundShortName, strategyId, subStrategyId, parentFundId, navFrequency, isAuthorized, isRanking, isRating, UserId);
  171. MessageBox.Show("所有更新顺利存盘", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  172. }
  173. }
  174. private Dictionary<int, string> LoadSubStrategy(int strategyId)
  175. {
  176. Dictionary<int, string> d;
  177. int[] keysToSelect = null;
  178. switch (cmbStrategy.SelectedValue)
  179. {
  180. case 1:
  181. keysToSelect = new int[] { 1010, 1020, 1030, -1 };
  182. break;
  183. case 2:
  184. keysToSelect = new int[] { 2010, -1 };
  185. break;
  186. case 3:
  187. keysToSelect = new int[] { 3010, 3020, 3030, 3040, 3050, -1 };
  188. break;
  189. case 4:
  190. keysToSelect = new int[] { 4010, 4020, 4030, 4040, -1 };
  191. break;
  192. case 5:
  193. keysToSelect = new int[] { 5010, 5020, 5030, -1 };
  194. break;
  195. case 6:
  196. keysToSelect = new int[] { 6010, 6020, 6030, -1 };
  197. break;
  198. case 7:
  199. keysToSelect = new int[] { 7010, 7020, -1 };
  200. break;
  201. case 8:
  202. keysToSelect = new int[] { 8010, 8020, -1 };
  203. break;
  204. default:
  205. keysToSelect = new int[] { -1 };
  206. break;
  207. }
  208. d = UIConstants.HedgeFundSubStrategy.Where(kvp => keysToSelect.Contains(kvp.Key)).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  209. return d;
  210. }
  211. /// <summary>
  212. /// 二级策略选项跟随改变
  213. /// </summary>
  214. /// <param name="sender"></param>
  215. /// <param name="e"></param>
  216. private void cmbStrategy_SelectedIndexChanged(object sender, EventArgs e)
  217. {
  218. // 避免初始化绑定数据源时触发
  219. if (cmbStrategy.ContainsFocus)
  220. {
  221. int strategyId = int.Parse(cmbStrategy.SelectedValue.ToString());
  222. cmbSubStrategy.DataSource = new BindingSource(LoadSubStrategy(strategyId), null);
  223. cmbSubStrategy.DisplayMember = "Value";
  224. cmbSubStrategy.ValueMember = "Key";
  225. }
  226. }
  227. private void lblCompany_Click(object sender, EventArgs e)
  228. {
  229. string companyId = fundInfo.Rows[0]["advisor_id"].ToString();
  230. if (companyId.Length == 10)
  231. {
  232. UICompany frm = new UICompany(companyId, UserId);
  233. frm.ShowDialog();
  234. }
  235. }
  236. private void LoadNavGrid(string fundId, string providerId, string externalId, DateTime? startDate, DateTime? endDate)
  237. {
  238. tbNav = DataAccess.Get_dm_nav(fundId, providerId, externalId, startDate, endDate);
  239. grdNav.DataSource = tbNav;
  240. grdNav.Columns["fund_id"].Visible = false;
  241. grdNav.Columns["provider_id"].Visible = false;
  242. grdNav.Columns["provider_name"].HeaderText = "数据源";
  243. grdNav.Columns["external_id"].HeaderText = "外部ID";
  244. grdNav.Columns["price_date"].HeaderText = "净值日期";
  245. grdNav.Columns["nav"].HeaderText = "净值";
  246. grdNav.Columns["cumulative_nav_withdrawal"].HeaderText = "现金分红累计净值";
  247. grdNav.Columns["cumulative_nav"].HeaderText = "分红再投累计净值";
  248. grdNav.Columns["cumulative_nav"].DefaultCellStyle.BackColor = Color.AntiqueWhite;
  249. grdNav.Columns["isvalid"].HeaderText = "状态";
  250. grdNav.Columns["creatorid"].Visible = false;
  251. grdNav.Columns["creator_name"].HeaderText = "创建";
  252. grdNav.Columns["createtime"].HeaderText = "创建日期";
  253. grdNav.Columns["updaterid"].Visible = false;
  254. grdNav.Columns["updater_name"].HeaderText = "更新";
  255. grdNav.Columns["updatetime"].HeaderText = "更新日期";
  256. grdNav.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  257. grdNav.RowHeadersVisible = false;
  258. }
  259. private void btnDrawNavLineChart_Click(object sender, EventArgs e)
  260. {
  261. NavChart chart = new NavChart(FundId, tbNav);
  262. chart.Show();
  263. }
  264. private void grdNav_CellClick(object sender, DataGridViewCellEventArgs e)
  265. {
  266. //int rowIndex = e.RowIndex;
  267. //int columnIndex = e.ColumnIndex;
  268. //if (rowIndex < 0 || columnIndex < 0) return;
  269. //DataGridViewRow row = grdNav.Rows[rowIndex];
  270. //if(row == null) return;
  271. }
  272. private void btnAddNav_Click(object sender, EventArgs e)
  273. {
  274. }
  275. private void dtpNavEndDate_ValueChanged(object sender, EventArgs e)
  276. {
  277. DateTime startDate = dtpNavStartDate.Value;
  278. if (!dtpNavStartDate.Checked) startDate = dtpNavStartDate.MinDate;
  279. DateTime endDate = dtpNavEndDate.Value;
  280. if (!dtpNavEndDate.Checked) endDate = DateTime.Today;
  281. DataTable dt = FilterDate(tbNav, startDate, endDate);
  282. if(dt!=null) grdNav.DataSource = dt;
  283. }
  284. private DataTable FilterDate(DataTable data, DateTime startDate, DateTime endDate)
  285. {
  286. DataTable dt = null;
  287. if (startDate > endDate)
  288. {
  289. MessageBox.Show("起始日不能大于截止日哦", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
  290. return null;
  291. }
  292. if (data != null && data.Rows.Count > 0)
  293. {
  294. string expression = "price_date <= #" + endDate.ToString() + "# and price_date >= #" + startDate.ToString() + "#";
  295. DataRow[] rows = data.Select(expression, "price_date DESC");
  296. if (rows != null && rows.Length > 0)
  297. dt = rows.CopyToDataTable();
  298. }
  299. return dt;
  300. }
  301. private void dtpNavStartDate_ValueChanged(object sender, EventArgs e)
  302. {
  303. dtpNavEndDate_ValueChanged(sender, e);
  304. }
  305. }
  306. }