锐腾搅拌上料功能
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.Data.Linq;
  6. using System.Linq;
  7. using System.Drawing;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using DevExpress.XtraGrid.Views.BandedGrid;
  12. using DevExpress.XtraGrid.Columns;
  13. using DevExpress.XtraGrid;
  14. using System.IO;
  15. using System.Threading;
  16. using ICSSoft.Base.Language.Tool;
  17. using ICSSoft.Base.Config.AppConfig;
  18. using ICSSoft.Base.UserControl.MessageControl;
  19. using ICSSoft.Base.Config.DBHelper;
  20. using ICSSoft.Base.Report.Filter;
  21. using ICSSoft.Base.UserControl.FormControl;
  22. using ICSSoft.Base.Report.GridReport;
  23. using ICSSoft.Base.ReferForm.AppReferForm;
  24. using ICSSoft.Frame.Data.BLL;
  25. using ICSSoft.Base.Lable.PrintTool;
  26. namespace ICSSoft.Frame.APP
  27. {
  28. public partial class FormICSPJXPrint : DevExpress.XtraEditors.XtraForm
  29. {
  30. private string sqltxt = "";
  31. private string sqlconn = "";
  32. String guid = AppConfig.GetGuid();
  33. private DataTable dataSource = null;
  34. List<string> LotNo = new List<string> ();
  35. #region 构造函数
  36. public FormICSPJXPrint()
  37. {
  38. InitializeComponent();
  39. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  40. this.WindowState = FormWindowState.Maximized;
  41. }
  42. #endregion
  43. #region 操作权限
  44. public DataTable RightOfExute()
  45. {
  46. DataTable rData = new DataTable();
  47. rData.Columns.Add("BtnName");
  48. rData.Columns.Add("ActionName");
  49. //查看权限(必须有)
  50. DataRow seeRow = rData.NewRow();
  51. seeRow["BtnName"] = "see";
  52. seeRow["ActionName"] = "查看";
  53. rData.Rows.Add(seeRow);
  54. List<Control> ControlList = new List<Control>();
  55. ControlList.Add(btnPrint);
  56. foreach (Control ctr in ControlList)
  57. {
  58. if (ctr.GetType() == typeof(SimpleButton))
  59. {
  60. DataRow dr = rData.NewRow();
  61. dr["BtnName"] = ctr.Name;
  62. dr["ActionName"] = ctr.Text;
  63. rData.Rows.Add(dr);
  64. }
  65. }
  66. rData.AcceptChanges();
  67. return rData;
  68. }
  69. public DataTable RightOfData()// 数据权限
  70. {
  71. DataTable rData = new DataTable();
  72. rData.Columns.Add("BodyName");
  73. rData.Columns.Add("ControlName");
  74. rData.Columns.Add("ControlCaption");
  75. rData.AcceptChanges();
  76. return rData;
  77. }
  78. #endregion
  79. #region 退出
  80. private void btnClose_Click(object sender, EventArgs e)
  81. {
  82. AppConfig.CloseFormShow(this.Text);
  83. this.Close();
  84. }
  85. private void btnExit_Click(object sender, EventArgs e)
  86. {
  87. AppConfig.CloseFormShow(this.Text);
  88. this.Close();
  89. }
  90. #endregion
  91. #region 移动窗体
  92. private const int WM_NCHITTEST = 0x84;
  93. private const int HTCLIENT = 0x1;
  94. private const int HTCAPTION = 0x2;
  95. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  96. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  97. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  98. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  99. //重写窗体,使窗体可以不通过自带标题栏实现移动
  100. protected override void WndProc(ref Message m)
  101. {
  102. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  103. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  104. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  105. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  106. switch (m.Msg)
  107. {
  108. case WM_NCHITTEST:
  109. base.WndProc(ref m);
  110. if ((int)m.Result == HTCLIENT)
  111. m.Result = (IntPtr)HTCAPTION;
  112. return;
  113. }
  114. //拦截双击标题栏、移动窗体的系统消息
  115. if (m.Msg != 0xA3)
  116. {
  117. base.WndProc(ref m);
  118. }
  119. }
  120. #endregion
  121. #region 列表
  122. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  123. {
  124. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  125. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  126. }
  127. #endregion
  128. #region 过滤
  129. private string tempTableName = "";
  130. private void btnFilter_Click(object sender, EventArgs e)
  131. {
  132. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  133. filter.OldTempTableName = tempTableName;
  134. if (filter.ShowDialog() == DialogResult.OK)
  135. {
  136. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  137. try
  138. {
  139. _wait.Show();
  140. tempTableName = filter.NewTempTableName;
  141. sqltxt = filter.SqlText;
  142. sqlconn = filter.FilterConnectString;
  143. dataSource = filter.FilterData.Tables[0];
  144. grdDetail.DataSource = dataSource;
  145. grvDetail.BestFitColumns();
  146. rptPage.RecordNum = dataSource.Rows.Count;
  147. rptPage.PageSize = 499;
  148. rptPage.PageIndex = 1;
  149. rptPage.ReLoad();
  150. rptPage.PageSize = 500;
  151. rptPage.PageIndex = 1;
  152. rptPage.ReLoad();
  153. _wait.Close();
  154. }
  155. catch (Exception ex)
  156. {
  157. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  158. _wait.Close();
  159. }
  160. }
  161. }
  162. #endregion
  163. #region 绑定数据源
  164. private void btnConfig_Click(object sender, EventArgs e)
  165. {
  166. if (AppConfig.UserCode.ToLower() != "demo")
  167. {
  168. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  169. return;
  170. }
  171. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  172. fdata.ShowDialog();
  173. }
  174. #endregion
  175. #region 分页
  176. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  177. {
  178. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  179. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  180. grdDetail.DataSource = data;
  181. }
  182. #endregion
  183. #region 过滤方法
  184. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  185. {
  186. AppConfig.DropTemTable(tempTableName);
  187. }
  188. #endregion
  189. #region 全选
  190. private void btnSelectAll_Click(object sender, EventArgs e)
  191. {
  192. grvDetail.PostEditor();
  193. this.Validate();
  194. for (int i = 0; i < grvDetail.RowCount; i++)
  195. {
  196. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  197. }
  198. }
  199. #endregion
  200. #region 全消
  201. private void btnCancelAll_Click(object sender, EventArgs e)
  202. {
  203. grvDetail.PostEditor();
  204. this.Validate();
  205. for (int i = 0; i < grvDetail.RowCount; i++)
  206. {
  207. grvDetail.SetRowCellValue(i, colisSelect, "");
  208. }
  209. }
  210. #endregion
  211. #region 双击
  212. private void grvDetail_DoubleClick(object sender, EventArgs e)
  213. {
  214. if (grvDetail.FocusedRowHandle < 0)
  215. {
  216. return;
  217. }
  218. if (grvDetail.FocusedColumn == colisSelect)
  219. {
  220. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  221. {
  222. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  223. }
  224. else
  225. {
  226. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  227. }
  228. }
  229. }
  230. #endregion
  231. #region 刷新
  232. private void btnRefresh_Click(object sender, EventArgs e)
  233. {
  234. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  235. try
  236. {
  237. _wait.Show();
  238. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  239. filter.OldTempTableName = tempTableName;
  240. //tempTableName = filter.NewTempTableName;
  241. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  242. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  243. grdDetail.DataSource = dataSource;
  244. grvDetail.BestFitColumns();
  245. rptPage.RecordNum = dataSource.Rows.Count;
  246. rptPage.PageIndex = 1;
  247. rptPage.ReLoad();
  248. _wait.Close();
  249. }
  250. catch (Exception ex)
  251. {
  252. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  253. _wait.Close();
  254. }
  255. }
  256. #endregion
  257. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  258. {
  259. AppConfig.DropTemTable(tempTableName);
  260. }
  261. private void FormICSInvConnect_Load(object sender, EventArgs e)
  262. {
  263. btnFilter_Click(sender, e);
  264. }
  265. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  266. {
  267. if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  268. {
  269. e.CellValue = "cccc";
  270. }
  271. }
  272. private void btnPrint_Click(object sender, EventArgs e)
  273. {
  274. List<PrintPara> parasList = new List<PrintPara>();
  275. for (int i = 0; i < grvDetail.RowCount; i++)
  276. {
  277. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  278. {
  279. PrintPara printInfo = new PrintPara();
  280. printInfo.PrintKey = "LotNo";
  281. printInfo.PrintValues = new object[] {grvDetail.GetRowCellValue(i, colAutoID).ToString() };
  282. parasList.Add(printInfo);
  283. }
  284. }
  285. try
  286. {
  287. #region
  288. SimpleButton btntemp = (SimpleButton)sender;
  289. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  290. {
  291. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  292. return;
  293. }
  294. if (parasList.Count == 0)
  295. {
  296. ICSBaseSimpleCode.AppshowMessageBox("没有选择数据");
  297. return;
  298. }
  299. FormPrintDialog printDialog = new FormPrintDialog("020", this.Text, parasList, false, null);
  300. printDialog.ShowDialog();
  301. #endregion
  302. }
  303. catch (Exception ex)
  304. {
  305. MessageBox.Show(ex.ToString());
  306. }
  307. }
  308. #region 编辑数量
  309. private void btnEdit_Click(object sender, EventArgs e)
  310. {
  311. String id = "";
  312. String row = "";
  313. String cBatch = "";
  314. String cInvCode = "";
  315. String Supplier = "";
  316. String QTY = "";
  317. SimpleButton btntemp = (SimpleButton)sender;
  318. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  319. {
  320. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  321. return;
  322. }
  323. List<String> editList = new List<string>();
  324. for (int i = 0; i < grvDetail.RowCount; i++)
  325. {
  326. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  327. {
  328. id = grvDetail.GetRowCellValue(i, colAutoID).ToString();
  329. cBatch = grvDetail.GetRowCellValue(i, ColcBatch).ToString();
  330. cInvCode = grvDetail.GetRowCellValue(i, colcInvCode).ToString();
  331. Supplier = grvDetail.GetRowCellValue(i, colSupplier).ToString();
  332. QTY = grvDetail.GetRowCellValue(i, colquantity).ToString();
  333. editList.Add(id);
  334. }
  335. }
  336. if (editList.Count != 1)
  337. {
  338. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  339. return;
  340. }
  341. try
  342. {
  343. ICSPJXPrintBLL.select(id, cBatch,AppConfig.AppConnectString);
  344. FormICSPJXPrintEdit add = new FormICSPJXPrintEdit(id,row, cBatch, cInvCode, Supplier, QTY);
  345. add.ShowDialog();
  346. btnRefresh_Click(null, null);
  347. }
  348. catch (Exception ex)
  349. {
  350. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  351. }
  352. }
  353. #endregion
  354. #region 删除
  355. private void btnDelLable_Click(object sender, EventArgs e)
  356. {
  357. String Batch = "";
  358. grvDetail.PostEditor();
  359. this.Validate();
  360. if (grvDetail.RowCount == 0)
  361. return;
  362. SimpleButton btntemp = (SimpleButton)sender;
  363. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  364. {
  365. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  366. return;
  367. }
  368. List<string> guidList = new List<string>();
  369. for (int i = 0; i < grvDetail.RowCount; i++)
  370. {
  371. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  372. {
  373. guidList.Add(grvDetail.GetRowCellValue(i, colDisID).ToString());
  374. guidList.Add(grvDetail.GetRowCellValue(i, ColcBatch).ToString());
  375. }
  376. }
  377. if (guidList.Count == 0)
  378. {
  379. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  380. return;
  381. }
  382. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该单据吗?单据删除后无法恢复,确定吗?") != DialogResult.OK)
  383. return;
  384. try
  385. {
  386. ICSPJXPrintBLL.delete(guidList);
  387. ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  388. btnRefresh_Click(null, null);
  389. }
  390. catch (Exception ex)
  391. {
  392. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  393. return;
  394. }
  395. }
  396. #endregion
  397. }
  398. }