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

392 lines
13 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using DevExpress.XtraEditors;
  9. using ICSSoft.Base.Language.Tool;
  10. using ICSSoft.Base.UserControl.MessageControl;
  11. using System.Data.SqlClient;
  12. using ICSSoft.Base.Config.AppConfig;
  13. using ICSSoft.Base.Report.Filter;
  14. using ICSSoft.Base.Config.DBHelper;
  15. using ICSSoft.Base.UserControl.FormControl;
  16. using ICSSoft.Base.ReferForm.AppReferForm;
  17. using ICSSoft.Frame.Data.BLL;
  18. namespace ICSSoft.Frame.APP
  19. {
  20. public partial class FormICSEQPMaterialTRANSDetail : DevExpress.XtraEditors.XtraForm
  21. {
  22. private string sqltxt = "";
  23. private string sqlconn = "";
  24. String guid = AppConfig.GetGuid();
  25. private DataTable dataSource = null;
  26. private string MCODE = "";
  27. #region 构造函数
  28. public FormICSEQPMaterialTRANSDetail(string mcode)
  29. {
  30. InitializeComponent();
  31. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  32. this.WindowState = FormWindowState.Maximized;
  33. MCODE = mcode;
  34. SearchItemLotInfo(mcode);
  35. }
  36. #endregion
  37. private void SearchItemLotInfo(string mcode)
  38. {
  39. string sql = @"select '' as [isSelect],
  40. b.ItemCode as MCODE,
  41. c.MToolCode as MToolCode,
  42. a.MTRANSType as MTRANSType,
  43. a.MTRANSQty as MTRANSQty,
  44. a.MRRUSER as MRRUSER,
  45. a.MUSERName as MUSERName,
  46. a.MTIME as MTIME
  47. from dbo.ICSEQPMaterialTRANS a
  48. left join Base_Inventory b on a.MCODE=b.ItemCode
  49. left join ICSEQPMaterialInfo c on a.MToolCode=c.MToolCode
  50. where b.ItemCode='{0}'";
  51. sql = string.Format(sql, mcode);
  52. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  53. grdDetail.DataSource = dt;
  54. }
  55. #region 移动窗体
  56. private const int WM_NCHITTEST = 0x84;
  57. private const int HTCLIENT = 0x1;
  58. private const int HTCAPTION = 0x2;
  59. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  60. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  61. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  62. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  63. //重写窗体,使窗体可以不通过自带标题栏实现移动
  64. protected override void WndProc(ref Message m)
  65. {
  66. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  67. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  68. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  69. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  70. switch (m.Msg)
  71. {
  72. case WM_NCHITTEST:
  73. base.WndProc(ref m);
  74. if ((int)m.Result == HTCLIENT)
  75. m.Result = (IntPtr)HTCAPTION;
  76. return;
  77. }
  78. //拦截双击标题栏、移动窗体的系统消息
  79. if (m.Msg != 0xA3)
  80. {
  81. base.WndProc(ref m);
  82. }
  83. }
  84. #endregion
  85. #region SystemOptition
  86. /// <summary>
  87. /// 操作权限
  88. /// </summary>
  89. /// <returns></returns>
  90. public DataTable RightOfExute()
  91. {
  92. DataTable rData = new DataTable();
  93. rData.Columns.Add("BtnName");
  94. rData.Columns.Add("ActionName");
  95. //查看权限(必须有)
  96. DataRow seeRow = rData.NewRow();
  97. seeRow["BtnName"] = "see";
  98. seeRow["ActionName"] = "查看";
  99. rData.Rows.Add(seeRow);
  100. List<Control> ControlList = new List<Control>();
  101. //ControlList.Add(btnConfig);
  102. //ControlList.Add(btnAdd);
  103. //ControlList.Add(btnEdit);
  104. //ControlList.Add(btnDelLable);
  105. foreach (Control ctr in ControlList)
  106. {
  107. if (ctr.GetType() == typeof(SimpleButton))
  108. {
  109. DataRow dr = rData.NewRow();
  110. dr["BtnName"] = ctr.Name;
  111. dr["ActionName"] = ctr.Text;
  112. rData.Rows.Add(dr);
  113. }
  114. }
  115. rData.AcceptChanges();
  116. return rData;
  117. }
  118. /// <summary>
  119. /// 数据权限
  120. /// </summary>
  121. /// <returns></returns>
  122. public DataTable RightOfData()
  123. {
  124. DataTable rData = new DataTable();
  125. rData.Columns.Add("BodyName");
  126. rData.Columns.Add("ControlName");
  127. rData.Columns.Add("ControlCaption");
  128. rData.AcceptChanges();
  129. return rData;
  130. }
  131. #endregion
  132. #region 退出
  133. private void btnClose_Click(object sender, EventArgs e)
  134. {
  135. AppConfig.CloseFormShow(this.Text);
  136. this.Close();
  137. }
  138. private void btnExit_Click(object sender, EventArgs e)
  139. {
  140. AppConfig.CloseFormShow(this.Text);
  141. this.Close();
  142. }
  143. #endregion
  144. #region 分页
  145. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  146. {
  147. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  148. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  149. grdDetail.DataSource = data;
  150. }
  151. #endregion
  152. #region 全选
  153. private void btnSelect_Click(object sender, EventArgs e)
  154. {
  155. for (int i = 0; i < grvDetail.RowCount; i++)
  156. {
  157. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  158. }
  159. }
  160. #endregion
  161. #region 全消
  162. private void btnCanSelect_Click(object sender, EventArgs e)
  163. {
  164. for (int i = 0; i < grvDetail.RowCount; i++)
  165. {
  166. grvDetail.SetRowCellValue(i, colisSelect, "");
  167. }
  168. }
  169. #endregion
  170. #region 刷新
  171. private void btnFalsh_Click(object sender, EventArgs e)
  172. {
  173. SearchItemLotInfo(MCODE);
  174. }
  175. #endregion
  176. #region 列表
  177. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  178. {
  179. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  180. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  181. }
  182. #endregion
  183. #region 双击选择
  184. private void grvDetail_DoubleClick(object sender, EventArgs e)
  185. {
  186. if (grvDetail.FocusedRowHandle < 0)
  187. {
  188. return;
  189. }
  190. if (grvDetail.FocusedColumn == colisSelect)
  191. {
  192. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  193. {
  194. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  195. }
  196. else
  197. {
  198. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  199. }
  200. }
  201. }
  202. #endregion
  203. #region 删除
  204. private void btnDel_Click(object sender, EventArgs e)
  205. {
  206. grvDetail.PostEditor();
  207. this.Validate();
  208. if (grvDetail.RowCount == 0)
  209. return;
  210. SimpleButton btntemp = (SimpleButton)sender;
  211. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  212. {
  213. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  214. }
  215. List<string> guidList = new List<string>();
  216. List<string> guidList1 = new List<string>();
  217. for (int i = 0; i < grvDetail.RowCount; i++)
  218. {
  219. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  220. {
  221. //guidList.Add(grvDetail.GetRowCellValue(i, colEQPID).ToString());
  222. }
  223. }
  224. if (guidList.Count == 0)
  225. {
  226. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  227. return;
  228. }
  229. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除该设备吗?设备删除后无法恢复,确定吗?") != DialogResult.OK)
  230. return;
  231. try
  232. {
  233. ICSEquipmentBLL.delete(guidList);
  234. ICSBaseSimpleCode.AppshowMessageBox(0, "删除成功");
  235. }
  236. catch (Exception ex)
  237. {
  238. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  239. }
  240. btnFalsh_Click(null, null);
  241. }
  242. #endregion
  243. #region 新增
  244. private void btnAdd_Click(object sender, EventArgs e)
  245. {
  246. FormICSEQPMaterialTRANSAdd add = new FormICSEQPMaterialTRANSAdd();
  247. add.ShowDialog();
  248. SearchItemLotInfo(MCODE);
  249. }
  250. #endregion
  251. #region 修改
  252. private void btnEdit_Click(object sender, EventArgs e)
  253. {
  254. SimpleButton btntemp = (SimpleButton)sender;
  255. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  256. {
  257. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  258. return;
  259. }
  260. int count = 0;
  261. for (int i = 0; i < grvDetail.RowCount; i++)
  262. {
  263. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  264. {
  265. count++;
  266. }
  267. }
  268. if (count != 1)
  269. {
  270. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  271. return;
  272. }
  273. try
  274. {
  275. string id;
  276. for (int i = 0; i < grvDetail.RowCount; i++)
  277. {
  278. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  279. {
  280. //id = grvDetail.GetRowCellValue(i, colEQPID).ToString();
  281. //FormICSEquipmentAdd add = new FormICSEquipmentAdd(id);
  282. //add.ShowDialog();
  283. }
  284. }
  285. btnFalsh_Click(null, null);
  286. }
  287. catch (Exception ex)
  288. {
  289. //throw ex;
  290. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  291. }
  292. }
  293. #endregion
  294. private void btnOutPut_Click(object sender, EventArgs e)
  295. {
  296. try
  297. {
  298. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  299. foe.ShowDialog();
  300. }
  301. catch (Exception ex)
  302. {
  303. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  304. }
  305. //FormOutExcel foe = new FormOutExcel();
  306. //if (foe.ShowDialog() == DialogResult.OK)
  307. //{
  308. // try
  309. // {
  310. // string outtype = foe._OutType;
  311. // string exceltype = foe._ExcelType;
  312. // string filename = foe._FileName;
  313. // string url = foe._Url;
  314. // string sheetname = foe._SheetName;
  315. // if (outtype.ToLower() == "excel")
  316. // {
  317. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  318. // op.SheetName = sheetname;
  319. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  320. // }
  321. // else
  322. // {
  323. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  324. // }
  325. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  326. // }
  327. // catch (Exception ex)
  328. // {
  329. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  330. // }
  331. //}
  332. }
  333. }
  334. }