frmPrintTemplate.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. using ComponentFactory.Krypton.Toolkit;
  2. using NXWMS.Client.Code.Extends;
  3. using NXWMS.Client.Model.AppModels.Condition.Rule;
  4. using NXWMS.Client.Model.AppModels.Result;
  5. using NXWMS.Client.Model.AppModels.Result.Rule;
  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.Rule
  19. {
  20. public partial class frmPrintTemplate : Form
  21. {
  22. /// <summary>
  23. /// 客户端字段排序列表
  24. /// </summary>
  25. private List<ClientFieldOrderResult> _clientFieldOrderList;
  26. /// <summary>
  27. /// 界面最后执行操作
  28. /// </summary>
  29. private EnumOperation _LastOperation;
  30. private int _pageSize;
  31. private int _pageIndex;
  32. private int _totalCount;
  33. public frmPrintTemplate()
  34. {
  35. InitializeComponent();
  36. InitData();
  37. InitControl();
  38. }
  39. private int _selectIndex;
  40. private int _selectId;
  41. private string _selectNo;
  42. /// <summary>
  43. /// 主键Key
  44. /// </summary>
  45. private string _PrimaryKey = "PRINT_TEMPLATE_ID";
  46. /// <summary>
  47. /// 主键编码
  48. /// </summary>
  49. private string _PrimaryNo = "PRINT_TEMPLATE_CODE";
  50. /// <summary>
  51. /// 选择行主键列表
  52. /// </summary>
  53. private List<string> _CheckRowIdList = new List<string>();
  54. /// <summary>
  55. /// 数据初始化
  56. /// </summary>
  57. private void InitData()
  58. {
  59. _clientFieldOrderList = new List<ClientFieldOrderResult>();
  60. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PRINT_TEMPLATE_CODE", FieldDesc = "打印模版编码" });
  61. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PRINT_TEMPLATE_NAME", FieldDesc = "打印模版名称" });
  62. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PrintModeName", FieldDesc = "打印方式" });
  63. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "IsShowLogoName", FieldDesc = "是否显示公司Logo标识" });
  64. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "IsPrintHeaderName", FieldDesc = "是否打印表头" });
  65. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "IsShowWatermarkName", FieldDesc = "是否添加水印" });
  66. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "PrintNumber", FieldDesc = "打印数量" });
  67. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "SourceTypeName", FieldDesc = "数据源类型" });
  68. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "SourceName", FieldDesc = "数据源名称" });
  69. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "SourceContent", FieldDesc = "数据源内容" });
  70. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "SourceCode", FieldDesc = "数据源编码" });
  71. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UsedFlagName", FieldDesc = "使用标识" });
  72. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CreateName", FieldDesc = "创建人" });
  73. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "CREATE_TIME", FieldDesc = "创建时间" });
  74. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UpdateName", FieldDesc = "更新人" });
  75. _clientFieldOrderList.Add(new ClientFieldOrderResult { FieldName = "UPDATE_TIME", FieldDesc = "更新时间" });
  76. }
  77. /// <summary>
  78. /// 控件初始化
  79. /// </summary>
  80. private void InitControl()
  81. {
  82. CheckForIllegalCrossThreadCalls = false;
  83. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  84. groupOperation.MouseDown += new MouseEventHandler(this.groupOperation_MouseDown);
  85. groupOperation.MouseMove += new MouseEventHandler(this.groupOperation_MouseMove);
  86. dataGridView.CellDoubleClick += new DataGridViewCellEventHandler(this.dataGridView_CellDoubleClick);
  87. var fieldList = new List<FieldValue>().Add<FieldValue>(new FieldValue { Code = "", Name = "全部" });
  88. cmbSearchTemplateMode.DataSource = fieldList.GetFieldValueIdList<PrintTemplateMode>();
  89. cmbSearchTemplateMode.DisplayMember = "Name";
  90. cmbSearchTemplateMode.ValueMember = "Id";
  91. cmbPrintMode.DataSource = new List<FieldValue>().GetFieldValueIdList<PrintTemplateMode>();
  92. cmbPrintMode.DisplayMember = "Name";
  93. cmbPrintMode.ValueMember = "Id";
  94. cmbSourceType.DataSource = new List<FieldValue>().GetFieldValueIdList<SourceType>();
  95. cmbSourceType.DisplayMember = "Name";
  96. cmbSourceType.ValueMember = "Id";
  97. _pageIndex = 1;
  98. _pageSize = 20;
  99. }
  100. private Point mouse_offset;
  101. private void groupOperation_MouseDown(object sender, MouseEventArgs e)
  102. {
  103. mouse_offset = new Point(-e.X, -e.Y);
  104. }
  105. private void groupOperation_MouseMove(object sender, MouseEventArgs e)
  106. {
  107. ((Control)sender).Cursor = Cursors.Arrow;
  108. if (e.Button == MouseButtons.Left)
  109. {
  110. Point mousePos = MousePosition;
  111. mousePos.Offset(mouse_offset.X, mouse_offset.Y);
  112. ((Control)sender).Location = ((Control)sender).Parent.PointToClient(mousePos);
  113. Application.DoEvents();
  114. }
  115. }
  116. private void btnSearch_Click(object sender, EventArgs e)
  117. {
  118. _pageIndex = 1;
  119. var loadfrm = new frmLoading();
  120. loadfrm.Show();
  121. var message = loadfrm.EventCalExec(LoadSearch, this.pageTool.PageIndex, this.pageTool.PageSize);
  122. pageTool.DataCount = _totalCount;
  123. if (!string.IsNullOrWhiteSpace(message))
  124. {
  125. KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  126. }
  127. }
  128. private string LoadSearch(int pageIndex, int pageSize)
  129. {
  130. var result = RuleServices.printTemplateService.GetList(new PrintTemplateSearchCondition
  131. {
  132. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  133. PrintMode = cmbSearchTemplateMode.SelectedValue.GetObjectToInt(),
  134. IsUsed = chkSearchUse.Checked,
  135. TemplateCode = txtSearchTemplateCode.Text,
  136. SourceName = txtSearchSourceName.Text,
  137. TemplateName = txtSearchTemplateName.Text,
  138. PageIndex = pageIndex,
  139. PageSize = pageSize
  140. });
  141. if (result.Status == OperateStatus.Success)
  142. {
  143. _totalCount = result.Data.TotalCount;
  144. _pageIndex = pageIndex;
  145. _pageSize = pageSize;
  146. if (result.Data.RowData.Any())
  147. {
  148. dataGridView.Columns.Clear();
  149. dataGridView.DataSource = result.Data.RowData.ToList();
  150. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList));
  151. }
  152. else
  153. {
  154. if (dataGridView.DataSource != null)
  155. {
  156. dataGridView.DataSource = new List<PrintTemplateResult>();
  157. }
  158. dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false);
  159. }
  160. return string.Empty;
  161. }
  162. else
  163. {
  164. return result.Message;
  165. }
  166. }
  167. private void btnSearchExport_Click(object sender, EventArgs e)
  168. {
  169. this.dataGridView.DataGridViewExport($"{AppConfig.CurrentMenu.FirstOrDefault().MenuName}列表" + DateTime.Now.ToString("yyyyMMddHH"));
  170. }
  171. private void btnAdd_Click(object sender, EventArgs e)
  172. {
  173. if (!groupOperation.Visible)
  174. {
  175. tableLayoutPanelInput.SetGroupControlsEmpty(dataGridView);
  176. richDescibe.Text = "";
  177. _LastOperation = EnumOperation.Add;
  178. txtTemplateCode.Enabled = true;
  179. numPrintNumber.Value = 1;
  180. chkUse.Checked = true;
  181. groupOperation.Visible = true;
  182. groupOperation.Focus();
  183. }
  184. }
  185. private void SelectInit()
  186. {
  187. if (dataGridView.SelectedRows.Count > 0)
  188. {
  189. _selectIndex = dataGridView.SelectedRows[0].Index;
  190. if (_selectIndex >= 0)
  191. {
  192. _selectId = Convert.ToInt32(dataGridView.Rows[_selectIndex].Cells[_PrimaryKey].Value);
  193. _selectNo = dataGridView.Rows[_selectIndex].Cells[_PrimaryNo].Value.ToString();
  194. }
  195. }
  196. else
  197. {
  198. _selectIndex = -1;
  199. }
  200. _CheckRowIdList = new List<string>();
  201. foreach (DataGridViewRow item in dataGridView.Rows)
  202. {
  203. if (item.Cells["#SELECTED"].Value.GetObjectToInt() == 1)
  204. {
  205. _CheckRowIdList.Add(item.Cells[_PrimaryKey].Value.ToString());
  206. }
  207. }
  208. }
  209. private void btnEdit_Click(object sender, EventArgs e)
  210. {
  211. if (!groupOperation.Visible)
  212. {
  213. SelectInit();
  214. if (_selectIndex >= 0)
  215. {
  216. _LastOperation = EnumOperation.Edit;
  217. richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  218. dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  219. groupOperation.Visible = true;
  220. tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  221. txtTemplateCode.Enabled = false;
  222. groupOperation.Visible = true;
  223. groupOperation.Focus();
  224. }
  225. }
  226. }
  227. private void btnRemove_Click(object sender, EventArgs e)
  228. {
  229. SelectInit();
  230. if (_CheckRowIdList.Count == 0)
  231. {
  232. return;
  233. }
  234. if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  235. {
  236. var editResult = RuleServices.printTemplateService.Deleted(new PrintTemplateCondition
  237. {
  238. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  239. TemplateIds = string.Join(",", _CheckRowIdList),
  240. });
  241. if (editResult.Status == OperateStatus.Success)
  242. {
  243. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  244. btnSearch_Click(null, null);
  245. }
  246. else
  247. {
  248. KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  249. }
  250. }
  251. }
  252. private void btnSave_Click(object sender, EventArgs e)
  253. {
  254. if (string.IsNullOrWhiteSpace(txtTemplateCode.Text))
  255. {
  256. KryptonMessageBox.Show($"请输入模版编码。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  257. return;
  258. }
  259. if (string.IsNullOrWhiteSpace(txtTemplateName.Text))
  260. {
  261. KryptonMessageBox.Show($"请输入模版名称。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  262. return;
  263. }
  264. if (string.IsNullOrWhiteSpace(cmbPrintMode.Text))
  265. {
  266. KryptonMessageBox.Show($"请选择打印方式。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  267. return;
  268. }
  269. if (string.IsNullOrWhiteSpace(cmbSourceType.Text))
  270. {
  271. KryptonMessageBox.Show($"请选择数据源类型。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  272. return;
  273. }
  274. switch (_LastOperation)
  275. {
  276. case EnumOperation.Add:
  277. var addResult = RuleServices.printTemplateService.Add(new PrintTemplateCondition
  278. {
  279. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  280. IsUsed = chkUse.Checked,
  281. Describe = richDescibe.Text,
  282. IsShowLogo = chkShowLogoFlag.Checked,
  283. IsShowWatermark = chkShowWatermark.Checked,
  284. PrintMode = cmbPrintMode.SelectedValue.GetObjectToInt().Value,
  285. PrintNumber = numPrintNumber.Value.GetObjectToInt(),
  286. SourceCode = txtSourceCode.Text,
  287. SourceContent = txtSourceContent.Text,
  288. SourceName = txtSourceName.Text,
  289. SourceType = cmbSourceType.SelectedValue.GetObjectToInt().Value,
  290. TemplateCode = txtTemplateCode.Text,
  291. TemplateName = txtTemplateName.Text,
  292. });
  293. if (addResult.Status == OperateStatus.Success)
  294. {
  295. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  296. InitControl();
  297. groupOperation.Visible = false;
  298. btnSearch_Click(null, null);
  299. dataGridView.ClearSelection();
  300. }
  301. else
  302. {
  303. KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  304. }
  305. break;
  306. case EnumOperation.Edit:
  307. var editResult = RuleServices.printTemplateService.Edit(new PrintTemplateCondition
  308. {
  309. OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
  310. IsUsed = chkUse.Checked,
  311. Describe = richDescibe.Text,
  312. IsShowLogo = chkShowLogoFlag.Checked,
  313. IsShowWatermark = chkShowWatermark.Checked,
  314. PrintMode = cmbPrintMode.SelectedValue.GetObjectToInt().Value,
  315. PrintNumber = numPrintNumber.Value.GetObjectToInt(),
  316. SourceCode = txtSourceCode.Text,
  317. SourceContent = txtSourceContent.Text,
  318. SourceName = txtSourceName.Text,
  319. SourceType = cmbSourceType.SelectedValue.GetObjectToInt().Value,
  320. TemplateCode = txtTemplateCode.Text,
  321. TemplateName = txtTemplateName.Text,
  322. TemplateId = _selectId,
  323. });
  324. if (editResult.Status == OperateStatus.Success)
  325. {
  326. KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  327. InitControl();
  328. groupOperation.Visible = false;
  329. btnSearch_Click(null, null);
  330. dataGridView.ClearSelection();
  331. }
  332. else
  333. {
  334. KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
  335. }
  336. break;
  337. }
  338. }
  339. private void btnExit_Click(object sender, EventArgs e)
  340. {
  341. if (KryptonMessageBox.Show($"确认退出 {_LastOperation.Display()}数据操作?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  342. {
  343. groupOperation.Visible = false;
  344. }
  345. else
  346. {
  347. groupOperation.Visible = true;
  348. groupOperation.Focus();
  349. }
  350. }
  351. private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  352. {
  353. SelectInit();
  354. if (_selectIndex >= 0)
  355. {
  356. _LastOperation = EnumOperation.Edit;
  357. txtTemplateCode.Enabled = false;
  358. tableLayoutPanelInput.SetGroupControls(dataGridView, dataGridView.Rows[_selectIndex]);
  359. richDescibe.Text = dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value == null ? "" :
  360. dataGridView.Rows[_selectIndex].Cells["DESCRIBE"].Value.ToString();
  361. groupOperation.Visible = true;
  362. groupOperation.Focus();
  363. }
  364. }
  365. private void btnSearchImport_Click(object sender, EventArgs e)
  366. {
  367. var from = new frmTempImportData(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name);
  368. from.ShowDialog();
  369. }
  370. }
  371. }