frmUnit.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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.Forms.Rule;
  10. using NXWMS.Services;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Data;
  15. using System.Drawing;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Windows.Forms;
  19. namespace NXWMS.Forms.Base
  20. {
  21. /// <summary>
  22. /// 单位
  23. /// </summary>
  24. public partial class frmUnit : KryptonForm
  25. {
  26. /// <summary>
  27. /// 界面最后执行操作
  28. /// </summary>
  29. private EnumOperation _LastOperation;
  30. /// <summary>
  31. /// 客户端字段排序列表
  32. /// </summary>
  33. private List<ClientFieldOrderResult> _clientFieldOrderList;
  34. private int _selectIndex;
  35. private int _selectId;
  36. public frmUnit()
  37. {
  38. InitializeComponent();
  39. InitData();
  40. InitControl();
  41. }
  42. protected override CreateParams CreateParams
  43. {
  44. get
  45. {
  46. CreateParams cp = base.CreateParams;
  47. cp.ExStyle |= 0x02000000;
  48. return cp;
  49. }
  50. }
  51. /// <summary>
  52. /// 数据初始化
  53. /// </summary>
  54. private void InitData()
  55. {
  56. _clientFieldOrderList = new List<ClientFieldOrderResult>();
  57. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UNIT_CODE", FieldDesc = "单位编码" });
  58. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UNIT_NAME", FieldDesc = "单位名称" });
  59. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UNIT_TYPE", FieldDesc = "单位类型编码" });
  60. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "DESCRIBE", FieldDesc = "描述" });
  61. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" });
  62. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" });
  63. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" });
  64. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" });
  65. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" });
  66. }
  67. /// <summary>
  68. /// 控件初始化
  69. /// </summary>
  70. private void InitControl()
  71. {
  72. CheckForIllegalCrossThreadCalls = false;
  73. //groupOperation.GotFocus += new EventHandler(groupOperation_GostFocus);
  74. dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick);
  75. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  76. var fieldList = new List<FieldValue>().GetFieldValueCodeList<UnitType>();
  77. cmbSearchUnitType.DataSource = fieldList;
  78. cmbSearchUnitType.DisplayMember = "Name";
  79. cmbSearchUnitType.ValueMember = "Code";
  80. cmbSearchUnitType.SelectedIndex = -1;
  81. //cmbUnitType.DataSource = fieldList;
  82. //cmbUnitType.DisplayMember = "Name";
  83. //cmbUnitType.ValueMember = "Code";
  84. //cmbUnitType.SelectedIndex = -1;
  85. _pageIndex = 1;
  86. _pageSize = 20;
  87. }
  88. private void groupOperation_GostFocus(object sender, EventArgs e)
  89. {
  90. //groupOperation.Values.Heading = _LastOperation.Display();
  91. ////groupOperation.Values.Image = Image.FromFile(_LastOperation.ImagePath());
  92. //groupOperation.Text = $"{ _LastOperation.Display()}数据";
  93. //lbStatusMessage.Visible = true;
  94. }
  95. private void btnSearch_Click(object sender, EventArgs e)
  96. {
  97. _pageIndex = 1;
  98. var loadfrm = new frmLoading();
  99. loadfrm.Show();
  100. var message = loadfrm.EventCalExec(LoadSearch, this.pageTool.PageIndex, this.pageTool.PageSize);
  101. pageTool.DataCount = _totalCount;
  102. if (!string.IsNullOrWhiteSpace(message))
  103. {
  104. KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  105. }
  106. }
  107. private int _pageSize;
  108. private int _pageIndex;
  109. private int _totalCount;
  110. private string LoadSearch(int pageIndex, int pageSize)
  111. {
  112. var result = BaseServices.unitService.GetList(new UnitSearchCondition
  113. {
  114. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  115. UnitCode = txtSearchUnitCode.Text,
  116. //UnitName=txtUnitName.Text,
  117. UnitType= cmbSearchUnitType.SelectedValue.GetObjectToString(),
  118. IsUsed = chkSearchUse.Checked,
  119. PageIndex = pageIndex,
  120. PageSize = pageSize
  121. });
  122. if (result.Status == OperateStatus.Success)
  123. {
  124. _totalCount = result.Data.TotalCount;
  125. _pageIndex = pageIndex;
  126. _pageSize = pageSize;
  127. if (result.Data.RowData.Any())
  128. {
  129. dataGridView.Columns.Clear();
  130. dataGridView.DataSource = result.Data.RowData.ToList();
  131. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
  132. }
  133. else
  134. {
  135. if (dataGridView.DataSource != null)
  136. {
  137. dataGridView.DataSource = new List<UnitResult>();
  138. }
  139. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  140. }
  141. return string.Empty;
  142. }
  143. else
  144. {
  145. return result.Message;
  146. }
  147. }
  148. private void btnSearchExport_Click(object sender, EventArgs e)
  149. {
  150. this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault().MenuName}列表" + DateTime.Now.ToString("yyyyMMddHH"));
  151. }
  152. private void btnAdd_Click(object sender, EventArgs e)
  153. {
  154. var frm = new ChildFrm.FrmUitEdit();
  155. frm.operation = EnumOperation.Add;
  156. frm.InitControl();
  157. if (frm.ShowDialog()==DialogResult.OK)
  158. {
  159. this.btnSearch_Click(null, null);
  160. }
  161. //if (!groupOperation.Visible)
  162. //{
  163. // _selectId = 0;
  164. // tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
  165. // richDescibe.Text = "";
  166. // _LastOperation = EnumOperation.Add;
  167. // txtUnitCode.Enabled = true;
  168. // groupOperation.Visible = true;
  169. // groupOperation.Focus();
  170. //}
  171. }
  172. private void btnEdit_Click(object sender, EventArgs e)
  173. {
  174. dataGridView_CellDoubleClick(null, null);
  175. }
  176. private void SelectInit()
  177. {
  178. _selectIndex = dataGridView.SelectedRows[0].Index;
  179. if (_selectIndex >= 0)
  180. {
  181. _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  182. }
  183. }
  184. /// <summary>
  185. /// 选择行主键列表
  186. /// </summary>
  187. private List<string> _CheckRowIdList = new List<string>();
  188. /// <summary>
  189. /// 当前页面操作的主键
  190. /// </summary>
  191. private string _PrimaryKey = "UNIT_ID";
  192. private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
  193. {
  194. if (e.RowIndex >= 0 && e.ColumnIndex == 0)
  195. {
  196. if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null)
  197. {
  198. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  199. {
  200. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  201. }
  202. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  203. }
  204. else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1")
  205. {
  206. if (_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  207. {
  208. _CheckRowIdList.Remove(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  209. }
  210. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
  211. }
  212. else
  213. {
  214. if (!_CheckRowIdList.Where(s => s == dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString()).Any())
  215. {
  216. _CheckRowIdList.Add(dataGridView.Rows[e.RowIndex].Cells[_PrimaryKey].Value.ToString());
  217. }
  218. this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1;
  219. }
  220. }
  221. }
  222. private void btnRemove_Click(object sender, EventArgs e)
  223. {
  224. SelectInit();
  225. if (_selectIndex >= 0)
  226. {
  227. if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  228. {
  229. _LastOperation = EnumOperation.Remove;
  230. var editResult = BaseServices.unitService.Deleted(new UnitCondition
  231. {
  232. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  233. Ids = string.Join(",", _CheckRowIdList)
  234. });
  235. if (editResult.Status == OperateStatus.Success)
  236. {
  237. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  238. //groupOperation.Visible = false;
  239. btnSearch_Click(null, null);
  240. }
  241. else
  242. {
  243. KryptonMessageBox.Show($"操作失败!\r\n" + editResult.Message, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  244. }
  245. }
  246. }
  247. }
  248. private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  249. {
  250. SelectInit();
  251. if (_selectIndex >= 0)
  252. {
  253. var frm = new ChildFrm.FrmUitEdit();
  254. frm.operation = EnumOperation.Add;
  255. frm.Id = this._selectId;
  256. frm.InitControl();
  257. frm.tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  258. if (frm.ShowDialog() == DialogResult.OK)
  259. {
  260. this.btnSearch_Click(null, null);
  261. }
  262. //_LastOperation = EnumOperation.Edit;
  263. //tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  264. //richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  265. // dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  266. //txtUnitCode.Enabled = false;
  267. //groupOperation.Visible = true;
  268. //groupOperation.Focus();
  269. }
  270. }
  271. //private void btnSave_Click(object sender, EventArgs e)
  272. //{
  273. // if (string.IsNullOrWhiteSpace(txtUnitCode.Text))
  274. // {
  275. // KryptonMessageBox.Show($"请输入单位编码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  276. // return;
  277. // }
  278. // if (string.IsNullOrWhiteSpace(cmbUnitType.Text))
  279. // {
  280. // KryptonMessageBox.Show($"请选择单位类型!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  281. // return;
  282. // }
  283. // switch (_LastOperation)
  284. // {
  285. // case EnumOperation.Add:
  286. // var addResult = BaseServices.unitService.Add(new UnitCondition
  287. // {
  288. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  289. // IsUsed = chkUse.Checked,
  290. // Describe = richDescibe.Text,
  291. // UnitCode = txtUnitCode.Text,
  292. // UnitName = txtUnitName.Text,
  293. // UnitType = cmbUnitType.SelectedValue == null ? "" :
  294. // cmbUnitType.SelectedValue.ToString(),
  295. // }); ;
  296. // if (addResult.Status == OperateStatus.Success)
  297. // {
  298. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  299. // InitControl();
  300. // groupOperation.Visible = false;
  301. // btnSearch_Click(null, null);
  302. // dataGridView.ClearSelection();
  303. // }
  304. // else
  305. // {
  306. // KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  307. // }
  308. // break;
  309. // case EnumOperation.Edit:
  310. // var editResult = BaseServices.unitService.Edit(new UnitCondition
  311. // {
  312. // OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  313. // IsUsed = chkUse.Checked,
  314. // Describe = richDescibe.Text,
  315. // UnitCode = txtUnitCode.Text,
  316. // UnitName = txtUnitName.Text,
  317. // UnitType = cmbUnitType.SelectedValue == null ? "" :
  318. // cmbUnitType.SelectedValue.ToString(),
  319. // Id = _selectId,
  320. // });
  321. // if (editResult.Status == OperateStatus.Success)
  322. // {
  323. // KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  324. // InitControl();
  325. // groupOperation.Visible = false;
  326. // btnSearch_Click(null, null);
  327. // dataGridView.ClearSelection();
  328. // }
  329. // else
  330. // {
  331. // KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  332. // }
  333. // break;
  334. // }
  335. //}
  336. private void dataGridView_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
  337. {
  338. e.Row.HeaderCell.Value = string.Format("{0}", (_pageIndex - 1) * _pageSize + e.Row.Index + 1);
  339. }
  340. private void btnExit_Click(object sender, EventArgs e)
  341. {
  342. if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  343. {
  344. //groupOperation.Visible = false;
  345. }
  346. else
  347. {
  348. //groupOperation.Visible = true;
  349. //groupOperation.Focus();
  350. }
  351. }
  352. private Point mouse_offset;
  353. private void groupOperation_MouseDown(object sender, MouseEventArgs e)
  354. {
  355. mouse_offset = new Point(-e.X, -e.Y);
  356. }
  357. private void groupOperation_MouseMove(object sender, MouseEventArgs e)
  358. {
  359. ((Control)sender).Cursor = Cursors.Arrow;
  360. if (e.Button == MouseButtons.Left)
  361. {
  362. Point mousePos = MousePosition;
  363. mousePos.Offset(mouse_offset.X, mouse_offset.Y);
  364. ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
  365. Application.DoEvents();
  366. }
  367. }
  368. private void btnSearchImport_Click(object sender, EventArgs e)
  369. {
  370. var from = new frmTempImportData(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
  371. from.ShowDialog();
  372. }
  373. private void pageTool_OnPageChange(int PageIndex, int PageSzie)
  374. {
  375. this.btnSearch_Click(null, null);
  376. }
  377. }
  378. }