frmSupplier.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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 frmSupplier : KryptonForm
  21. {
  22. /// <summary>
  23. /// 界面最后执行操作
  24. /// </summary>
  25. private EnumOperation _LastOperation;
  26. /// <summary>
  27. /// 客户端字段排序列表
  28. /// </summary>
  29. private List<ClientFieldOrderResult> _clientFieldOrderList;
  30. public frmSupplier()
  31. {
  32. InitializeComponent();
  33. InitData();
  34. InitControl();
  35. }
  36. protected override CreateParams CreateParams
  37. {
  38. get
  39. {
  40. CreateParams cp = base.CreateParams;
  41. cp.ExStyle |= 0x02000000;
  42. return cp;
  43. }
  44. }
  45. private int _selectIndex;
  46. private int _selectId;
  47. /// <summary>
  48. /// 数据初始化
  49. /// </summary>
  50. private void InitData()
  51. {
  52. _clientFieldOrderList = new List<ClientFieldOrderResult>();
  53. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "SUPPLIER_CODE", FieldDesc = "供应商编号" });
  54. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "SUPPLIER_NAME", FieldDesc = "供应商名称" });
  55. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "SUPPLIER_TYPE", FieldDesc = "供应商类型" });
  56. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PROVINCE", FieldDesc = "省" });
  57. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CITY", FieldDesc = "市" });
  58. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "AREA", FieldDesc = "区" });
  59. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "STREET", FieldDesc = "街道" });
  60. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "ROUTE", FieldDesc = "路线" });
  61. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "POSTAL_CODE", FieldDesc = "邮政编码" });
  62. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "ADDRESS", FieldDesc = "地址" });
  63. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" });
  64. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CONTRACT", FieldDesc = "联系人" });
  65. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CONTRACT_PHONE", FieldDesc = "联系人电话" });
  66. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" });
  67. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" });
  68. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" });
  69. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" });
  70. }
  71. private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
  72. {
  73. if (e.RowIndex >= 0 && e.ColumnIndex == 0)
  74. {
  75. if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
  76. {
  77. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  78. {
  79. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  80. }
  81. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  82. }
  83. else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
  84. {
  85. if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  86. {
  87. _CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  88. }
  89. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
  90. }
  91. else
  92. {
  93. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  94. {
  95. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  96. }
  97. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  98. }
  99. }
  100. }
  101. /// <summary>
  102. /// 选择行主键列表
  103. /// </summary>
  104. private List<string> _CheckRowIdList = new List<string>();
  105. /// <summary>
  106. /// 当前页面操作的主键
  107. /// </summary>
  108. private string _PrimaryKey = "SUPPLIER_ID";
  109. private void btnRemove_Click(object sender, EventArgs e)
  110. {
  111. if (_CheckRowIdList.Count == 0)
  112. {
  113. return;
  114. }
  115. if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  116. {
  117. _LastOperation = EnumOperation.Remove;
  118. var editResult = BaseServices.supplierService.Deleted(new SupplierCondition
  119. {
  120. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  121. Ids = string.Join(",", _CheckRowIdList)
  122. });
  123. if (editResult.Status == OperateStatus.Success)
  124. {
  125. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  126. //groupOperation.Visible = false;
  127. btnSearch_Click(null, null);
  128. }
  129. }
  130. }
  131. /// <summary>
  132. /// 控件初始化
  133. /// </summary>
  134. private void InitControl()
  135. {
  136. CheckForIllegalCrossThreadCalls = false;
  137. //groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus);
  138. dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick);
  139. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  140. //TODO 0805 以下所有配置都需要从数据库或者其它地方读取,这里暂时写死,后期加上配置表,联动查询
  141. var fieldList = new List<FieldValue>().GetFieldValueCodeList<SupplierType>();
  142. cmbSearchSupplierType.DataSource = fieldList;
  143. cmbSearchSupplierType.DisplayMember = "Name";
  144. cmbSearchSupplierType.ValueMember = "Code";
  145. cmbSearchSupplierType.SelectedIndex = -1;
  146. //cmbSupplierType.DataSource = fieldList;
  147. //cmbSupplierType.DisplayMember = "Name";
  148. //cmbSupplierType.ValueMember = "Code";
  149. //cmbSupplierType.SelectedIndex = -1;
  150. fieldList = new List<FieldValue>();
  151. fieldList.Add(new FieldValue { Code = "江苏省", Name = "江苏省" });
  152. cmbSearchProvince.DataSource = fieldList;
  153. cmbSearchProvince.DisplayMember = "Name";
  154. cmbSearchProvince.ValueMember = "Code";
  155. cmbSearchProvince.SelectedIndex = -1;
  156. //cmbProvince.DataSource = fieldList;
  157. //cmbProvince.DisplayMember = "Name";
  158. //cmbProvince.ValueMember = "Code";
  159. //cmbProvince.SelectedIndex = -1;
  160. fieldList = new List<FieldValue>();
  161. fieldList.Add(new FieldValue { Code = "无锡市", Name = "无锡市" });
  162. cmbSearchCity.DataSource = fieldList;
  163. cmbSearchCity.DisplayMember = "Name";
  164. cmbSearchCity.ValueMember = "Code";
  165. cmbSearchCity.SelectedIndex = -1;
  166. //cmbCity.DataSource = fieldList;
  167. //cmbCity.DisplayMember = "Name";
  168. //cmbCity.ValueMember = "Code";
  169. //cmbCity.SelectedIndex = -1;
  170. fieldList = new List<FieldValue>();
  171. fieldList.Add(new FieldValue { Code = "锡山区", Name = "锡山区" });
  172. //cmbArea.DataSource = fieldList;
  173. //cmbArea.DisplayMember = "Name";
  174. //cmbArea.ValueMember = "Code";
  175. //cmbArea.SelectedIndex = -1;
  176. _pageIndex = 1;
  177. _pageSize = 20;
  178. }
  179. private void groupOperation_GostFocus(object sender, EventArgs e)
  180. {
  181. //groupOperation.Values.Heading = _LastOperation.Display();
  182. ////groupOperation.Values.Image = Image.FromFile(_LastOperation.ImagePath());
  183. //groupOperation.Text = $"{ _LastOperation.Display()}数据";
  184. //lbStatusMessage.Visible = true;
  185. }
  186. private void btnAdd_Click(object sender, EventArgs e)
  187. {
  188. var frm = new ChildFrm.FrmSupplierEdit();
  189. frm.operation = EnumOperation.Add;
  190. frm.InitControl();
  191. if (frm.ShowDialog()==DialogResult.OK)
  192. {
  193. this.btnSearch_Click(null, null);
  194. }
  195. //if (!groupOperation.Visible)
  196. //{
  197. // _selectId = 0;
  198. // tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
  199. // richDescibe.Text = "";
  200. // _LastOperation = EnumOperation.Add;
  201. // txtSupplierCode.Enabled = true;
  202. // groupOperation.Visible = true;
  203. // groupOperation.Focus();
  204. //}
  205. }
  206. private void btnEdit_Click(object sender, EventArgs e)
  207. {
  208. dataGridView_CellDoubleClick(null, null);
  209. }
  210. private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  211. {
  212. SelectInit();
  213. if (_selectIndex >= 0)
  214. {
  215. var frm = new ChildFrm.FrmSupplierEdit();
  216. frm.operation = EnumOperation.Add;
  217. frm.Id = this._selectId;
  218. frm.InitControl();
  219. frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  220. if (frm.ShowDialog() == DialogResult.OK)
  221. {
  222. this.btnSearch_Click(null, null);
  223. }
  224. //_LastOperation = EnumOperation.Edit;
  225. //tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  226. //richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  227. // dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  228. //txtSupplierCode.Enabled = false;
  229. //groupOperation.Visible = true;
  230. //groupOperation.Focus();
  231. }
  232. }
  233. private void SelectInit()
  234. {
  235. _selectIndex = dataGridView.SelectedRows[0].Index;
  236. if (_selectIndex >= 0)
  237. {
  238. _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  239. }
  240. }
  241. private void btnSearch_Click(object sender, EventArgs e)
  242. {
  243. _pageIndex = 1;
  244. var loadfrm = new frmLoading();
  245. loadfrm.Show();
  246. var message = loadfrm.EventCalExec(LoadSearch, this.pageTool.PageIndex, this.pageTool.PageSize);
  247. pageTool.DataCount = _totalCount;
  248. if (!string.IsNullOrWhiteSpace(message))
  249. {
  250. KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  251. }
  252. }
  253. private int _pageSize;
  254. private int _pageIndex;
  255. private int _totalCount;
  256. private string LoadSearch(int pageIndex, int pageSize)
  257. {
  258. var result = BaseServices.supplierService.GetList(new SupplierSearchCondition
  259. {
  260. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  261. City = cmbSearchCity.SelectedValue.GetObjectToString(),
  262. SupplierCode = txtSearchSupplierCode.Text,
  263. SupplierName = txtSearchSupplierName.Text,
  264. SupplierType = cmbSearchSupplierType.SelectedValue.GetObjectToString(),
  265. Province = cmbSearchProvince.SelectedValue.GetObjectToString(),
  266. IsUsed = chkSearchUse.Checked,
  267. PageIndex = pageIndex,
  268. PageSize = pageSize
  269. });
  270. if (result.Status == OperateStatus.Success)
  271. {
  272. _totalCount = result.Data.TotalCount;
  273. _pageIndex = pageIndex;
  274. _pageSize = pageSize;
  275. if (result.Data.RowData.Any())
  276. {
  277. dataGridView.Columns.Clear();
  278. dataGridView.DataSource = result.Data.RowData.ToList();
  279. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
  280. }
  281. else
  282. {
  283. if (dataGridView.DataSource != null)
  284. {
  285. dataGridView.DataSource = new List<SupplierResult>();
  286. }
  287. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  288. }
  289. return string.Empty;
  290. }
  291. else
  292. {
  293. return result.Message;
  294. }
  295. }
  296. private void btnSearchExport_Click(object sender, EventArgs e)
  297. {
  298. this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault().MenuName}列表" + DateTime.Now.ToString("yyyyMMddHH"));
  299. }
  300. //private void btnSave_Click(object sender, EventArgs e)
  301. //{
  302. // if (string.IsNullOrWhiteSpace(txtSupplierCode.Text))
  303. // {
  304. // KryptonMessageBox.Show($"请输入客户编码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  305. // return;
  306. // }
  307. // switch (_LastOperation)
  308. // {
  309. // case EnumOperation.Add:
  310. // var addResult = BaseServices.supplierService.Add(new SupplierCondition
  311. // {
  312. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  313. // IsUsed = chkUse.Checked,
  314. // SupplierType = cmbSupplierType.SelectedValue == null ? "" :
  315. // cmbSupplierType.SelectedValue.ToString(),
  316. // Describe = richDescibe.Text,
  317. // Address = txtAddress.Text,
  318. // Area = cmbArea.Text,
  319. // City = cmbCity.Text,
  320. // Contract = txtContract.Text,
  321. // ContractPhone = txtContractPhone.Text,
  322. // SupplierCode = txtSupplierCode.Text,
  323. // SupplierName = txtSupplierName.Text,
  324. // PostalCode = txtPostalCode.Text,
  325. // Province = cmbProvince.Text,
  326. // Route = txtRoute.Text,
  327. // Street = cmbStreet.Text,
  328. // });
  329. // if (addResult.Status == OperateStatus.Success)
  330. // {
  331. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  332. // InitControl();
  333. // groupOperation.Visible = false;
  334. // btnSearch_Click(null, null);
  335. // dataGridView.ClearSelection();
  336. // }
  337. // else
  338. // {
  339. // KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  340. // }
  341. // break;
  342. // case EnumOperation.Edit:
  343. // var editResult = BaseServices.supplierService.Edit(new SupplierCondition
  344. // {
  345. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  346. // IsUsed = chkUse.Checked,
  347. // SupplierType = cmbSupplierType.SelectedValue == null ? "" :
  348. // cmbSupplierType.SelectedValue.ToString(),
  349. // Describe = richDescibe.Text,
  350. // Address = txtAddress.Text,
  351. // Area = cmbArea.Text,
  352. // City = cmbCity.Text,
  353. // Contract = txtContract.Text,
  354. // ContractPhone = txtContractPhone.Text,
  355. // SupplierCode = txtSupplierCode.Text,
  356. // SupplierName = txtSupplierName.Text,
  357. // PostalCode = txtPostalCode.Text,
  358. // Province = cmbProvince.Text,
  359. // Route = txtRoute.Text,
  360. // Street = cmbStreet.Text,
  361. // Id = _selectId
  362. // });
  363. // if (editResult.Status == OperateStatus.Success)
  364. // {
  365. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  366. // InitControl();
  367. // groupOperation.Visible = false;
  368. // btnSearch_Click(null, null);
  369. // dataGridView.ClearSelection();
  370. // }
  371. // else
  372. // {
  373. // KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  374. // }
  375. // break;
  376. // }
  377. //}
  378. private void btnExit_Click(object sender, EventArgs e)
  379. {
  380. if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  381. {
  382. //groupOperation.Visible = false;
  383. }
  384. else
  385. {
  386. //groupOperation.Visible = true;
  387. //groupOperation.Focus();
  388. }
  389. }
  390. private Point mouse_offset;
  391. private void groupOperation_MouseDown(object sender, MouseEventArgs e)
  392. {
  393. mouse_offset = new Point(-e.X, -e.Y);
  394. }
  395. private void groupOperation_MouseMove(object sender, MouseEventArgs e)
  396. {
  397. ((Control)sender).Cursor = Cursors.Arrow;
  398. if (e.Button == MouseButtons.Left)
  399. {
  400. Point mousePos = MousePosition;
  401. mousePos.Offset(mouse_offset.X, mouse_offset.Y);
  402. ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
  403. Application.DoEvents();
  404. }
  405. }
  406. private void dataGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
  407. {
  408. e.Row.HeaderCell.Value = string.Format("{0}", (_pageIndex - 1) * _pageSize + e.Row.Index + 1);
  409. }
  410. private void pageTool_OnPageChange(int PageIndex, int PageSzie)
  411. {
  412. this.btnSearch_Click(null, null);
  413. }
  414. private void btnSearchImport_Click(object sender, EventArgs e)
  415. {
  416. }
  417. }
  418. }