锐腾搅拌上料功能
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.

382 lines
14 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. namespace ICSSoft.Frame.APP
  22. {
  23. public partial class FormICSWWLotPrint : DevExpress.XtraEditors.XtraForm
  24. {
  25. private string sqltxt = "";
  26. private string sqlconn = "";
  27. String guid = AppConfig.GetGuid();
  28. private DataTable dataSource = null;
  29. #region 构造函数
  30. public FormICSWWLotPrint()
  31. {
  32. InitializeComponent();
  33. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  34. this.WindowState = FormWindowState.Maximized;
  35. }
  36. #endregion
  37. #region 移动窗体
  38. private const int WM_NCHITTEST = 0x84;
  39. private const int HTCLIENT = 0x1;
  40. private const int HTCAPTION = 0x2;
  41. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  42. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  43. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  44. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  45. //重写窗体,使窗体可以不通过自带标题栏实现移动
  46. protected override void WndProc(ref Message m)
  47. {
  48. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  49. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  50. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  51. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  52. switch (m.Msg)
  53. {
  54. case WM_NCHITTEST:
  55. base.WndProc(ref m);
  56. if ((int)m.Result == HTCLIENT)
  57. m.Result = (IntPtr)HTCAPTION;
  58. return;
  59. }
  60. //拦截双击标题栏、移动窗体的系统消息
  61. if (m.Msg != 0xA3)
  62. {
  63. base.WndProc(ref m);
  64. }
  65. }
  66. #endregion
  67. #region SystemOptition
  68. /// <summary>
  69. /// 操作权限
  70. /// </summary>
  71. /// <returns></returns>
  72. public DataTable RightOfExute()
  73. {
  74. DataTable rData = new DataTable();
  75. rData.Columns.Add("BtnName");
  76. rData.Columns.Add("ActionName");
  77. //查看权限(必须有)
  78. DataRow seeRow = rData.NewRow();
  79. seeRow["BtnName"] = "see";
  80. seeRow["ActionName"] = "查看";
  81. rData.Rows.Add(seeRow);
  82. List<Control> ControlList = new List<Control>();
  83. //ControlList.Add(btnSelect);
  84. //ControlList.Add(btnCanSelect);
  85. //ControlList.Add(btnExit);
  86. ControlList.Add(simpleButton4);
  87. ControlList.Add(btnOutPut);
  88. foreach (Control ctr in ControlList)
  89. {
  90. if (ctr.GetType() == typeof(SimpleButton))
  91. {
  92. DataRow dr = rData.NewRow();
  93. dr["BtnName"] = ctr.Name;
  94. dr["ActionName"] = ctr.Text;
  95. rData.Rows.Add(dr);
  96. }
  97. }
  98. rData.AcceptChanges();
  99. return rData;
  100. }
  101. /// <summary>
  102. /// 数据权限
  103. /// </summary>
  104. /// <returns></returns>
  105. public DataTable RightOfData()
  106. {
  107. DataTable rData = new DataTable();
  108. rData.Columns.Add("BodyName");
  109. rData.Columns.Add("ControlName");
  110. rData.Columns.Add("ControlCaption");
  111. rData.AcceptChanges();
  112. return rData;
  113. }
  114. #endregion
  115. #region 退出
  116. private void btnClose_Click(object sender, EventArgs e)
  117. {
  118. AppConfig.CloseFormShow(this.Text);
  119. this.Close();
  120. }
  121. private void btnExit_Click(object sender, EventArgs e)
  122. {
  123. AppConfig.CloseFormShow(this.Text);
  124. this.Close();
  125. }
  126. #endregion
  127. #region 过滤
  128. private string tempTableName = "";
  129. private void btnFilter_Click(object sender, EventArgs e)
  130. {
  131. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  132. filter.OldTempTableName = tempTableName;
  133. if (filter.ShowDialog() == DialogResult.OK)
  134. {
  135. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  136. try
  137. {
  138. _wait.Show();
  139. tempTableName = filter.NewTempTableName;
  140. sqltxt = filter.SqlText;
  141. sqlconn = filter.FilterConnectString;
  142. dataSource = filter.FilterData.Tables[0];
  143. grdDetail.DataSource = dataSource;
  144. grvDetail.BestFitColumns();
  145. rptPage.RecordNum = dataSource.Rows.Count;
  146. rptPage.PageSize = 99;
  147. rptPage.PageIndex = 1;
  148. rptPage.ReLoad();
  149. rptPage.PageSize = 100;
  150. rptPage.PageIndex = 1;
  151. rptPage.ReLoad();
  152. _wait.Close();
  153. }
  154. catch (Exception ex)
  155. {
  156. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  157. _wait.Close();
  158. }
  159. }
  160. }
  161. #endregion
  162. #region 绑定数据源
  163. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  164. {
  165. if (AppConfig.UserCode.ToLower() != "demo")
  166. {
  167. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  168. return;
  169. }
  170. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  171. fdata.ShowDialog();
  172. }
  173. #endregion
  174. #region 全选
  175. private void btnSelect_Click(object sender, EventArgs e)
  176. {
  177. for (int i = 0; i < grvDetail.RowCount; i++)
  178. {
  179. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  180. }
  181. }
  182. #endregion
  183. #region 全消
  184. private void btnCanSelect_Click(object sender, EventArgs e)
  185. {
  186. for (int i = 0; i < grvDetail.RowCount; i++)
  187. {
  188. grvDetail.SetRowCellValue(i, colisSelect, "");
  189. }
  190. }
  191. #endregion
  192. #region 刷新
  193. private void btnFalsh_Click(object sender, EventArgs e)
  194. {
  195. if (sqlconn == null || sqlconn == "")
  196. {
  197. return;
  198. }
  199. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  200. try
  201. {
  202. _wait.Show();
  203. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  204. filter.OldTempTableName = tempTableName;
  205. //tempTableName = filter.NewTempTableName;
  206. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  207. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  208. grdDetail.DataSource = dataSource;
  209. rptPage.RecordNum = 100;
  210. rptPage.PageIndex = 1;
  211. rptPage.ReLoad();
  212. _wait.Close();
  213. }
  214. catch (Exception ex)
  215. {
  216. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  217. _wait.Close();
  218. }
  219. }
  220. #endregion
  221. #region 列表
  222. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  223. {
  224. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  225. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  226. }
  227. #endregion
  228. #region 过滤方法
  229. private void FormICSStack_FormClosing(object sender, FormClosingEventArgs e)
  230. {
  231. AppConfig.DropTemTable(tempTableName);
  232. }
  233. #endregion
  234. #region 分页
  235. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  236. {
  237. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  238. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  239. grdDetail.DataSource = data;
  240. }
  241. #endregion
  242. private void grdDetail_Click(object sender, EventArgs e)
  243. {
  244. DataTable dt = new DataTable();
  245. dt.Columns.Add();
  246. }
  247. private void FormICSSum_Manday_Load_1(object sender, EventArgs e)
  248. {
  249. btnFilter_Click(sender, e);
  250. }
  251. #region 双击选择
  252. private void grdDetail_DoubleClick(object sender, EventArgs e)
  253. {
  254. if (grvDetail.FocusedRowHandle < 0)
  255. {
  256. return;
  257. }
  258. if (grvDetail.FocusedColumn == colisSelect)
  259. {
  260. string a = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString();
  261. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  262. {
  263. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  264. }
  265. else
  266. {
  267. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  268. }
  269. }
  270. }
  271. #endregion
  272. #region 导出
  273. private void btnOutPut_Click(object sender, EventArgs e)
  274. {
  275. SimpleButton btntemp = (SimpleButton)sender;
  276. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  277. {
  278. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  279. return;
  280. }
  281. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  282. foe.ShowDialog();
  283. }
  284. #endregion
  285. #region 打印
  286. private void simpleButton4_Click(object sender, EventArgs e)
  287. {
  288. try
  289. {
  290. SimpleButton btntemp = (SimpleButton)sender;
  291. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  292. {
  293. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  294. return;
  295. }
  296. List<PrintPara> parasList = new List<PrintPara>();
  297. string VenCode = "";
  298. string LotNoList = "";
  299. for (int i = 0; i < grvDetail.RowCount; i++)
  300. {
  301. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  302. {
  303. if (VenCode == "")
  304. {
  305. LotNoList += "" + grvDetail.GetRowCellValue(i, colLOTNO).ToString() + "+" + grvDetail.GetRowCellValue(i, colOPCode).ToString() + "'";
  306. VenCode = grvDetail.GetRowCellValue(i, colVenCode).ToString();
  307. }
  308. else
  309. {
  310. if (VenCode != grvDetail.GetRowCellValue(i, colVenCode).ToString())
  311. {
  312. ICSBaseSimpleCode.AppshowMessageBox("打印时选择的条码必须属于同一个供应商,请确认后重新选择!");
  313. return;
  314. }
  315. else
  316. {
  317. LotNoList += ",'" + grvDetail.GetRowCellValue(i, colLOTNO).ToString() + "+" + grvDetail.GetRowCellValue(i, colOPCode).ToString() + "'";
  318. }
  319. }
  320. }
  321. }
  322. if (LotNoList == "")
  323. {
  324. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  325. return;
  326. }
  327. else
  328. {
  329. PrintPara para = new PrintPara();
  330. para.PrintKey = "LOTNO";
  331. para.PrintValues = new object[] { LotNoList.TrimEnd('\'') };
  332. parasList.Add(para);
  333. }
  334. #region 根据类型选择打印模板
  335. FormPrintDialog f = new FormPrintDialog("028", this.Text, parasList, false, null);
  336. f.ShowDialog();
  337. #endregion
  338. }
  339. catch (Exception ex)
  340. {
  341. MessageBox.Show(ex.ToString());
  342. }
  343. }
  344. #endregion
  345. }
  346. }