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

404 lines
14 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 FormICSMODEL2ECSG : DevExpress.XtraEditors.XtraForm
  28. {
  29. private string sqltxt = "";
  30. private string sqlconn = "";
  31. String guid = AppConfig.GetGuid();
  32. private DataTable dataSource = null;
  33. string itemid="";
  34. string itemcode="";
  35. #region 构造函数
  36. public FormICSMODEL2ECSG()
  37. {
  38. InitializeComponent();
  39. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  40. this.WindowState = FormWindowState.Maximized;
  41. }
  42. #endregion
  43. public FormICSMODEL2ECSG(string id, string code)
  44. {
  45. InitializeComponent();
  46. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  47. this.WindowState = FormWindowState.Maximized;
  48. itemid = id;
  49. itemcode = code;
  50. }
  51. #region 操作权限
  52. public DataTable RightOfExute()
  53. {
  54. DataTable rData = new DataTable();
  55. rData.Columns.Add("BtnName");
  56. rData.Columns.Add("ActionName");
  57. //查看权限(必须有)
  58. DataRow seeRow = rData.NewRow();
  59. seeRow["BtnName"] = "see";
  60. seeRow["ActionName"] = "查看";
  61. rData.Rows.Add(seeRow);
  62. List<Control> ControlList = new List<Control>();
  63. ControlList.Add(btnCreate);
  64. //ControlList.Add(btnModify);
  65. ControlList.Add(btnDel);
  66. foreach (Control ctr in ControlList)
  67. {
  68. if (ctr.GetType() == typeof(SimpleButton))
  69. {
  70. DataRow dr = rData.NewRow();
  71. dr["BtnName"] = ctr.Name;
  72. dr["ActionName"] = ctr.Text;
  73. rData.Rows.Add(dr);
  74. }
  75. }
  76. rData.AcceptChanges();
  77. return rData;
  78. }
  79. public DataTable RightOfData()// 数据权限
  80. {
  81. DataTable rData = new DataTable();
  82. rData.Columns.Add("BodyName");
  83. rData.Columns.Add("ControlName");
  84. rData.Columns.Add("ControlCaption");
  85. rData.AcceptChanges();
  86. return rData;
  87. }
  88. #endregion
  89. #region 退出
  90. private void btnClose_Click(object sender, EventArgs e)
  91. {
  92. AppConfig.CloseFormShow(this.Text);
  93. this.Close();
  94. }
  95. private void btnExit_Click(object sender, EventArgs e)
  96. {
  97. AppConfig.CloseFormShow(this.Text);
  98. this.Close();
  99. }
  100. #endregion
  101. #region 移动窗体
  102. private const int WM_NCHITTEST = 0x84;
  103. private const int HTCLIENT = 0x1;
  104. private const int HTCAPTION = 0x2;
  105. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  106. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  107. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  108. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  109. //重写窗体,使窗体可以不通过自带标题栏实现移动
  110. protected override void WndProc(ref Message m)
  111. {
  112. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  113. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  114. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  115. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  116. switch (m.Msg)
  117. {
  118. case WM_NCHITTEST:
  119. base.WndProc(ref m);
  120. if ((int)m.Result == HTCLIENT)
  121. m.Result = (IntPtr)HTCAPTION;
  122. return;
  123. }
  124. //拦截双击标题栏、移动窗体的系统消息
  125. if (m.Msg != 0xA3)
  126. {
  127. base.WndProc(ref m);
  128. }
  129. }
  130. #endregion
  131. #region 列表
  132. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  133. {
  134. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  135. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  136. }
  137. #endregion
  138. #region 分页
  139. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  140. {
  141. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  142. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  143. grdDetail.DataSource = data;
  144. }
  145. #endregion
  146. #region 全选
  147. private void btnSelectAll_Click(object sender, EventArgs e)
  148. {
  149. grvDetail.PostEditor();
  150. this.Validate();
  151. for (int i = 0; i < grvDetail.RowCount; i++)
  152. {
  153. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  154. }
  155. }
  156. #endregion
  157. #region 全消
  158. private void btnCancelAll_Click(object sender, EventArgs e)
  159. {
  160. grvDetail.PostEditor();
  161. this.Validate();
  162. for (int i = 0; i < grvDetail.RowCount; i++)
  163. {
  164. grvDetail.SetRowCellValue(i, colisSelect, "");
  165. }
  166. }
  167. #endregion
  168. #region 双击
  169. private void grvDetail_DoubleClick(object sender, EventArgs e)
  170. {
  171. if (grvDetail.FocusedRowHandle < 0)
  172. {
  173. return;
  174. }
  175. if (grvDetail.FocusedColumn == colisSelect)
  176. {
  177. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  178. {
  179. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  180. }
  181. else
  182. {
  183. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  184. }
  185. }
  186. }
  187. #endregion
  188. #region 删除
  189. private void btnDel_Click(object sender, EventArgs e)
  190. {
  191. List<string> guidList = new List<string>();
  192. for (int i = 0; i < grvDetail.RowCount; i++)
  193. {
  194. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  195. {
  196. guidList.Add(grvDetail.GetRowCellValue(i, colMODELID).ToString());
  197. guidList.Add(grvDetail.GetRowCellValue(i, colECSGID).ToString());
  198. }
  199. }
  200. if (guidList.Count == 0 || guidList == null)
  201. {
  202. ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
  203. return;
  204. }
  205. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该产品别与不良原因组关系吗?删除后无法恢复") != DialogResult.OK)
  206. {
  207. for (int i = 0; i < grvDetail.RowCount; i++)
  208. {
  209. grvDetail.SetRowCellValue(i, colisSelect, "");
  210. }
  211. return;
  212. }
  213. ICSMODEL2ECSGBLL.delete(guidList);
  214. ICSBaseSimpleCode.AppshowMessageBox("删除成功");
  215. FormICSMODEL2ECSG_Load(null, null);
  216. }
  217. #endregion
  218. #region 导出
  219. private void btnOutPut_Click(object sender, EventArgs e)
  220. {
  221. FormOutExcel foe = new FormOutExcel();
  222. if (foe.ShowDialog() == DialogResult.OK)
  223. {
  224. try
  225. {
  226. string outtype = foe._OutType;
  227. string exceltype = foe._ExcelType;
  228. string filename = foe._FileName;
  229. string url = foe._Url;
  230. string sheetname = foe._SheetName;
  231. if (outtype.ToLower() == "excel")
  232. {
  233. DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  234. op.SheetName = sheetname;
  235. grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  236. }
  237. else
  238. {
  239. grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  240. }
  241. MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  242. }
  243. catch (Exception ex)
  244. {
  245. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  246. }
  247. }
  248. }
  249. #endregion
  250. #region 新增
  251. private void btnCreate_Click(object sender, EventArgs e)
  252. {
  253. string sql = @"SELECT a.[ID]
  254. ,a.[ECSGCODE] AS ''
  255. ,a.[ECSGDESC] AS ''
  256. FROM [ICSECSG] a WHERE a.ID NOT IN (SELECT ECSGID from dbo.ICSMODEL2ECSG WHERE MODELCODE='"+itemcode+"') and 1=1";
  257. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  258. FormDataRefer reForm = new FormDataRefer();
  259. reForm.FormTitle = "不良代码组信息";
  260. DataTable menuData = data;
  261. reForm.DataSource = menuData;
  262. reForm.MSelectFlag = true;
  263. reForm.RowIndexWidth = 35;
  264. reForm.HideCols.Add("ID");
  265. reForm.FormWidth = 500;
  266. reForm.FormHeight = 500;
  267. reForm.FilterKey = ""; //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  268. if (reForm.ShowDialog() == DialogResult.OK)
  269. {
  270. DataTable retData = reForm.ReturnData;
  271. if (retData.Rows.Count == 0)
  272. {
  273. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  274. return;
  275. }
  276. ICSMODEL2ECSGBLL.Add(retData, itemid, itemcode, AppConfig.AppConnectString);
  277. ICSBaseSimpleCode.AppshowMessageBox(0, "保存成功");
  278. FormICSMODEL2ECSG_Load(null, null);
  279. }
  280. }
  281. #endregion
  282. //#region 保存
  283. //private void btnSave_Click(object sender, EventArgs e)
  284. //{
  285. // List<string> ecgidList = new List<string>();
  286. // List<string> ecidList = new List<string>();
  287. // for (int i = 0; i < grvDetail.RowCount; i++)
  288. // {
  289. // ecidList.Add(grvDetail.GetRowCellValue(i, colECID).ToString());
  290. // ecgidList.Add(grvDetail.GetRowCellValue(i, colECGID).ToString());
  291. // }
  292. // //if (seqload.Count() == seqList.Count() && seqload.Count(t => !seqList.Contains(t)) == 0)
  293. // //{
  294. // // ICSBaseSimpleCode.AppshowMessageBox(0, "没有要保存的数据!!");
  295. // // return;
  296. // //}
  297. // ICSECG2ECBLL.Save(ecidList,ecgidList);
  298. // ICSBaseSimpleCode.AppshowMessageBox(0, "保存成功");
  299. //}
  300. //#endregion
  301. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  302. {
  303. if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  304. {
  305. //e.DisplayText = FormatHelper.
  306. e.CellValue = "cccc";
  307. }
  308. }
  309. private void FormICSMODEL2ECSG_Load(object sender, EventArgs e)
  310. {
  311. string sql = @"select '' as [isSelect],
  312. b.ID as MODELID,
  313. b.MODELCODE as MODELCODE,
  314. b.MODELDESC as MODELDESC,
  315. c.ID as ECSGID,
  316. c.ECSGCODE as ECSGCODE,
  317. c.ECSGDESC as ECSGDESC,
  318. a.MUSERName as MUSERName,
  319. a.MTIME as MTIME
  320. from dbo.ICSMODEL2ECSG a
  321. left join ICSMODEL b on a.MODELID=b.ID
  322. left join ICSECSG c on a.ECSGCODE=c.ECSGCODE
  323. where b.ID='{0}'";
  324. sql = string.Format(sql, itemid);
  325. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  326. grdDetail.DataSource = dt;
  327. }
  328. //private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  329. //{
  330. // if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  331. // {
  332. // //e.DisplayText = FormatHelper.
  333. // e.CellValue = "cccc";
  334. // }
  335. //}
  336. }
  337. }