华恒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.

421 lines
17 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 FormICSInvConnect : 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 FormICSInvConnect()
  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. try
  234. {
  235. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  236. foe.ShowDialog();
  237. }
  238. catch (Exception ex)
  239. {
  240. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  241. }
  242. //SimpleButton btntemp = (SimpleButton)sender;
  243. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  244. //{
  245. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  246. // return;
  247. //}
  248. //FormOutExcel foe = new FormOutExcel();
  249. //if (foe.ShowDialog() == DialogResult.OK)
  250. //{
  251. // try
  252. // {
  253. // string outtype = foe._OutType;
  254. // string exceltype = foe._ExcelType;
  255. // string filename = foe._FileName;
  256. // string url = foe._Url;
  257. // string sheetname = foe._SheetName;
  258. // if (outtype.ToLower() == "excel")
  259. // {
  260. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  261. // op.SheetName = sheetname;
  262. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  263. // }
  264. // else
  265. // {
  266. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  267. // }
  268. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  269. // }
  270. // catch (Exception ex)
  271. // {
  272. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  273. // }
  274. //}
  275. }
  276. #endregion
  277. #region 刷新
  278. private void btnRefresh_Click(object sender, EventArgs e)
  279. {
  280. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  281. try
  282. {
  283. _wait.Show();
  284. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  285. filter.OldTempTableName = tempTableName;
  286. //tempTableName = filter.NewTempTableName;
  287. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  288. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  289. grdDetail.DataSource = dataSource;
  290. grvDetail.BestFitColumns();
  291. rptPage.RecordNum = dataSource.Rows.Count;
  292. rptPage.PageIndex = 1;
  293. rptPage.ReLoad();
  294. _wait.Close();
  295. }
  296. catch (Exception ex)
  297. {
  298. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  299. _wait.Close();
  300. }
  301. }
  302. #endregion
  303. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  304. {
  305. AppConfig.DropTemTable(tempTableName);
  306. }
  307. private void FormICSInvConnect_Load(object sender, EventArgs e)
  308. {
  309. btnFilter_Click(sender, e);
  310. }
  311. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  312. {
  313. if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  314. {
  315. //e.DisplayText = FormatHelper.
  316. e.CellValue = "cccc";
  317. }
  318. }
  319. private void btnGetInfo_Click(object sender, EventArgs e)
  320. {
  321. SimpleButton btntemp = (SimpleButton)sender;
  322. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  323. {
  324. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  325. return;
  326. }
  327. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在同步请稍等...");
  328. try
  329. {
  330. string sql = @"DELETE [dbo].ICSInvTransferDetail
  331. WHERE TransferNO IN
  332. (SELECT a.cTVCode
  333. FROM {1}.dbo.TransVouch a
  334. LEFT JOIN [dbo].ICSInvTransfer b ON a.cTVCode = b.TransferNO
  335. AND ISNULL(b.EffectedTIME,'') = ISNULL(a.dnmodifytime,'')
  336. WHERE (a.cVerifyPerson IS NULL OR a.cVerifyPerson = '')
  337. AND b.TransferNO IS NULL and ISNULL(cDefine1,'') <> '')
  338. DELETE [dbo].ICSInvTransfer
  339. WHERE TransferNO IN
  340. (SELECT a.cTVCode
  341. FROM {1}.dbo.TransVouch a
  342. LEFT JOIN [dbo].ICSInvTransfer b ON a.cTVCode = b.TransferNO
  343. AND ISNULL(b.EffectedTIME,'') = ISNULL(a.dnmodifytime,'')
  344. WHERE (a.cVerifyPerson IS NULL OR a.cVerifyPerson = '')
  345. AND b.TransferNO IS NULL and ISNULL(cDefine1,'') <> '')
  346. INSERT INTO [dbo].ICSInvTransfer
  347. (ID,TransferNO,FRMStorageCode,TOStorageCode,TransferSTATUS,RECTYPE,
  348. TIMETYPE,MEMO,CreateTIME,CreateUSER,WorkPoint,MUSER,MUSERName,MTIME,EffectedTIME)
  349. SELECT NEWID(),cTVCode,cOWhCode,cIWhCode,'','','',cTVMemo,
  350. dnmaketime,cMaker,'{0}','',
  351. a.cMaker,GETDATE(),a.dnmodifytime
  352. FROM {1}.dbo.TransVouch a
  353. LEFT JOIN [dbo].ICSInvTransfer b ON a.cTVCode = b.TransferNO
  354. WHERE (a.cVerifyPerson IS NULL OR a.cVerifyPerson = '')
  355. AND b.TransferNO IS NULL and ISNULL(cDefine1,'') <> ''
  356. INSERT INTO [dbo].ICSInvTransferDetail
  357. (ID,TransferID,TransferNO,TransferLine,TransferSTATUS,ITEMCODE,
  358. PLANQTY,ACTQTY,FROMStorageCode,TOStorageCode,WorkPoint,
  359. MUSER,MUSERName,MTIME,ORDERNO)
  360. SELECT NEWID(),'',a.cTVCode,b.irowno,'',b.cInvCode,b.iTVQuantity,'0',
  361. a.cOWhCode,a.cIWhCode,'{0}',''
  362. ,a.cMaker,GETDATE(),b.autoID FROM {1}.dbo.TransVouch a
  363. INNER JOIN {1}.dbo.TransVouchs b ON a.ID = b.ID
  364. LEFT JOIN [dbo].ICSInvTransferDetail c ON b.autoID = c.ORDERNO
  365. WHERE (a.cVerifyPerson IS NULL OR a.cVerifyPerson = '')
  366. AND c.ID IS NULL and ISNULL(cDefine1,'') <> ''";
  367. sql = string.Format(sql, AppConfig.WorkPointCode, ICSBaseSimpleCode.GetWorkPointErpData());
  368. DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, sql);
  369. _wait.Close();
  370. ICSBaseSimpleCode.AppshowMessageBox("同步成功");
  371. }
  372. catch (Exception ex)
  373. {
  374. _wait.Close();
  375. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  376. }
  377. }
  378. }
  379. }