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

583 lines
25 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 FormICSIntSupCalLog : 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_AppVouchNB";
  35. #region 构造函数
  36. public FormICSIntSupCalLog()
  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 mocode = grvDetail.GetRowCellValue(i, colMOCODE).ToString();
  342. string moseq = grvDetail.GetRowCellValue(i, Colmoseq).ToString();
  343. string eqpcode = grvDetail.GetRowCellValue(i, Coleqpcode).ToString();
  344. string opcode = grvDetail.GetRowCellValue(i, COlopcode).ToString();
  345. string invcode = grvDetail.GetRowCellValue(i, ColInvcode).ToString();
  346. if (Convert.ToDecimal(grvDetail.GetRowCellValue(i, ColCanUpqty)) <= 0)
  347. {
  348. ICSBaseSimpleCode.AppshowMessageBox("生产订单号:" + mocode + ",行号:" + moseq + ",设备编码:" + eqpcode + ",工序编码:" + opcode + "无可上传数量,请确认!");
  349. return;
  350. }
  351. if (string.IsNullOrEmpty(grvDetail.GetRowCellValue(i, unitprice).ToString())) {
  352. ICSBaseSimpleCode.AppshowMessageBox("物料编码:" + invcode + ",工序编码:" + opcode + "未维护单价,,请确认!");
  353. return;
  354. }
  355. row.Add(grvDetail.GetRow(i) as DataRowView);
  356. }
  357. }
  358. if (row.Count < 0) {
  359. ICSBaseSimpleCode.AppshowMessageBox("请选择要上传的数据!");
  360. return;
  361. }
  362. if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定产生委外请购单吗?") != DialogResult.OK)
  363. {
  364. return;
  365. }
  366. //新增
  367. FormICSERPVendor vendor = new FormICSERPVendor();
  368. if (vendor.ShowDialog() != DialogResult.OK)
  369. {
  370. return;
  371. }
  372. string vendorcode = vendor.vencode;
  373. DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在创建...请稍等...");
  374. try
  375. {
  376. _wait.Show();
  377. //从配置中获取
  378. string _EnumKey = "00010";
  379. string sqlcInvCCode = @"SELECT DISTINCT EnumText from Sys_EnumValues WHERE EnumKey='" + _EnumKey + "' ";
  380. DataTable dtcInvCCode = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqlcInvCCode).Tables[0];
  381. string _cInvCCode = string.Empty;
  382. if (dtcInvCCode != null && dtcInvCCode.Rows.Count > 0)
  383. {
  384. _cInvCCode = dtcInvCCode.Rows[0][0].ToString();
  385. }
  386. List<PU_AppVouchs> contextsWWList = new List<PU_AppVouchs>();
  387. List<PU_AppVouch> listcontextWW = new List<PU_AppVouch>();
  388. List<string> de = new List<string>();
  389. PU_AppVouch contextWW = new PU_AppVouch();
  390. contextWW.UserCode = AppConfig.UserCode;
  391. contextWW.UserName = AppConfig.UserName;
  392. contextWW.TargetAccount = ConfigurationManager.AppSettings["TargetAccountU8"];
  393. contextWW.Vencode = vendorcode;
  394. string sqladdress = "select '['+DBIPADDRESS+']'+'.'+DBNAME as address from Sys_DataBase where dbsourcename='ERP'";
  395. string ipaddress = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqladdress).Tables[0].Rows[0]["address"].ToString();
  396. //产生ERP请购单
  397. foreach (DataRowView a in row)
  398. {
  399. string MOCode = a.Row["工单号"].ToString();
  400. string MOSEQ = a.Row["工单行"].ToString();
  401. //查询工单部门
  402. string sqldepart = @"SELECT MDeptCode,b.closetime
  403. FROM " + ipaddress + @".dbo.mom_order a
  404. INNER JOIN " + ipaddress + @".dbo.mom_orderdetail b ON a.MoId = b.MoId
  405. WHERE a.MoCode = '" + MOCode + "' and b.SortSeq='" + MOSEQ + "'";
  406. DataTable depart = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sqldepart).Tables[0];
  407. if (depart.Rows.Count > 0)
  408. {
  409. if (!de.Contains(depart.Rows[0]["MDeptCode"].ToString()))
  410. {
  411. de.Add(depart.Rows[0]["MDeptCode"].ToString());
  412. }
  413. if (!String.IsNullOrEmpty(depart.Rows[0]["closetime"].ToString())) {
  414. ICSBaseSimpleCode.AppshowMessageBox("工单号:"+MOCode+",工单行:"+MOSEQ+"已关闭!");
  415. _wait.Close();
  416. return;
  417. }
  418. }
  419. if (de.Count == 0)
  420. {
  421. ICSBaseSimpleCode.AppshowMessageBox("获取工单部门失败!");
  422. _wait.Close();
  423. return;
  424. }
  425. if (de.Count > 1)
  426. {
  427. ICSBaseSimpleCode.AppshowMessageBox("请选择相同部门的数据!");
  428. _wait.Close();
  429. return;
  430. }
  431. contextWW.cDepCode = depart.Rows[0]["MDeptCode"].ToString();
  432. PU_AppVouchs contextsWW = new PU_AppVouchs();
  433. contextsWW.cInvCCode = _cInvCCode;//物料大类
  434. contextsWW.cInvCode = a.Row["物料编码"].ToString();//料号
  435. contextsWW.cInvName = a.Row["物料名称"].ToString();//料号名称
  436. contextsWW.OPCode = a.Row["工序编码"].ToString();//工序
  437. contextsWW.iQuantity = Decimal.Parse(a.Row["本次可上传数量"].ToString());
  438. contextsWW.iNum = Convert.ToInt32(MOSEQ);// lotinfo.LOTQTY * Convert.ToDecimal(lotinfo.EATTRIBUTE3);
  439. contextsWW.PRLine = a.Row["工序名称"].ToString(); //contextsWW.cBatch = lotinfo.VenderLotNO;
  440. contextsWW.MOCode = MOCode;//工单号
  441. contextsWW.dArriveDate = Convert.ToDateTime(a.Row["MOPLANENDTIME"].ToString()).ToShortDateString();
  442. contextsWW.dRequirDate = DateTime.Now.ToShortDateString();
  443. //contextsWW.LotNo = _dr["LOTNO"].ToString();//产品产品跟踪单号 2020.7.13 delete by summer
  444. contextsWW.LotNo = a.Row["设备编码"].ToString();//报工设备
  445. if (!string.IsNullOrEmpty(a.Row["unitprice"].ToString()))//单价
  446. contextsWW.Price = (decimal)a.Row["unitprice"];
  447. contextsWWList.Add(contextsWW);
  448. }
  449. contextWW.list = contextsWWList;
  450. listcontextWW.Add(contextWW);
  451. string WWPR = JsonConvert.SerializeObject(listcontextWW);
  452. string iresultMO = HttpPost(DataCollectWW, WWPR);
  453. U8Result INVINResultMO = new U8Result();
  454. INVINResultMO = JsonConvert.DeserializeObject<U8Result>(iresultMO);
  455. StringBuilder str = new StringBuilder();
  456. str.AppendLine("创建U8委外请购单接口:" + WWPR);
  457. str.AppendLine("接口返回结果:" + INVINResultMO.code);
  458. str.AppendLine("接口返回数据:" + INVINResultMO.msg);
  459. ICSMO2UserDAL.WriteLogFile(str.ToString(), "创建U8委外请购单接口");
  460. if (INVINResultMO.code != "200")
  461. {
  462. _wait.Close();
  463. ICSBaseSimpleCode.AppshowMessageBox(INVINResultMO.msg);
  464. return;
  465. }
  466. List<PU_AppVouchs> _list = new List<PU_AppVouchs>();
  467. if (!string.IsNullOrWhiteSpace(INVINResultMO.msg))
  468. {
  469. _list = JsonConvert.DeserializeObject<List<PU_AppVouchs>>(INVINResultMO.msg.ToString());
  470. }
  471. else
  472. {
  473. _wait.Close();
  474. throw new Exception("未获取到请购单数据!");
  475. }
  476. //调用成功插入ICSIntSupCalLog表
  477. foreach (var item in _list)
  478. {
  479. var qty=contextsWWList.Where(a => a.LotNo == item.LotNo && a.MOCode == item.MOCode && a.iNum == item.iNum && a.OPCode == item.OPCode).Select(a=>a.iQuantity).FirstOrDefault();
  480. string UpdateSql = "insert into ICSIntSupCalLog values(newid(),'"+item.MOCode+"','"+item.iNum+"','"+item.LotNo+"','"+item.OPCode+"','"+item.PRLine+"','"+qty+"',NULL,'false',null,null,null)";
  481. DBHelper.ExecuteNonQuery(AppConfig.AppConnectString, CommandType.Text, UpdateSql);
  482. }
  483. _wait.Close();
  484. ICSBaseSimpleCode.AppshowMessageBox("产生委外请购单成功!");
  485. btnRefresh_Click(null, null);
  486. }
  487. catch (Exception ex) {
  488. _wait.Close();
  489. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  490. }
  491. }
  492. public static string HttpPost(string url, string body)
  493. {
  494. try
  495. {
  496. System.Text.Encoding encoding = Encoding.UTF8;
  497. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  498. request.Method = "POST";
  499. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  500. request.ContentType = "application/json; charset=utf-8";
  501. byte[] buffer = encoding.GetBytes(body);
  502. request.ContentLength = buffer.Length;
  503. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  504. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  505. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  506. {
  507. return reader.ReadToEnd();
  508. }
  509. }
  510. catch (WebException ex)
  511. {
  512. var res = (HttpWebResponse)ex.Response;
  513. StringBuilder sb = new StringBuilder();
  514. StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
  515. sb.Append(sr.ReadToEnd());
  516. throw new Exception(sb.ToString());
  517. }
  518. }
  519. private void grvDetail_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
  520. {
  521. if (grvDetail.GetFocusedRowCellValue(ColPrline).ToString() != ""&&(grvDetail.FocusedColumn==unitprice|| grvDetail.FocusedColumn == totalprice|| grvDetail.FocusedColumn ==memo)) {
  522. e.Cancel = true;
  523. }
  524. }
  525. }
  526. }