锐腾搅拌上料功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

369 lines
12 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using DevExpress.XtraEditors;
  9. using ICSSoft.Frame.User.BLL;
  10. using ICSSoft.Base.Language.Tool;
  11. using ICSSoft.Base.UserControl.MessageControl;
  12. using ICSSoft.Frame.Data.BLL;
  13. using System.Data.SqlClient;
  14. using ICSSoft.Base.Config.AppConfig;
  15. using ICSSoft.Frame.Data.Entity;
  16. using ICSSoft.Base.Report.Filter;
  17. using ICSSoft.Base.Config.DBHelper;
  18. using ICSSoft.Base.UserControl.FormControl;
  19. using ICSSoft.Base.ReferForm.AppReferForm;
  20. using ICSSoft.Base.Lable.PrintTool;
  21. using System.IO;
  22. namespace ICSSoft.Frame.APP
  23. {
  24. public partial class FormICSItemLotPrint : DevExpress.XtraEditors.XtraForm
  25. {
  26. private string _PrintTableName = "标签复制";
  27. private string _LableType = "008";
  28. #region 构造函数
  29. public FormICSItemLotPrint()
  30. {
  31. InitializeComponent();
  32. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  33. this.WindowState = FormWindowState.Maximized;
  34. }
  35. #endregion
  36. #region 移动窗体
  37. private const int WM_NCHITTEST = 0x84;
  38. private const int HTCLIENT = 0x1;
  39. private const int HTCAPTION = 0x2;
  40. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  41. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  42. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  43. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  44. //重写窗体,使窗体可以不通过自带标题栏实现移动
  45. protected override void WndProc(ref Message m)
  46. {
  47. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  48. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  49. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  50. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  51. switch (m.Msg)
  52. {
  53. case WM_NCHITTEST:
  54. base.WndProc(ref m);
  55. if ((int)m.Result == HTCLIENT)
  56. m.Result = (IntPtr)HTCAPTION;
  57. return;
  58. }
  59. //拦截双击标题栏、移动窗体的系统消息
  60. if (m.Msg != 0xA3)
  61. {
  62. base.WndProc(ref m);
  63. }
  64. }
  65. #endregion
  66. #region SystemOptition
  67. /// <summary>
  68. /// 操作权限
  69. /// </summary>
  70. /// <returns></returns>
  71. public DataTable RightOfExute()
  72. {
  73. DataTable rData = new DataTable();
  74. rData.Columns.Add("BtnName");
  75. rData.Columns.Add("ActionName");
  76. //查看权限(必须有)
  77. DataRow seeRow = rData.NewRow();
  78. seeRow["BtnName"] = "see";
  79. seeRow["ActionName"] = "查看";
  80. rData.Rows.Add(seeRow);
  81. List<Control> ControlList = new List<Control>();
  82. ControlList.Add(btnPrint);
  83. //ControlList.Add(btnExit);
  84. foreach (Control ctr in ControlList)
  85. {
  86. if (ctr.GetType() == typeof(SimpleButton))
  87. {
  88. DataRow dr = rData.NewRow();
  89. dr["BtnName"] = ctr.Name;
  90. dr["ActionName"] = ctr.Text;
  91. rData.Rows.Add(dr);
  92. }
  93. }
  94. rData.AcceptChanges();
  95. return rData;
  96. }
  97. /// <summary>
  98. /// 数据权限
  99. /// </summary>
  100. /// <returns></returns>
  101. public DataTable RightOfData()
  102. {
  103. DataTable rData = new DataTable();
  104. rData.Columns.Add("BodyName");
  105. rData.Columns.Add("ControlName");
  106. rData.Columns.Add("ControlCaption");
  107. rData.AcceptChanges();
  108. return rData;
  109. }
  110. #endregion
  111. #region 退出
  112. private void btnClose_Click(object sender, EventArgs e)
  113. {
  114. AppConfig.CloseFormShow(this.Text);
  115. this.Close();
  116. }
  117. private void btnExit_Click(object sender, EventArgs e)
  118. {
  119. AppConfig.CloseFormShow(this.Text);
  120. this.Close();
  121. }
  122. #endregion
  123. #region 打印
  124. private void simpleButton4_Click(object sender, EventArgs e)
  125. {
  126. try
  127. {
  128. SimpleButton btntemp = (SimpleButton)sender;
  129. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  130. {
  131. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  132. return;
  133. }
  134. if (string.IsNullOrWhiteSpace(txtLOTNO.Text.Trim()))
  135. {
  136. MessageBox.Show("请输入产品条码!");
  137. return;
  138. }
  139. if (txtTempName.EditValue == null)
  140. {
  141. MessageBox.Show("请选择打印模板!");
  142. return;
  143. }
  144. if (txtPrint.Text.Trim() == "")
  145. {
  146. MessageBox.Show("请选择本地打印机!");
  147. return;
  148. }
  149. List<PrintPara> parasList = new List<PrintPara>();
  150. PrintPara para = new PrintPara();
  151. para.PrintKey = "LOTNO";
  152. para.PrintValues = new object[] { txtLOTNO.Text.Trim() };
  153. parasList.Add(para);
  154. if (chkShowDialogFlag.Checked)
  155. {
  156. FormPrint pr = new FormPrint(txtTempName.EditValue.ToString(), txtPrint.Text, true, true, _PrintTableName, 1, "", "本地打印", parasList);
  157. pr.ShowDialog();
  158. }
  159. else
  160. {
  161. PrintReport pr = new PrintReport(txtTempName.EditValue.ToString(), txtPrint.Text, true, false, _PrintTableName, 1, "", "本地打印", parasList);
  162. }
  163. SetDefaultLastPrinter();
  164. List<ICSITEMLot> InfoList = new List<ICSITEMLot>();
  165. ICSITEMLot Info = new ICSITEMLot();
  166. Info.LotNO = txtLOTNO.Text.Trim();
  167. Info.lastPrintUSERID = AppConfig.UserId;
  168. Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  169. Info.WorkPoint = AppConfig.WorkPointCode;
  170. InfoList.Add(Info);
  171. //更新打印信息
  172. ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString);
  173. }
  174. catch (Exception ex)
  175. {
  176. MessageBox.Show(ex.ToString());
  177. }
  178. }
  179. #endregion
  180. private void SetDefaultLastPrinter()
  181. {
  182. try
  183. {
  184. string PrinterPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\temp\\";
  185. string PrinterFileName = PrinterPath + _LableType + _PrintTableName + "printerName.ini";
  186. if (!Directory.Exists(PrinterPath))
  187. {
  188. Directory.CreateDirectory(PrinterPath);
  189. }
  190. if (!File.Exists(PrinterFileName))
  191. {
  192. using (File.Create(PrinterFileName))
  193. {
  194. }
  195. }
  196. using (StreamWriter sw = new StreamWriter(PrinterFileName))
  197. {
  198. sw.WriteLine(txtTempName.EditValue == null ? "" : txtTempName.EditValue.ToString());
  199. sw.WriteLine(txtPrint.Text);
  200. sw.WriteLine(chkShowDialogFlag.Checked.ToString());
  201. }
  202. }
  203. catch
  204. {
  205. }
  206. }
  207. private void FormICSItemLotPrint_Load(object sender, EventArgs e)
  208. {
  209. BindPrinters();
  210. BindLables();
  211. GetDefaultLastPrinter();
  212. }
  213. private void BindPrinters()
  214. {
  215. try
  216. {
  217. List<string> list = GetPrinterInfo.GetPrinters();
  218. foreach (string s in list)
  219. {
  220. txtPrint.Properties.Items.Add(s);
  221. }
  222. }
  223. catch (Exception ex)
  224. {
  225. }
  226. }
  227. private void BindLables()
  228. {
  229. string sql = "SELECT ID as [编号],LableName as [名称] FROM dbo.Sys_Lables a WHERE (LableType='{0}' AND WorkPointCode='{1}') ";
  230. sql = string.Format(sql, new object[] { _LableType, AppConfig.WorkPointCode });
  231. DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, sql).Tables[0];
  232. txtTempName.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("编号", "编号"));
  233. txtTempName.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("名称", "名称"));
  234. txtTempName.Properties.ValueMember = "编号";
  235. txtTempName.Properties.DisplayMember = "名称";
  236. txtTempName.Properties.Columns[0].Visible = false;
  237. txtTempName.Properties.DataSource = data;
  238. if (data.Rows.Count > 0)
  239. {
  240. txtTempName.EditValue = data.Rows[0]["编号"];
  241. }
  242. }
  243. private void GetDefaultLastPrinter()
  244. {
  245. try
  246. {
  247. string PrinterPath = System.AppDomain.CurrentDomain.BaseDirectory + "\\temp\\";
  248. string PrinterFileName = PrinterPath + _LableType + _PrintTableName + "printerName.ini";
  249. if (!Directory.Exists(PrinterPath))
  250. {
  251. Directory.CreateDirectory(PrinterPath);
  252. }
  253. if (!File.Exists(PrinterFileName))
  254. {
  255. using (File.Create(PrinterFileName))
  256. {
  257. }
  258. }
  259. Dictionary<int, string> infoDic = new Dictionary<int, string>();
  260. using (StreamReader fReader = new StreamReader(PrinterFileName))
  261. {
  262. int key = 0;
  263. while (fReader.Peek() > -1)
  264. {
  265. string value = fReader.ReadLine();
  266. if (value != null)
  267. {
  268. infoDic.Add(key, value);
  269. key++;
  270. }
  271. }
  272. }
  273. if (infoDic.Count == 3)
  274. { //
  275. if (infoDic[0] != "")
  276. {
  277. if (txtTempName.Properties.DataSource != null)
  278. {
  279. DataTable dt = txtTempName.Properties.DataSource as DataTable;
  280. if (dt.Select("编号 = '" + infoDic[0] + "'").Length > 0)
  281. {
  282. txtTempName.EditValue = infoDic[0];
  283. }
  284. }
  285. }
  286. if (infoDic[1] != "")
  287. {
  288. if (txtPrint.Properties.Items.Contains(infoDic[1]))
  289. {
  290. txtPrint.Text = infoDic[1];
  291. }
  292. }
  293. if (infoDic[2] != "")
  294. {
  295. bool boolvalue = false;
  296. if (bool.TryParse(infoDic[2], out boolvalue))
  297. {
  298. chkShowDialogFlag.Checked = boolvalue;
  299. }
  300. }
  301. }
  302. }
  303. catch
  304. {
  305. }
  306. }
  307. private void txtLOTNO_KeyPress(object sender, KeyPressEventArgs e)
  308. {
  309. try
  310. {
  311. if (e.KeyChar == 13)
  312. {
  313. simpleButton4_Click(null, null);
  314. }
  315. }
  316. catch (Exception ex)
  317. {
  318. ICSBaseSimpleCode.AppshowMessageBox(ex.ToString());
  319. }
  320. }
  321. }
  322. }