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

561 lines
21 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 System.Data.SqlClient;
  10. using ICSSoft.Frame.Data.BLL;
  11. using ICSSoft.Base.Language.Tool;
  12. using ICSSoft.Base.UserControl.MessageControl;
  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.Base.Lable.PrintTool;
  18. using ICSSoft.Base.Config.AppConfig;
  19. using ICSSoft.Base.Report.GridReport;
  20. using ICSSoft.Frame.APP.Entity;
  21. using ICSSoft.Frame.Data.Entity;
  22. namespace ICSSoft.Frame.APP
  23. {
  24. public partial class FormICSItemOPPrice : DevExpress.XtraEditors.XtraForm
  25. {
  26. private string sqltxt = "";
  27. private string sqlconn = "";
  28. String guid = AppConfig.GetGuid();
  29. private DataTable dataSource = null;
  30. //WorkPointBLL workBll = new WorkPointBLL();
  31. #region 构造函数
  32. public FormICSItemOPPrice()
  33. {
  34. InitializeComponent();
  35. this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
  36. this.WindowState = FormWindowState.Maximized;
  37. }
  38. #endregion
  39. #region 移动窗体
  40. private const int WM_NCHITTEST = 0x84;
  41. private const int HTCLIENT = 0x1;
  42. private const int HTCAPTION = 0x2;
  43. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  44. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  45. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  46. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  47. //重写窗体,使窗体可以不通过自带标题栏实现移动
  48. protected override void WndProc(ref Message m)
  49. {
  50. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  51. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  52. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  53. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  54. switch (m.Msg)
  55. {
  56. case WM_NCHITTEST:
  57. base.WndProc(ref m);
  58. if ((int)m.Result == HTCLIENT)
  59. m.Result = (IntPtr)HTCAPTION;
  60. return;
  61. }
  62. //拦截双击标题栏、移动窗体的系统消息
  63. if (m.Msg != 0xA3)
  64. {
  65. base.WndProc(ref m);
  66. }
  67. }
  68. #endregion
  69. #region SystemOptition
  70. /// <summary>
  71. /// 操作权限
  72. /// </summary>
  73. /// <returns></returns>
  74. public DataTable RightOfExute()
  75. {
  76. DataTable rData = new DataTable();
  77. rData.Columns.Add("BtnName");
  78. rData.Columns.Add("ActionName");
  79. //查看权限(必须有)
  80. DataRow seeRow = rData.NewRow();
  81. seeRow["BtnName"] = "see";
  82. seeRow["ActionName"] = "查看";
  83. rData.Rows.Add(seeRow);
  84. foreach (Control ctr in panelControl3.Controls)
  85. {
  86. if (ctr.Name == btnFilter.Name || ctr.Name == btnConfig.Name ||
  87. ctr.Name == btnSelect.Name || ctr.Name == btnCanSelect.Name ||
  88. ctr.Name == btnImportMould.Name || ctr.Name == btnOutPut.Name ||
  89. ctr.Name == btnFalsh.Name || ctr.Name == btnExit.Name || ctr.Name == lblTitle.Name || ctr.Name == btnClose.Name)
  90. continue;
  91. DataRow dr = rData.NewRow();
  92. dr["BtnName"] = ctr.Name;
  93. dr["ActionName"] = ctr.Text;
  94. rData.Rows.Add(dr);
  95. }
  96. //List<Control> ControlList = new List<Control>();
  97. //ControlList.Add(btnConfig);
  98. //ControlList.Add(btnAdd);
  99. //ControlList.Add(btnEdit);
  100. //ControlList.Add(btnDelLable);
  101. //foreach (Control ctr in ControlList)
  102. //{
  103. // if (ctr.GetType() == typeof(SimpleButton))
  104. // {
  105. // DataRow dr = rData.NewRow();
  106. // dr["BtnName"] = ctr.Name;
  107. // dr["ActionName"] = ctr.Text;
  108. // rData.Rows.Add(dr);
  109. // }
  110. //}
  111. rData.AcceptChanges();
  112. return rData;
  113. }
  114. /// <summary>
  115. /// 数据权限
  116. /// </summary>
  117. /// <returns></returns>
  118. public DataTable RightOfData()
  119. {
  120. DataTable rData = new DataTable();
  121. rData.Columns.Add("BodyName");
  122. rData.Columns.Add("ControlName");
  123. rData.Columns.Add("ControlCaption");
  124. rData.AcceptChanges();
  125. return rData;
  126. }
  127. #endregion
  128. #region 退出
  129. private void btnClose_Click(object sender, EventArgs e)
  130. {
  131. AppConfig.CloseFormShow(this.Text);
  132. this.Close();
  133. }
  134. private void btnExit_Click(object sender, EventArgs e)
  135. {
  136. AppConfig.CloseFormShow(this.Text);
  137. this.Close();
  138. }
  139. #endregion
  140. #region 过滤
  141. private string tempTableName = "";
  142. private void btnFilter_Click(object sender, EventArgs e)
  143. {
  144. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  145. filter.OldTempTableName = tempTableName;
  146. if (filter.ShowDialog() == DialogResult.OK)
  147. {
  148. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  149. try
  150. {
  151. _wait.Show();
  152. tempTableName = filter.NewTempTableName;
  153. sqltxt = filter.SqlText;
  154. sqlconn = filter.FilterConnectString;
  155. dataSource = filter.FilterData.Tables[0];
  156. grdDetail.DataSource = dataSource;
  157. grvDetail.BestFitColumns();
  158. rptPage.RecordNum = dataSource.Rows.Count;
  159. rptPage.PageSize = 490;
  160. rptPage.PageIndex = 1;
  161. rptPage.ReLoad();
  162. rptPage.PageIndex = 1;
  163. rptPage.PageSize = 500;
  164. rptPage.ReLoad();
  165. _wait.Close();
  166. }
  167. catch (Exception ex)
  168. {
  169. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  170. _wait.Close();
  171. }
  172. }
  173. }
  174. #endregion
  175. #region 全选
  176. private void btnSelect_Click(object sender, EventArgs e)
  177. {
  178. grvDetail.PostEditor();
  179. this.Validate();
  180. for (int i = 0; i < grvDetail.RowCount; i++)
  181. {
  182. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  183. }
  184. }
  185. #endregion
  186. #region 全消
  187. private void btnCanSelect_Click(object sender, EventArgs e)
  188. {
  189. grvDetail.PostEditor();
  190. this.Validate();
  191. for (int i = 0; i < grvDetail.RowCount; i++)
  192. {
  193. grvDetail.SetRowCellValue(i, colisSelect, "");
  194. }
  195. }
  196. #endregion
  197. #region 刷新
  198. private void btnFalsh_Click(object sender, EventArgs e)
  199. {
  200. if (sqlconn == null || sqlconn == "")
  201. {
  202. return;
  203. }
  204. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  205. try
  206. {
  207. _wait.Show();
  208. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  209. filter.OldTempTableName = tempTableName;
  210. //tempTableName = filter.NewTempTableName;
  211. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  212. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  213. grdDetail.DataSource = dataSource;
  214. rptPage.RecordNum = dataSource.Rows.Count;
  215. rptPage.PageIndex = 1;
  216. rptPage.ReLoad();
  217. _wait.Close();
  218. }
  219. catch (Exception ex)
  220. {
  221. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  222. _wait.Close();
  223. }
  224. }
  225. #endregion
  226. #region 列表
  227. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  228. {
  229. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  230. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  231. }
  232. #endregion
  233. #region 双击选择
  234. private void grvDetail_DoubleClick(object sender, EventArgs e)
  235. {
  236. if (grvDetail.FocusedRowHandle < 0)
  237. {
  238. return;
  239. }
  240. if (grvDetail.FocusedColumn == colisSelect)
  241. {
  242. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  243. {
  244. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  245. }
  246. else
  247. {
  248. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  249. }
  250. }
  251. }
  252. #endregion
  253. #region 绑定数据源
  254. private void btnConfig_Click(object sender, EventArgs e)//绑定数据源
  255. {
  256. if (AppConfig.UserCode.ToLower() != "demo")
  257. {
  258. //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  259. return;
  260. }
  261. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  262. fdata.ShowDialog();
  263. }
  264. #endregion
  265. #region 分页
  266. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  267. {
  268. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  269. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  270. grdDetail.DataSource = data;
  271. }
  272. #endregion
  273. #region 加载
  274. private void FormICSFACTORY_Load(object sender, EventArgs e)
  275. {
  276. btnFilter_Click(sender, e);
  277. }
  278. #endregion
  279. #region 增加
  280. private void btnAdd_Click(object sender, EventArgs e)
  281. {
  282. SimpleButton btntemp = (SimpleButton)sender;
  283. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  284. {
  285. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  286. return;
  287. }
  288. FormICSItemOPPriceAdd add = new FormICSItemOPPriceAdd();
  289. add.ShowDialog();
  290. btnFalsh_Click(null, null);
  291. }
  292. #endregion
  293. #region 修改
  294. private void btnEdit_Click(object sender, EventArgs e)
  295. {
  296. SimpleButton btntemp = (SimpleButton)sender;
  297. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  298. {
  299. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  300. return;
  301. }
  302. int count = 0;
  303. for (int i = 0; i < grvDetail.RowCount; i++)
  304. {
  305. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  306. {
  307. count++;
  308. }
  309. }
  310. if (count != 1)
  311. {
  312. ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!");
  313. return;
  314. }
  315. try
  316. {
  317. string id;
  318. for (int i = 0; i < grvDetail.RowCount; i++)
  319. {
  320. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  321. {
  322. id = grvDetail.GetRowCellValue(i, colID).ToString();
  323. FormICSItemOPPriceAdd add = new FormICSItemOPPriceAdd(id);
  324. add.ShowDialog();
  325. }
  326. }
  327. btnFalsh_Click(null, null);
  328. }
  329. catch (Exception ex)
  330. {
  331. //throw ex;
  332. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  333. }
  334. }
  335. #endregion
  336. #region 删除
  337. private void btnDel_Click(object sender, EventArgs e)
  338. {
  339. SimpleButton btntemp = (SimpleButton)sender;
  340. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  341. {
  342. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  343. return;
  344. }
  345. List<string> routecodeList = new List<string>();
  346. for (int i = 0; i < grvDetail.RowCount; i++)
  347. {
  348. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  349. {
  350. routecodeList.Add(grvDetail.GetRowCellValue(i, colID).ToString());
  351. }
  352. }
  353. if (routecodeList.Count == 0 || routecodeList == null)
  354. {
  355. ICSBaseSimpleCode.AppshowMessageBox("请选择数据");
  356. return;
  357. }
  358. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除吗?删除后无法恢复,确定吗?") != DialogResult.OK)
  359. {
  360. btnCanSelect_Click(sender, e);
  361. return;
  362. }
  363. ICSItemOPPriceBLL.deleteInfo(routecodeList, AppConfig.AppConnectString);
  364. ICSBaseSimpleCode.AppshowMessageBox("删除成功");
  365. btnFalsh_Click(null, null);
  366. }
  367. #endregion
  368. #region 导出
  369. private void btnOutPut_Click(object sender, EventArgs e)
  370. {
  371. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  372. foe.ShowDialog();
  373. }
  374. #endregion
  375. #region 导入
  376. private void btnImportData_Click(object sender, EventArgs e)
  377. {
  378. SimpleButton btntemp = (SimpleButton)sender;
  379. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  380. {
  381. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  382. return;
  383. }
  384. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm();
  385. _wait.Hide();
  386. try
  387. {
  388. FormReadExcel fre = new FormReadExcel();
  389. if (fre.ShowDialog() != DialogResult.OK)
  390. {
  391. return;
  392. }
  393. DataTable dataSource = fre._excelData;
  394. if (dataSource == null)
  395. {
  396. throw new Exception("excel数据取得失败");
  397. }
  398. _wait.Show();
  399. _wait.Caption = "判断模版是否正确......";
  400. #region 判断模版是否正确
  401. List<FormReadExcelUIModelColumns> colNameList = new List<FormReadExcelUIModelColumns>();
  402. colNameList.Add(new FormReadExcelUIModelColumns("存货编码", true));
  403. colNameList.Add(new FormReadExcelUIModelColumns("工序代码", true));
  404. colNameList.Add(new FormReadExcelUIModelColumns("价格", true));
  405. foreach (FormReadExcelUIModelColumns columnsName in colNameList)
  406. {
  407. if (!dataSource.Columns.Contains(columnsName.columnsName))
  408. {
  409. throw new Exception("模版不正确,缺少列" + columnsName.columnsName);
  410. }
  411. }
  412. #endregion
  413. _wait.Caption = "数据整理中......";
  414. List<ICSItemOPPrice> InitInvInfoList = new List<ICSItemOPPrice>();
  415. foreach (DataRow dr in dataSource.Rows)
  416. {
  417. ///判断必输项目是否为空
  418. foreach (FormReadExcelUIModelColumns columnsName in colNameList)
  419. {
  420. if (string.IsNullOrWhiteSpace(dr[columnsName.columnsName].ToString()) == true && columnsName.NotNull == true)
  421. {
  422. throw new Exception("列" + columnsName.columnsName + "没有输入值");
  423. }
  424. }
  425. ICSItemOPPrice Info = new ICSItemOPPrice();
  426. Info.ID = AppConfig.GetGuid();
  427. Info.ITEMCODE = dr["存货编码"].ToString();
  428. Info.OPCODE = dr["工序代码"].ToString();
  429. decimal t = 0m;
  430. if (decimal.TryParse(dr["价格"].ToString(), out t))
  431. {
  432. Info.Price = Convert.ToDecimal(dr["价格"].ToString());
  433. }
  434. else
  435. {
  436. throw new Exception("价格格式不正确");
  437. }
  438. Info.EATTRIBUTE1 = "";
  439. InitInvInfoList.Add(Info);
  440. }
  441. _wait.Caption = "导入数据......";
  442. string str= ICSItemOPPriceBLL.AddList(InitInvInfoList, AppConfig.AppConnectString);
  443. _wait.Close();
  444. if (str == "")
  445. {
  446. ICSBaseSimpleCode.AppshowMessageBox("数据导入成功!");
  447. }
  448. else
  449. {
  450. ICSBaseSimpleCode.AppshowMessageBox(str);
  451. }
  452. btnFalsh_Click(null, null);
  453. }
  454. catch (Exception ex)
  455. {
  456. _wait.Close();
  457. ICSBaseSimpleCode.AppshowMessageBox("数据导入失败:" + ex.Message);
  458. }
  459. }
  460. #endregion
  461. #region 导入模板下载
  462. private void btnImportMould_Click(object sender, EventArgs e)
  463. {
  464. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm();
  465. _wait.Hide();
  466. string anjianExcelFileName = Environment.CommandLine.Substring(1, Environment.CommandLine.LastIndexOf("\\")) + "Output\\";
  467. try
  468. {
  469. _wait.Show();
  470. _wait.Caption = "模板下载中......";
  471. SaveFileDialog dlgSaveFileDialog = new SaveFileDialog(); //弹框提示保存
  472. dlgSaveFileDialog.InitialDirectory = anjianExcelFileName; //默认打开目录
  473. dlgSaveFileDialog.FilterIndex = 1;
  474. dlgSaveFileDialog.RestoreDirectory = true;
  475. dlgSaveFileDialog.FileName = "产品工序价格导入模板.xlsx"; //默认保存名称
  476. dlgSaveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
  477. if (dlgSaveFileDialog.ShowDialog() == DialogResult.OK)
  478. {
  479. string fileName = dlgSaveFileDialog.FileName; //获取弹出框选择或填写的文件名称
  480. List<FormReadExcelUIModelColumns> colNameList = new List<FormReadExcelUIModelColumns>();
  481. colNameList.Add(new FormReadExcelUIModelColumns("存货编码", true));
  482. colNameList.Add(new FormReadExcelUIModelColumns("工序代码", true));
  483. colNameList.Add(new FormReadExcelUIModelColumns("价格", true));
  484. FileUtil.exportToExcelFile(fileName, colNameList);
  485. _wait.Close();
  486. ICSBaseSimpleCode.AppshowMessageBox("模板下载成功!");
  487. }
  488. _wait.Close();
  489. }
  490. catch (Exception ex)
  491. {
  492. _wait.Close();
  493. ICSBaseSimpleCode.AppshowMessageBox("模板下载失败:" + ex.Message);
  494. }
  495. }
  496. #endregion
  497. }
  498. }