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

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