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

506 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 DevExpress.XtraPrinting;
  26. namespace ICSSoft.Frame.APP
  27. {
  28. public partial class FormICSItemBack : DevExpress.XtraEditors.XtraForm
  29. {
  30. private string sqltxt = "";
  31. private string sqlconn = "";
  32. String guid = AppConfig.GetGuid();
  33. private DataTable dataSource = null;
  34. #region 构造函数
  35. public FormICSItemBack()
  36. {
  37. InitializeComponent();
  38. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  39. this.WindowState = FormWindowState.Maximized;
  40. }
  41. #endregion
  42. #region 操作权限
  43. public DataTable RightOfExute()
  44. {
  45. DataTable rData = new DataTable();
  46. rData.Columns.Add("BtnName");
  47. rData.Columns.Add("ActionName");
  48. //查看权限(必须有)
  49. DataRow seeRow = rData.NewRow();
  50. seeRow["BtnName"] = "see";
  51. seeRow["ActionName"] = "查看";
  52. rData.Rows.Add(seeRow);
  53. List<Control> ControlList = new List<Control>();
  54. ControlList.Add(btnCreate);
  55. ControlList.Add(btnModify);
  56. ControlList.Add(btnDel);
  57. ControlList.Add(btnOutPut);
  58. foreach (Control ctr in ControlList)
  59. {
  60. if (ctr.GetType() == typeof(SimpleButton))
  61. {
  62. DataRow dr = rData.NewRow();
  63. dr["BtnName"] = ctr.Name;
  64. dr["ActionName"] = ctr.Text;
  65. rData.Rows.Add(dr);
  66. }
  67. }
  68. rData.AcceptChanges();
  69. return rData;
  70. }
  71. public DataTable RightOfData()// 数据权限
  72. {
  73. DataTable rData = new DataTable();
  74. rData.Columns.Add("BodyName");
  75. rData.Columns.Add("ControlName");
  76. rData.Columns.Add("ControlCaption");
  77. rData.AcceptChanges();
  78. return rData;
  79. }
  80. #endregion
  81. #region 退出
  82. private void btnClose_Click(object sender, EventArgs e)
  83. {
  84. AppConfig.CloseFormShow(this.Text);
  85. this.Close();
  86. }
  87. private void btnExit_Click(object sender, EventArgs e)
  88. {
  89. AppConfig.CloseFormShow(this.Text);
  90. this.Close();
  91. }
  92. #endregion
  93. #region 移动窗体
  94. private const int WM_NCHITTEST = 0x84;
  95. private const int HTCLIENT = 0x1;
  96. private const int HTCAPTION = 0x2;
  97. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  98. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  99. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  100. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  101. //重写窗体,使窗体可以不通过自带标题栏实现移动
  102. protected override void WndProc(ref Message m)
  103. {
  104. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  105. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  106. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  107. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  108. switch (m.Msg)
  109. {
  110. case WM_NCHITTEST:
  111. base.WndProc(ref m);
  112. if ((int)m.Result == HTCLIENT)
  113. m.Result = (IntPtr)HTCAPTION;
  114. return;
  115. }
  116. //拦截双击标题栏、移动窗体的系统消息
  117. if (m.Msg != 0xA3)
  118. {
  119. base.WndProc(ref m);
  120. }
  121. }
  122. #endregion
  123. #region 列表
  124. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  125. {
  126. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  127. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  128. }
  129. #endregion
  130. #region 过滤
  131. private string tempTableName = "";
  132. private void btnFilter_Click(object sender, EventArgs e)
  133. {
  134. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  135. filter.OldTempTableName = tempTableName;
  136. if (filter.ShowDialog() == DialogResult.OK)
  137. {
  138. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  139. try
  140. {
  141. _wait.Show();
  142. tempTableName = filter.NewTempTableName;
  143. sqltxt = filter.SqlText;
  144. sqlconn = filter.FilterConnectString;
  145. dataSource = filter.FilterData.Tables[0];
  146. grdDetail.DataSource = dataSource;
  147. grvDetail.BestFitColumns();
  148. rptPage.RecordNum = dataSource.Rows.Count;
  149. rptPage.PageSize = 499;
  150. rptPage.PageIndex = 1;
  151. rptPage.ReLoad();
  152. rptPage.PageSize = 500;
  153. rptPage.PageIndex = 1;
  154. rptPage.ReLoad();
  155. _wait.Close();
  156. }
  157. catch (Exception ex)
  158. {
  159. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  160. _wait.Close();
  161. }
  162. }
  163. }
  164. #endregion
  165. #region 绑定数据源
  166. private void btnConfig_Click(object sender, EventArgs e)
  167. {
  168. if (AppConfig.UserCode.ToLower() != "demo")
  169. {
  170. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  171. return;
  172. }
  173. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  174. fdata.ShowDialog();
  175. }
  176. #endregion
  177. #region 分页
  178. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  179. {
  180. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  181. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  182. grdDetail.DataSource = data;
  183. }
  184. #endregion
  185. #region 过滤方法
  186. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  187. {
  188. AppConfig.DropTemTable(tempTableName);
  189. }
  190. #endregion
  191. #region 全选
  192. private void btnSelectAll_Click(object sender, EventArgs e)
  193. {
  194. grvDetail.PostEditor();
  195. this.Validate();
  196. for (int i = 0; i < grvDetail.RowCount; i++)
  197. {
  198. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  199. }
  200. }
  201. #endregion
  202. #region 全消
  203. private void btnCancelAll_Click(object sender, EventArgs e)
  204. {
  205. grvDetail.PostEditor();
  206. this.Validate();
  207. for (int i = 0; i < grvDetail.RowCount; i++)
  208. {
  209. grvDetail.SetRowCellValue(i, colisSelect, "");
  210. }
  211. }
  212. #endregion
  213. #region 双击
  214. private void grvDetail_DoubleClick(object sender, EventArgs e)
  215. {
  216. if (grvDetail.FocusedRowHandle < 0)
  217. {
  218. return;
  219. }
  220. if (grvDetail.FocusedColumn == colisSelect)
  221. {
  222. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  223. {
  224. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  225. }
  226. else
  227. {
  228. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  229. }
  230. }
  231. }
  232. #endregion
  233. #region 删除
  234. private void btnDel_Click(object sender, EventArgs e)
  235. {
  236. grvDetail.PostEditor();
  237. this.Validate();
  238. if (grvDetail.RowCount == 0)
  239. return;
  240. SimpleButton btntemp = (SimpleButton)sender;
  241. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  242. {
  243. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  244. return;
  245. }
  246. List<string> guidList = new List<string>();
  247. List<string> codeList = new List<string>();
  248. for (int i = 0; i < grvDetail.RowCount; i++)
  249. {
  250. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  251. {
  252. guidList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  253. codeList.Add(grvDetail.GetRowCellValue(i, colMOCODE).ToString());
  254. }
  255. }
  256. if (guidList.Count == 0)
  257. {
  258. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  259. return;
  260. }
  261. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该厂商吗?删除后无法恢复,确定吗?") != DialogResult.OK)
  262. return;
  263. try
  264. {
  265. ICSItemBackBLL.delete(guidList,codeList);
  266. ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  267. btnRefresh_Click(null, null);
  268. }
  269. catch (Exception ex)
  270. {
  271. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  272. }
  273. }
  274. #endregion
  275. #region 导出
  276. private void btnOutPut_Click(object sender, EventArgs e)
  277. {
  278. try
  279. {
  280. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  281. foe.ShowDialog();
  282. }
  283. catch (Exception ex)
  284. {
  285. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  286. }
  287. //FormOutExcel foe = new FormOutExcel();
  288. //if (foe.ShowDialog() == DialogResult.OK)
  289. //{
  290. // try
  291. // {
  292. // string outtype = foe._OutType;
  293. // string exceltype = foe._ExcelType;
  294. // string filename = foe._FileName;
  295. // string url = foe._Url;
  296. // string sheetname = foe._SheetName;
  297. // if (outtype.ToLower() == "excel")
  298. // {
  299. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  300. // op.SheetName = sheetname;
  301. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  302. // }
  303. // else
  304. // {
  305. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  306. // }
  307. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  308. // }
  309. // catch (Exception ex)
  310. // {
  311. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  312. // }
  313. //}
  314. }
  315. #endregion
  316. #region 刷新
  317. private void btnRefresh_Click(object sender, EventArgs e)
  318. {
  319. if (sqlconn == null || sqlconn == "")
  320. {
  321. return;
  322. }
  323. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  324. try
  325. {
  326. _wait.Show();
  327. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  328. filter.OldTempTableName = tempTableName;
  329. //tempTableName = filter.NewTempTableName;
  330. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  331. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  332. grdDetail.DataSource = dataSource;
  333. grvDetail.BestFitColumns();
  334. rptPage.RecordNum = dataSource.Rows.Count;
  335. rptPage.PageIndex = 1;
  336. rptPage.ReLoad();
  337. _wait.Close();
  338. }
  339. catch (Exception ex)
  340. {
  341. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  342. _wait.Close();
  343. }
  344. }
  345. #endregion
  346. #region 新增
  347. private void btnCreate_Click(object sender, EventArgs e)
  348. {
  349. SimpleButton btntemp = (SimpleButton)sender;
  350. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  351. {
  352. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  353. return;
  354. }
  355. FormICSItemBackAdd add = new FormICSItemBackAdd();
  356. add.ShowDialog();
  357. btnRefresh_Click(null, null);
  358. }
  359. #endregion
  360. #region 修改
  361. private void btnModify_Click(object sender, EventArgs e)
  362. {
  363. String id = "";
  364. SimpleButton btntemp = (SimpleButton)sender;
  365. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  366. {
  367. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  368. return;
  369. }
  370. List<string> editList = new List<string>();
  371. List<string> guidList1 = new List<string>();
  372. for (int i = 0; i < grvDetail.RowCount; i++)
  373. {
  374. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  375. {
  376. if (grvDetail.GetRowCellValue(i, colSTATUS).ToString() == "已退")
  377. {
  378. ICSBaseSimpleCode.AppshowMessageBox("已退状态不能修改!");
  379. return;
  380. }
  381. id = grvDetail.GetRowCellValue(i, colID).ToString();
  382. editList.Add(id);
  383. }
  384. }
  385. if (editList.Count != 1)
  386. {
  387. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  388. return;
  389. }
  390. try
  391. {
  392. ICSItemBackBLL.select(id, AppConfig.AppConnectString);
  393. FormICSItemBackAdd add = new FormICSItemBackAdd(id);
  394. add.ShowDialog();
  395. btnRefresh_Click(null, null);
  396. }
  397. catch (Exception ex)
  398. {
  399. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  400. }
  401. }
  402. #endregion
  403. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  404. {
  405. AppConfig.DropTemTable(tempTableName);
  406. }
  407. private void FormDCT_Load(object sender, EventArgs e)
  408. {
  409. btnFilter_Click(sender, e);
  410. }
  411. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  412. {
  413. if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  414. {
  415. //e.DisplayText = FormatHelper.
  416. e.CellValue = "cccc";
  417. }
  418. }
  419. #region 打印
  420. private void btnPrint_Click(object sender, EventArgs e)
  421. {
  422. try
  423. {
  424. this.grvDetail.OptionsView.RowAutoHeight = true;
  425. PrintingSystem print = new DevExpress.XtraPrinting.PrintingSystem();
  426. PrintableComponentLink link = new PrintableComponentLink(print);
  427. DevExpress.XtraPrintingLinks.CompositeLink compositeLink = new DevExpress.XtraPrintingLinks.CompositeLink();
  428. print.Links.Add(link);
  429. link.Component = grdDetail;//这里可以是可打印的部件
  430. link.Margins.Top = 50;
  431. link.Margins.Bottom = 0;
  432. link.Margins.Left = 0;
  433. link.Margins.Right = 0;
  434. string _PrintHeader = lblTitle.Text;
  435. PageHeaderFooter phf = link.PageHeaderFooter as PageHeaderFooter;
  436. phf.Header.Content.Clear();
  437. phf.Header.Content.AddRange(new string[] { "", _PrintHeader, "" });
  438. phf.Header.Font = new System.Drawing.Font("宋体", 14, System.Drawing.FontStyle.Bold);
  439. phf.Header.LineAlignment = BrickAlignment.Center;
  440. link.CreateDocument(); //建立文档
  441. print.PreviewFormEx.Show();//进行预览
  442. }
  443. catch (Exception ex)
  444. {
  445. MessageBox.Show(ex.ToString());
  446. }
  447. }
  448. #endregion
  449. }
  450. }