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.

485 lines
20 KiB

  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. using Newtonsoft.Json.Linq;
  18. using NFine.Domain._03_Entity.WMS;
  19. using System.Net;
  20. using System.IO;
  21. namespace NFine.Application.WMS
  22. {
  23. public class ICSMOApp: RepositoryFactory<ICSVendor>
  24. {
  25. public static DataTable Invmes = new DataTable();
  26. // public static DataTable Supplier = new DataTable();
  27. /// <summary>
  28. /// 退料
  29. /// </summary>
  30. /// <param name="jqgridparam"></param>
  31. /// <returns></returns>
  32. public DataTable GetICSMOApplyNeg(ref Pagination jqgridparam)
  33. {
  34. DataTable dt = new DataTable();
  35. List<DbParameter> parameter = new List<DbParameter>();
  36. string sql = @"select a.mocode, a.MUSER,a.MUSERName as CreatePerson ,a.MOstatus from ICSMO a
  37. --LEFT JOIN ICSType d ON d.TableCode='ICSMO' AND d.ColumnCode='MOStatus' AND a.MOStatus=d.Code AND a.WorkPoint=d.WorkPoint
  38. group by a.mocode,a.CreatePerson,a.CreateDateTime, a.MUSER,a.MUSERName,a.MOstatus
  39. having 1=1 and a.MOStatus<>'3' ";
  40. sql = string.Format(sql);
  41. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  42. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  43. }
  44. //子表查询
  45. public DataTable GetICSMOApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
  46. {
  47. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  48. DataTable dt = new DataTable();
  49. //var queryParam = queryJson.ToJObject();
  50. List<DbParameter> parameter = new List<DbParameter>();
  51. string sql = @"select a.id ,a.MOcode,a.Sequence,a.InvCode,a.Quantity,a.RCVQuantity,a.CreatePerson,a.CreateDateTime, a.MUSER,a.MUSERName,a.MTIME,a.ExtensionID,
  52. f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  53. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 ,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  54. a.EATTRIBUTE9,a.EATTRIBUTE10 from ICSMO a
  55. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  56. where a.MOStatus<> '3' and a.MOCode = '" + ApplyNegCode + "' ";
  57. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  58. }
  59. public DataTable GetINV(string invcode, ref Pagination jqgridparam)
  60. {
  61. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  62. List<DbParameter> parameter = new List<DbParameter>();
  63. DataTable table = new DataTable();
  64. string wherestr = "";
  65. if (!string.IsNullOrEmpty(invcode))
  66. {
  67. wherestr += " and InvCode like '%" + invcode + "%'";
  68. }
  69. string sql = @"select ID, InvCode ,InvName ,InvStd ,InvUnit ,ClassCode ,ClassName from ICSInventory where WorkPoint = '" + WorkPoint + "'" + wherestr;
  70. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  71. }
  72. public DataTable GetICSMOPickLog(string invcode, ref Pagination jqgridparam)
  73. {
  74. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  75. List<DbParameter> parameter = new List<DbParameter>();
  76. DataTable table = new DataTable();
  77. //string wherestr = "";
  78. //if (!string.IsNullOrEmpty(invcode))
  79. //{
  80. // wherestr += " and a.InvCode like '%" + invcode + "'%";
  81. //}
  82. string sql = @" select distinct a.WHCode,b.MOCode,b.Sequence,a.Sequence as ZJHH,c.BatchCode,a.Quantity,a.Amount,a.ID,a.InvCode
  83. ,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
  85. from ICSMOPick a
  86. left join ICSMO b on b.ID=a.MODetailID and b.WorkPoint=a.WorkPoint and b.MOStatus<>'3'
  87. left join ICSExtension f on a.ExtensionID=f.ID
  88. where a.InvCode='{0}' and a.WorkPoint='{1}'
  89. ";
  90. sql = string.Format(sql, invcode, WorkPoint);
  91. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  92. }
  93. /// <summary>
  94. /// 获取仓库列表
  95. /// </summary>
  96. /// <returns></returns>
  97. public DataTable GetWHCode()
  98. {
  99. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  100. string sql = @"
  101. select '' as WarehouseCode,'' as WarehouseName
  102. union all
  103. select WarehouseCode,WarehouseName from ICSWarehouse where Enable='1' and WorkPoint='{0}'
  104. ";
  105. //string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
  106. //if (role != "admin")
  107. //{
  108. // sql += " and b.WorkPoint=" + WorkPoint.TrimEnd(',') + "";
  109. //}
  110. sql = string.Format(sql, WorkPoint);
  111. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  112. return dt;
  113. }
  114. public DataTable GetICSReturnTemporary(string rfqno)
  115. {
  116. string sql = @"select a.mocode,a.CreatePerson,a.CreateDateTime, a.MUSER,a.MUSERName from ICSMO a where a.MOStatus<>'3'
  117. group by a.mocode,a.CreatePerson,a.CreateDateTime, a.MUSER,a.MUSERName
  118. having a.mocode='" + rfqno + "'";
  119. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  120. DataTable dtCloned = table.Clone();
  121. foreach (DataColumn col in dtCloned.Columns)
  122. {
  123. col.DataType = typeof(string);
  124. }
  125. foreach (DataRow row in table.Rows)
  126. {
  127. DataRow newrow = dtCloned.NewRow();
  128. foreach (DataColumn column in dtCloned.Columns)
  129. {
  130. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  131. }
  132. dtCloned.Rows.Add(newrow);
  133. }
  134. if (Invmes.Rows.Count > 0)
  135. {
  136. dtCloned.Merge(Invmes, false);
  137. }
  138. return dtCloned;
  139. }
  140. public string GetNewid()
  141. {
  142. string sql = "select newid() AS ID";
  143. return Repository().FindTableBySql(sql, null).Rows[0]["ID"].ToString();
  144. }
  145. public void AddMOApplyNegTemp(string json)
  146. {
  147. var data = json.ToJObject();
  148. if (Invmes.Columns.Count <= 0)
  149. {
  150. // ID: ID,
  151. Invmes.Columns.Add("InvCode", typeof(string));
  152. Invmes.Columns.Add("INVNAME", typeof(string));
  153. Invmes.Columns.Add("InvStd", typeof(string));
  154. Invmes.Columns.Add("InvUnit", typeof(string));
  155. Invmes.Columns.Add("ID", typeof(string));
  156. Invmes.Columns.Add("ProjectCode", typeof(string));
  157. Invmes.Columns.Add("BatchCode", typeof(string));
  158. Invmes.Columns.Add("Version", typeof(string));
  159. Invmes.Columns.Add("Brand", typeof(string));
  160. Invmes.Columns.Add("cFree1", typeof(string));
  161. Invmes.Columns.Add("cFree2", typeof(string));
  162. Invmes.Columns.Add("cFree3", typeof(string));
  163. Invmes.Columns.Add("cFree4", typeof(string));
  164. Invmes.Columns.Add("cFree5", typeof(string));
  165. Invmes.Columns.Add("cFree6", typeof(string));
  166. Invmes.Columns.Add("cFree7", typeof(string));
  167. Invmes.Columns.Add("cFree8", typeof(string));
  168. Invmes.Columns.Add("cFree9", typeof(string));
  169. Invmes.Columns.Add("cFree10", typeof(string));
  170. Invmes.Columns.Add("BeginDate", typeof(string));
  171. Invmes.Columns.Add("EndDate", typeof(string));
  172. }
  173. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  174. DataRow newrow = Invmes.NewRow();
  175. newrow["InvName"] = data["InvName"];
  176. newrow["InvCode"] = data["InvCode"];
  177. newrow["InvStd"] = data["InvStd"];
  178. newrow["InvUnit"] = data["InvUnit"];
  179. newrow["ID"] = data["ID"];
  180. newrow["ProjectCode"] = data["ProjectCode"];
  181. newrow["BatchCode"] = data["BatchCode"];
  182. newrow["Version"] = data["Version"];
  183. newrow["Brand"] = data["Brand"];
  184. newrow["cFree1"] = data["cFree1"];
  185. newrow["cFree2"] = data["cFree2"];
  186. newrow["cFree3"] = data["cFree3"];
  187. newrow["cFree4"] = data["cFree4"];
  188. newrow["cFree5"] = data["cFree5"];
  189. newrow["cFree6"] = data["cFree6"];
  190. newrow["cFree7"] = data["cFree7"];
  191. newrow["cFree8"] = data["cFree8"];
  192. newrow["cFree9"] = data["cFree9"];
  193. newrow["cFree10"] = data["cFree10"];
  194. newrow["BeginDate"] = data["BeginDate"];
  195. newrow["EndDate"] = data["EndDate"];
  196. Invmes.Rows.Add(newrow);
  197. }
  198. public string DeleteMopick(string json)
  199. {
  200. try
  201. {
  202. string wheresql = "(";
  203. string[] id = json.Split(',');
  204. for (int i = 0; i < id.Length; i++)
  205. {
  206. wheresql += "'" + id[i].Replace(']', ' ').Replace('[', ' ').Replace('"', ' ').Trim() + "',";
  207. }
  208. wheresql = wheresql.Trim(',') + ")";
  209. string sql = "delete from ICSMOApplyNeg where id in" + wheresql;
  210. int count = DbHelper.ExecuteNonQuery(CommandType.Text, sql);
  211. DataRow[] row = Invmes.Select("ID in " + wheresql + "");
  212. foreach (DataRow a in row)
  213. {
  214. Invmes.Rows.Remove(a);
  215. }
  216. return "删除成功!";
  217. }
  218. catch (Exception ex)
  219. {
  220. return ex.Message + " 删除失败!";
  221. }
  222. }
  223. public void ClearTemp()
  224. {
  225. Invmes.Rows.Clear();
  226. }
  227. public string SaveICSMOApplyNeg(string ICSASN)
  228. {
  229. string msg = "";
  230. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "ICSMO/Create";
  231. string result = HttpPost(APIURL, ICSASN);
  232. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  233. string MessAge = Obj["Message"].ToString();
  234. string Success = Obj["Success"].ToString();
  235. if (Success.ToUpper() == "FALSE")
  236. {
  237. msg = MessAge;
  238. }
  239. return msg;
  240. }
  241. public string UpdateICSMOApplyNeg(string ICSASN)
  242. {
  243. string msg = "";
  244. //string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Update";
  245. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "ICSMO/Update";
  246. string result = HttpPost(APIURL, ICSASN);
  247. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  248. string MessAge = Obj["Message"].ToString();
  249. string Success = Obj["Success"].ToString();
  250. if (Success.ToUpper() == "FALSE")
  251. {
  252. msg = MessAge;
  253. }
  254. return msg;
  255. }
  256. //接口api解析
  257. public static string HttpPost(string url, string body)
  258. {
  259. try
  260. {
  261. Encoding encoding = Encoding.UTF8;
  262. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  263. request.Method = "POST";
  264. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  265. request.ContentType = "application/json; charset=utf-8";
  266. byte[] buffer = encoding.GetBytes(body);
  267. request.ContentLength = buffer.Length;
  268. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  269. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  270. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  271. {
  272. return reader.ReadToEnd();
  273. }
  274. }
  275. catch (WebException ex)
  276. {
  277. throw new Exception(ex.Message);
  278. }
  279. }
  280. /// <summary>
  281. /// 获取料品属性修改文本框值
  282. /// </summary>
  283. /// <param name="POCode"></param>
  284. /// <param name="PORow"></param>
  285. /// <returns></returns>
  286. public DataTable GetInputValue(string ID)
  287. {
  288. try
  289. {
  290. DataTable dt = new DataTable();
  291. //var queryParam = queryJson.ToJObject();
  292. List<DbParameter> parameter = new List<DbParameter>();
  293. string sql = @"select InvCode,InvName,InvDesc,InvStd,InvUnit,AmountUnit, ClassCode,ClassName,InvRate,InvVersion,InvBrand,InvIQC,
  294. InvFQC,EffectiveEnable,EffectiveDays,BatchEnable,LotEnable,PrintEnable,WHUser
  295. from ICSInventory
  296. WHERE 1=1 AND ID='{0}' ";
  297. sql = string.Format(sql, ID);
  298. return Repository().FindTableBySql(sql.ToString());
  299. }
  300. catch (Exception ex)
  301. {
  302. throw new Exception(ex.Message.ToString());
  303. }
  304. }
  305. public DataTable GetICSMOApplyNegDetailTemp(string ApplyNegCode)
  306. {
  307. string sql = @"select a.ID ,a.MOcode,a.Sequence,a.InvCode,a.Quantity,a.RCVQuantity,a.CreatePerson,a.CreateDateTime, a.MUSER,a.MUSERName,a.MTIME,a.ExtensionID,
  308. f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  309. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 from ICSMO a
  310. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  311. where a.MOStatus<>'3' and a.MOCode = '" + ApplyNegCode + "' ";
  312. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  313. if(Invmes==null || Invmes.Columns.Count<=0)
  314. Invmes = table.Clone();
  315. DataTable dtCloned = table.Clone();
  316. foreach (DataColumn col in dtCloned.Columns)
  317. {
  318. col.DataType = typeof(string);
  319. }
  320. foreach (DataRow row in table.Rows)
  321. {
  322. DataRow newrow = dtCloned.NewRow();
  323. foreach (DataColumn column in dtCloned.Columns)
  324. {
  325. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  326. }
  327. dtCloned.Rows.Add(newrow);
  328. }
  329. if (Invmes.Rows.Count > 0)
  330. {
  331. //dtCloned.Merge(Invmes, false);
  332. foreach (DataRow data in Invmes.Rows)
  333. {
  334. var info = dtCloned.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  335. if (info != null && info.Length > 0)
  336. {
  337. info[0]["ZJID"] = data["ZJID"];
  338. info[0]["InvName"] = data["InvName"];
  339. info[0]["InvCode"] = data["InvCode"];
  340. info[0]["InvStd"] = data["InvStd"];
  341. info[0]["InvUnit"] = data["InvUnit"];
  342. info[0]["Amount"] = data["Amount"];
  343. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  344. info[0]["ExtensionID"] = data["ExtensionID"];
  345. info[0]["Quantity"] = 0;
  346. }
  347. else
  348. {
  349. DataRow newrow = dtCloned.NewRow();
  350. newrow["ZJID"] = data["ZJID"];
  351. newrow["InvName"] = data["InvName"];
  352. newrow["InvCode"] = data["InvCode"];
  353. newrow["InvStd"] = data["InvStd"];
  354. newrow["InvUnit"] = data["InvUnit"];
  355. newrow["Amount"] = data["Amount"];
  356. newrow["Quantity"] = 0;
  357. newrow["ID"] = data["ID"];
  358. newrow["TLZID"] = data["TLZID"];
  359. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  360. newrow["ExtensionID"] = data["ExtensionID"];
  361. dtCloned.Rows.Add(newrow);
  362. }
  363. }
  364. }
  365. return dtCloned;
  366. }
  367. public void UpdateMOApplyNegTemp(string json)
  368. {
  369. var data = json.ToJObject();
  370. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  371. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  372. if (info != null && info.Length > 0)
  373. {
  374. info[0]["ZJID"] = data["ZJID"];
  375. info[0]["InvName"] = data["InvName"];
  376. info[0]["InvCode"] = data["InvCode"];
  377. info[0]["InvStd"] = data["InvStd"];
  378. info[0]["InvUnit"] = data["InvUnit"];
  379. info[0]["Amount"] = data["Amount"];
  380. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  381. info[0]["ExtensionID"] = data["ExtensionID"];
  382. info[0]["Quantity"] = 0;
  383. }
  384. else
  385. {
  386. DataRow newrow = Invmes.NewRow();
  387. newrow["ZJID"] = data["ZJID"];
  388. newrow["InvName"] = data["InvName"];
  389. newrow["InvCode"] = data["InvCode"];
  390. newrow["InvStd"] = data["InvStd"];
  391. newrow["InvUnit"] = data["InvUnit"];
  392. newrow["Amount"] = data["Amount"];
  393. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  394. newrow["ExtensionID"] = data["ExtensionID"];
  395. newrow["Quantity"] = 0;
  396. newrow["ID"] = data["ID"];
  397. newrow["TLZID"] = data["TLZID"];
  398. Invmes.Rows.Add(newrow);
  399. }
  400. }
  401. public string AuditICSMOApplyNeg(string ICSASN)
  402. {
  403. string msg = "";
  404. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "ICSMO/Approve";
  405. string result = HttpPost(APIURL, ICSASN);
  406. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  407. string MessAge = Obj["Message"].ToString();
  408. string Success = Obj["Success"].ToString();
  409. if (Success.ToUpper() == "FALSE")
  410. {
  411. msg = MessAge;
  412. }
  413. return msg;
  414. }
  415. public string DeleteICSMOApplyNeg(string keyValue)
  416. {
  417. //站点信息
  418. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  419. string msg = "";
  420. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  421. string sql = string.Empty;
  422. sql += string.Format(@"DELETE FROM dbo.ICSMO WHERE MOCODE IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  423. //sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  424. try
  425. {
  426. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  427. {
  428. }
  429. }
  430. catch (Exception ex)
  431. {
  432. throw new Exception(ex.Message);
  433. }
  434. return msg;
  435. }
  436. }
  437. }