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

355 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. using ICSSoft.Base.Lable.PrintTool;
  26. namespace ICSSoft.Frame.APP
  27. {
  28. public partial class FormICSWare : DevExpress.XtraEditors.XtraForm
  29. {
  30. private string sqltxt = "";
  31. private string sqlconn = "";
  32. String guid = AppConfig.GetGuid();
  33. private DataTable dataSource = null;
  34. List<string> LotNo = new List<string> ();
  35. #region 构造函数
  36. public FormICSWare()
  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. #region 操作权限
  44. public DataTable RightOfExute()
  45. {
  46. DataTable rData = new DataTable();
  47. rData.Columns.Add("BtnName");
  48. rData.Columns.Add("ActionName");
  49. //查看权限(必须有)
  50. DataRow seeRow = rData.NewRow();
  51. seeRow["BtnName"] = "see";
  52. seeRow["ActionName"] = "查看";
  53. rData.Rows.Add(seeRow);
  54. List<Control> ControlList = new List<Control>();
  55. ControlList.Add(btnPrint);
  56. foreach (Control ctr in ControlList)
  57. {
  58. if (ctr.GetType() == typeof(SimpleButton))
  59. {
  60. DataRow dr = rData.NewRow();
  61. dr["BtnName"] = ctr.Name;
  62. dr["ActionName"] = ctr.Text;
  63. rData.Rows.Add(dr);
  64. }
  65. }
  66. rData.AcceptChanges();
  67. return rData;
  68. }
  69. public DataTable RightOfData()// 数据权限
  70. {
  71. DataTable rData = new DataTable();
  72. rData.Columns.Add("BodyName");
  73. rData.Columns.Add("ControlName");
  74. rData.Columns.Add("ControlCaption");
  75. rData.AcceptChanges();
  76. return rData;
  77. }
  78. #endregion
  79. #region 退出
  80. private void btnClose_Click(object sender, EventArgs e)
  81. {
  82. AppConfig.CloseFormShow(this.Text);
  83. this.Close();
  84. }
  85. private void btnExit_Click(object sender, EventArgs e)
  86. {
  87. AppConfig.CloseFormShow(this.Text);
  88. this.Close();
  89. }
  90. #endregion
  91. #region 移动窗体
  92. private const int WM_NCHITTEST = 0x84;
  93. private const int HTCLIENT = 0x1;
  94. private const int HTCAPTION = 0x2;
  95. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  96. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  97. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  98. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  99. //重写窗体,使窗体可以不通过自带标题栏实现移动
  100. protected override void WndProc(ref Message m)
  101. {
  102. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  103. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  104. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  105. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  106. switch (m.Msg)
  107. {
  108. case WM_NCHITTEST:
  109. base.WndProc(ref m);
  110. if ((int)m.Result == HTCLIENT)
  111. m.Result = (IntPtr)HTCAPTION;
  112. return;
  113. }
  114. //拦截双击标题栏、移动窗体的系统消息
  115. if (m.Msg != 0xA3)
  116. {
  117. base.WndProc(ref m);
  118. }
  119. }
  120. #endregion
  121. #region 列表
  122. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  123. {
  124. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  125. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  126. }
  127. #endregion
  128. #region 过滤
  129. private string tempTableName = "";
  130. private void btnFilter_Click(object sender, EventArgs e)
  131. {
  132. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  133. filter.OldTempTableName = tempTableName;
  134. if (filter.ShowDialog() == DialogResult.OK)
  135. {
  136. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  137. try
  138. {
  139. _wait.Show();
  140. tempTableName = filter.NewTempTableName;
  141. sqltxt = filter.SqlText;
  142. sqlconn = filter.FilterConnectString;
  143. dataSource = filter.FilterData.Tables[0];
  144. grdDetail.DataSource = dataSource;
  145. grvDetail.BestFitColumns();
  146. rptPage.RecordNum = dataSource.Rows.Count;
  147. rptPage.PageSize = 499;
  148. rptPage.PageIndex = 1;
  149. rptPage.ReLoad();
  150. rptPage.PageSize = 500;
  151. rptPage.PageIndex = 1;
  152. rptPage.ReLoad();
  153. _wait.Close();
  154. }
  155. catch (Exception ex)
  156. {
  157. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  158. _wait.Close();
  159. }
  160. }
  161. }
  162. #endregion
  163. #region 绑定数据源
  164. private void btnConfig_Click(object sender, EventArgs e)
  165. {
  166. if (AppConfig.UserCode.ToLower() != "demo")
  167. {
  168. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  169. return;
  170. }
  171. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  172. fdata.ShowDialog();
  173. }
  174. #endregion
  175. #region 分页
  176. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  177. {
  178. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  179. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  180. grdDetail.DataSource = data;
  181. }
  182. #endregion
  183. #region 过滤方法
  184. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  185. {
  186. AppConfig.DropTemTable(tempTableName);
  187. }
  188. #endregion
  189. #region 全选
  190. private void btnSelectAll_Click(object sender, EventArgs e)
  191. {
  192. grvDetail.PostEditor();
  193. this.Validate();
  194. for (int i = 0; i < grvDetail.RowCount; i++)
  195. {
  196. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  197. }
  198. }
  199. #endregion
  200. #region 全消
  201. private void btnCancelAll_Click(object sender, EventArgs e)
  202. {
  203. grvDetail.PostEditor();
  204. this.Validate();
  205. for (int i = 0; i < grvDetail.RowCount; i++)
  206. {
  207. grvDetail.SetRowCellValue(i, colisSelect, "");
  208. }
  209. }
  210. #endregion
  211. #region 双击
  212. private void grvDetail_DoubleClick(object sender, EventArgs e)
  213. {
  214. if (grvDetail.FocusedRowHandle < 0)
  215. {
  216. return;
  217. }
  218. if (grvDetail.FocusedColumn == colisSelect)
  219. {
  220. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  221. {
  222. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  223. }
  224. else
  225. {
  226. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  227. }
  228. }
  229. }
  230. #endregion
  231. #region 刷新
  232. private void btnRefresh_Click(object sender, EventArgs e)
  233. {
  234. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  235. try
  236. {
  237. _wait.Show();
  238. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  239. filter.OldTempTableName = tempTableName;
  240. //tempTableName = filter.NewTempTableName;
  241. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  242. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  243. grdDetail.DataSource = dataSource;
  244. grvDetail.BestFitColumns();
  245. rptPage.RecordNum = dataSource.Rows.Count;
  246. rptPage.PageIndex = 1;
  247. rptPage.ReLoad();
  248. _wait.Close();
  249. }
  250. catch (Exception ex)
  251. {
  252. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  253. _wait.Close();
  254. }
  255. }
  256. #endregion
  257. private void ICSItemLot_FormClosing(object sender, FormClosingEventArgs e)
  258. {
  259. AppConfig.DropTemTable(tempTableName);
  260. }
  261. private void FormICSInvConnect_Load(object sender, EventArgs e)
  262. {
  263. btnFilter_Click(sender, e);
  264. }
  265. private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
  266. {
  267. if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE")
  268. {
  269. e.CellValue = "cccc";
  270. }
  271. }
  272. private void btnPrint_Click(object sender, EventArgs e)
  273. {
  274. string lot_NO = "";
  275. LotNo.Clear();
  276. for (int i = 0; i < grvDetail.RowCount; i++)
  277. {
  278. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  279. {
  280. LotNo.Add(grvDetail.GetRowCellValue(i, colLotNO).ToString());
  281. }
  282. }
  283. for (int i = 0; i < LotNo.Count; i++)
  284. {
  285. if (i == 0)
  286. {
  287. lot_NO = LotNo[0];
  288. }
  289. else
  290. {
  291. lot_NO += "' or a.LotNo ='" + LotNo[i] + " ";
  292. }
  293. }
  294. try
  295. {
  296. #region
  297. SimpleButton btntemp = (SimpleButton)sender;
  298. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  299. {
  300. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  301. return;
  302. }
  303. List<PrintPara> parasList = new List<PrintPara>();
  304. PrintPara para = new PrintPara();
  305. para.PrintKey = "LotNO";
  306. para.PrintValues = new object[] { lot_NO };
  307. parasList.Add(para);
  308. if (parasList.Count == 0)
  309. {
  310. ICSBaseSimpleCode.AppshowMessageBox("请选择数据!");
  311. return;
  312. }
  313. FormPrintDialog f = new FormPrintDialog("007", this.Text, parasList, false, null);
  314. f.ShowDialog();
  315. #endregion
  316. }
  317. catch (Exception ex)
  318. {
  319. MessageBox.Show(ex.ToString());
  320. }
  321. }
  322. }
  323. }