DefaultPrinterSetFormMain.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Drawing.Printing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. namespace LYFZ.Software.MainBusiness.StudioDataSet
  12. {
  13. public partial class DefaultPrinterSetFormMain : LYFZ.Software.UI.StudioDataSet.DefaultPrinterSetFormMain
  14. {
  15. public DefaultPrinterSetFormMain()
  16. {
  17. this.Load += DefaultPrinterSetFormMain_Load;
  18. //this.dgvData_A4_Size.CellMouseDown += dgvData_A4_Size_CellMouseDown;
  19. //this.dgvData_A4_Path.CellMouseDown += dgvData_A4_Path_CellMouseDown;
  20. //this.dgvData_DMX_Dots.CellMouseDown += dgvData_DMX_Dots_CellMouseDown;
  21. //this.dgvData_DMX_Path.CellMouseDown += dgvData_DMX_Path_CellMouseDown;
  22. //this.dgvData_STicket_Path.CellMouseDown += dgvData_STicket_Path_CellMouseDown;
  23. //this.dgvData_DMX_PrintTitles.CellMouseDown += dgvData_DMX_PrintTitles_CellMouseDown;
  24. //this.contextMenuStripEx1.ItemClicked += contextMenuStripEx1_ItemClicked;
  25. //this.dgvData_DMX_PrintTitles.CellMouseDoubleClick += dgvData_DMX_PrintTitles_CellMouseDoubleClick;
  26. //this.txtPrintTitles.Leave += txtPrintTitles_Leave;
  27. }
  28. LYFZ.BLL.BLL_ErpPrinterSet psbll = new BLL.BLL_ErpPrinterSet();
  29. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  30. /// <summary>
  31. /// 窗体加载
  32. /// </summary>
  33. /// <param name="sender"></param>
  34. /// <param name="e"></param>
  35. void DefaultPrinterSetFormMain_Load(object sender, EventArgs e)
  36. {
  37. string StrShopName = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
  38. //A4路径设置
  39. string ExecuteSql = orbll.GetView_CustomReturnExecuteSql("tb_ErpPrinterSet", StrWhere: "ps_PrintAppliesType = '适用于(A4纸打印机)' and ps_DividedShop = '" + StrShopName + "'", ShowColumnName: "ID , row_number() over(order by ps_SingleSort) AS 序号, ps_SingleName AS 打印单名称,ps_PrinterName AS 打印机名称,ps_PrinterPath AS 打印机路径,ps_PrintAppliesType AS 适用打印类型");
  40. //针式分辨率设置
  41. ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpPrinterSet", StrWhere: "ps_PrintAppliesType = '适用于(针式打印机)' and ps_DividedShop = '" + StrShopName + "'", ShowColumnName: "ID , row_number() over(order by ps_SingleSort) AS 序号, ps_SingleName AS 打印单名称,(case ps_PaperFeed when '0' then '前进纸' else (case ps_PaperFeed when '1' then '后进纸' else '' end) end) AS 针式进纸设置,ps_ResolutionName AS 针式分辨率,ps_ResolutionX,ps_ResolutionY,ps_PrintAppliesType AS 适用打印类型");
  42. //A4打印字体设置
  43. ExecuteSql += ";" + orbll.GetView_CustomReturnExecuteSql("tb_ErpPrinterSet", StrWhere: "ps_SingleName = '订单打印' and ps_DividedShop = '" + StrShopName + "'", ShowColumnName: "ID , row_number() over(order by ps_SingleSort) AS 序号, ps_SingleName AS 打印单名称,dbo.Get_StrArrayStrOfIndex(dbo.Get_StrArrayStrOfIndex(ps_FontSize,',',1),':',1) AS 详情内容,dbo.Get_StrArrayStrOfIndex(dbo.Get_StrArrayStrOfIndex(ps_FontSize,',',1),':',2) AS 详情内容Tag, dbo.Get_StrArrayStrOfIndex(dbo.Get_StrArrayStrOfIndex(ps_FontSize,',',2),':',1) AS 注意事项, dbo.Get_StrArrayStrOfIndex(dbo.Get_StrArrayStrOfIndex(ps_FontSize,',',2),':',2) AS 注意事项Tag, ps_PrintAppliesType AS 适用打印类型");
  44. //热敏小票设置
  45. ExecuteSql += orbll.GetView_CustomReturnExecuteSql("tb_ErpPrinterSet", StrWhere: "ps_PrintAppliesType = '适用于(针式打印机)' and ps_DividedShop = '" + StrShopName + "'", ShowColumnName: "ID , row_number() over(order by ps_SingleSort) AS 序号, ps_SingleName AS 打印单名称, ps_SmallTicketPrintName AS 打印机名称, ps_SmallTicketPrintPath AS 打印机路径, '适用于(小票打印机)' AS 适用打印类型");
  46. //针式纸路径设置
  47. ExecuteSql += orbll.GetView_CustomReturnExecuteSql("tb_ErpPrinterSet", StrWhere: "ps_PrintAppliesType = '适用于(针式打印机)' and ps_DividedShop = '" + StrShopName + "'", ShowColumnName: "ID , row_number() over(order by ps_SingleSort) AS 序号, ps_SingleName AS 打印单名称, ps_PrinterName AS 打印机名称, ps_PrinterPath AS 打印机路径, ps_PrintAppliesType AS 适用打印类型");
  48. //针式打印标题设置
  49. ExecuteSql += orbll.GetView_CustomReturnExecuteSql("tb_ErpPrinterSet", StrWhere: "ps_PrintAppliesType = '适用于(针式打印机)' and ps_DividedShop = '" + StrShopName + "'", ShowColumnName: "ID , row_number() over(order by ps_SingleSort) AS 序号, ps_SingleName AS 打印单名称, ps_PrintTitles AS 打印标题, ps_PrintAppliesType AS 适用打印类型");
  50. DataSet dtSet = orbll.GetView_Custom(ExecuteSql);
  51. //A4打印机路径设置
  52. this.dgvData_A4_Path.DataSource(dtSet.Tables[0]);
  53. this.dgvData_A4_Path.Columns["ID"].Visible = false;
  54. this.dgvData_A4_Path.Columns["序号"].FillWeight = 20;
  55. this.dgvData_A4_Path.Columns["打印单名称"].FillWeight = 70;
  56. //A4打印机字体大小设置
  57. #region A4打印机字体大小设置
  58. DataTable tbl3 = dtSet.Tables[2];
  59. if (this.dgvData_A4_Size.Columns.Count <= 0)
  60. {
  61. DataGridViewColumn dgvColumn = null;
  62. for (int i = 0; i < tbl3.Columns.Count; i++)
  63. {
  64. if (tbl3.Columns[i].ColumnName.Trim() != "详情内容Tag" && tbl3.Columns[i].ColumnName.Trim() != "注意事项Tag")
  65. {
  66. dgvColumn = new DataGridViewColumn();
  67. dgvColumn.ReadOnly = true;
  68. dgvColumn.Name = tbl3.Columns[i].ColumnName.Trim();
  69. dgvColumn.HeaderText = tbl3.Columns[i].ColumnName.Trim();
  70. dgvColumn.ToolTipText = tbl3.Columns[i].ColumnName.Trim();
  71. if (tbl3.Columns[i].ColumnName.Trim() == "ID")
  72. { dgvColumn.Visible = false; }
  73. if (tbl3.Columns[i].ColumnName.Trim() == "序号")
  74. { dgvColumn.FillWeight = 20; }
  75. this.dgvData_A4_Size.Columns.Add(dgvColumn);
  76. }
  77. }
  78. }
  79. this.dgvData_A4_Size.Rows.Clear();
  80. for (int i = 0; i < tbl3.Rows.Count; i++)
  81. {
  82. DataGridViewRow dgvr = new DataGridViewRow();
  83. DataGridViewCell cell = null;
  84. cell = new DataGridViewTextBoxCell();
  85. cell.Value = tbl3.Rows[i]["ID"].ToString().Trim();
  86. dgvr.Cells.Add(cell);
  87. cell = new DataGridViewTextBoxCell();
  88. cell.Value = tbl3.Rows[i]["序号"].ToString().Trim();
  89. dgvr.Cells.Add(cell);
  90. cell = new DataGridViewTextBoxCell();
  91. cell.Value = tbl3.Rows[i]["打印单名称"].ToString().Trim();
  92. dgvr.Cells.Add(cell);
  93. cell = new DataGridViewTextBoxCell();
  94. cell.Value = tbl3.Rows[i]["详情内容"].ToString().Trim();
  95. cell.Tag = tbl3.Rows[i]["详情内容Tag"].ToString().Trim();
  96. dgvr.Cells.Add(cell);
  97. cell = new DataGridViewTextBoxCell();
  98. cell.Value = tbl3.Rows[i]["注意事项"].ToString().Trim();
  99. cell.Tag = tbl3.Rows[i]["注意事项Tag"].ToString().Trim();
  100. dgvr.Cells.Add(cell);
  101. cell = new DataGridViewTextBoxCell();
  102. cell.Value = tbl3.Rows[i]["适用打印类型"].ToString().Trim();
  103. dgvr.Cells.Add(cell);
  104. this.dgvData_A4_Size.Rows.Add(dgvr);
  105. }
  106. #endregion
  107. //针式打印机路径设置
  108. this.dgvData_DMX_Path.DataSource(dtSet.Tables[4]);
  109. this.dgvData_DMX_Path.Columns["ID"].Visible = false;
  110. this.dgvData_DMX_Path.Columns["序号"].FillWeight = 20;
  111. this.dgvData_DMX_Path.Columns["打印单名称"].FillWeight = 70;
  112. //针式打印机分辨率设置
  113. this.dgvData_DMX_Dots.DataSource(dtSet.Tables[1]);
  114. this.dgvData_DMX_Dots.Columns["ID"].Visible = false;
  115. this.dgvData_DMX_Dots.Columns["序号"].FillWeight = 20;
  116. this.dgvData_DMX_Dots.Columns["ps_ResolutionX"].Visible = false;
  117. this.dgvData_DMX_Dots.Columns["ps_ResolutionY"].Visible = false;
  118. //热敏打印机路径设置
  119. this.dgvData_STicket_Path.DataSource(dtSet.Tables[3]);
  120. this.dgvData_STicket_Path.Columns["ID"].Visible = false;
  121. this.dgvData_STicket_Path.Columns["序号"].FillWeight = 20;
  122. //针式打印标题设置
  123. this.dgvData_DMX_PrintTitles.DataSource(dtSet.Tables[5]);
  124. this.dgvData_DMX_PrintTitles.Columns["ID"].Visible = false;
  125. this.dgvData_DMX_PrintTitles.Columns["序号"].FillWeight = 20;
  126. }
  127. /// <summary>
  128. /// A4打印机打印机路径设置 列表列点击事件(右键)
  129. /// </summary>
  130. /// <param name="sender"></param>
  131. /// <param name="e"></param>
  132. void dgvData_A4_Path_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  133. {
  134. if (e.Button == MouseButtons.Right)
  135. {
  136. this.contextMenuStripEx1.Items.Clear();
  137. this.contextMenuStripEx1.Show(MousePosition.X, MousePosition.Y);
  138. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  139. {
  140. ToolStripMenuItem item = new ToolStripMenuItem();
  141. item.Text = "清空值";
  142. item.Tag = "StrPrinter";
  143. contextMenuStripEx1.Items.Add(item);
  144. item = new ToolStripMenuItem();
  145. item.Text = "设置打印机";
  146. item.Tag = "StrPrinter";
  147. contextMenuStripEx1.Items.Add(item);
  148. }
  149. }
  150. }
  151. /// <summary>
  152. /// A4纸字体大小设置 列表列点击事件(右键)
  153. /// </summary>
  154. /// <param name="sender"></param>
  155. /// <param name="e"></param>
  156. void dgvData_A4_Size_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  157. {
  158. if (e.Button == MouseButtons.Right)
  159. {
  160. this.contextMenuStripEx1.Items.Clear();
  161. //弹出操作菜单
  162. this.contextMenuStripEx1.Show(MousePosition.X, MousePosition.Y);
  163. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  164. {
  165. if (this.dgvData_A4_Size.Columns[e.ColumnIndex].Name.Trim() == "详情内容" || this.dgvData_A4_Size.Columns[e.ColumnIndex].Name.Trim() == "打印单名称")
  166. {
  167. ToolStripMenuItem item = new ToolStripMenuItem();
  168. item.Text = "17号";
  169. item.Name = "17";
  170. item.Tag = "StrFontSize_Detail";
  171. contextMenuStripEx1.Items.Add(item);
  172. item = new ToolStripMenuItem();
  173. item.Text = "16号";
  174. item.Name = "16";
  175. item.Tag = "StrFontSize_Detail";
  176. contextMenuStripEx1.Items.Add(item);
  177. item = new ToolStripMenuItem();
  178. item.Text = "15号";
  179. item.Name = "15";
  180. item.Tag = "StrFontSize_Detail";
  181. contextMenuStripEx1.Items.Add(item);
  182. item = new ToolStripMenuItem();
  183. item.Text = "14号";
  184. item.Name = "14";
  185. item.Tag = "StrFontSize_Detail";
  186. contextMenuStripEx1.Items.Add(item);
  187. item = new ToolStripMenuItem();
  188. item.Text = "13号";
  189. item.Name = "13";
  190. item.Tag = "StrFontSize_Detail";
  191. contextMenuStripEx1.Items.Add(item);
  192. item = new ToolStripMenuItem();
  193. item.Text = "12号";
  194. item.Name = "12";
  195. item.Tag = "StrFontSize_Detail";
  196. contextMenuStripEx1.Items.Add(item);
  197. item = new ToolStripMenuItem();
  198. item.Text = "11号";
  199. item.Name = "11";
  200. item.Tag = "StrFontSize_Detail";
  201. contextMenuStripEx1.Items.Add(item);
  202. item = new ToolStripMenuItem();
  203. item.Text = "10号";
  204. item.Name = "10";
  205. item.Tag = "StrFontSize_Detail";
  206. contextMenuStripEx1.Items.Add(item);
  207. item = new ToolStripMenuItem();
  208. item.Text = "9号";
  209. item.Name = "9";
  210. item.Tag = "StrFontSize_Detail";
  211. contextMenuStripEx1.Items.Add(item);
  212. item = new ToolStripMenuItem();
  213. item.Text = "8号";
  214. item.Name = "8";
  215. item.Tag = "StrFontSize_Detail";
  216. contextMenuStripEx1.Items.Add(item);
  217. item = new ToolStripMenuItem();
  218. item.Text = "7号";
  219. item.Name = "7";
  220. item.Tag = "StrFontSize_Detail";
  221. contextMenuStripEx1.Items.Add(item);
  222. }
  223. else if (this.dgvData_A4_Size.Columns[e.ColumnIndex].Name.Trim() == "注意事项" || this.dgvData_A4_Size.Columns[e.ColumnIndex].Name.Trim() == "适用打印类型")
  224. {
  225. ToolStripMenuItem item = new ToolStripMenuItem();
  226. item.Text = "17号";
  227. item.Name = "17";
  228. item.Tag = "StrFontSize_Note";
  229. contextMenuStripEx1.Items.Add(item);
  230. item = new ToolStripMenuItem();
  231. item.Text = "16号";
  232. item.Name = "16";
  233. item.Tag = "StrFontSize_Note";
  234. contextMenuStripEx1.Items.Add(item);
  235. item = new ToolStripMenuItem();
  236. item.Text = "15号";
  237. item.Name = "15";
  238. item.Tag = "StrFontSize_Note";
  239. contextMenuStripEx1.Items.Add(item);
  240. item = new ToolStripMenuItem();
  241. item.Text = "14号";
  242. item.Name = "14";
  243. item.Tag = "StrFontSize_Note";
  244. contextMenuStripEx1.Items.Add(item);
  245. item = new ToolStripMenuItem();
  246. item.Text = "13号";
  247. item.Name = "13";
  248. item.Tag = "StrFontSize_Note";
  249. contextMenuStripEx1.Items.Add(item);
  250. item = new ToolStripMenuItem();
  251. item.Text = "12号";
  252. item.Name = "12";
  253. item.Tag = "StrFontSize_Note";
  254. contextMenuStripEx1.Items.Add(item);
  255. item = new ToolStripMenuItem();
  256. item.Text = "11号";
  257. item.Name = "11";
  258. item.Tag = "StrFontSize_Note";
  259. contextMenuStripEx1.Items.Add(item);
  260. item = new ToolStripMenuItem();
  261. item.Text = "10号";
  262. item.Name = "10";
  263. item.Tag = "StrFontSize_Note";
  264. contextMenuStripEx1.Items.Add(item);
  265. item = new ToolStripMenuItem();
  266. item.Text = "9号";
  267. item.Name = "9";
  268. item.Tag = "StrFontSize_Note";
  269. contextMenuStripEx1.Items.Add(item);
  270. item = new ToolStripMenuItem();
  271. item.Text = "8号";
  272. item.Name = "8";
  273. item.Tag = "StrFontSize_Note";
  274. contextMenuStripEx1.Items.Add(item);
  275. item = new ToolStripMenuItem();
  276. item.Text = "7号";
  277. item.Name = "7";
  278. item.Tag = "StrFontSize_Note";
  279. contextMenuStripEx1.Items.Add(item);
  280. }
  281. }
  282. }
  283. }
  284. /// <summary>
  285. /// 针式打印分辨率设置 列表列点击事件(右键)
  286. /// </summary>
  287. /// <param name="sender"></param>
  288. /// <param name="e"></param>
  289. void dgvData_DMX_Dots_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  290. {
  291. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  292. {
  293. if (e.Button == MouseButtons.Right)
  294. {
  295. this.contextMenuStripEx1.Items.Clear();
  296. //弹出操作菜单
  297. this.contextMenuStripEx1.Show(MousePosition.X, MousePosition.Y);
  298. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  299. {
  300. ToolStripMenuItem item = new ToolStripMenuItem();
  301. if (this.dgvData_DMX_Dots.Columns[e.ColumnIndex].Name.Trim() == "针式进纸设置" || this.dgvData_DMX_Dots.Columns[e.ColumnIndex].Name.Trim() == "打印单名称")
  302. {
  303. item.Text = "前进纸";
  304. item.Tag = "StrPaperFeed";
  305. contextMenuStripEx1.Items.Add(item);
  306. item = new ToolStripMenuItem();
  307. item.Text = "后进纸";
  308. item.Tag = "StrPaperFeed";
  309. contextMenuStripEx1.Items.Add(item);
  310. }
  311. else if (this.dgvData_DMX_Dots.Columns[e.ColumnIndex].Name.Trim() == "针式分辨率" || this.dgvData_DMX_Dots.Columns[e.ColumnIndex].Name.Trim() == "适用打印类型")
  312. {
  313. DataTable tbl = orbll.GetView_Custom("tb_ErpPrinterSet", StrWhere: "ID = '" + Convert.ToInt32(this.dgvData_DMX_Dots.Rows[e.RowIndex].Cells["ID"].Value) + "'", ShowColumnName: "ps_PrinterPath").Tables[0];
  314. if (tbl.Rows.Count > 0)
  315. {
  316. if (tbl.Rows[0]["ps_PrinterPath"].ToString().Trim() == "")
  317. { MessageBoxCustom.Show("未设置打印机,无法获取打印机分辨率!"); return; }
  318. PrintDocument pd = new PrintDocument();
  319. pd.PrinterSettings.PrinterName = tbl.Rows[0]["ps_PrinterPath"].ToString().Trim();
  320. int dlgCount = pd.PrinterSettings.PrinterResolutions.Count;
  321. for (int i = 0; i < dlgCount; i++)
  322. {
  323. int dlg_X = pd.PrinterSettings.PrinterResolutions[i].X;
  324. int dlg_Y = pd.PrinterSettings.PrinterResolutions[i].Y;
  325. item = new ToolStripMenuItem();
  326. item.Text = "X:" + dlg_X + " Y:" + dlg_Y;
  327. item.Name = "X:" + dlg_X + "|Y:" + dlg_Y;
  328. item.Tag = "StrResolution";
  329. contextMenuStripEx1.Items.Add(item);
  330. }
  331. }
  332. }
  333. }
  334. }
  335. }
  336. }
  337. /// <summary>
  338. /// 针式打印机路径设置 列表点击事件(右键)
  339. /// </summary>
  340. /// <param name="sender"></param>
  341. /// <param name="e"></param>
  342. void dgvData_DMX_Path_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  343. {
  344. if (e.Button == MouseButtons.Right)
  345. {
  346. this.contextMenuStripEx1.Items.Clear();
  347. this.contextMenuStripEx1.Show(MousePosition.X, MousePosition.Y);
  348. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  349. {
  350. ToolStripMenuItem item = new ToolStripMenuItem();
  351. item.Text = "清空值";
  352. item.Tag = "StrPrinter_DMX";
  353. contextMenuStripEx1.Items.Add(item);
  354. item = new ToolStripMenuItem();
  355. item.Text = "设置打印机";
  356. item.Tag = "StrPrinter_DMX";
  357. contextMenuStripEx1.Items.Add(item);
  358. }
  359. }
  360. }
  361. /// <summary>
  362. /// 热敏(小票)打印机路径设置 列表点击事件(右键)
  363. /// </summary>
  364. /// <param name="sender"></param>
  365. /// <param name="e"></param>
  366. void dgvData_STicket_Path_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  367. {
  368. if (e.Button == MouseButtons.Right)
  369. {
  370. this.contextMenuStripEx1.Items.Clear();
  371. this.contextMenuStripEx1.Show(MousePosition.X, MousePosition.Y);
  372. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  373. {
  374. ToolStripMenuItem item = new ToolStripMenuItem();
  375. item.Text = "清空值";
  376. item.Tag = "StrPrinter_STicket";
  377. contextMenuStripEx1.Items.Add(item);
  378. item = new ToolStripMenuItem();
  379. item.Text = "设置打印机";
  380. item.Tag = "StrPrinter_STicket";
  381. contextMenuStripEx1.Items.Add(item);
  382. }
  383. }
  384. }
  385. /// <summary>
  386. /// 热敏(小票)打印标题设置 列表点击事件(右键)
  387. /// </summary>
  388. /// <param name="sender"></param>
  389. /// <param name="e"></param>
  390. void dgvData_DMX_PrintTitles_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
  391. {
  392. if (e.Button == MouseButtons.Right)
  393. {
  394. this.contextMenuStripEx1.Items.Clear();
  395. this.contextMenuStripEx1.Show(MousePosition.X, MousePosition.Y);
  396. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  397. {
  398. ToolStripMenuItem item = new ToolStripMenuItem();
  399. item.Text = "清空值";
  400. item.Tag = "StrPrinter_PrintTitles";
  401. contextMenuStripEx1.Items.Add(item);
  402. item = new ToolStripMenuItem();
  403. item.Text = "设置打印标题";
  404. item.Tag = "StrPrinter_PrintTitles";
  405. contextMenuStripEx1.Items.Add(item);
  406. }
  407. }
  408. }
  409. /// <summary>
  410. /// 右键菜单选择项事件
  411. /// </summary>
  412. /// <param name="sender"></param>
  413. /// <param name="e"></param>
  414. void contextMenuStripEx1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  415. {
  416. DateTime StrTime = SDateTime.Now;
  417. try
  418. {
  419. #region 权限
  420. if (!LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.BLL.BLL_ErpUser.CurrentUserRights.PrinterSetup, LYFZ.CustomAttributes.OperatingAuthority.Setting))
  421. { MessageBoxCustom.Show("您无权限修改!"); return; }
  422. #endregion
  423. ToolStripItem item = e.ClickedItem;
  424. string StrName = "";
  425. string StrPath = "";
  426. string StrEmployeeID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  427. Hashtable htData = new Hashtable();
  428. if (item.Tag.ToString().Trim() == "StrPrinter")
  429. {
  430. #region A4打印机路径设置
  431. if (item.Text.Trim() == "设置打印机")
  432. {
  433. PrintDialog dlg = new PrintDialog();
  434. this.contextMenuStripEx1.Visible = false;
  435. if (dlg.ShowDialog() == DialogResult.OK)
  436. {
  437. StrName = dlg.PrinterSettings.PrinterName;
  438. StrPath = System.IO.Path.GetFileName(StrName);
  439. }
  440. else
  441. { return; }
  442. }
  443. for (int i = 0; i < this.dgvData_A4_Path.SelectedRows.Count; i++)
  444. {
  445. htData["where ID = '" + this.dgvData_A4_Path.SelectedRows[i].Cells["ID"].Value + "'"] = " ps_PrinterName = '" + StrPath + "',ps_PrinterPath = '" + StrName + "', ps_UpdateDateTime = '" + StrTime.ToString("yyyy-MM-dd HH:mm:ss") + "', ps_UpdateName = '" + StrEmployeeID + "'";
  446. this.dgvData_A4_Path.SelectedRows[i].Cells["打印机名称"].Value = StrPath;
  447. this.dgvData_A4_Path.SelectedRows[i].Cells["打印机路径"].Value = StrName;
  448. }
  449. #endregion
  450. }
  451. else if (item.Tag.ToString().Trim() == "StrFontSize_Detail")
  452. {
  453. #region A4纸详情内容字体大小设置
  454. for (int i = 0; i < this.dgvData_A4_Size.Rows.Count; i++)
  455. {
  456. htData["where ID = '" + this.dgvData_A4_Size.SelectedRows[i].Cells["ID"].Value + "'"] = " ps_FontSize = '" + item.Text.Trim() + ":" + item.Name.Trim() + "," + this.dgvData_A4_Size.SelectedRows[i].Cells["注意事项"].Value + ":" + this.dgvData_A4_Size.SelectedRows[i].Cells["注意事项"].Tag.ToString().Trim() + "', ps_UpdateDateTime = '" + StrTime.ToString("yyyy-MM-dd HH:mm:ss") + "', ps_UpdateName = '" + StrEmployeeID + "'";
  457. this.dgvData_A4_Size.Rows[i].Cells["详情内容"].Value = item.Text.Trim();
  458. this.dgvData_A4_Size.Rows[i].Cells["详情内容"].Tag = item.Name.Trim();
  459. }
  460. #endregion
  461. }
  462. else if (item.Tag.ToString().Trim() == "StrFontSize_Note")
  463. {
  464. #region A4纸注意事项字体大小设置
  465. for (int i = 0; i < this.dgvData_A4_Size.Rows.Count; i++)
  466. {
  467. htData["where ID = '" + this.dgvData_A4_Size.SelectedRows[i].Cells["ID"].Value + "'"] = " ps_FontSize = '" + this.dgvData_A4_Size.SelectedRows[i].Cells["详情内容"].Value + ":" + this.dgvData_A4_Size.SelectedRows[i].Cells["详情内容"].Tag.ToString().Trim() + "," + item.Text.Trim() + ":" + item.Name.Trim() + "', ps_UpdateDateTime = '" + StrTime.ToString("yyyy-MM-dd HH:mm:ss") + "', ps_UpdateName = '" + StrEmployeeID + "'";
  468. this.dgvData_A4_Size.Rows[i].Cells["注意事项"].Value = item.Text.Trim();
  469. this.dgvData_A4_Size.Rows[i].Cells["注意事项"].Tag = item.Name.Trim();
  470. }
  471. #endregion
  472. }
  473. else if (item.Tag.ToString().Trim() == "StrPaperFeed")
  474. {
  475. #region 针式进纸设置
  476. for (int i = 0; i < this.dgvData_DMX_Dots.SelectedRows.Count; i++)
  477. {
  478. if (this.dgvData_DMX_Dots.SelectedRows[i].Cells["适用打印类型"].Value.ToString().ToString().Trim() == "适用于(针式打印机)")
  479. {
  480. string strValue = "0";
  481. if (item.Text.Trim() == "后进纸")
  482. { strValue = "1"; }
  483. htData["where ID = '" + this.dgvData_DMX_Dots.SelectedRows[i].Cells["ID"].Value + "'"] = " ps_PaperFeed = '" + strValue + "', ps_UpdateDateTime = '" + StrTime.ToString("yyyy-MM-dd HH:mm:ss") + "', ps_UpdateName = '" + StrEmployeeID + "'";
  484. this.dgvData_DMX_Dots.SelectedRows[i].Cells["针式进纸设置"].Value = item.Text.Trim();
  485. }
  486. }
  487. #endregion
  488. }
  489. else if (item.Tag.ToString().Trim() == "StrResolution")
  490. {
  491. #region 针式打印分辨率
  492. string StrX_Y = item.Text.Trim();
  493. string StrX = "";
  494. string StrY = "";
  495. if (StrX_Y != "")
  496. {
  497. string[] StrNameSplit = item.Name.Trim().Split('|');
  498. StrX = StrNameSplit[0].Trim().Split(':')[1];
  499. StrY = StrNameSplit[1].Trim().Split(':')[1];
  500. }
  501. for (int i = 0; i < this.dgvData_DMX_Dots.SelectedRows.Count; i++)
  502. {
  503. if (this.dgvData_DMX_Dots.SelectedRows[i].Cells["适用打印类型"].Value.ToString().ToString().Trim() == "适用于(针式打印机)")
  504. {
  505. htData["where ID = '" + this.dgvData_DMX_Dots.SelectedRows[i].Cells["ID"].Value + "'"] = " ps_ResolutionName = '" + StrX_Y + "',ps_ResolutionX='" + StrX + "',ps_ResolutionY='" + StrY + "', ps_UpdateDateTime = '" + StrTime.ToString("yyyy-MM-dd HH:mm:ss") + "', ps_UpdateName = '" + StrEmployeeID + "'";
  506. this.dgvData_DMX_Dots.SelectedRows[i].Cells["针式分辨率"].Value = StrX_Y;
  507. }
  508. }
  509. #endregion
  510. }
  511. else if (item.Tag.ToString().Trim() == "StrPrinter_DMX")
  512. {
  513. #region 针式打印机路径设置
  514. if (item.Text.Trim() == "设置打印机")
  515. {
  516. PrintDialog dlg = new PrintDialog();
  517. this.contextMenuStripEx1.Visible = false;
  518. if (dlg.ShowDialog() == DialogResult.OK)
  519. {
  520. StrName = dlg.PrinterSettings.PrinterName;
  521. StrPath = System.IO.Path.GetFileName(StrName);
  522. }
  523. else
  524. { return; }
  525. }
  526. for (int i = 0; i < this.dgvData_DMX_Path.SelectedRows.Count; i++)
  527. {
  528. htData["where ID = '" + this.dgvData_DMX_Path.SelectedRows[i].Cells["ID"].Value + "'"] = " ps_PrinterName = '" + StrPath + "',ps_PrinterPath = '" + StrName + "', ps_UpdateDateTime = '" + StrTime.ToString("yyyy-MM-dd HH:mm:ss") + "', ps_UpdateName = '" + StrEmployeeID + "'";
  529. this.dgvData_DMX_Path.SelectedRows[i].Cells["打印机名称"].Value = StrPath;
  530. this.dgvData_DMX_Path.SelectedRows[i].Cells["打印机路径"].Value = StrName;
  531. }
  532. #endregion
  533. }
  534. else if (item.Tag.ToString().Trim() == "StrPrinter_STicket")
  535. {
  536. #region 针式打印机路径设置
  537. if (item.Text.Trim() == "设置打印机")
  538. {
  539. PrintDialog dlg = new PrintDialog();
  540. this.contextMenuStripEx1.Visible = false;
  541. if (dlg.ShowDialog() == DialogResult.OK)
  542. {
  543. StrName = dlg.PrinterSettings.PrinterName;
  544. StrPath = System.IO.Path.GetFileName(StrName);
  545. }
  546. else
  547. { return; }
  548. }
  549. for (int i = 0; i < this.dgvData_STicket_Path.SelectedRows.Count; i++)
  550. {
  551. htData["where ID = '" + this.dgvData_STicket_Path.SelectedRows[i].Cells["ID"].Value + "'"] = " ps_SmallTicketPrintName = '" + StrPath + "',ps_SmallTicketPrintPath = '" + StrName + "', ps_UpdateDateTime = '" + StrTime.ToString("yyyy-MM-dd HH:mm:ss") + "', ps_UpdateName = '" + StrEmployeeID + "'";
  552. this.dgvData_STicket_Path.SelectedRows[i].Cells["打印机名称"].Value = StrPath;
  553. this.dgvData_STicket_Path.SelectedRows[i].Cells["打印机路径"].Value = StrName;
  554. }
  555. #endregion
  556. }
  557. else if (item.Tag.ToString().Trim() == "StrPrinter_PrintTitles")
  558. {
  559. #region 针式打印标题设置
  560. if (item.Text.Trim() == "设置打印标题")
  561. {
  562. LYFZ.Software.MainBusiness.CameraControlBook.SuperSmallForm.GetTextSuperSmallForm frm = new CameraControlBook.SuperSmallForm.GetTextSuperSmallForm();
  563. frm.ShowDialog();
  564. this.contextMenuStripEx1.Visible = false;
  565. if (frm.IsOK)
  566. { StrName = frm.StrValue; }
  567. else
  568. { return; }
  569. if (StrName.Trim().Length > 40)
  570. { MessageBoxCustom.Show("标题名称长度不能超过40字符!"); return; }
  571. }
  572. for (int i = 0; i < this.dgvData_DMX_PrintTitles.SelectedRows.Count; i++)
  573. {
  574. htData["where ID = '" + this.dgvData_DMX_PrintTitles.SelectedRows[i].Cells["ID"].Value + "'"] = " ps_PrintTitles = '" + StrName + "', ps_UpdateDateTime = '" + StrTime.ToString("yyyy-MM-dd HH:mm:ss") + "', ps_UpdateName = '" + StrEmployeeID + "'";
  575. this.dgvData_DMX_PrintTitles.SelectedRows[i].Cells["打印标题"].Value = StrName;
  576. }
  577. #endregion
  578. }
  579. psbll.UpdatePrinterSet(htData);
  580. }
  581. catch { MessageBoxCustom.Show(StrTime.ToString()); }
  582. }
  583. /// <summary>
  584. /// 打印标题设置
  585. /// </summary>
  586. /// <param name="sender"></param>
  587. /// <param name="e"></param>
  588. void dgvData_DMX_PrintTitles_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  589. {
  590. if (e.RowIndex != -1 && e.ColumnIndex != -1)
  591. {
  592. this.txtPrintTitles.Visible = false;
  593. if (this.dgvData_DMX_PrintTitles.Columns[e.ColumnIndex].Name == "打印标题")//
  594. {
  595. DataGridViewCell cell = this.dgvData_DMX_PrintTitles.Rows[e.RowIndex].Cells[e.ColumnIndex];
  596. Rectangle rect = this.dgvData_DMX_PrintTitles.GetCellDisplayRectangle(cell.ColumnIndex, cell.RowIndex, true);
  597. this.txtPrintTitles.Location = new Point(rect.Location.X + this.dgvData_DMX_PrintTitles.Location.X, rect.Location.Y + this.dgvData_DMX_PrintTitles.Location.Y);
  598. this.txtPrintTitles.Size = rect.Size;
  599. this.txtPrintTitles.Visible = true;
  600. this.txtPrintTitles.Text = cell.Value.ToString().Trim();
  601. this.txtPrintTitles.Tag = "PT";
  602. this.txtPrintTitles.Focus();
  603. }
  604. }
  605. }
  606. /// <summary>
  607. /// 离开事件
  608. /// </summary>
  609. /// <param name="sender"></param>
  610. /// <param name="e"></param>
  611. void txtPrintTitles_Leave(object sender, EventArgs e)
  612. {
  613. if (this.txtPrintTitles.Tag != null)
  614. {
  615. if (this.txtPrintTitles.Tag.ToString().Trim() == "PT")
  616. {
  617. this.dgvData_DMX_PrintTitles.CurrentRow.Cells["打印标题"].Value = this.txtPrintTitles.Text.Trim();
  618. LYFZ.Model.Model_ErpPrinterSet model = psbll.GetModel(Convert.ToInt32(this.dgvData_DMX_PrintTitles.CurrentRow.Cells["ID"].Value));
  619. model.Ps_printtitles = this.txtPrintTitles.Text.Trim();
  620. if (!psbll.Update(model))
  621. { MessageBoxCustom.Show("设置打印标题失败!"); return; }
  622. }
  623. this.txtPrintTitles.Visible = false;
  624. }
  625. }
  626. }
  627. }