UICollectionTask.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. using System;
  2. using System.CodeDom;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace DataManager
  12. {
  13. public partial class UICollectionTask : Form
  14. {
  15. private CollectionTask task = null;
  16. private string memo = string.Empty;
  17. // 模式:0-新任务,1-编辑已有任务, 2-指定公司的新任务
  18. private int mode = 0;
  19. public UICollectionTask(int userId)
  20. {
  21. task = new CollectionTask();
  22. task.UserId = userId;
  23. task.TaskType = 6; // 净值缺失
  24. task.TaskDate = DateTime.Now;
  25. task.Isvalid = 3; // 等待回复
  26. InitializeComponent();
  27. this.mode = 0;
  28. InitializeData();
  29. }
  30. public UICollectionTask(int userId, string providerId, string providerShortName)
  31. {
  32. task = new CollectionTask();
  33. task.UserId = userId;
  34. task.TaskType = 6; // 净值缺失
  35. task.TaskDate = DateTime.Now;
  36. task.Isvalid = 3; // 等待回复
  37. task.ProviderId = providerId;
  38. task.ProviderName = providerShortName;
  39. InitializeComponent();
  40. this.mode = 2;
  41. InitializeData();
  42. }
  43. public UICollectionTask(CollectionTask task)
  44. {
  45. this.task = task;
  46. InitializeComponent();
  47. this.mode = 1;
  48. InitializeData();
  49. memo = GetTaskMemo();
  50. }
  51. private void InitializeData()
  52. {
  53. this.Text = this.Text + " " + (mode == 0 ? "新任务" : task.TaskId.ToString());
  54. BindingSource bs1 = new BindingSource();
  55. bs1.DataSource = UIConstants.CollectionTaskType;
  56. this.cmbTaskType.DataSource = bs1;
  57. this.cmbTaskType.DisplayMember = "Value";
  58. this.cmbTaskType.ValueMember = "Key";
  59. this.cmbTaskType.SelectedValue = (int)task.TaskType;
  60. // 已有任务不可以改变任务类型
  61. cmbTaskType.Enabled = (mode == 0 ? true : false);
  62. this.dtpTaskDate.Text = task.TaskDate.ToString();
  63. this.txtCompanyShortName.Text = task.ProviderName;
  64. switch (mode)
  65. {
  66. case 1:
  67. this.cmbTaskType.Enabled = false;
  68. this.dtpTaskDate.Enabled = false;
  69. this.txtCompanyShortName.ReadOnly = true;
  70. this.btnCompanySearch.Enabled = false;
  71. this.txtEntityName.ReadOnly = true;
  72. this.txtEntityName.Text = task.EntityName;
  73. break;
  74. case 0:
  75. this.btnDelTask.Visible = false;
  76. break;
  77. case 2:
  78. this.cmbTaskType.Enabled = true;
  79. this.dtpTaskDate.Enabled = true;
  80. this.txtCompanyShortName.ReadOnly = true;
  81. this.btnCompanySearch.Enabled = false;
  82. this.btnDelTask.Visible = false;
  83. break;
  84. }
  85. BindingSource bs2 = new BindingSource();
  86. bs2.DataSource = UIConstants.CollectionTaskStatus;;
  87. this.cmbIsValid.DataSource = bs2;
  88. this.cmbIsValid.DisplayMember = "Value";
  89. this.cmbIsValid.ValueMember = "Key";
  90. this.cmbIsValid.SelectedValue = (int)task.Isvalid;
  91. }
  92. private string GetTaskMemo()
  93. {
  94. string memo = string.Empty;
  95. if (task != null && task.TaskId > 0)
  96. {
  97. DataTable dt = DataAccess.Get_dm_memo((sbyte)UIConstants.JobType.采集, task.TaskId);
  98. if (dt != null && dt.Rows.Count > 0)
  99. {
  100. memo = dt.Rows[0]["memo"].ToString().Trim();
  101. }
  102. }
  103. txtMemo.Text = memo;
  104. return memo;
  105. }
  106. private void SaveTaskMemo()
  107. {
  108. string newMemo = txtMemo.Text.Trim();
  109. if (memo != newMemo)
  110. {
  111. DataAccess.Set_dm_memo((sbyte)UIConstants.JobType.采集, task.TaskId, newMemo, int.Parse(task.UserId.ToString()));
  112. }
  113. return;
  114. }
  115. private void btnSaveTask_Click(object sender, EventArgs e)
  116. {
  117. if (task.TaskId <= 0)
  118. {
  119. // need generate a new task id
  120. };
  121. if (task.ProviderId == null || task.ProviderId.Length != 10)
  122. {
  123. MessageBox.Show("还没输入公司呢...", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  124. txtCompanyShortName.Focus();
  125. return;
  126. }
  127. task.TaskType = Int16.Parse(cmbTaskType.SelectedValue.ToString());
  128. task.TaskDate = DateTime.Parse(dtpTaskDate.Text);
  129. task.Isvalid = SByte.Parse(cmbIsValid.SelectedValue.ToString());
  130. // 写回数据库时,新记录会INSERT记录并产生一个自增长的task_id
  131. task.TaskId = task.SaveToSQL(int.Parse(task.UserId.ToString()));
  132. SaveTaskMemo();
  133. this.DialogResult = DialogResult.OK;
  134. this.Close();
  135. }
  136. private void btnCompanySearch_Click(object sender, EventArgs e)
  137. {
  138. if (txtCompanyShortName.TextLength < 2)
  139. {
  140. MessageBox.Show("请输入至少两个字,不然结果太多看不过来 @@", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  141. txtCompanyShortName.Focus();
  142. return;
  143. }
  144. // 只搜私募
  145. DataTable companys = DataAccess.Search_dm_company(UIConstants.CompanyType.FirstOrDefault(x=>x.Value=="私募证券投资").Key, txtCompanyShortName.Text.Trim());
  146. if (companys == null || companys.Rows.Count == 0)
  147. {
  148. MessageBox.Show("- - 没有找到结果,换个关键字试试?", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  149. txtCompanyShortName.Focus();
  150. return;
  151. }
  152. grdCompany.DataSource = companys;
  153. grdCompany.Columns["company_id"].Visible = false;
  154. grdCompany.Columns["company_name"].Visible = false;
  155. grdCompany.Columns["company_asset_size"].Visible = false;
  156. grdCompany.Columns["register_number"].Visible = false;
  157. grdCompany.Columns["establish_date"].Visible = false;
  158. grdCompany.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  159. grdCompany.Columns["company_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  160. grdCompany.Visible = true;
  161. }
  162. private void grdCompany_CellContentClick(object sender, DataGridViewCellEventArgs e)
  163. {
  164. int rowIndex = e.RowIndex;
  165. int columnIndex = e.ColumnIndex;
  166. if (columnIndex < 0 || rowIndex < 0) return;
  167. task.ProviderId = grdCompany.Rows[rowIndex].Cells["company_id"].Value.ToString();
  168. txtCompanyShortName.Text = grdCompany.Rows[rowIndex].Cells["company_short_name"].Value.ToString().Trim();
  169. grdCompany.Visible = false;
  170. return;
  171. }
  172. private void cmbTaskType_SelectedIndexChanged(object sender, EventArgs e)
  173. {
  174. string taskType = cmbTaskType.Text;
  175. bool isSaveable = false;
  176. switch (taskType)
  177. {
  178. case "净值校验":
  179. case "资产校验":
  180. case "新基金":
  181. case "净值缺失":
  182. case "资产缺失":
  183. case "历史净值":
  184. case "历史资产":
  185. lblEntityTypeName.Text = "基金";
  186. isSaveable = true;
  187. break;
  188. case "邮件处理":
  189. lblEntityTypeName.Text = "邮件";
  190. txtEntityName.Text = "暂不支持";
  191. isSaveable = false;
  192. break;
  193. case "文件解析":
  194. lblEntityTypeName.Text = "文件";
  195. txtEntityName.Text = "暂不支持";
  196. isSaveable = false;
  197. break;
  198. default:
  199. lblEntityTypeName.Text = "未知";
  200. break;
  201. }
  202. if (isSaveable == false)
  203. {
  204. txtEntityName.Enabled = false;
  205. btnEntitySearch.Enabled = false;
  206. btnSaveTask.Enabled = false;
  207. }
  208. else
  209. {
  210. txtCompanyShortName.Enabled = false;
  211. btnCompanySearch.Enabled = false;
  212. txtEntityName.Enabled = true;
  213. btnEntitySearch.Enabled = true;
  214. btnSaveTask.Enabled = true;
  215. }
  216. }
  217. private void btnEntitySearch_Click(object sender, EventArgs e)
  218. {
  219. if (txtEntityName.TextLength < 3)
  220. {
  221. MessageBox.Show("请输入至少三个字,不然结果太多看不过来 @@", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  222. txtEntityName.Focus();
  223. return;
  224. }
  225. // 只搜私募
  226. DataTable funds = DataAccess.Search_dm_fund(UIConstants.RaiseType.FirstOrDefault(x=>x.Value=="私募").Key, txtEntityName.Text.Trim());
  227. if (funds == null || funds.Rows.Count == 0)
  228. {
  229. MessageBox.Show("- - 没有找到结果,换个关键字试试?", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  230. txtEntityName.Focus();
  231. return;
  232. }
  233. grdEntity.DataSource = funds;
  234. grdEntity.Columns["fund_id"].Visible = false;
  235. grdEntity.Columns["fund_name"].Visible = false;
  236. grdEntity.Columns["company_id"].Visible = false;
  237. grdEntity.Columns["company_short_name"].Visible = false;
  238. grdEntity.Columns["strategy"].Visible = false;
  239. grdEntity.Columns["substrategy"].Visible = false;
  240. //grdEntity.Columns["max_price_date"].Visible = false;
  241. grdEntity.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  242. grdEntity.Columns["fund_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  243. grdEntity.Visible = true;
  244. }
  245. private void grdEntity_CellContentClick(object sender, DataGridViewCellEventArgs e)
  246. {
  247. int rowIndex = e.RowIndex;
  248. int columnIndex = e.ColumnIndex;
  249. if (columnIndex < 0 || rowIndex < 0) return;
  250. task.EntityId = grdEntity.Rows[rowIndex].Cells["fund_id"].Value.ToString();
  251. task.ProviderId = grdEntity.Rows[rowIndex].Cells["company_id"].Value.ToString();
  252. txtEntityName.Text = grdEntity.Rows[rowIndex].Cells["fund_short_name"].Value.ToString();
  253. txtCompanyShortName.Text = grdEntity.Rows[rowIndex].Cells["company_short_name"].Value.ToString();
  254. grdEntity.Visible = false;
  255. return;
  256. }
  257. }
  258. }