锐腾搅拌上料功能
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.

379 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.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(this.Tag.ToString(), grdDetail);
  222. foe.ShowDialog();
  223. }
  224. #endregion
  225. #region 新增
  226. private void btnCreate_Click(object sender, EventArgs e)
  227. {
  228. string sql = @"SELECT a.[ID]
  229. ,a.[ECSGCODE] AS ''
  230. ,a.[ECSGDESC] AS ''
  231. FROM [ICSECSG] a WHERE a.ID NOT IN (SELECT ECSGID from dbo.ICSMODEL2ECSG WHERE MODELCODE='"+itemcode+"') and 1=1";
  232. DataTable data = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0];
  233. FormDataRefer reForm = new FormDataRefer();
  234. reForm.FormTitle = "不良代码组信息";
  235. DataTable menuData = data;
  236. reForm.DataSource = menuData;
  237. reForm.MSelectFlag = true;
  238. reForm.RowIndexWidth = 35;
  239. reForm.HideCols.Add("ID");
  240. reForm.FormWidth = 500;
  241. reForm.FormHeight = 500;
  242. reForm.FilterKey = ""; //grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, grvDetail.FocusedColumn).ToString().Trim();
  243. if (reForm.ShowDialog() == DialogResult.OK)
  244. {
  245. DataTable retData = reForm.ReturnData;
  246. if (retData.Rows.Count == 0)
  247. {
  248. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  249. return;
  250. }
  251. ICSMODEL2ECSGBLL.Add(retData, itemid, itemcode, AppConfig.AppConnectString);
  252. ICSBaseSimpleCode.AppshowMessageBox(0, "保存成功");
  253. FormICSMODEL2ECSG_Load(null, null);
  254. }
  255. }
  256. #endregion
  257. //#region 保存
  258. //private void btnSave_Click(object sender, EventArgs e)
  259. //{
  260. // List<string> ecgidList = new List<string>();
  261. // List<string> ecidList = new List<string>();
  262. // for (int i = 0; i < grvDetail.RowCount; i++)
  263. // {
  264. // ecidList.Add(grvDetail.GetRowCellValue(i, colECID).ToString());
  265. // ecgidList.Add(grvDetail.GetRowCellValue(i, colECGID).ToString());
  266. // }
  267. // //if (seqload.Count() == seqList.Count() && seqload.Count(t => !seqList.Contains(t)) == 0)
  268. // //{
  269. // // ICSBaseSimpleCode.AppshowMessageBox(0, "没有要保存的数据!!");
  270. // // return;
  271. // //}
  272. // ICSECG2ECBLL.Save(ecidList,ecgidList);
  273. // ICSBaseSimpleCode.AppshowMessageBox(0, "保存成功");
  274. //}
  275. //#endregion
  276. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  277. {
  278. if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  279. {
  280. //e.DisplayText = FormatHelper.
  281. e.CellValue = "cccc";
  282. }
  283. }
  284. private void FormICSMODEL2ECSG_Load(object sender, EventArgs e)
  285. {
  286. string sql = @"select '' as [isSelect],
  287. b.ID as MODELID,
  288. b.MODELCODE as MODELCODE,
  289. b.MODELDESC as MODELDESC,
  290. c.ID as ECSGID,
  291. c.ECSGCODE as ECSGCODE,
  292. c.ECSGDESC as ECSGDESC,
  293. a.MUSERName as MUSERName,
  294. a.MTIME as MTIME
  295. from dbo.ICSMODEL2ECSG a
  296. left join ICSMODEL b on a.MODELID=b.ID
  297. left join ICSECSG c on a.ECSGCODE=c.ECSGCODE
  298. where b.ID='{0}'";
  299. sql = string.Format(sql, itemid);
  300. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  301. grdDetail.DataSource = dt;
  302. }
  303. //private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  304. //{
  305. // if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  306. // {
  307. // //e.DisplayText = FormatHelper.
  308. // e.CellValue = "cccc";
  309. // }
  310. //}
  311. }
  312. }