UIContactTask.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Xml.XPath;
  11. using static DataManager.UIConstants;
  12. namespace DataManager
  13. {
  14. public partial class frmContactTask : Form
  15. {
  16. private ContactTask task = null;
  17. private string memo = string.Empty;
  18. // 模式:0-新任务,1-编辑已有任务,2-指定公司的新任务
  19. private int mode = 0;
  20. public frmContactTask(int userId)
  21. {
  22. task = new ContactTask();
  23. task.UserId = userId;
  24. task.TaskType = 1; // 建立联系
  25. task.TaskDate = DateTime.Now;
  26. task.Priority = 2; // 高
  27. task.Isvalid = 3; // 等待答复
  28. task.FollowUpDate = DateTime.Now.AddDays(3); // 缺省3天之后跟进
  29. InitializeComponent();
  30. this.mode = 0;
  31. InitializeData();
  32. }
  33. public frmContactTask(int userId, string companyId, string companyShortName)
  34. {
  35. task = new ContactTask();
  36. task.UserId = userId;
  37. task.TaskType = 1; // 建立联系
  38. task.TaskDate = DateTime.Now;
  39. task.Priority = 2; // 高
  40. task.Isvalid = 3; // 等待答复
  41. task.FollowUpDate = DateTime.Now.AddDays(3); // 缺省3天之后跟进
  42. task.CompanyId = companyId;
  43. task.CompanyShortName = companyShortName;
  44. InitializeComponent();
  45. this.mode = 2;
  46. InitializeData();
  47. }
  48. public frmContactTask(ContactTask contactTask)
  49. {
  50. this.task = contactTask;
  51. InitializeComponent();
  52. this.mode = 1;
  53. InitializeData();
  54. memo = GetTaskMemo();
  55. }
  56. private void InitializeData()
  57. {
  58. this.Text = this.Text + " " + (mode == 0 ? "新任务" : task.TaskId.ToString());
  59. BindingSource bs1 = new BindingSource();
  60. bs1.DataSource = UIConstants.ContactTaskType;
  61. this.cmbTaskType.DataSource = bs1;
  62. this.cmbTaskType.DisplayMember = "Value";
  63. this.cmbTaskType.ValueMember = "Key";
  64. this.cmbTaskType.SelectedValue = (int)task.TaskType;
  65. // 已有任务不可以改变任务类型
  66. cmbTaskType.Enabled = (mode == 0 ? true : false);
  67. this.dtpTaskDate.Text = task.TaskDate.ToString();
  68. this.txtCompanyShortName.Text = task.CompanyShortName;
  69. switch(mode)
  70. {
  71. case 1:
  72. this.cmbTaskType.Enabled = false;
  73. this.dtpTaskDate.Enabled = false;
  74. this.txtCompanyShortName.ReadOnly = true;
  75. this.btnCompanySearch.Enabled = false;
  76. break;
  77. case 0:
  78. this.btnDelTask.Enabled = false;
  79. break;
  80. case 2:
  81. this.cmbTaskType.Enabled = true;
  82. this.dtpTaskDate.Enabled = true;
  83. this.txtCompanyShortName.ReadOnly = true;
  84. this.btnCompanySearch.Enabled = false;
  85. this.btnDelTask.Enabled = false;
  86. break;
  87. }
  88. BindingSource bs = new BindingSource();
  89. bs.DataSource = UIConstants.TaskPriority;
  90. this.cmbPriority.DataSource = bs;
  91. this.cmbPriority.DisplayMember = "Value";
  92. this.cmbPriority.ValueMember = "Key";
  93. this.cmbPriority.SelectedValue = (int)task.Priority;
  94. BindingSource bs2 = new BindingSource();
  95. bs2.DataSource = UIConstants.ContactTaskStatus;
  96. this.cmbIsValid.DataSource = bs2;
  97. this.cmbIsValid.DisplayMember = "Value";
  98. this.cmbIsValid.ValueMember = "Key";
  99. this.cmbIsValid.SelectedValue = (int)task.Isvalid;
  100. this.dtpFollowUpDate.ShowCheckBox = true;
  101. if (task.FollowUpDate != null)
  102. {
  103. this.dtpFollowUpDate.Text = task.FollowUpDate.ToString();
  104. this.dtpFollowUpDate.Checked = true;
  105. }
  106. else
  107. this.dtpFollowUpDate.Checked = false;
  108. }
  109. private string GetTaskMemo()
  110. {
  111. string memo = string.Empty;
  112. if (task != null && task.TaskId > 0)
  113. {
  114. DataTable dt = DataAccess.Get_dm_memo((sbyte)UIConstants.JobType.联络, task.TaskId);
  115. if (dt != null && dt.Rows.Count > 0)
  116. {
  117. memo = dt.Rows[0]["memo"].ToString().Trim();
  118. }
  119. }
  120. txtMemo.Text = memo;
  121. return memo;
  122. }
  123. private void SaveTaskMemo()
  124. {
  125. string newMemo = txtMemo.Text.Trim();
  126. if (memo != newMemo)
  127. {
  128. DataAccess.Set_dm_memo((sbyte)UIConstants.JobType.联络, task.TaskId, newMemo, task.UserId);
  129. }
  130. return;
  131. }
  132. private void btnSaveTask_Click(object sender, EventArgs e)
  133. {
  134. if (task.CompanyId == null || task.CompanyId.Length != 10)
  135. {
  136. MessageBox.Show("还没输入公司呢...", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  137. txtCompanyShortName.Focus();
  138. return;
  139. }
  140. task.TaskType = Int16.Parse(cmbTaskType.SelectedValue.ToString());
  141. task.TaskDate = DateTime.Parse(dtpTaskDate.Text);
  142. task.Priority = SByte.Parse(cmbPriority.SelectedValue.ToString());
  143. task.Isvalid = SByte.Parse(cmbIsValid.SelectedValue.ToString());
  144. if (dtpFollowUpDate.Checked == false)
  145. task.FollowUpDate = null;
  146. else
  147. task.FollowUpDate = DateTime.Parse(dtpFollowUpDate.Text);
  148. // 写回数据库时,新记录会INSERT记录并产生一个自增长的task_id
  149. task.TaskId = task.SaveToSQL(task.UserId);
  150. SaveTaskMemo();
  151. this.DialogResult = DialogResult.OK;
  152. this.Close();
  153. }
  154. private void btnCompanySearch_Click(object sender, EventArgs e)
  155. {
  156. if(txtCompanyShortName.TextLength < 2)
  157. {
  158. MessageBox.Show("请输入至少两个字,不然结果太多看不过来 @@", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  159. txtCompanyShortName.Focus();
  160. return;
  161. }
  162. // 只搜索私募公司
  163. DataTable companys = DataAccess.Search_dm_company(UIConstants.CompanyType.FirstOrDefault(x=>x.Value== "私募证券投资").Key, txtCompanyShortName.Text.Trim());
  164. if (companys == null || companys.Rows.Count == 0)
  165. {
  166. MessageBox.Show("- - 没有找到结果,换个关键字试试?", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  167. txtCompanyShortName.Focus();
  168. return;
  169. }
  170. grdCompany.DataSource = companys;
  171. grdCompany.Columns["company_id"].Visible = false;
  172. grdCompany.Columns["company_name"].Visible = false;
  173. grdCompany.Columns["company_asset_size"].Visible = false;
  174. grdCompany.Columns["register_number"].Visible = false;
  175. grdCompany.Columns["establish_date"].Visible = false;
  176. grdCompany.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  177. grdCompany.Columns["company_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
  178. grdCompany.Visible = true;
  179. }
  180. private void grdCompany_CellContentClick(object sender, DataGridViewCellEventArgs e)
  181. {
  182. int rowIndex = e.RowIndex;
  183. int columnIndex = e.ColumnIndex;
  184. if (columnIndex < 0 || rowIndex < 0) return;
  185. task.CompanyId = grdCompany.Rows[rowIndex].Cells["company_id"].Value.ToString();
  186. txtCompanyShortName.Text = grdCompany.Rows[rowIndex].Cells["company_short_name"].Value.ToString().Trim();
  187. grdCompany.Visible = false;
  188. return;
  189. }
  190. }
  191. }