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

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