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

435 lines
16 KiB

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