123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- using System;
- using System.CodeDom;
- 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;
- namespace DataManager
- {
- public partial class UICollectionTask : Form
- {
- private CollectionTask task = null;
- private string memo = string.Empty;
- // 模式:0-新任务,1-编辑已有任务, 2-指定公司的新任务
- private int mode = 0;
- public UICollectionTask(int userId)
- {
- task = new CollectionTask();
- task.UserId = userId;
- task.TaskType = 6; // 净值缺失
- task.TaskDate = DateTime.Now;
- task.Isvalid = 3; // 等待回复
- InitializeComponent();
- this.mode = 0;
- InitializeData();
- }
- public UICollectionTask(int userId, string providerId, string providerShortName)
- {
- task = new CollectionTask();
- task.UserId = userId;
- task.TaskType = 6; // 净值缺失
- task.TaskDate = DateTime.Now;
- task.Isvalid = 3; // 等待回复
- task.ProviderId = providerId;
- task.ProviderName = providerShortName;
- InitializeComponent();
- this.mode = 2;
- InitializeData();
- }
- public UICollectionTask(CollectionTask task)
- {
- this.task = task;
- 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.CollectionTaskType;
- 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.ProviderName;
- switch (mode)
- {
- case 1:
- this.cmbTaskType.Enabled = false;
- this.dtpTaskDate.Enabled = false;
- this.txtCompanyShortName.ReadOnly = true;
- this.btnCompanySearch.Enabled = false;
- this.txtEntityName.ReadOnly = true;
- this.txtEntityName.Text = task.EntityName;
- break;
- case 0:
- this.btnDelTask.Visible = false;
- break;
- case 2:
- this.cmbTaskType.Enabled = true;
- this.dtpTaskDate.Enabled = true;
- this.txtCompanyShortName.ReadOnly = true;
- this.btnCompanySearch.Enabled = false;
- this.btnDelTask.Visible = false;
- break;
- }
- BindingSource bs2 = new BindingSource();
- bs2.DataSource = UIConstants.CollectionTaskStatus;;
- this.cmbIsValid.DataSource = bs2;
- this.cmbIsValid.DisplayMember = "Value";
- this.cmbIsValid.ValueMember = "Key";
- this.cmbIsValid.SelectedValue = (int)task.Isvalid;
- }
- 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, int.Parse(task.UserId.ToString()));
- }
- return;
- }
- private void btnSaveTask_Click(object sender, EventArgs e)
- {
- if (task.TaskId <= 0)
- {
- // need generate a new task id
- };
- if (task.ProviderId == null || task.ProviderId.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.Isvalid = SByte.Parse(cmbIsValid.SelectedValue.ToString());
- // 写回数据库时,新记录会INSERT记录并产生一个自增长的task_id
- task.TaskId = task.SaveToSQL(int.Parse(task.UserId.ToString()));
-
- 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.ProviderId = grdCompany.Rows[rowIndex].Cells["company_id"].Value.ToString();
- txtCompanyShortName.Text = grdCompany.Rows[rowIndex].Cells["company_short_name"].Value.ToString().Trim();
- grdCompany.Visible = false;
- return;
- }
- private void cmbTaskType_SelectedIndexChanged(object sender, EventArgs e)
- {
- string taskType = cmbTaskType.Text;
- bool isSaveable = false;
- switch (taskType)
- {
- case "净值校验":
- case "资产校验":
- case "新基金":
- case "净值缺失":
- case "资产缺失":
- case "历史净值":
- case "历史资产":
- lblEntityTypeName.Text = "基金";
- isSaveable = true;
- break;
- case "邮件处理":
- lblEntityTypeName.Text = "邮件";
- txtEntityName.Text = "暂不支持";
- isSaveable = false;
- break;
- case "文件解析":
- lblEntityTypeName.Text = "文件";
- txtEntityName.Text = "暂不支持";
- isSaveable = false;
- break;
- default:
- lblEntityTypeName.Text = "未知";
- break;
- }
- if (isSaveable == false)
- {
- txtEntityName.Enabled = false;
- btnEntitySearch.Enabled = false;
- btnSaveTask.Enabled = false;
- }
- else
- {
- txtCompanyShortName.Enabled = false;
- btnCompanySearch.Enabled = false;
- txtEntityName.Enabled = true;
- btnEntitySearch.Enabled = true;
- btnSaveTask.Enabled = true;
- }
- }
- private void btnEntitySearch_Click(object sender, EventArgs e)
- {
- if (txtEntityName.TextLength < 3)
- {
- MessageBox.Show("请输入至少三个字,不然结果太多看不过来 @@", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- txtEntityName.Focus();
- return;
- }
- // 只搜私募
- DataTable funds = DataAccess.Search_dm_fund(UIConstants.RaiseType.FirstOrDefault(x=>x.Value=="私募").Key, txtEntityName.Text.Trim());
- if (funds == null || funds.Rows.Count == 0)
- {
- MessageBox.Show("- - 没有找到结果,换个关键字试试?", "建议信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- txtEntityName.Focus();
- return;
- }
- grdEntity.DataSource = funds;
- grdEntity.Columns["fund_id"].Visible = false;
- grdEntity.Columns["fund_name"].Visible = false;
- grdEntity.Columns["company_id"].Visible = false;
- grdEntity.Columns["company_short_name"].Visible = false;
- grdEntity.Columns["strategy"].Visible = false;
- grdEntity.Columns["substrategy"].Visible = false;
- //grdEntity.Columns["max_price_date"].Visible = false;
- grdEntity.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
- grdEntity.Columns["fund_short_name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
- grdEntity.Visible = true;
- }
- private void grdEntity_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- int rowIndex = e.RowIndex;
- int columnIndex = e.ColumnIndex;
- if (columnIndex < 0 || rowIndex < 0) return;
- task.EntityId = grdEntity.Rows[rowIndex].Cells["fund_id"].Value.ToString();
- task.ProviderId = grdEntity.Rows[rowIndex].Cells["company_id"].Value.ToString();
- txtEntityName.Text = grdEntity.Rows[rowIndex].Cells["fund_short_name"].Value.ToString();
- txtCompanyShortName.Text = grdEntity.Rows[rowIndex].Cells["company_short_name"].Value.ToString();
-
- grdEntity.Visible = false;
- return;
- }
- }
- }
|