123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- using ComponentFactory.Krypton.Toolkit;
- using NXWMS.Client.Code.Extends;
- using NXWMS.Client.Model.AppModels.Condition.Base;
- using NXWMS.Client.Model.AppModels.Result;
- using NXWMS.Client.Model.AppModels.Result.Base;
- using NXWMS.Client.Model.CoreModels;
- using NXWMS.Client.String.Enums;
- using NXWMS.Commons;
- using NXWMS.Services;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace NXWMS.Forms.Base
- {
- public partial class frmCustomer : KryptonForm
- {
- /// <summary>
- /// 界面最后执行操作
- /// </summary>
- private EnumOperation _LastOperation;
- /// <summary>
- /// 客户端字段排序列表
- /// </summary>
- private List<ClientFieldOrderResult> _clientFieldOrderList;
-
- //private int _pageSize;
- //private int _pageIndex;
- //private int _totalCount;
- private int _selectIndex;
- private int _selectId;
- public frmCustomer()
- {
- InitializeComponent();
- InitData();
- InitControl();
- }
- protected override CreateParams CreateParams
- {
- get
- {
- CreateParams cp = base.CreateParams;
- cp.ExStyle |= 0x02000000;
- return cp;
- }
- }
- /// <summary>
- /// 数据初始化
- /// </summary>
- private void InitData()
- {
- _clientFieldOrderList = new List<ClientFieldOrderResult>();
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CUSTOMER_CODE", FieldDesc = "客户编号" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CUSTOMER_NAME", FieldDesc = "客户名称" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CUSTOMER_TYPE", FieldDesc = "客户类型" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PROVINCE", FieldDesc = "省" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CITY", FieldDesc = "市" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "AREA", FieldDesc = "区" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "STREET", FieldDesc = "街道" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "ROUTE", FieldDesc = "路线" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "POSTAL_CODE", FieldDesc = "邮政编码" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "ADDRESS", FieldDesc = "地址" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CONTRACT", FieldDesc = "联系人" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CONTRACT_PHONE", FieldDesc = "联系人电话" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PUT_SHELF_ORDER", FieldDesc = "缺省上架规则" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "DOWN_SHELF_ORDER", FieldDesc = "缺省分配规则" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" });
- _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" });
- }
- private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- if (e.RowIndex >= 0 && e.ColumnIndex == 0)
- {
- if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
- {
- if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
- {
- _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
- }
- this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
- }
- else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
- {
- if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
- {
- _CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
- }
- this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
- }
- else
- {
- if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
- {
- _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
- }
- this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
- }
- }
- }
- /// <summary>
- /// 选择行主键列表
- /// </summary>
- private List<string> _CheckRowIdList = new List<string>();
- /// <summary>
- /// 当前页面操作的主键
- /// </summary>
- private string _PrimaryKey = "CUSTOMER_ID";
- private void btnRemove_Click(object sender, EventArgs e)
- {
- if (_CheckRowIdList.Count == 0)
- {
- return;
- }
-
- if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
- {
- _LastOperation = EnumOperation.Remove;
- var editResult = BaseServices.customerService.Deleted(new CustomerCondition
- {
- OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
- Ids = string.Join(",", _CheckRowIdList)
- });
- if (editResult.Status == OperateStatus.Success)
- {
- KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- //groupOperation.Visible = false;
- btnSearch_Click(null, null);
- }
- }
- }
- /// <summary>
- /// 控件初始化
- /// </summary>
- private void InitControl()
- {
- CheckForIllegalCrossThreadCalls = false;
- //groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus);
- dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick);
- dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
- //TODO 0805 以下所有配置都需要从数据库或者其它地方读取,这里暂时写死,后期加上配置表,联动查询
- var fieldList = new List<FieldValue>();
- fieldList.Add(new FieldValue { Code = "Common", Name = "普通客户" });
- cmbSearchCustomerType.DataSource = fieldList;
- cmbSearchCustomerType.DisplayMember = "Name";
- cmbSearchCustomerType.ValueMember = "Code";
- cmbSearchCustomerType.SelectedIndex = -1;
- //cmbCustomerType.DataSource = fieldList;
- //cmbCustomerType.DisplayMember = "Name";
- //cmbCustomerType.ValueMember = "Code";
- //cmbCustomerType.SelectedIndex = -1;
- fieldList = new List<FieldValue>();
- fieldList.Add(new FieldValue { Code = "江苏省", Name = "江苏省" });
- cmbSearchProvince.DataSource = fieldList;
- cmbSearchProvince.DisplayMember = "Name";
- cmbSearchProvince.ValueMember = "Code";
- cmbSearchProvince.SelectedIndex = -1;
- //cmbProvince.DataSource = fieldList;
- //cmbProvince.DisplayMember = "Name";
- //cmbProvince.ValueMember = "Code";
- //cmbProvince.SelectedIndex = -1;
- fieldList = new List<FieldValue>();
- fieldList.Add(new FieldValue { Code = "无锡市", Name = "无锡市" });
- cmbSearchCity.DataSource = fieldList;
- cmbSearchCity.DisplayMember = "Name";
- cmbSearchCity.ValueMember = "Code";
- cmbSearchCity.SelectedIndex = -1;
- //cmbCity.DataSource = fieldList;
- //cmbCity.DisplayMember = "Name";
- //cmbCity.ValueMember = "Code";
- //cmbCity.SelectedIndex = -1;
- fieldList = new List<FieldValue>();
- fieldList.Add(new FieldValue { Code = "锡山区", Name = "锡山区" });
- //cmbArea.DataSource = fieldList;
- //cmbArea.DisplayMember = "Name";
- //cmbArea.ValueMember = "Code";
- //cmbArea.SelectedIndex = -1;
- //_pageIndex = 1;
- //_pageSize = 20;
- }
- private void groupOperation_GostFocus(object sender, EventArgs e)
- {
- //groupOperation.Values.Heading = _LastOperation.Display();
- ////groupOperation.Values.Image = Image.FromFile(_LastOperation.ImagePath());
- //groupOperation.Text = $"{ _LastOperation.Display()}数据";
- //lbStatusMessage.Visible = true;
- }
- private void btnSearch_Click(object sender, EventArgs e)
- {
- //_pageIndex = 1;
- var loadfrm = new frmLoading();
- loadfrm.Show();
- // pageTool.Initialize(LoadSearch, 0, _pageSize);
- var message = loadfrm.EventCalExec(LoadSearch,this.pageTool.PageIndex,this.pageTool.PageSize);
- //pageTool.DataCount = _totalCount;
- if (!string.IsNullOrWhiteSpace(message))
- {
- KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- private string LoadSearch(int pageIndex, int pageSize)
- {
- var result = BaseServices.customerService.GetList(new CustomerSearchCondition
- {
- OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
- City = cmbSearchCity.SelectedValue.GetObjectToString(),
- //CustomerCode = txtCustomerCode.Text,
- CustomerName = txtSearchCustomerName.Text,
- CustomerType = cmbSearchCustomerType.SelectedValue.GetObjectToString(),
- Province = cmbSearchProvince.SelectedValue.GetObjectToString(),
- IsUsed = chkSearchUse.Checked,
- PageIndex = pageIndex,
- PageSize = pageSize
- });
- if (result.Status == OperateStatus.Success)
- {
- this.pageTool.DataCount = result.Data.TotalCount;
- //_totalCount = result.Data.TotalCount;
- //_pageIndex = pageIndex;
- //_pageSize = pageSize;
- if (result.Data.RowData.Any())
- {
- dataGridView.Columns.Clear();
- dataGridView.DataSource = result.Data.RowData.ToList();
- dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
- }
- else
- {
- if (dataGridView.DataSource != null)
- {
- dataGridView.DataSource = new List<CustomerResult>();
- }
- dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
- }
- return string.Empty;
- }
- else
- {
- return result.Message;
- }
- }
- private void btnSearchExport_Click(object sender, EventArgs e)
- {
- this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault().MenuName}列表" + DateTime.Now.ToString("yyyyMMddHH"));
- }
- private void btnAdd_Click(object sender, EventArgs e)
- {
- //if (!groupOperation.Visible)
- //{
- _selectId = 0;
- var frm = new ChildFrm.FrmCustomerEdit();
- frm.Id = _selectId;
- frm.tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
- frm.operation = EnumOperation.Add;
- frm.InitControl();
- if (frm.ShowDialog()==DialogResult.OK)
- {
- this.btnSearch_Click(null, null);
- }
- //richDescibe.Text = "";
- //_LastOperation = EnumOperation.Add;
- //txtCustomerCode.Enabled = true;
- //groupOperation.Visible = true;
- //groupOperation.Focus();
- //}
- }
- private void btnEdit_Click(object sender, EventArgs e)
- {
- dataGridView_CellDoubleClick(null, null);
- }
- private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- SelectInit();
- if (_selectIndex >= 0)
- {
- var frm = new ChildFrm.FrmCustomerEdit();
- frm.Id = this._selectIndex;
- frm.operation = EnumOperation.Edit;
- frm.InitControl();
- //_LastOperation = EnumOperation.Edit;
- frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
- if (frm.ShowDialog() == DialogResult.OK)
- {
- this.btnSearch_Click(null, null);
- dataGridView.ClearSelection();
- }
- //richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
- // dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
- //txtCustomerCode.Enabled = false;
- //groupOperation.Visible = true;
- //groupOperation.Focus();
- }
- }
- private void SelectInit()
- {
- _selectIndex = dataGridView.SelectedRows[0].Index;
- if (_selectIndex >= 0)
- {
- _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
- }
- }
-
- private void dataGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
- {
- // e.Row.HeaderCell.Value = string.Format("{0}", (_pageIndex - 1) * _pageSize + e.Row.Index + 1);
- }
- private void btnExit_Click(object sender, EventArgs e)
- {
- if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
- {
- //groupOperation.Visible = false;
- }
- else
- {
- //groupOperation.Visible = true;
- //groupOperation.Focus();
- }
- }
- private Point mouse_offset;
- private void groupOperation_MouseDown(object sender, MouseEventArgs e)
- {
- mouse_offset = new Point(-e.X, -e.Y);
- }
- private void groupOperation_MouseMove(object sender, MouseEventArgs e)
- {
- ((Control)sender).Cursor = Cursors.Arrow;
- if (e.Button == MouseButtons.Left)
- {
- Point mousePos = MousePosition;
- mousePos.Offset(mouse_offset.X, mouse_offset.Y);
- ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
- Application.DoEvents();
- }
- }
- private void pageTool_OnPageChange(int PageIndex, int PageSzie)
- {
- this.btnSearch_Click(null, null);
- }
- private void kryptonLabel5_Paint(object sender, PaintEventArgs e)
- {
- }
- private void btnSearchImport_Click(object sender, EventArgs e)
- {
- var SyncResult = BaseServices.customerService.SyncERP();
- if (SyncResult.Status == OperateStatus.Success)
- {
- this.btnSearch_Click(null, null);
- } else
- {
- KryptonMessageBox.Show($"操作失败!\r\n{SyncResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- }
- }
|