华恒Mes鼎捷代码
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.

445 lines
17 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using DevExpress.XtraEditors;
  8. using ICSSoft.Base.Config.AppConfig;
  9. using ICSSoft.Base.Config.DBHelper;
  10. using ICSSoft.Base.Report.Filter;
  11. using ICSSoft.Base.UserControl.FormControl;
  12. namespace ICSSoft.Frame.APP
  13. {
  14. public partial class FormICSICSTransferNOBack : DevExpress.XtraEditors.XtraForm
  15. {
  16. private string sqltxt = "";
  17. private string sqlconn = "";
  18. String guid = AppConfig.GetGuid();
  19. private DataTable dataSource = null;
  20. #region 构造函数
  21. public FormICSICSTransferNOBack()
  22. {
  23. InitializeComponent();
  24. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  25. this.WindowState = FormWindowState.Maximized;
  26. }
  27. #endregion
  28. #region 操作权限
  29. public DataTable RightOfExute()
  30. {
  31. DataTable rData = new DataTable();
  32. rData.Columns.Add("BtnName");
  33. rData.Columns.Add("ActionName");
  34. //查看权限(必须有)
  35. DataRow seeRow = rData.NewRow();
  36. seeRow["BtnName"] = "see";
  37. seeRow["ActionName"] = "查看";
  38. rData.Rows.Add(seeRow);
  39. List<Control> ControlList = new List<Control>();
  40. ControlList.Add(btnOutPut);
  41. ControlList.Add(btnDel);
  42. ControlList.Add(btBack);
  43. foreach (Control ctr in ControlList)
  44. {
  45. if (ctr.GetType() == typeof(SimpleButton))
  46. {
  47. DataRow dr = rData.NewRow();
  48. dr["BtnName"] = ctr.Name;
  49. dr["ActionName"] = ctr.Text;
  50. rData.Rows.Add(dr);
  51. }
  52. }
  53. rData.AcceptChanges();
  54. return rData;
  55. }
  56. public DataTable RightOfData()// 数据权限
  57. {
  58. DataTable rData = new DataTable();
  59. rData.Columns.Add("BodyName");
  60. rData.Columns.Add("ControlName");
  61. rData.Columns.Add("ControlCaption");
  62. rData.AcceptChanges();
  63. return rData;
  64. }
  65. #endregion
  66. #region 退出
  67. private void btnClose_Click(object sender, EventArgs e)
  68. {
  69. AppConfig.CloseFormShow(this.Text);
  70. this.Close();
  71. }
  72. private void btnExit_Click(object sender, EventArgs e)
  73. {
  74. AppConfig.CloseFormShow(this.Text);
  75. this.Close();
  76. }
  77. #endregion
  78. #region 移动窗体
  79. private const int WM_NCHITTEST = 0x84;
  80. private const int HTCLIENT = 0x1;
  81. private const int HTCAPTION = 0x2;
  82. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  83. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  84. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  85. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  86. //重写窗体,使窗体可以不通过自带标题栏实现移动
  87. protected override void WndProc(ref Message m)
  88. {
  89. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  90. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  91. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  92. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  93. switch (m.Msg)
  94. {
  95. case WM_NCHITTEST:
  96. base.WndProc(ref m);
  97. if ((int)m.Result == HTCLIENT)
  98. m.Result = (IntPtr)HTCAPTION;
  99. return;
  100. }
  101. //拦截双击标题栏、移动窗体的系统消息
  102. if (m.Msg != 0xA3)
  103. {
  104. base.WndProc(ref m);
  105. }
  106. }
  107. #endregion
  108. #region 列表
  109. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  110. {
  111. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  112. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  113. }
  114. #endregion
  115. #region 过滤
  116. private string tempTableName = "";
  117. private void btnFilter_Click(object sender, EventArgs e)
  118. {
  119. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  120. filter.OldTempTableName = tempTableName;
  121. if (filter.ShowDialog() == DialogResult.OK)
  122. {
  123. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  124. try
  125. {
  126. _wait.Show();
  127. tempTableName = filter.NewTempTableName;
  128. sqltxt = filter.SqlText;
  129. sqlconn = filter.FilterConnectString;
  130. dataSource = filter.FilterData.Tables[0];
  131. grdDetail.DataSource = dataSource;
  132. grvDetail.BestFitColumns();
  133. _wait.Close();
  134. }
  135. catch (Exception ex)
  136. {
  137. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  138. _wait.Close();
  139. }
  140. }
  141. }
  142. #endregion
  143. #region 绑定数据源
  144. private void btnConfig_Click(object sender, EventArgs e)
  145. {
  146. if (AppConfig.UserCode.ToLower() != "demo")
  147. {
  148. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  149. return;
  150. }
  151. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  152. fdata.ShowDialog();
  153. }
  154. #endregion
  155. #region 过滤方法
  156. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  157. {
  158. AppConfig.DropTemTable(tempTableName);
  159. }
  160. #endregion
  161. #region 全选
  162. private void btnSelectAll_Click(object sender, EventArgs e)
  163. {
  164. grvDetail.PostEditor();
  165. this.Validate();
  166. for (int i = 0; i < grvDetail.RowCount; i++)
  167. {
  168. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  169. }
  170. }
  171. #endregion
  172. #region 全消
  173. private void btnCancelAll_Click(object sender, EventArgs e)
  174. {
  175. grvDetail.PostEditor();
  176. this.Validate();
  177. for (int i = 0; i < grvDetail.RowCount; i++)
  178. {
  179. grvDetail.SetRowCellValue(i, colisSelect, "");
  180. }
  181. }
  182. #endregion
  183. #region 双击
  184. private void grvDetail_DoubleClick(object sender, EventArgs e)
  185. {
  186. if (grvDetail.FocusedRowHandle < 0)
  187. {
  188. return;
  189. }
  190. if (grvDetail.FocusedColumn == colisSelect)
  191. {
  192. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  193. {
  194. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  195. }
  196. else
  197. {
  198. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  199. }
  200. }
  201. }
  202. #endregion
  203. #region 导出
  204. private void btnOutPut_Click(object sender, EventArgs e)
  205. {
  206. try
  207. {
  208. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  209. foe.ShowDialog();
  210. }
  211. catch (Exception ex)
  212. {
  213. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  214. }
  215. //FormOutExcel foe = new FormOutExcel();
  216. //if (foe.ShowDialog() == DialogResult.OK)
  217. //{
  218. // try
  219. // {
  220. // string outtype = foe._OutType;
  221. // string exceltype = foe._ExcelType;
  222. // string filename = foe._FileName;
  223. // string url = foe._Url;
  224. // string sheetname = foe._SheetName;
  225. // if (outtype.ToLower() == "excel")
  226. // {
  227. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  228. // op.SheetName = sheetname;
  229. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  230. // }
  231. // else
  232. // {
  233. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  234. // }
  235. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  236. // }
  237. // catch (Exception ex)
  238. // {
  239. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  240. // }
  241. //}
  242. }
  243. #endregion
  244. #region 刷新
  245. private void btnRefresh_Click(object sender, EventArgs e)
  246. {
  247. if (sqlconn == null || sqlconn == "")
  248. {
  249. return;
  250. }
  251. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  252. try
  253. {
  254. _wait.Show();
  255. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  256. filter.OldTempTableName = tempTableName;
  257. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  258. grdDetail.DataSource = dataSource;
  259. grvDetail.BestFitColumns();
  260. _wait.Close();
  261. }
  262. catch (Exception ex)
  263. {
  264. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  265. _wait.Close();
  266. }
  267. }
  268. #endregion
  269. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  270. {
  271. AppConfig.DropTemTable(tempTableName);
  272. }
  273. private void FormICSPACKINGLog_Load(object sender, EventArgs e)
  274. {
  275. btnFilter_Click(sender, e);
  276. }
  277. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  278. {
  279. if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  280. {
  281. e.CellValue = "cccc";
  282. }
  283. }
  284. private void btnDel_Click(object sender, EventArgs e)
  285. {
  286. grvDetail.PostEditor();
  287. this.Validate();
  288. if (grvDetail.RowCount == 0)
  289. return;
  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<string> guidList = new List<string>();
  297. for (int i = 0; i < grvDetail.RowCount; i++)
  298. {
  299. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  300. {
  301. guidList.Add(grvDetail.GetRowCellValue(i, colisSelect).ToString());
  302. }
  303. }
  304. if (guidList.Count == 0)
  305. {
  306. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  307. return;
  308. }
  309. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该退料单吗?删除后无法恢复,确定吗?") == DialogResult.OK)
  310. {
  311. string err = "", mes = "";
  312. int count = 0;
  313. for (int i = 0; i < grvDetail.RowCount; i++)
  314. {
  315. if (grvDetail.GetRowCellValue(i, colStatus).ToString() == "已审核")
  316. {
  317. if (count == 0)
  318. {
  319. int x = i + 1;
  320. mes = x.ToString();
  321. count++;
  322. }
  323. else
  324. {
  325. int x = i + 1;
  326. err = x.ToString();
  327. mes = mes + ", " + err;
  328. count++;
  329. }
  330. }
  331. }
  332. ICSBaseSimpleCode.AppshowMessageBox("第" + mes + "行的退料单已审核,不能删除");
  333. return;
  334. }
  335. try
  336. {
  337. for (int i = 0; i < grvDetail.RowCount; i++)
  338. {
  339. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  340. {
  341. SqlConnection conn = new SqlConnection(AppConfig.AppConnectString);
  342. SqlCommand com = conn.CreateCommand();
  343. SqlTransaction tran;
  344. conn.Open();
  345. tran = conn.BeginTransaction();
  346. com.Transaction = tran;
  347. string sqlText = @"DELETE FROM ICSTransferNOBack WHERE TransferNO = @TransferNO AND TransLine = @TransLine";
  348. com.CommandText = sqlText;
  349. com.Parameters.Clear();
  350. com.Parameters.AddWithValue("@TransferNO", grvDetail.GetRowCellValue(i, colTransferNO));
  351. com.Parameters.AddWithValue("@TransLine", grvDetail.GetRowCellValue(i, colTransLine));
  352. com.ExecuteNonQuery();
  353. sqlText = @"DELETE FROM ICSITEMLot WHERE TransNO = @TransferNO AND TransLine = '@TransLine";
  354. com.CommandText = sqlText;
  355. com.Parameters.Clear();
  356. com.Parameters.AddWithValue("@TransferNO", grvDetail.GetRowCellValue(i, colTransferNO));
  357. com.Parameters.AddWithValue("@TransLine", grvDetail.GetRowCellValue(i, colTransLine));
  358. com.ExecuteNonQuery();
  359. tran.Commit();
  360. }
  361. }
  362. btnRefresh_Click(sender, e);
  363. }
  364. catch (Exception ex)
  365. {
  366. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  367. }
  368. }
  369. private void btBack_Click(object sender, EventArgs e)
  370. {
  371. string status = "";
  372. try
  373. {
  374. for (int i = 0; i < grvDetail.RowCount; i++)
  375. {
  376. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  377. {
  378. if (grvDetail.GetRowCellValue(i, colStatus).ToString() == "已退库")
  379. {
  380. status = "err";
  381. break;
  382. }
  383. }
  384. }
  385. if (status == "err")
  386. {
  387. ICSBaseSimpleCode.AppshowMessageBox("已经退库的退料单无法反审核!");
  388. return;
  389. }
  390. else
  391. {
  392. for (int i = 0; i < grvDetail.RowCount; i++)
  393. {
  394. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  395. {
  396. SqlConnection conn = new SqlConnection(AppConfig.AppConnectString);
  397. SqlCommand com = conn.CreateCommand();
  398. SqlTransaction tran;
  399. conn.Open();
  400. tran = conn.BeginTransaction();
  401. com.Transaction = tran;
  402. string sqlText = @"UPDATE ICSTransferNOBack SET Status = '反审核' WHERE TransferNO = @TransferNO AND TransLine = @TransLine";
  403. com.CommandText = sqlText;
  404. com.Parameters.Clear();
  405. com.Parameters.AddWithValue("@TransferNO", grvDetail.GetRowCellValue(i, colTransferNO).ToString());
  406. com.Parameters.AddWithValue("@TransLine", grvDetail.GetRowCellValue(i, colTransLine).ToString());
  407. com.ExecuteNonQuery();
  408. tran.Commit();
  409. }
  410. }
  411. ICSBaseSimpleCode.AppshowMessageBox(0, "反审核成功");
  412. btnRefresh_Click(null, null);
  413. }
  414. }
  415. catch (Exception ex)
  416. {
  417. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  418. return;
  419. }
  420. }
  421. }
  422. }