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

473 lines
18 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.Frame.Data.Entity;
  26. namespace ICSSoft.Frame.APP
  27. {
  28. public partial class FormICSAllocation : DevExpress.XtraEditors.XtraForm
  29. {
  30. private DataSet ds;
  31. //内存表
  32. private DataTable dtzhu;
  33. private DataTable dtone;
  34. private DataTable dttwo;
  35. private string sqltxt = "";
  36. private string sqlconn = "";
  37. String guid = AppConfig.GetGuid();
  38. private DataTable dataSource = null;
  39. #region 构造函数
  40. public FormICSAllocation()
  41. {
  42. InitializeComponent();
  43. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  44. this.WindowState = FormWindowState.Maximized;
  45. ds = new DataSet();
  46. dtone = new DataTable();
  47. }
  48. #endregion
  49. #region 操作权限
  50. public DataTable RightOfExute()
  51. {
  52. DataTable rData = new DataTable();
  53. rData.Columns.Add("BtnName");
  54. rData.Columns.Add("ActionName");
  55. //查看权限(必须有)
  56. DataRow seeRow = rData.NewRow();
  57. seeRow["BtnName"] = "see";
  58. seeRow["ActionName"] = "查看";
  59. rData.Rows.Add(seeRow);
  60. List<Control> ControlList = new List<Control>();
  61. ControlList.Add(btnOutPut);
  62. foreach (Control ctr in ControlList)
  63. {
  64. if (ctr.GetType() == typeof(SimpleButton))
  65. {
  66. DataRow dr = rData.NewRow();
  67. dr["BtnName"] = ctr.Name;
  68. dr["ActionName"] = ctr.Text;
  69. rData.Rows.Add(dr);
  70. }
  71. }
  72. rData.AcceptChanges();
  73. return rData;
  74. }
  75. public DataTable RightOfData()// 数据权限
  76. {
  77. DataTable rData = new DataTable();
  78. rData.Columns.Add("BodyName");
  79. rData.Columns.Add("ControlName");
  80. rData.Columns.Add("ControlCaption");
  81. rData.AcceptChanges();
  82. return rData;
  83. }
  84. #endregion
  85. #region 退出r0
  86. private void btnClose_Click(object sender, EventArgs e)
  87. {
  88. AppConfig.CloseFormShow(this.Text);
  89. this.Close();
  90. }
  91. private void btnExit_Click(object sender, EventArgs e)
  92. {
  93. AppConfig.CloseFormShow(this.Text);
  94. this.Close();
  95. }
  96. #endregion[
  97. #region 移动窗体
  98. private const int WM_NCHITTEST = 0x84;
  99. private const int HTCLIENT = 0x1;
  100. private const int HTCAPTION = 0x2;
  101. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  102. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  103. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  104. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  105. //重写窗体,使窗体可以不通过自带标题栏实现移动
  106. protected override void WndProc(ref Message m)
  107. {
  108. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  109. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  110. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  111. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  112. switch (m.Msg)
  113. {
  114. case WM_NCHITTEST:
  115. base.WndProc(ref m);
  116. if ((int)m.Result == HTCLIENT)
  117. m.Result = (IntPtr)HTCAPTION;
  118. return;
  119. }
  120. //拦截双击标题栏、移动窗体的系统消息
  121. if (m.Msg != 0xA3)
  122. {
  123. base.WndProc(ref m);
  124. }
  125. }
  126. #endregion
  127. #region 列表
  128. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  129. {
  130. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  131. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  132. }
  133. #endregion
  134. #region 分页
  135. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  136. {
  137. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  138. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  139. grdDetail.DataSource = data;
  140. }
  141. #endregion
  142. #region 导出
  143. private void btnOutPut_Click(object sender, EventArgs e)
  144. {
  145. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  146. foe.ShowDialog();
  147. }
  148. #endregion
  149. #region 刷新
  150. private void btnRefresh_Click(object sender, EventArgs e)
  151. {
  152. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  153. try
  154. {
  155. }
  156. catch (Exception ex)
  157. {
  158. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  159. _wait.Close();
  160. }
  161. }
  162. #endregion
  163. private void FormICSAllocation_Load(object sender, EventArgs e)
  164. {
  165. //btnFilter_Click(sender, e);
  166. }
  167. #region 选择转移单号
  168. private void txtTransferNO_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
  169. {
  170. txtTransferNO.Text = "";
  171. ButtonEdit btn = (ButtonEdit)sender;
  172. string sql = @"select TransferNO as [调拨单号] from ICSInvTransfer";
  173. sql = string.Format(sql);
  174. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  175. FormDataRefer reForm = new FormDataRefer();
  176. reForm.FormTitle = "调拨单信息";
  177. DataTable menuData = data;
  178. reForm.DataSource = menuData;
  179. reForm.MSelectFlag = false;
  180. reForm.RowIndexWidth = 35;
  181. reForm.HideCols.Add("ID");
  182. reForm.FormWidth = 800;
  183. reForm.FormHeight = 600;
  184. reForm.FilterKey = btn.Text;
  185. if (reForm.ShowDialog() == DialogResult.OK)
  186. {
  187. DataTable retData = reForm.ReturnData;
  188. foreach (DataRow dr in retData.Rows)
  189. {
  190. txtTransferNO.Text = dr["调拨单号"].ToString();
  191. }
  192. Bindvalue( txtTransferNO.Text);
  193. }
  194. }
  195. #endregion
  196. #region 转移单表
  197. public DataTable MainTable()
  198. {
  199. try
  200. {
  201. string sql = @"select cast( 0 as bit) as isSelect,
  202. c.ID,
  203. a.TransferNO,
  204. a.TransferLine,
  205. a.ITEMCODE,
  206. b.INVNAME as ITEMNAME,
  207. a.FROMStorageCode,
  208. a.FROMStackCode,
  209. a.TOStorageCode,
  210. a.TOStackCode,
  211. a.PLANQTY,
  212. c.TransQTY as ACTQTY
  213. from ICSInvTransferDetail a
  214. left join ICSINVENTORY b on a.ITEMCODE=b.INVCODE
  215. left join ICSITEMTrans c on a.TransferNO=c.TransNO and a.TransferLine=c.TransLine
  216. where a.TransferNO='" + txtTransferNO.Text.Trim() + "' ";
  217. sql = string.Format(sql);
  218. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  219. return data;
  220. }
  221. catch (Exception ex)
  222. {
  223. MessageBox.Show(ex.Message);
  224. return null;
  225. }
  226. }
  227. #endregion
  228. #region 子表
  229. public DataTable OneTable()
  230. {
  231. string sql = @"select ITEMTransID,
  232. LotNO,
  233. TransQTY
  234. from ICSITEMTransLot";
  235. sql = string.Format(sql);
  236. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  237. return data;
  238. }
  239. #endregion
  240. private void grvDetailone_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  241. {
  242. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  243. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  244. }
  245. private void txtInput_KeyPress(object sender, KeyPressEventArgs e)
  246. {
  247. //取消负号
  248. if (e.KeyChar == '-')
  249. {
  250. e.Handled = true;
  251. }
  252. //执行回车
  253. if (e.KeyChar == 13)
  254. {
  255. List<string> LineList = new List<string>();
  256. string storage = "";
  257. string stack = "";
  258. for (int i = 0; i < grvDetail.RowCount; i++)
  259. {
  260. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "True")
  261. {
  262. string line = grvDetail.GetRowCellValue(i, colID).ToString();
  263. LineList.Add(line);
  264. storage = grvDetail.GetRowCellValue(i, colFROMStorageCode).ToString();
  265. stack = grvDetail.GetRowCellValue(i, colFROMStackCode).ToString();
  266. }
  267. }
  268. if (LineList.Count != 1)
  269. {
  270. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行调拨 !!!");
  271. return;
  272. }
  273. decimal snum = 0.00m;
  274. if (txtInput.Text == "")
  275. {
  276. ICSBaseSimpleCode.AppshowMessageBox("批号不可为空!!!");
  277. return;
  278. }
  279. string sqlall = @"select a.LotNO,a.WHCode,a.BinCode,a.INVCode,a.ReceiveDate,
  280. a.LotQty
  281. from ICSWareHouseLotInfo a
  282. where a.LotNO='" + txtInput.Text + "' and a.WHCode='" + storage + "' and a.BinCode='" + stack + "'";
  283. sqlall = string.Format(sqlall);
  284. DataTable dataall = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlall).Tables[0];
  285. if (dataall == null || dataall.Rows.Count == 0)
  286. {
  287. ICSBaseSimpleCode.AppshowMessageBox("发货库房库位不存该改批号");
  288. return;
  289. }
  290. //源库存数量
  291. string sqlone = @"select sum(LotQty) as sourcenum
  292. from ICSWareHouseLotInfo
  293. where WHCode='{0}' and BinCode='{1}' and INVCode='{2}' ";
  294. sqlone = string.Format(sqlone, dataall.Rows[0]["WHCode"].ToString(), dataall.Rows[0]["BinCode"].ToString(), dataall.Rows[0]["INVCode"].ToString());
  295. DataTable dataone = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlone).Tables[0];
  296. snum = Convert.ToDecimal(dataone.Rows[0]["sourcenum"].ToString().Equals("") ? "0.00" : dataone.Rows[0]["sourcenum"].ToString());
  297. if (snum == 0)
  298. {
  299. ICSBaseSimpleCode.AppshowMessageBox("无源库位数量");
  300. return;
  301. }
  302. try
  303. {
  304. #region
  305. FormICSITEMTransUIModel infomodel = new FormICSITEMTransUIModel();
  306. infomodel.TransNO = txtTransferNO.Text;
  307. infomodel.TransLine = int.Parse(grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colTransferLine).ToString());
  308. infomodel.ITEMCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colITEMCODE).ToString();
  309. infomodel.FRMStorageCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colFROMStorageCode).ToString();
  310. infomodel.FRMStackCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colFROMStackCode).ToString();
  311. infomodel.TOStorageCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colTOStorageCode).ToString();
  312. infomodel.TOStackCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colTOStackCode).ToString();
  313. //infomodel.LotNO = txtInput.Text;
  314. infomodel.TransQTY = decimal.Parse(dataall.Rows[0]["LotQty"].ToString().Equals("") ? "0" : dataall.Rows[0]["LotQty"].ToString());
  315. infomodel.Memo = "";
  316. infomodel.TransType = "";
  317. infomodel.BusinessCode = "";
  318. FormICSITEMTransLotUIModel lotmodel = new FormICSITEMTransLotUIModel();
  319. lotmodel.LotNO = txtInput.Text;
  320. lotmodel.ITEMCODE = grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colITEMCODE).ToString();
  321. lotmodel.TransQTY = decimal.Parse(dataall.Rows[0]["LotQty"].ToString().Equals("") ? "0" : dataall.Rows[0]["LotQty"].ToString());
  322. ICSAllocationBLL.AddJiLu(infomodel, lotmodel, AppConfig.AppConnectString);
  323. ICSBaseSimpleCode.AppshowMessageBox("调拨成功");
  324. Bindvalue(txtTransferNO.Text);
  325. #endregion
  326. }
  327. catch (Exception ex)
  328. {
  329. throw ex;
  330. }
  331. }
  332. }
  333. private void grvDetail_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e)
  334. {
  335. grvDetailone = grvDetail.GetDetailView(e.RowHandle, e.RelationIndex) as DevExpress.XtraGrid.Views.Grid.GridView;
  336. }
  337. private void grvDetailmin_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  338. {
  339. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  340. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  341. }
  342. private void Bindvalue(string transNo)
  343. {
  344. try
  345. {
  346. string sql = @"select a.FROMStorageCode,
  347. b.StorageName,
  348. a.FROMStackCode,
  349. a.TOStorageCode,
  350. c.StorageName,
  351. a.TOStackCode,
  352. a.MEMO,
  353. a.TransferLine,
  354. a.PLANQTY,
  355. a.ACTQTY,
  356. a.ITEMCODE,
  357. d.INVNAME as ITEMNAME
  358. from ICSInvTransferDetail a
  359. left join ICSStorage b on a.FROMStorageCode=b.StorageCode
  360. left join ICSStorage c on a.TOStorageCode=c.StorageCode
  361. left join ICSINVENTORY d on a.ITEMCODE=d.INVCODE
  362. where a.TransferNO='" + transNo + "' and a.WorkPoint='" + AppConfig.WorkPointCode + "'";
  363. sql = string.Format(sql);
  364. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  365. if (data == null || data.Rows.Count == 0)
  366. {
  367. throw new Exception("调拨单信息为空");
  368. }
  369. DataRow transdr = data.Rows[0];
  370. txtfromstorage.Text = transdr["FROMStorageCode"].ToString();
  371. txttostorage.Text= transdr["TOStorageCode"].ToString();
  372. txtMEMO.Text = transdr["MEMO"].ToString();
  373. decimal planqty = Convert.ToDecimal(transdr["PLANQTY"].ToString().Equals("") ? "0" : transdr["PLANQTY"].ToString());
  374. decimal actqty = Convert.ToDecimal(transdr["ACTQTY"].ToString().Equals("") ? "0" : transdr["ACTQTY"].ToString());
  375. if (planqty > actqty)
  376. txtISSend.Checked = true;
  377. else
  378. txtISSend.Checked = false;
  379. //绑定
  380. ds.Reset();
  381. dtzhu = null;
  382. dtone.Rows.Clear();
  383. dtzhu = MainTable().Copy();
  384. dtone = OneTable().Copy();
  385. dtzhu.TableName = "one";
  386. dtone.TableName = "two";
  387. ds.Tables.Add(dtzhu);
  388. ds.Tables.Add(dtone);
  389. DataRelation dr = new DataRelation("Level1", new DataColumn[] { ds.Tables[0].Columns["ID"] }, new DataColumn[] { ds.Tables[1].Columns["ITEMTransID"] });
  390. ds.Relations.Add(dr);
  391. grdDetail.DataSource = dtzhu;
  392. grvDetail.BestFitColumns();
  393. grvDetailone.BestFitColumns();
  394. }
  395. catch(Exception ex)
  396. {
  397. throw new Exception(ex.Message);
  398. }
  399. }
  400. }
  401. }