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

519 lines
20 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using DevExpress.XtraEditors;
  7. using ICSSoft.Base.Config.AppConfig;
  8. using ICSSoft.Base.Config.DBHelper;
  9. using ICSSoft.Base.Report.Filter;
  10. using ICSSoft.Base.UserControl.FormControl;
  11. using ICSSoft.Frame.Data.BLL;
  12. using ICSSoft.Frame.Data.Entity;
  13. using ICSSoft.Entity.PU_AppVouch;
  14. using System.Configuration;
  15. using Newtonsoft.Json;
  16. using System.Text;
  17. using System.Net;
  18. using System.IO;
  19. using ICSSoft.Frame.Data.Entity.WWModel;
  20. using ICSSoft.Frame.Data.DAL;
  21. using System.Linq;
  22. namespace ICSSoft.Frame.APP
  23. {
  24. public partial class FormICSIntSupCal : DevExpress.XtraEditors.XtraForm
  25. {
  26. private string sqltxt = "";
  27. private string sqlconn = "";
  28. String guid = AppConfig.GetGuid();
  29. private DataTable dataSource = null;
  30. private DataTable body = null;
  31. private DataSet ds = new DataSet();
  32. static string APIURL = System.Configuration.ConfigurationSettings.AppSettings["APIURL"].ToString();
  33. //static string APIURL = "http://localhost:51182/api/";
  34. static string DataCollectWW = APIURL + "APICreateInventory_PU_AppVouch";
  35. #region 构造函数
  36. public FormICSIntSupCal()
  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(btnFilter);
  56. ControlList.Add(btnSelectAll);
  57. ControlList.Add(btnCancelAll);
  58. ControlList.Add(btnCreate);
  59. ControlList.Add(btnOutPut);
  60. ControlList.Add(btnRefresh);
  61. foreach (Control ctr in ControlList)
  62. {
  63. if (ctr.GetType() == typeof(SimpleButton))
  64. {
  65. DataRow dr = rData.NewRow();
  66. dr["BtnName"] = ctr.Name;
  67. dr["ActionName"] = ctr.Text;
  68. rData.Rows.Add(dr);
  69. }
  70. }
  71. rData.AcceptChanges();
  72. return rData;
  73. }
  74. public DataTable RightOfData()// 数据权限
  75. {
  76. DataTable rData = new DataTable();
  77. rData.Columns.Add("BodyName");
  78. rData.Columns.Add("ControlName");
  79. rData.Columns.Add("ControlCaption");
  80. rData.AcceptChanges();
  81. return rData;
  82. }
  83. #endregion
  84. #region 退出
  85. private void btnClose_Click(object sender, EventArgs e)
  86. {
  87. AppConfig.CloseFormShow(this.Text);
  88. this.Close();
  89. }
  90. private void btnExit_Click(object sender, EventArgs e)
  91. {
  92. AppConfig.CloseFormShow(this.Text);
  93. this.Close();
  94. }
  95. #endregion
  96. #region 移动窗体
  97. private const int WM_NCHITTEST = 0x84;
  98. private const int HTCLIENT = 0x1;
  99. private const int HTCAPTION = 0x2;
  100. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  101. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  102. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  103. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  104. //重写窗体,使窗体可以不通过自带标题栏实现移动
  105. protected override void WndProc(ref Message m)
  106. {
  107. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  108. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  109. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  110. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  111. switch (m.Msg)
  112. {
  113. case WM_NCHITTEST:
  114. base.WndProc(ref m);
  115. if ((int)m.Result == HTCLIENT)
  116. m.Result = (IntPtr)HTCAPTION;
  117. return;
  118. }
  119. //拦截双击标题栏、移动窗体的系统消息
  120. if (m.Msg != 0xA3)
  121. {
  122. base.WndProc(ref m);
  123. }
  124. }
  125. #endregion
  126. #region 列表
  127. private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  128. {
  129. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  130. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  131. }
  132. #endregion
  133. #region 过滤
  134. private string tempTableName = "";
  135. private void btnFilter_Click(object sender, EventArgs e)
  136. {
  137. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name));
  138. filter.OldTempTableName = tempTableName;
  139. if (filter.ShowDialog() == DialogResult.OK)
  140. {
  141. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  142. try
  143. {
  144. _wait.Show();
  145. ds.Reset();
  146. dataSource = null;
  147. body = null;
  148. tempTableName = filter.NewTempTableName;
  149. sqltxt = filter.SqlText;
  150. sqlconn = filter.FilterConnectString;
  151. dataSource = filter.FilterData.Tables[0];
  152. dataSource.TableName = "Hand";
  153. ds.Tables.Add(dataSource.Copy());
  154. grdDetail.DataSource = ds.Tables["Hand"];
  155. grvDetail.BestFitColumns();
  156. rptPage.RecordNum = dataSource.Rows.Count;
  157. rptPage.PageSize = 499;
  158. rptPage.PageIndex = 1;
  159. rptPage.ReLoad();
  160. rptPage.PageSize = 500;
  161. rptPage.PageIndex = 1;
  162. //rptPage.ReLoad();
  163. _wait.Close();
  164. }
  165. catch (Exception ex)
  166. {
  167. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  168. _wait.Close();
  169. }
  170. }
  171. }
  172. #endregion
  173. #region 绑定数据源
  174. private void btnConfig_Click(object sender, EventArgs e)
  175. {
  176. if (AppConfig.UserCode.ToLower() != "demo")
  177. {
  178. ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!");
  179. return;
  180. }
  181. FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name);
  182. fdata.ShowDialog();
  183. }
  184. #endregion
  185. #region 分页
  186. private void rptPage_PageIndexChanged(object Sender, EventArgs e)
  187. {
  188. DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
  189. ds.Tables.Add(dataSource.Copy());
  190. ds.Tables.Add(body.Copy());
  191. DataRelation dr = new DataRelation("详情", new DataColumn[] { ds.Tables["Hand"].Columns["VouchCode"] }, new DataColumn[] { ds.Tables["Body"].Columns["VouchCode"] });
  192. ds.Relations.Add(dr);
  193. grdDetail.DataSource = ds.Tables["Hand"];
  194. //DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
  195. grdDetail.DataSource = data;
  196. }
  197. #endregion
  198. #region 过滤方法
  199. private void FormContainerManager_FormClosing(object sender, FormClosingEventArgs e)
  200. {
  201. AppConfig.DropTemTable(tempTableName);
  202. }
  203. #endregion
  204. #region 全选
  205. private void btnSelectAll_Click(object sender, EventArgs e)
  206. {
  207. grvDetail.PostEditor();
  208. this.Validate();
  209. for (int i = 0; i < grvDetail.RowCount; i++)
  210. {
  211. grvDetail.SetRowCellValue(i, colisSelect, "Y");
  212. }
  213. }
  214. #endregion
  215. #region 全消
  216. private void btnCancelAll_Click(object sender, EventArgs e)
  217. {
  218. grvDetail.PostEditor();
  219. this.Validate();
  220. for (int i = 0; i < grvDetail.RowCount; i++)
  221. {
  222. grvDetail.SetRowCellValue(i, colisSelect, "");
  223. }
  224. }
  225. #endregion
  226. #region 双击
  227. private void grvDetail_DoubleClick(object sender, EventArgs e)
  228. {
  229. if (grvDetail.FocusedRowHandle < 0)
  230. {
  231. return;
  232. }
  233. if (grvDetail.FocusedColumn == colisSelect)
  234. {
  235. if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
  236. {
  237. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
  238. }
  239. else
  240. {
  241. grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
  242. }
  243. }
  244. }
  245. #endregion
  246. #region 导出
  247. private void btnOutPut_Click(object sender, EventArgs e)
  248. {
  249. try
  250. {
  251. FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), grdDetail);
  252. foe.ShowDialog();
  253. }
  254. catch (Exception ex)
  255. {
  256. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  257. }
  258. //SimpleButton btntemp = (SimpleButton)sender;
  259. //if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  260. //{
  261. // ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  262. // return;
  263. //}
  264. //FormOutExcel foe = new FormOutExcel();
  265. //if (foe.ShowDialog() == DialogResult.OK)
  266. //{
  267. // try
  268. // {
  269. // string outtype = foe._OutType;
  270. // string exceltype = foe._ExcelType;
  271. // string filename = foe._FileName;
  272. // string url = foe._Url;
  273. // string sheetname = foe._SheetName;
  274. // if (outtype.ToLower() == "excel")
  275. // {
  276. // DevExpress.XtraPrinting.XlsExportOptions op = new DevExpress.XtraPrinting.XlsExportOptions();
  277. // op.SheetName = sheetname;
  278. // grdDetail.MainView.ExportToXls((url + "\\" + filename + (exceltype == "2003" ? ".xls" : ".xlsx")), op);
  279. // }
  280. // else
  281. // {
  282. // grdDetail.MainView.ExportToPdf(url + "\\" + filename + ".pdf");
  283. // }
  284. // MessageBox.Show("导出成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  285. // }
  286. // catch (Exception ex)
  287. // {
  288. // MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  289. // }
  290. //}
  291. }
  292. #endregion
  293. #region 刷新
  294. private void btnRefresh_Click(object sender, EventArgs e)
  295. {
  296. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等...");
  297. try
  298. {
  299. _wait.Show();
  300. ds.Reset();
  301. dataSource = null;
  302. body = null;
  303. FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false);
  304. filter.OldTempTableName = tempTableName;
  305. //tempTableName = filter.NewTempTableName;
  306. //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0];
  307. dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt).Tables[0];
  308. dataSource.TableName = "Hand";
  309. ds.Tables.Add(dataSource.Copy());
  310. grdDetail.DataSource = ds.Tables["Hand"];
  311. grvDetail.BestFitColumns();
  312. rptPage.RecordNum = dataSource.Rows.Count;
  313. rptPage.PageIndex = 1;
  314. //rptPage.ReLoad();
  315. _wait.Close();
  316. }
  317. catch (Exception ex)
  318. {
  319. MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
  320. _wait.Close();
  321. }
  322. }
  323. #endregion
  324. private void FormICSMO_Load(object sender, EventArgs e)
  325. {
  326. btnFilter_Click(sender, e);
  327. }
  328. private void btnCreate_Click(object sender, EventArgs e)
  329. {
  330. SimpleButton btntemp = (SimpleButton)sender;
  331. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  332. {
  333. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  334. return;
  335. }
  336. List<DataRowView> row = new List<DataRowView>();
  337. for (int i = 0; i < grvDetail.RowCount; i++)
  338. {
  339. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  340. {
  341. string PRCODE = grvDetail.GetRowCellValue(i, Colprcode).ToString();
  342. string PRLINE = grvDetail.GetRowCellValue(i, Colprline).ToString();
  343. string prlineid= grvDetail.GetRowCellValue(i, Colprlineid).ToString();
  344. if (string.IsNullOrEmpty(PRCODE)) {
  345. ICSBaseSimpleCode.AppshowMessageBox("请购单行id:"+prlineid+"关联的请购单号不存在或已删除!");
  346. return;
  347. }
  348. if (string.IsNullOrEmpty(grvDetail.GetRowCellValue(i,ColPocode).ToString()))
  349. {
  350. ICSBaseSimpleCode.AppshowMessageBox("请购单号:"+ PRCODE+",请购单行:"+PRLINE+"还未关联采购单!");
  351. return;
  352. }
  353. if (grvDetail.GetRowCellValue(i, cState).ToString() != "1") {
  354. ICSBaseSimpleCode.AppshowMessageBox("请先审核采购单:"+ grvDetail.GetRowCellValue(i, ColPocode).ToString()+"!");
  355. return;
  356. }
  357. row.Add(grvDetail.GetRow(i) as DataRowView);
  358. }
  359. }
  360. if (row.Count < 0)
  361. {
  362. ICSBaseSimpleCode.AppshowMessageBox("请选择要结算的数据!");
  363. return;
  364. }
  365. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定结算?") != DialogResult.OK)
  366. {
  367. return;
  368. }
  369. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在创建...请稍等...");
  370. try
  371. {
  372. List<ICSIntSupCalLog> list = new List<ICSIntSupCalLog>();
  373. foreach (DataRowView a in row)
  374. {
  375. ICSIntSupCalLog cal = new ICSIntSupCalLog();
  376. cal.id = a.Row["ID"].ToString();
  377. cal.Prqty = Convert.ToDecimal(a.Row["请购数量"]);
  378. cal.Mocode = a.Row["工单号"].ToString();
  379. cal.Moseq = a.Row["工单行"].ToString();
  380. cal.Pocode = a.Row["poid"].ToString() + "-" + a.Row["podid"].ToString();
  381. cal.Opcode = a.Row["工序编码"].ToString();
  382. list.Add(cal);
  383. }
  384. ICSIntSupCalBLL.Calculate(list, AppConfig.AppConnectString);
  385. _wait.Close();
  386. ICSBaseSimpleCode.AppshowMessageBox("结算成功!");
  387. btnRefresh_Click(null, null);
  388. }
  389. catch (Exception ex)
  390. {
  391. _wait.Close();
  392. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  393. }
  394. }
  395. public static string HttpPost(string url, string body)
  396. {
  397. try
  398. {
  399. System.Text.Encoding encoding = Encoding.UTF8;
  400. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  401. request.Method = "POST";
  402. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  403. request.ContentType = "application/json; charset=utf-8";
  404. byte[] buffer = encoding.GetBytes(body);
  405. request.ContentLength = buffer.Length;
  406. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  407. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  408. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  409. {
  410. return reader.ReadToEnd();
  411. }
  412. }
  413. catch (WebException ex)
  414. {
  415. var res = (HttpWebResponse)ex.Response;
  416. StringBuilder sb = new StringBuilder();
  417. StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
  418. sb.Append(sr.ReadToEnd());
  419. throw new Exception(sb.ToString());
  420. }
  421. }
  422. private void simpleButton1_Click(object sender, EventArgs e)
  423. {
  424. SimpleButton btntemp = (SimpleButton)sender;
  425. if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
  426. {
  427. ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
  428. return;
  429. }
  430. List<DataRowView> row = new List<DataRowView>();
  431. for (int i = 0; i < grvDetail.RowCount; i++)
  432. {
  433. if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
  434. {
  435. string prlineid = grvDetail.GetRowCellValue(i, Colprlineid).ToString();
  436. if (!string.IsNullOrEmpty(grvDetail.GetRowCellValue(i, Colprcode).ToString()))
  437. {
  438. ICSBaseSimpleCode.AppshowMessageBox("请先删除u8请购单数据!");
  439. return;
  440. }
  441. row.Add(grvDetail.GetRow(i) as DataRowView);
  442. }
  443. }
  444. if (row.Count <=0)
  445. {
  446. ICSBaseSimpleCode.AppshowMessageBox("请选择要撤销上传的数据!");
  447. return;
  448. }
  449. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定撤销上传吗?") != DialogResult.OK)
  450. {
  451. return;
  452. }
  453. try
  454. {
  455. List<string> id = new List<string>();
  456. foreach (var a in row)
  457. {
  458. id.Add(a.Row["ID"].ToString());
  459. }
  460. ICSIntSupCalBLL.Delete(id, AppConfig.AppConnectString);
  461. ICSBaseSimpleCode.AppshowMessageBox("操作成功!");
  462. btnRefresh_Click(null,null);
  463. }
  464. catch (Exception ex) {
  465. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  466. }
  467. }
  468. }
  469. }