123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- 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.Xml.XPath;
- using static DataManager.UIConstants;
- namespace DataManager
- {
- public partial class frmContactTask : Form
- {
- private ContactTask task = null;
- private string memo = string.Empty;
-
- // 模式:0-新任务,1-编辑已有任务,2-指定公司的新任务
- private int mode = 0;
- public frmContactTask(int userId)
- {
- task = new ContactTask();
- task.UserId = userId;
- task.TaskType = 1; // 建立联系
- task.TaskDate = DateTime.Now;
- task.Priority = 2; // 高
- task.Isvalid = 3; // 等待答复
- task.FollowUpDate = DateTime.Now.AddDays(3); // 缺省3天之后跟进
- InitializeComponent();
- this.mode = 0;
- InitializeData();
- }
- public frmContactTask(int userId, string companyId, string companyShortName)
- {
- task = new ContactTask();
- task.UserId = userId;
- task.TaskType = 1; // 建立联系
- task.TaskDate = DateTime.Now;
- task.Priority = 2; // 高
- task.Isvalid = 3; // 等待答复
- task.FollowUpDate = DateTime.Now.AddDays(3); // 缺省3天之后跟进
- task.CompanyId = companyId;
- task.CompanyShortName = companyShortName;
- InitializeComponent();
- this.mode = 2;
- InitializeData();
- }
- public frmContactTask(ContactTask contactTask)
- {
- this.task = contactTask;
-
- InitializeComponent();
-
- this.mode = 1;
- InitializeData();
- memo = GetTaskMemo();
- }
- private void InitializeData()
- {
- this.Text = this.Text + " " + (mode == 0 ? "新任务" : task.TaskId.ToString());
- BindingSource bs1 = new BindingSource();
- bs1.DataSource = UIConstants.ContactTaskType;
- this.cmbTaskType.DataSource = bs1;
- this.cmbTaskType.DisplayMember = "Value";
- this.cmbTaskType.ValueMember = "Key";
- this.cmbTaskType.SelectedValue = (int)task.TaskType;
- // 已有任务不可以改变任务类型
- cmbTaskType.Enabled = (mode == 0 ? true : false);
- this.dtpTaskDate.Text = task.TaskDate.ToString();
- this.txtCompanyShortName.Text = task.CompanyShortName;
-
- switch(mode)
- {
- case 1:
- this.cmbTaskType.Enabled = false;
- this.dtpTaskDate.Enabled = false;
- this.txtCompanyShortName.ReadOnly = true;
- this.btnCompanySearch.Enabled = false;
- break;
- case 0:
- this.btnDelTask.Enabled = false;
- break;
- case 2:
- this.cmbTaskType.Enabled = true;
- this.dtpTaskDate.Enabled = true;
- this.txtCompanyShortName.ReadOnly = true;
- this.btnCompanySearch.Enabled = false;
- this.btnDelTask.Enabled = false;
- break;
- }
- BindingSource bs = new BindingSource();
- bs.DataSource = UIConstants.TaskPriority;
- this.cmbPriority.DataSource = bs;
- this.cmbPriority.DisplayMember = "Value";
- this.cmbPriority.ValueMember = "Key";
- this.cmbPriority.SelectedValue = (int)task.Priority;
- BindingSource bs2 = new BindingSource();
- bs2.DataSource = UIConstants.ContactTaskStatus;
- this.cmbIsValid.DataSource = bs2;
- this.cmbIsValid.DisplayMember = "Value";
- this.cmbIsValid.ValueMember = "Key";
- this.cmbIsValid.SelectedValue = (int)task.Isvalid;
- this.dtpFollowUpDate.ShowCheckBox = true;
- if (task.FollowUpDate != null)
- {
- this.dtpFollowUpDate.Text = task.FollowUpDate.ToString();
- this.dtpFollowUpDate.Checked = true;
- }
- else
- this.dtpFollowUpDate.Checked = false;
- }
- private string GetTaskMemo()
- {
- string memo = string.Empty;
- if (task != null && task.TaskId > 0)
- {
- DataTable dt = DataAccess.Get_dm_memo((sbyte)UIConstants.JobType.联络, task.TaskId);
- if (dt != null && dt.Rows.Count > 0)
- {
- memo = dt.Rows[0]["memo"].ToString().Trim();
- }
- }
- txtMemo.Text = memo;
- return memo;
- }
- private void SaveTaskMemo()
- {
- string newMemo = txtMemo.Text.Trim();
- if (memo != newMemo)
- {
- DataAccess.Set_dm_memo((sbyte)UIConstants.JobType.联络, task.TaskId, newMemo, task.UserId);
- }
- return;
- }
- private void btnSaveTask_Click(object sender, EventArgs e)
- {
- if (task.CompanyId == null || task.CompanyId.Length != 10)
- {
- MessageBox.Show("还没输入公司呢...", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- txtCompanyShortName.Focus();
- return;
- }
- task.TaskType = Int16.Parse(cmbTaskType.SelectedValue.ToString());
- task.TaskDate = DateTime.Parse(dtpTaskDate.Text);
- task.Priority = SByte.Parse(cmbPriority.SelectedValue.ToString());
- task.Isvalid = SByte.Parse(cmbIsValid.SelectedValue.ToString());
- if (dtpFollowUpDate.Checked == false)
- task.FollowUpDate = null;
- else
- task.FollowUpDate = DateTime.Parse(dtpFollowUpDate.Text);
- // 写回数据库时,新记录会INSERT记录并产生一个自增长的task_id
- task.TaskId = task.SaveToSQL(task.UserId);
- SaveTaskMemo();
- this.DialogResult = DialogResult.OK;
- this.Close();
-
- }
- private void btnCompanySearch_Click(object sender, EventArgs e)
- {
- if(txtCompanyShortName.TextLength < 2)
- {
- MessageBox.Show("请输入至少两个字,不然结果太多看不过来 @@", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- txtCompanyShortName.Focus();
- return;
- }
- // 只搜索私募公司
- DataTable companys = DataAccess.Search_dm_company(UIConstants.CompanyType.FirstOrDefault(x=>x.Value== "私募证券投资").Key, txtCompanyShortName.Text.Trim());
- if (companys == null || companys.Rows.Count == 0)
- {
- MessageBox.Show("- - 没有找到结果,换个关键字试试?", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- txtCompanyShortName.Focus();
- return;
- }
-
- grdCompany.DataSource = companys;
- grdCompany.Columns["company_id"].Visible = false;
- grdCompany.Columns["company_name"].Visible = false;
- grdCompany.Columns["company_asset_size"].Visible = false;
- grdCompany.Columns["register_number"].Visible = false;
- grdCompany.Columns["establish_date"].Visible = false;
- grdCompany.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
- grdCompany.Columns["company_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
- grdCompany.Visible = true;
- }
- private void grdCompany_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- int rowIndex = e.RowIndex;
- int columnIndex = e.ColumnIndex;
- if (columnIndex < 0 || rowIndex < 0) return;
- task.CompanyId = grdCompany.Rows[rowIndex].Cells["company_id"].Value.ToString();
- txtCompanyShortName.Text = grdCompany.Rows[rowIndex].Cells["company_short_name"].Value.ToString().Trim();
- grdCompany.Visible = false;
- return;
- }
- }
- }
|