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

388 lines
15 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. namespace ICSSoft.Frame.APP
  26. {
  27. public partial class FormICSInvTransferNew : DevExpress.XtraEditors.XtraForm
  28. {
  29. private string sqltxt = "";
  30. private string sqlconn = "";
  31. String guid = AppConfig.GetGuid();
  32. private DataTable dataSource = null;
  33. #region 构造函数
  34. public FormICSInvTransferNew()
  35. {
  36. InitializeComponent();
  37. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  38. this.WindowState = FormWindowState.Maximized;
  39. }
  40. #endregion
  41. #region 操作权限
  42. public DataTable RightOfExute()
  43. {
  44. DataTable rData = new DataTable();
  45. rData.Columns.Add("BtnName");
  46. rData.Columns.Add("ActionName");
  47. //查看权限(必须有)
  48. DataRow seeRow = rData.NewRow();
  49. seeRow["BtnName"] = "see";
  50. seeRow["ActionName"] = "查看";
  51. rData.Rows.Add(seeRow);
  52. List<Control> ControlList = new List<Control>();
  53. ControlList.Add(btnGetInfo);
  54. ControlList.Add(btnOutPut);
  55. foreach (Control ctr in ControlList)
  56. {
  57. if (ctr.GetType() == typeof(SimpleButton))
  58. {
  59. DataRow dr = rData.NewRow();
  60. dr["BtnName"] = ctr.Name;
  61. dr["ActionName"] = ctr.Text;
  62. rData.Rows.Add(dr);
  63. }
  64. }
  65. rData.AcceptChanges();
  66. return rData;
  67. }
  68. public DataTable RightOfData()// 数据权限
  69. {
  70. DataTable rData = new DataTable();
  71. rData.Columns.Add("BodyName");
  72. rData.Columns.Add("ControlName");
  73. rData.Columns.Add("ControlCaption");
  74. rData.AcceptChanges();
  75. return rData;
  76. }
  77. #endregion
  78. #region 退出
  79. private void btnClose_Click(object sender, EventArgs e)
  80. {
  81. AppConfig.CloseFormShow(this.Text);
  82. this.Close();
  83. }
  84. private void btnExit_Click(object sender, EventArgs e)
  85. {
  86. AppConfig.CloseFormShow(this.Text);
  87. this.Close();
  88. }
  89. #endregion
  90. #region 移动窗体
  91. private const int WM_NCHITTEST = 0x84;
  92. private const int HTCLIENT = 0x1;
  93. private const int HTCAPTION = 0x2;
  94. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  95. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  96. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  97. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  98. //重写窗体,使窗体可以不通过自带标题栏实现移动
  99. protected override void WndProc(ref Message m)
  100. {
  101. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  102. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  103. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  104. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  105. switch (m.Msg)
  106. {
  107. case WM_NCHITTEST:
  108. base.WndProc(ref m);
  109. if ((int)m.Result == HTCLIENT)
  110. m.Result = (IntPtr)HTCAPTION;
  111. return;
  112. }
  113. //拦截双击标题栏、移动窗体的系统消息
  114. if (m.Msg != 0xA3)
  115. {
  116. base.WndProc(ref m);
  117. }
  118. }
  119. #endregion
  120. #region 列表
  121. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  122. {
  123. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  124. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  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 = 499;
  147. rptPage.PageIndex = 1;
  148. rptPage.ReLoad();
  149. rptPage.PageSize = 500;
  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 rptPage_PageIndexChanged(object Sender, EventArgs e)
  176. {
  177. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  178. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  179. grdDetail.DataSource = data;
  180. }
  181. #endregion
  182. #region 过滤方法
  183. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  184. {
  185. AppConfig.DropTemTable(tempTableName);
  186. }
  187. #endregion
  188. #region 全选
  189. private void btnSelectAll_Click(object sender, EventArgs e)
  190. {
  191. grvDetail.PostEditor();
  192. this.Validate();
  193. for (int i = 0; i < grvDetail.RowCount; i++)
  194. {
  195. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  196. }
  197. }
  198. #endregion
  199. #region 全消
  200. private void btnCancelAll_Click(object sender, EventArgs e)
  201. {
  202. grvDetail.PostEditor();
  203. this.Validate();
  204. for (int i = 0; i < grvDetail.RowCount; i++)
  205. {
  206. grvDetail.SetRowCellValue(i, colisSelect, "");
  207. }
  208. }
  209. #endregion
  210. #region 双击
  211. private void grvDetail_DoubleClick(object sender, EventArgs e)
  212. {
  213. if (grvDetail.FocusedRowHandle < 0)
  214. {
  215. return;
  216. }
  217. if (grvDetail.FocusedColumn == colisSelect)
  218. {
  219. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  220. {
  221. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  222. }
  223. else
  224. {
  225. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  226. }
  227. }
  228. }
  229. #endregion
  230. #region 导出
  231. private void btnOutPut_Click(object sender, EventArgs e)
  232. {
  233. SimpleButton btntemp = (SimpleButton)sender;
  234. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  235. {
  236. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  237. return;
  238. }
  239. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  240. foe.ShowDialog();
  241. }
  242. #endregion
  243. #region 刷新
  244. private void btnRefresh_Click(object sender, EventArgs e)
  245. {
  246. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  247. try
  248. {
  249. _wait.Show();
  250. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  251. filter.OldTempTableName = tempTableName;
  252. //tempTableName = filter.NewTempTableName;
  253. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  254. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  255. grdDetail.DataSource = dataSource;
  256. grvDetail.BestFitColumns();
  257. rptPage.RecordNum = dataSource.Rows.Count;
  258. rptPage.PageIndex = 1;
  259. rptPage.ReLoad();
  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 FormICSInvTransferNew_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.DisplayText = FormatHelper.
  282. e.CellValue = "cccc";
  283. }
  284. }
  285. private void btnGetInfo_Click(object sender, EventArgs e)
  286. {
  287. SimpleButton btntemp = (SimpleButton)sender;
  288. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  289. {
  290. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  291. return;
  292. }
  293. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在同步请稍等...");
  294. try
  295. {
  296. string sql = @"DELETE [dbo].ICSInvTransferDetail
  297. WHERE TransferNO IN
  298. (SELECT a.cTVCode
  299. FROM {1}.dbo.TransVouch a
  300. LEFT JOIN [dbo].ICSInvTransfer b ON a.cTVCode = b.TransferNO
  301. AND ISNULL(b.EffectedTIME,'') = ISNULL(a.dnmodifytime,'')
  302. WHERE (a.cVerifyPerson IS NULL OR a.cVerifyPerson = '')
  303. AND b.TransferNO IS NULL and ISNULL(cDefine1,'') <> '')
  304. DELETE [dbo].ICSInvTransfer
  305. WHERE TransferNO IN
  306. (SELECT a.cTVCode
  307. FROM {1}.dbo.TransVouch a
  308. LEFT JOIN [dbo].ICSInvTransfer b ON a.cTVCode = b.TransferNO
  309. AND ISNULL(b.EffectedTIME,'') = ISNULL(a.dnmodifytime,'')
  310. WHERE (a.cVerifyPerson IS NULL OR a.cVerifyPerson = '')
  311. AND b.TransferNO IS NULL and ISNULL(cDefine1,'') <> '')
  312. INSERT INTO [dbo].ICSInvTransfer
  313. (ID,TransferNO,FRMStorageCode,TOStorageCode,TransferSTATUS,RECTYPE,
  314. TIMETYPE,MEMO,CreateTIME,CreateUSER,WorkPoint,MUSER,MUSERName,MTIME,EffectedTIME)
  315. SELECT NEWID(),cTVCode,cOWhCode,cIWhCode,'','','',cTVMemo,
  316. dnmaketime,cMaker,'{0}','',
  317. a.cMaker,GETDATE(),a.dnmodifytime
  318. FROM {1}.dbo.TransVouch a
  319. LEFT JOIN [dbo].ICSInvTransfer b ON a.cTVCode = b.TransferNO
  320. WHERE (a.cVerifyPerson IS NULL OR a.cVerifyPerson = '')
  321. AND b.TransferNO IS NULL and ISNULL(cDefine1,'') <> ''
  322. INSERT INTO [dbo].ICSInvTransferDetail
  323. (ID,TransferID,TransferNO,TransferLine,TransferSTATUS,ITEMCODE,
  324. PLANQTY,ACTQTY,FROMStorageCode,TOStorageCode,WorkPoint,
  325. MUSER,MUSERName,MTIME,ORDERNO)
  326. SELECT NEWID(),'',a.cTVCode,b.irowno,'',b.cInvCode,b.iTVQuantity,'0',
  327. a.cOWhCode,a.cIWhCode,'{0}',''
  328. ,a.cMaker,GETDATE(),b.autoID FROM {1}.dbo.TransVouch a
  329. INNER JOIN {1}.dbo.TransVouchs b ON a.ID = b.ID
  330. LEFT JOIN [dbo].ICSInvTransferDetail c ON b.autoID = c.ORDERNO
  331. WHERE (a.cVerifyPerson IS NULL OR a.cVerifyPerson = '')
  332. AND c.ID IS NULL and ISNULL(cDefine1,'') <> ''";
  333. sql = string.Format(sql, AppConfig.WorkPointCode, ICSBaseSimpleCode.GetWorkPointErpData());
  334. DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
  335. _wait.Close();
  336. ICSBaseSimpleCode.AppshowMessageBox("同步成功");
  337. }
  338. catch (Exception ex)
  339. {
  340. _wait.Close();
  341. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  342. }
  343. }
  344. }
  345. }