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.

505 lines
25 KiB

3 weeks ago
  1. using Newtonsoft.Json.Linq;
  2. using Newtonsoft.Json;
  3. using NFine.Code;
  4. using NFine.Data.Extensions;
  5. using NFine.Domain._03_Entity.SRM;
  6. using NFine.Repository;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Configuration;
  10. using System.Data.Common;
  11. using System.Data;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Net;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using NFine.Application.Entity;
  18. using NFine.Application.Models;
  19. namespace NFine.Application.WMS
  20. {
  21. public class ICSPurchaseReceiveApp : RepositoryFactory<ICSVendor>
  22. {
  23. public static DataTable Invmes = new DataTable();
  24. /// <summary>
  25. /// 红字采购入库 删除
  26. /// </summary>
  27. /// <param name="keyValue"></param>
  28. /// <returns></returns>
  29. /// <exception cref="Exception"></exception>
  30. public string DeleteICSPurchaseReceiveApplyNeg(string keyValue)
  31. {
  32. //站点信息
  33. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  34. string msg = "";
  35. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  36. string sql = string.Empty;
  37. sql += string.Format(@"DELETE FROM dbo.ICSPurchaseReceive WHERE RCVCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  38. //sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  39. try
  40. {
  41. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  42. {
  43. }
  44. }
  45. catch (Exception ex)
  46. {
  47. throw new Exception(ex.Message);
  48. }
  49. return msg;
  50. }
  51. /// <summary>
  52. /// 红字采购入库 查询
  53. /// </summary>
  54. /// <param name="jqgridparam"></param>
  55. /// <returns></returns>
  56. public DataTable GetPurchaseReceiveApplyNeg(ref Pagination jqgridparam)
  57. {
  58. DataTable dt = new DataTable();
  59. List<DbParameter> parameter = new List<DbParameter>();
  60. string sql = @"select a.RCVCode,a.MTIME,a.MUSERName from ICSPurchaseReceive a
  61. group by a.RCVCode,a.MTIME,a.MUSERName";
  62. sql = string.Format(sql);
  63. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  64. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  65. }
  66. /// <summary>
  67. /// 红字采购入库 明细查询
  68. /// </summary>
  69. /// <param name="jqgridparam"></param>
  70. /// <returns></returns>
  71. public DataTable GetPurchaseReceiveApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
  72. {
  73. DataTable dt = new DataTable();
  74. object Figure = GetDecimalDigits();
  75. List<DbParameter> parameter = new List<DbParameter>();
  76. string wherestr = "";
  77. if (!string.IsNullOrEmpty(ApplyNegCode))
  78. {
  79. wherestr += " and a.RCVCode = '" + ApplyNegCode + "' ";
  80. }
  81. string sql = @"SELECT a.ID,a.RCVCode,a.Sequence,a.InvCode,a.Quantity,a.RCVQuantity,a.Amount,a.Type,a.SourceCode,a.SourceSequence,b.InvName
  82. ,a.WHCode,e.WarehouseName as WHName,a.Status,a.CreatePerson,a.CreateDateTime
  83. ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  84. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 ,a.EATTRIBUTE,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  85. a.EATTRIBUTE9,a.EATTRIBUTE10
  86. from ICSPurchaseReceive a
  87. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  88. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  89. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  90. where 1 = 1 " + wherestr;
  91. sql = string.Format(sql, Figure);
  92. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  93. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  94. }
  95. public object GetDecimalDigits()
  96. {
  97. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  98. try
  99. {
  100. string sql = string.Empty;
  101. sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
  102. object Figure = SqlHelper.ExecuteScalar(sql);
  103. return Figure;
  104. }
  105. catch (Exception ex)
  106. {
  107. throw new Exception(ex.Message.ToString());
  108. }
  109. }
  110. public void ClearTemp()
  111. {
  112. Invmes.Rows.Clear();
  113. }
  114. ///// <summary>
  115. ///// 新增
  116. ///// </summary>
  117. ///// <param name="ICSASN"></param>
  118. ///// <returns></returns>
  119. //public string SaveICSPurchaseReceiveApplyNeg(string ICSASN)
  120. //{
  121. // string msg = "";
  122. // string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "PurchaseReceive/Create";
  123. // string result = HttpPost(APIURL, ICSASN);
  124. // JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  125. // string MessAge = Obj["Message"].ToString();
  126. // string Success = Obj["Success"].ToString();
  127. // if (Success.ToUpper() == "FALSE")
  128. // {
  129. // msg = MessAge;
  130. // }
  131. // return msg;
  132. //}
  133. ///// <summary>
  134. ///// 修改
  135. ///// </summary>
  136. ///// <param name="ICSASN"></param>
  137. ///// <returns></returns>
  138. //public string UpdateICSPurchaseReceiveApplyNeg(string ICSASN)
  139. //{
  140. // string msg = "";
  141. // string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "PurchaseReceive/Update";
  142. // string result = HttpPost(APIURL, ICSASN);
  143. // JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  144. // string MessAge = Obj["Message"].ToString();
  145. // string Success = Obj["Success"].ToString();
  146. // if (Success.ToUpper() == "FALSE")
  147. // {
  148. // msg = MessAge;
  149. // }
  150. // return msg;
  151. //}
  152. /// <summary>
  153. /// 新增、修改
  154. /// </summary>
  155. /// <param name="ICSASN"></param>
  156. /// <returns></returns>
  157. public string SaveICSPurchaseReceiveApplyNeg(string keyValue, string deleteIDs)
  158. {
  159. string returnValue = string.Empty;
  160. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  161. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  162. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  163. var Dates = DateTime.Now;
  164. string Colspan = string.Empty;
  165. string IDD = string.Empty;
  166. var sql = string.Empty;
  167. try
  168. {
  169. var modelList = JsonConvert.DeserializeObject<List<ICSPurchaseReceiveEdit>>(keyValue);
  170. if (!string.IsNullOrEmpty(deleteIDs))
  171. {
  172. var deleteentityList = deleteIDs.Split(',');
  173. foreach (var item in deleteentityList)
  174. {
  175. if (!string.IsNullOrEmpty(item))
  176. {
  177. var deleteEntity = MsSqlData.Get<Entity.ICSPurchaseReceive>(item);
  178. sql += string.Format(@"DELETE FROM dbo.ICSPurchaseReceive WHERE ID IN ({0}) and WorkPoint ='{1}'", item, WorkPoint);
  179. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  180. {
  181. }
  182. }
  183. }
  184. }
  185. foreach (var model in modelList)
  186. {
  187. if (string.IsNullOrEmpty(model.ID))
  188. {
  189. if (string.IsNullOrEmpty(model.RCVCode))
  190. {
  191. throw new Exception("借用单号错误!");
  192. }
  193. //新增
  194. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSPurchaseReceive where RCVCode ='" + model.RCVCode + "' and Sequence ='" + model.Sequence + "'").ToInt();
  195. if (count > 0)
  196. {
  197. throw new Exception("当前借用单号以及行号已存在");
  198. }
  199. //检验自由项
  200. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  201. + "~" + model.Brand + "~" + model.cFree1
  202. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  203. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  204. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  205. sql = @"select ID,Colspan from ICSExtension a
  206. where Colspan='{0}' and WorkPoint='{1}'";
  207. sql = string.Format(sql, Colspan, model.WorkPoint);
  208. var dttt = SqlHelper.CmdExecuteDataTable(sql);
  209. if (dttt.Rows.Count == 0)
  210. {
  211. IDD = Guid.NewGuid().ToString();
  212. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  213. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  214. sql = string.Format(sql, Colspan, model.ProjectCode, model.BatchCode, model.Version, model.Brand, model.cFree1, model.cFree2, model.cFree3, model.cFree4, model.cFree5, model.cFree6, model.cFree7, model.cFree8, model.cFree9, model.cFree10, model.User, model.WorkPoint, IDD);
  215. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  216. {
  217. throw new Exception("自由项添加失败");
  218. }
  219. }
  220. else
  221. {
  222. IDD = dttt.Rows[0]["ID"].ToString();
  223. }
  224. var entity = new ICSPurchaseReceive();
  225. ConvertExt.Mapping(model, entity);
  226. entity.ID = Guid.NewGuid().ToString();
  227. entity.RCVID = "";
  228. entity.RCVDetailID = "";
  229. //entity.TransferID = "";
  230. //entity.TransferDetailID = "";
  231. entity.Status = "1";
  232. entity.CreatePerson = MUSER;
  233. entity.CreateDateTime = Dates;
  234. entity.MUSER = MUSER;
  235. entity.MUSERName = MUSERNAME;
  236. entity.MTIME = Dates;
  237. entity.WorkPoint = WorkPoint;
  238. entity.ExtensionID = IDD;
  239. var result = MsSqlData.Insert<ICSPurchaseReceive>(entity);
  240. if (!result)
  241. {
  242. returnValue = "借用单单新增失败";
  243. }
  244. }
  245. else
  246. {
  247. //修改
  248. var entity = MsSqlData.Get<ICSPurchaseReceive>(model.ID);
  249. if (entity == null)
  250. {
  251. //新增
  252. if (string.IsNullOrEmpty(model.RCVCode))
  253. {
  254. throw new Exception("借用单号错误!");
  255. }
  256. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSPurchaseReceive where RCVCode ='" + model.RCVCode + "' and Sequence ='" + model.Sequence + "'").ToInt();
  257. if (count > 0)
  258. {
  259. throw new Exception("当前借用单号以及行号已存在");
  260. }
  261. //检验自由项
  262. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  263. + "~" + model.Brand + "~" + model.cFree1
  264. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  265. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  266. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  267. sql = @"select ID,Colspan from ICSExtension a
  268. where Colspan='{0}' and WorkPoint='{1}'";
  269. sql = string.Format(sql, Colspan, model.WorkPoint);
  270. var dttt = SqlHelper.CmdExecuteDataTable(sql);
  271. if (dttt.Rows.Count == 0)
  272. {
  273. IDD = Guid.NewGuid().ToString();
  274. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  275. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  276. sql = string.Format(sql, Colspan, model.ProjectCode, model.BatchCode, model.Version, model.Brand, model.cFree1, model.cFree2, model.cFree3, model.cFree4, model.cFree5, model.cFree6, model.cFree7, model.cFree8, model.cFree9, model.cFree10, model.User, model.WorkPoint, IDD);
  277. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  278. {
  279. throw new Exception("自由项添加失败");
  280. }
  281. }
  282. else
  283. {
  284. IDD = dttt.Rows[0]["ID"].ToString();
  285. }
  286. entity = new ICSPurchaseReceive();
  287. ConvertExt.Mapping<ICSPurchaseReceiveEdit, ICSPurchaseReceive>(model, entity);
  288. entity.ID = Guid.NewGuid().ToString();
  289. entity.RCVID = "";
  290. entity.RCVDetailID = "";
  291. //entity.TransferID = "";
  292. //entity.TransferDetailID = "";
  293. entity.CreatePerson = MUSER;
  294. entity.CreateDateTime = Dates;
  295. entity.Status = "1";
  296. entity.MUSER = MUSER;
  297. entity.MUSERName = MUSERNAME;
  298. entity.MTIME = Dates;
  299. entity.WorkPoint = WorkPoint;
  300. entity.ExtensionID = IDD;
  301. var result = MsSqlData.Insert<ICSPurchaseReceive>(entity);
  302. if (!result)
  303. {
  304. returnValue = "新增失败";
  305. }
  306. }
  307. else
  308. {
  309. //检验自由项
  310. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  311. + "~" + model.Brand + "~" + model.cFree1
  312. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  313. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  314. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  315. sql = @"select ID,Colspan from ICSExtension a
  316. where Colspan='{0}' and WorkPoint='{1}'";
  317. sql = string.Format(sql, Colspan, model.WorkPoint);
  318. var dtt = SqlHelper.CmdExecuteDataTable(sql);
  319. if (dtt.Rows.Count == 0)
  320. {
  321. IDD = Guid.NewGuid().ToString();
  322. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  323. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  324. sql = string.Format(sql, Colspan, model.ProjectCode, model.BatchCode, model.Version, model.Brand, model.cFree1, model.cFree2, model.cFree3, model.cFree4, model.cFree5, model.cFree6, model.cFree7, model.cFree8, model.cFree9, model.cFree10, model.User, model.WorkPoint, IDD);
  325. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  326. {
  327. throw new Exception("自由项添加失败");
  328. }
  329. }
  330. else
  331. {
  332. IDD = dtt.Rows[0]["ID"].ToString();
  333. }
  334. ConvertExt.Mapping<ICSPurchaseReceiveEdit, ICSPurchaseReceive>(model, entity);
  335. entity.RCVID = "";
  336. entity.RCVDetailID = "";
  337. //entity.TransferID = "";
  338. //entity.TransferDetailID = "";
  339. entity.CreatePerson = MUSER;
  340. entity.CreateDateTime = Dates;
  341. entity.MUSER = MUSER;
  342. entity.MUSERName = MUSERNAME;
  343. entity.MTIME = Dates;
  344. entity.ExtensionID = IDD;
  345. var result = MsSqlData.Update<ICSPurchaseReceive>(entity);
  346. if (!result)
  347. {
  348. returnValue = "修改失败";
  349. }
  350. }
  351. }
  352. }
  353. }
  354. catch (Exception ex)
  355. {
  356. returnValue = ex.Message;
  357. }
  358. return returnValue;
  359. }
  360. /// <summary>
  361. /// 获取单号
  362. /// </summary>
  363. /// <param name="WorkPoint"></param>
  364. /// <returns></returns>
  365. public string GetCode(string WorkPoint)
  366. {
  367. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  368. string OOCode = string.Empty;
  369. if (!string.IsNullOrEmpty(WorkPoint))
  370. {
  371. OOCode = GetSerialCode(WorkPoint, "ICSPurchaseReceive", "RCVCode", "00", 8);
  372. }
  373. if (!string.IsNullOrWhiteSpace(OOCode))
  374. {
  375. string sqlISHave = @"SELECT RCVCode FROM ICSPurchaseReceive a
  376. WHERE a.RCVCode = '{0}'";
  377. sqlISHave = string.Format(sqlISHave, OOCode);
  378. DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave);
  379. if (dtIsHave.Rows.Count > 0)
  380. {
  381. throw new Exception("单号已存在!");
  382. }
  383. }
  384. return OOCode;
  385. }
  386. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  387. {
  388. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  389. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  390. return SqlHelper.ExecuteScalar(sql).ToString();
  391. }
  392. public void UpdatePurchaseReceiveOrderApplyNegTemp(string json)
  393. {
  394. var data = json.ToJObject();
  395. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  396. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  397. if (info != null && info.Length > 0)
  398. {
  399. info[0]["ZJID"] = data["ZJID"];
  400. info[0]["InvName"] = data["InvName"];
  401. }
  402. else
  403. {
  404. DataRow newrow = Invmes.NewRow();
  405. newrow["ZJID"] = data["ZJID"];
  406. Invmes.Rows.Add(newrow);
  407. }
  408. }
  409. public DataTable GetICSPurchaseReceiveReturnTemporary(string RCVCode)
  410. {
  411. string sql = @"SELECT a.ID,a.RCVCode,a.Sequence,a.InvCode,a.Quantity,a.RCVQuantity,a.Amount,a.Type,a.SourceCode as POCode,a.SourceSequence as POSequence
  412. ,a.WHCode,e.WarehouseName as WHName,a.Status,a.CreatePerson,a.CreateDateTime,b.InvName
  413. ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  414. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 ,a.EATTRIBUTE,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  415. a.EATTRIBUTE9,a.EATTRIBUTE10
  416. from ICSPurchaseReceive a
  417. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  418. left join ICSPurchaseOrder d on a.SourceCode = d.POCode and a.SourceSequence = d.Sequence and a.WorkPoint=d.WorkPoint
  419. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  420. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  421. where a.RCVCode ='" + RCVCode + "' ";
  422. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  423. DataTable dtCloned = table.Clone();
  424. foreach (DataColumn col in dtCloned.Columns)
  425. {
  426. col.DataType = typeof(string);
  427. }
  428. foreach (DataRow row in table.Rows)
  429. {
  430. DataRow newrow = dtCloned.NewRow();
  431. foreach (DataColumn column in dtCloned.Columns)
  432. {
  433. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  434. }
  435. dtCloned.Rows.Add(newrow);
  436. }
  437. if (Invmes.Rows.Count > 0)
  438. {
  439. dtCloned.Merge(Invmes, false);
  440. }
  441. return dtCloned;
  442. }
  443. /// <summary>
  444. /// 接口api解析
  445. /// </summary>
  446. /// <param name="url"></param>
  447. /// <param name="body"></param>
  448. /// <returns></returns>
  449. /// <exception cref="Exception"></exception>
  450. public static string HttpPost(string url, string body)
  451. {
  452. try
  453. {
  454. Encoding encoding = Encoding.UTF8;
  455. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  456. request.Method = "POST";
  457. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  458. request.ContentType = "application/json; charset=utf-8";
  459. byte[] buffer = encoding.GetBytes(body);
  460. request.ContentLength = buffer.Length;
  461. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  462. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  463. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  464. {
  465. return reader.ReadToEnd();
  466. }
  467. }
  468. catch (WebException ex)
  469. {
  470. throw new Exception(ex.Message);
  471. }
  472. }
  473. }
  474. }