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

443 lines
16 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 FormICSItemLot : 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 FormICSItemLot()
  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. ////上传事件
  274. //private void repositoryItemButtonEdit1_Click(object sender, EventArgs e)
  275. //{
  276. //}
  277. ////下载事件
  278. //private void repositoryItemButtonEdit2_Click(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  279. //{
  280. //}
  281. //#endregion
  282. private DataRow CheckStatus(string Status)
  283. {
  284. try
  285. {
  286. if (grvDetail.FocusedRowHandle < 0)
  287. { throw new Exception("error"); }
  288. DataRow df = grvDetail.GetDataRow(grvDetail.FocusedRowHandle);
  289. if (df == null)
  290. { throw new Exception("error"); }
  291. if (df["检验状态"].ToString() == Status)
  292. throw new Exception("error");
  293. df["检验状态"] = Status;
  294. return df;
  295. }
  296. catch (Exception ex) { throw ex; }
  297. }
  298. private void btnOutPut_Click(object sender, EventArgs e)
  299. {
  300. SimpleButton btntemp = (SimpleButton)sender;
  301. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  302. {
  303. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  304. return;
  305. }
  306. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  307. foe.ShowDialog();
  308. }
  309. #region 打印
  310. private void simpleButton4_Click(object sender, EventArgs e)
  311. {
  312. try
  313. {
  314. SimpleButton btntemp = (SimpleButton)sender;
  315. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  316. {
  317. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  318. return;
  319. }
  320. bool identical = true;
  321. string type="";
  322. List<PrintPara> parasList = new List<PrintPara>();
  323. List<ICSITEMLot> InfoList = new List<ICSITEMLot>();
  324. for (int i = 0; i < grvDetail.RowCount; i++)
  325. {
  326. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  327. {
  328. if (!string.IsNullOrWhiteSpace(type) && !type.Equals(grvDetail.GetRowCellValue(i, colTYPE).ToString()))
  329. {
  330. identical = false;
  331. break;
  332. }
  333. type = grvDetail.GetRowCellValue(i, colTYPE).ToString();
  334. PrintPara para = new PrintPara();
  335. para.PrintKey = "LOTNO";
  336. para.PrintValues = new object[] { grvDetail.GetRowCellValue(i, colLOTNO).ToString() };
  337. parasList.Add(para);
  338. ICSITEMLot Info = new ICSITEMLot();
  339. Info.LotNO = grvDetail.GetRowCellValue(i, colLOTNO).ToString();
  340. //Info.PrintTimes = Convert.ToInt32(grvDetail.GetRowCellValue(i, colPrintTimes).ToString()) + 1;
  341. Info.lastPrintUSERID = AppConfig.UserId;
  342. Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  343. Info.WorkPoint = AppConfig.WorkPointCode;
  344. InfoList.Add(Info);
  345. }
  346. }
  347. if (!identical)
  348. {
  349. ICSBaseSimpleCode.AppshowMessageBox("类型不同,不能打印!");
  350. return;
  351. }
  352. if (parasList.Count == 0)
  353. {
  354. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  355. return;
  356. }
  357. #region 根据类型选择打印模板
  358. if (type.Equals("到货"))
  359. {
  360. FormPrintDialog f = new FormPrintDialog("001", this.Text, parasList, false, null);
  361. f.ShowDialog();
  362. }
  363. else if (type.Equals("退料"))
  364. {
  365. FormPrintDialog f = new FormPrintDialog("019", this.Text, parasList, false, null);
  366. f.ShowDialog();
  367. }
  368. else if (type.Equals("原材料"))
  369. {
  370. FormPrintDialog f = new FormPrintDialog("003", this.Text, parasList, false, null);
  371. f.ShowDialog();
  372. }
  373. else if (type.Equals("销售退货"))
  374. {
  375. FormPrintDialog f = new FormPrintDialog("026", this.Text, parasList, false, null);
  376. f.ShowDialog();
  377. }
  378. else
  379. {
  380. FormPrintDialog f = new FormPrintDialog("007", this.Text, parasList, false, null);
  381. f.ShowDialog();
  382. }
  383. #endregion
  384. //更新打印信息
  385. ICSRdrecord2LOTBLL.updatePrint(InfoList, AppConfig.AppConnectString);
  386. }
  387. catch (Exception ex)
  388. {
  389. MessageBox.Show(ex.ToString());
  390. }
  391. }
  392. #endregion
  393. private void grdDetail_Click_1(object sender, EventArgs e)
  394. {
  395. }
  396. }
  397. }