frmCustomer.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Code.Extends;
  3. using NXWMS.Client.Model.AppModels.Condition.Base;
  4. using NXWMS.Client.Model.AppModels.Result;
  5. using NXWMS.Client.Model.AppModels.Result.Base;
  6. using NXWMS.Client.Model.CoreModels;
  7. using NXWMS.Client.String.Enums;
  8. using NXWMS.Commons;
  9. using NXWMS.Services;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Drawing;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Windows.Forms;
  18. namespace NXWMS.Forms.Base
  19. {
  20. public partial class frmCustomer : KryptonForm
  21. {
  22. /// <summary>
  23. /// 界面最后执行操作
  24. /// </summary>
  25. private EnumOperation _LastOperation;
  26. /// <summary>
  27. /// 客户端字段排序列表
  28. /// </summary>
  29. private List<ClientFieldOrderResult> _clientFieldOrderList;
  30. //private int _pageSize;
  31. //private int _pageIndex;
  32. //private int _totalCount;
  33. private int _selectIndex;
  34. private int _selectId;
  35. public frmCustomer()
  36. {
  37. InitializeComponent();
  38. InitData();
  39. InitControl();
  40. }
  41. protected override CreateParams CreateParams
  42. {
  43. get
  44. {
  45. CreateParams cp = base.CreateParams;
  46. cp.ExStyle |= 0x02000000;
  47. return cp;
  48. }
  49. }
  50. /// <summary>
  51. /// 数据初始化
  52. /// </summary>
  53. private void InitData()
  54. {
  55. _clientFieldOrderList = new List<ClientFieldOrderResult>();
  56. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CUSTOMER_CODE", FieldDesc = "客户编号" });
  57. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CUSTOMER_NAME", FieldDesc = "客户名称" });
  58. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CUSTOMER_TYPE", FieldDesc = "客户类型" });
  59. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PROVINCE", FieldDesc = "省" });
  60. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CITY", FieldDesc = "市" });
  61. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "AREA", FieldDesc = "区" });
  62. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "STREET", FieldDesc = "街道" });
  63. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "ROUTE", FieldDesc = "路线" });
  64. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "POSTAL_CODE", FieldDesc = "邮政编码" });
  65. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "ADDRESS", FieldDesc = "地址" });
  66. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" });
  67. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CONTRACT", FieldDesc = "联系人" });
  68. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CONTRACT_PHONE", FieldDesc = "联系人电话" });
  69. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PUT_SHELF_ORDER", FieldDesc = "缺省上架规则" });
  70. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "DOWN_SHELF_ORDER", FieldDesc = "缺省分配规则" });
  71. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" });
  72. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" });
  73. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" });
  74. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" });
  75. }
  76. private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
  77. {
  78. if (e.RowIndex >= 0 && e.ColumnIndex == 0)
  79. {
  80. if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
  81. {
  82. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  83. {
  84. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  85. }
  86. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  87. }
  88. else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
  89. {
  90. if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  91. {
  92. _CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  93. }
  94. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
  95. }
  96. else
  97. {
  98. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  99. {
  100. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  101. }
  102. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  103. }
  104. }
  105. }
  106. /// <summary>
  107. /// 选择行主键列表
  108. /// </summary>
  109. private List<string> _CheckRowIdList = new List<string>();
  110. /// <summary>
  111. /// 当前页面操作的主键
  112. /// </summary>
  113. private string _PrimaryKey = "CUSTOMER_ID";
  114. private void btnRemove_Click(object sender, EventArgs e)
  115. {
  116. if (_CheckRowIdList.Count == 0)
  117. {
  118. return;
  119. }
  120. if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  121. {
  122. _LastOperation = EnumOperation.Remove;
  123. var editResult = BaseServices.customerService.Deleted(new CustomerCondition
  124. {
  125. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  126. Ids = string.Join(",", _CheckRowIdList)
  127. });
  128. if (editResult.Status == OperateStatus.Success)
  129. {
  130. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  131. //groupOperation.Visible = false;
  132. btnSearch_Click(null, null);
  133. }
  134. }
  135. }
  136. /// <summary>
  137. /// 控件初始化
  138. /// </summary>
  139. private void InitControl()
  140. {
  141. CheckForIllegalCrossThreadCalls = false;
  142. //groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus);
  143. dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick);
  144. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  145. //TODO 0805 以下所有配置都需要从数据库或者其它地方读取,这里暂时写死,后期加上配置表,联动查询
  146. var fieldList = new List<FieldValue>();
  147. fieldList.Add(new FieldValue { Code = "Common", Name = "普通客户" });
  148. cmbSearchCustomerType.DataSource = fieldList;
  149. cmbSearchCustomerType.DisplayMember = "Name";
  150. cmbSearchCustomerType.ValueMember = "Code";
  151. cmbSearchCustomerType.SelectedIndex = -1;
  152. //cmbCustomerType.DataSource = fieldList;
  153. //cmbCustomerType.DisplayMember = "Name";
  154. //cmbCustomerType.ValueMember = "Code";
  155. //cmbCustomerType.SelectedIndex = -1;
  156. fieldList = new List<FieldValue>();
  157. fieldList.Add(new FieldValue { Code = "江苏省", Name = "江苏省" });
  158. cmbSearchProvince.DataSource = fieldList;
  159. cmbSearchProvince.DisplayMember = "Name";
  160. cmbSearchProvince.ValueMember = "Code";
  161. cmbSearchProvince.SelectedIndex = -1;
  162. //cmbProvince.DataSource = fieldList;
  163. //cmbProvince.DisplayMember = "Name";
  164. //cmbProvince.ValueMember = "Code";
  165. //cmbProvince.SelectedIndex = -1;
  166. fieldList = new List<FieldValue>();
  167. fieldList.Add(new FieldValue { Code = "无锡市", Name = "无锡市" });
  168. cmbSearchCity.DataSource = fieldList;
  169. cmbSearchCity.DisplayMember = "Name";
  170. cmbSearchCity.ValueMember = "Code";
  171. cmbSearchCity.SelectedIndex = -1;
  172. //cmbCity.DataSource = fieldList;
  173. //cmbCity.DisplayMember = "Name";
  174. //cmbCity.ValueMember = "Code";
  175. //cmbCity.SelectedIndex = -1;
  176. fieldList = new List<FieldValue>();
  177. fieldList.Add(new FieldValue { Code = "锡山区", Name = "锡山区" });
  178. //cmbArea.DataSource = fieldList;
  179. //cmbArea.DisplayMember = "Name";
  180. //cmbArea.ValueMember = "Code";
  181. //cmbArea.SelectedIndex = -1;
  182. //_pageIndex = 1;
  183. //_pageSize = 20;
  184. }
  185. private void groupOperation_GostFocus(object sender, EventArgs e)
  186. {
  187. //groupOperation.Values.Heading = _LastOperation.Display();
  188. ////groupOperation.Values.Image = Image.FromFile(_LastOperation.ImagePath());
  189. //groupOperation.Text = $"{ _LastOperation.Display()}数据";
  190. //lbStatusMessage.Visible = true;
  191. }
  192. private void btnSearch_Click(object sender, EventArgs e)
  193. {
  194. //_pageIndex = 1;
  195. var loadfrm = new frmLoading();
  196. loadfrm.Show();
  197. // pageTool.Initialize(LoadSearch, 0, _pageSize);
  198. var message = loadfrm.EventCalExec(LoadSearch,this.pageTool.PageIndex,this.pageTool.PageSize);
  199. //pageTool.DataCount = _totalCount;
  200. if (!string.IsNullOrWhiteSpace(message))
  201. {
  202. KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  203. }
  204. }
  205. private string LoadSearch(int pageIndex, int pageSize)
  206. {
  207. var result = BaseServices.customerService.GetList(new CustomerSearchCondition
  208. {
  209. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  210. City = cmbSearchCity.SelectedValue.GetObjectToString(),
  211. //CustomerCode = txtCustomerCode.Text,
  212. CustomerName = txtSearchCustomerName.Text,
  213. CustomerType = cmbSearchCustomerType.SelectedValue.GetObjectToString(),
  214. Province = cmbSearchProvince.SelectedValue.GetObjectToString(),
  215. IsUsed = chkSearchUse.Checked,
  216. PageIndex = pageIndex,
  217. PageSize = pageSize
  218. });
  219. if (result.Status == OperateStatus.Success)
  220. {
  221. this.pageTool.DataCount = result.Data.TotalCount;
  222. //_totalCount = result.Data.TotalCount;
  223. //_pageIndex = pageIndex;
  224. //_pageSize = pageSize;
  225. if (result.Data.RowData.Any())
  226. {
  227. dataGridView.Columns.Clear();
  228. dataGridView.DataSource = result.Data.RowData.ToList();
  229. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
  230. }
  231. else
  232. {
  233. if (dataGridView.DataSource != null)
  234. {
  235. dataGridView.DataSource = new List<CustomerResult>();
  236. }
  237. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  238. }
  239. return string.Empty;
  240. }
  241. else
  242. {
  243. return result.Message;
  244. }
  245. }
  246. private void btnSearchExport_Click(object sender, EventArgs e)
  247. {
  248. this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault().MenuName}列表" + DateTime.Now.ToString("yyyyMMddHH"));
  249. }
  250. private void btnAdd_Click(object sender, EventArgs e)
  251. {
  252. //if (!groupOperation.Visible)
  253. //{
  254. _selectId = 0;
  255. var frm = new ChildFrm.FrmCustomerEdit();
  256. frm.Id = _selectId;
  257. frm.tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
  258. frm.operation = EnumOperation.Add;
  259. frm.InitControl();
  260. if (frm.ShowDialog()==DialogResult.OK)
  261. {
  262. this.btnSearch_Click(null, null);
  263. }
  264. //richDescibe.Text = "";
  265. //_LastOperation = EnumOperation.Add;
  266. //txtCustomerCode.Enabled = true;
  267. //groupOperation.Visible = true;
  268. //groupOperation.Focus();
  269. //}
  270. }
  271. private void btnEdit_Click(object sender, EventArgs e)
  272. {
  273. dataGridView_CellDoubleClick(null, null);
  274. }
  275. private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  276. {
  277. SelectInit();
  278. if (_selectIndex >= 0)
  279. {
  280. var frm = new ChildFrm.FrmCustomerEdit();
  281. frm.Id = this._selectIndex;
  282. frm.operation = EnumOperation.Edit;
  283. frm.InitControl();
  284. //_LastOperation = EnumOperation.Edit;
  285. frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  286. if (frm.ShowDialog() == DialogResult.OK)
  287. {
  288. this.btnSearch_Click(null, null);
  289. dataGridView.ClearSelection();
  290. }
  291. //richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  292. // dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  293. //txtCustomerCode.Enabled = false;
  294. //groupOperation.Visible = true;
  295. //groupOperation.Focus();
  296. }
  297. }
  298. private void SelectInit()
  299. {
  300. _selectIndex = dataGridView.SelectedRows[0].Index;
  301. if (_selectIndex >= 0)
  302. {
  303. _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  304. }
  305. }
  306. private void dataGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
  307. {
  308. // e.Row.HeaderCell.Value = string.Format("{0}", (_pageIndex - 1) * _pageSize + e.Row.Index + 1);
  309. }
  310. private void btnExit_Click(object sender, EventArgs e)
  311. {
  312. if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  313. {
  314. //groupOperation.Visible = false;
  315. }
  316. else
  317. {
  318. //groupOperation.Visible = true;
  319. //groupOperation.Focus();
  320. }
  321. }
  322. private Point mouse_offset;
  323. private void groupOperation_MouseDown(object sender, MouseEventArgs e)
  324. {
  325. mouse_offset = new Point(-e.X, -e.Y);
  326. }
  327. private void groupOperation_MouseMove(object sender, MouseEventArgs e)
  328. {
  329. ((Control)sender).Cursor = Cursors.Arrow;
  330. if (e.Button == MouseButtons.Left)
  331. {
  332. Point mousePos = MousePosition;
  333. mousePos.Offset(mouse_offset.X, mouse_offset.Y);
  334. ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
  335. Application.DoEvents();
  336. }
  337. }
  338. private void pageTool_OnPageChange(int PageIndex, int PageSzie)
  339. {
  340. this.btnSearch_Click(null, null);
  341. }
  342. private void kryptonLabel5_Paint(object sender, PaintEventArgs e)
  343. {
  344. }
  345. private void btnSearchImport_Click(object sender, EventArgs e)
  346. {
  347. var SyncResult = BaseServices.customerService.SyncERP();
  348. if (SyncResult.Status == OperateStatus.Success)
  349. {
  350. this.btnSearch_Click(null, null);
  351. } else
  352. {
  353. KryptonMessageBox.Show($"操作失败!\r\n{SyncResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  354. }
  355. }
  356. }
  357. }