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.

697 lines
36 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. using System.Collections;
  20. using System.Data.SqlClient;
  21. using System.Data.Linq.Mapping;
  22. namespace NFine.Application.WMS
  23. {
  24. /// <summary>
  25. /// 发料申请
  26. /// </summary>
  27. public class ICSMOApplyApp : RepositoryFactory<ICSVendor>
  28. {
  29. public static DataTable Invmes = new DataTable();
  30. /// <summary>
  31. /// 委外发料申请删除
  32. /// </summary>
  33. /// <param name="keyValue"></param>
  34. /// <returns></returns>
  35. /// <exception cref="Exception"></exception>
  36. public string DeleteMOApplyApplyNeg(string keyValue)
  37. {
  38. //站点信息
  39. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  40. string msg = "";
  41. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  42. string sql = string.Empty;
  43. sql += string.Format(@"DELETE FROM dbo.ICSMOApply WHERE ApplyCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  44. //sql += string.Format(@"DELETE FROM dbo.ICSMMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  45. try
  46. {
  47. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  48. {
  49. }
  50. }
  51. catch (Exception ex)
  52. {
  53. throw new Exception(ex.Message);
  54. }
  55. return msg;
  56. }
  57. /// <summary>
  58. /// 委外申请单号查询
  59. /// </summary>
  60. /// <param name="jqgridparam"></param>
  61. /// <returns></returns>
  62. public DataTable GetMOApplyApplyNeg(ref Pagination jqgridparam)
  63. {
  64. DataTable dt = new DataTable();
  65. List<DbParameter> parameter = new List<DbParameter>();
  66. string sql = @"select a.ApplyCode, a.MUSERName,CONVERT(NVARCHAR(20), a.MTIME,20) AS MTIME,a.WHCode,b.WarehouseName from ICSMOApply a
  67. left join ICSWarehouse b on a.WHCode = b.WarehouseCode and a.WorkPoint=b.WorkPoint
  68. group by a.ApplyCode, a.MUSERName,a.MTIME,a.WHCode,b.WarehouseName";
  69. sql = string.Format(sql);
  70. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  71. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  72. }
  73. /// <summary>
  74. /// 委外订单明细查询
  75. /// </summary>
  76. /// <param name="jqgridparam"></param>
  77. /// <returns></returns>
  78. public DataTable GetMOApplyApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
  79. {
  80. DataTable dt = new DataTable();
  81. //object Figure = GetDecimalDigits();
  82. List<DbParameter> parameter = new List<DbParameter>();
  83. string sql = @"SELECT a.ID,a.ApplyCode,a.Sequence,a.SourceCode,a.SourceSequence,a.InvCode,a.Quantity,a.Amount,a.IssueQuantity,a.WHCode,e.WarehouseName as WHName,a.Type,a.Status,a.CreatePerson,a.CreateDateTime
  84. ,a.ApplyID,a.ApplyDetailID,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,b.InvName
  85. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  86. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 ,a.EATTRIBUTE as EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  87. a.EATTRIBUTE9,a.EATTRIBUTE10,b.EATTRIBUTE1 as ICSInventoryEATTRIBUTE1 ,b.EATTRIBUTE2 as ICSInventoryEATTRIBUTE2,b.EATTRIBUTE3 as ICSInventoryEATTRIBUTE3,b.EATTRIBUTE4 as ICSInventoryEATTRIBUTE4,b.EATTRIBUTE5 as ICSInventoryEATTRIBUTE5,b.EATTRIBUTE6 as ICSInventoryEATTRIBUTE6,b.EATTRIBUTE7 as ICSInventoryEATTRIBUTE7,b.EATTRIBUTE8 as ICSInventoryEATTRIBUTE8,
  88. b.EATTRIBUTE9 as ICSInventoryEATTRIBUTE9,b.EATTRIBUTE10 as ICSInventoryEATTRIBUTE10
  89. from ICSMOApply a
  90. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  91. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  92. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint
  93. where a.ApplyCode = '" + ApplyNegCode + "' ";
  94. //sql = string.Format(sql, Figure);
  95. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  96. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  97. }
  98. public object GetDecimalDigits()
  99. {
  100. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  101. try
  102. {
  103. string sql = string.Empty;
  104. sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
  105. object Figure = SqlHelper.ExecuteScalar(sql);
  106. return Figure;
  107. }
  108. catch (Exception ex)
  109. {
  110. throw new Exception(ex.Message.ToString());
  111. }
  112. }
  113. public void ClearTemp()
  114. {
  115. Invmes.Rows.Clear();
  116. }
  117. /// <summary>
  118. /// 新增、修改
  119. /// </summary>
  120. /// <param name="ICSASN"></param>
  121. /// <returns></returns>
  122. public string SaveICSMOApplyApplyNeg(string keyValue, string deleteIDs)
  123. {
  124. string returnValue = string.Empty;
  125. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  126. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  127. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  128. var Dates = DateTime.Now;
  129. string Colspan = string.Empty;
  130. string IDD = string.Empty;
  131. var sql = string.Empty;
  132. try
  133. {
  134. var modelList = JsonConvert.DeserializeObject<List<ICSMOApplyEdit>>(keyValue);
  135. if (!string.IsNullOrEmpty(deleteIDs))
  136. {
  137. var deleteentityList = deleteIDs.Split(',');
  138. foreach (var item in deleteentityList)
  139. {
  140. if (!string.IsNullOrEmpty(item))
  141. {
  142. var deleteEntity = MsSqlData.Get<ICSMOApply>(item);
  143. sql += string.Format(@"DELETE FROM dbo.ICSMOApply WHERE ID IN ({0}) and WorkPoint ='{1}'", item, WorkPoint);
  144. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  145. {
  146. }
  147. }
  148. }
  149. }
  150. foreach (var model in modelList)
  151. {
  152. if (string.IsNullOrEmpty(model.ID))
  153. {
  154. //新增
  155. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSMOApply where ApplyCode='" + model.ApplyCode + "' and Sequence ='" + model.Sequence + "'").ToInt();
  156. if (count > 0)
  157. {
  158. throw new Exception("当前代码已经存在");
  159. }
  160. //检验自由项
  161. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  162. + "~" + model.Brand + "~" + model.cFree1
  163. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  164. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  165. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  166. sql = @"select ID,Colspan from ICSExtension a
  167. where Colspan='{0}' and WorkPoint='{1}'";
  168. sql = string.Format(sql, Colspan, model.WorkPoint);
  169. var dttt = SqlHelper.CmdExecuteDataTable(sql);
  170. if (dttt.Rows.Count == 0)
  171. {
  172. IDD = Guid.NewGuid().ToString();
  173. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  174. 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}'";
  175. 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);
  176. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  177. {
  178. throw new Exception("自由项添加失败");
  179. }
  180. }
  181. else
  182. {
  183. IDD = dttt.Rows[0]["ID"].ToString();
  184. }
  185. var entity = new ICSMOApply();
  186. ConvertExt.Mapping<ICSMOApplyEdit, ICSMOApply>(model, entity);
  187. entity.ID = Guid.NewGuid().ToString();
  188. entity.Status = "2";
  189. entity.CreatePerson = MUSER;
  190. entity.CreateDateTime = Dates;
  191. entity.MUSER = MUSER;
  192. entity.MUSERName = MUSERNAME;
  193. entity.MTIME = Dates;
  194. entity.WorkPoint = WorkPoint;
  195. entity.ApplyID = "";
  196. entity.ApplyDetailID = "";
  197. entity.ExtensionID = IDD;
  198. var result = MsSqlData.Insert<ICSMOApply>(entity);
  199. if (!result)
  200. {
  201. returnValue = "新增失败";
  202. }
  203. }
  204. else
  205. {
  206. //修改
  207. var entity = MsSqlData.Get<ICSMOApply>(model.ID);
  208. if (entity == null)
  209. {
  210. //新增
  211. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSMOApply where ApplyCode='" + model.ApplyCode + "' and Sequence ='" + model.Sequence + "'").ToInt();
  212. if (count > 0)
  213. {
  214. throw new Exception("当前代码已经存在");
  215. }
  216. //检验自由项
  217. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  218. + "~" + model.Brand + "~" + model.cFree1
  219. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  220. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  221. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  222. sql = @"select ID,Colspan from ICSExtension a
  223. where Colspan='{0}' and WorkPoint='{1}'";
  224. sql = string.Format(sql, Colspan, model.WorkPoint);
  225. var dttt = SqlHelper.CmdExecuteDataTable(sql);
  226. if (dttt.Rows.Count == 0)
  227. {
  228. IDD = Guid.NewGuid().ToString();
  229. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  230. 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}'";
  231. 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);
  232. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  233. {
  234. throw new Exception("自由项添加失败");
  235. }
  236. }
  237. else
  238. {
  239. IDD = dttt.Rows[0]["ID"].ToString();
  240. }
  241. entity = new ICSMOApply();
  242. ConvertExt.Mapping<ICSMOApplyEdit, ICSMOApply>(model, entity);
  243. entity.ID = Guid.NewGuid().ToString();
  244. entity.Status = "2";
  245. entity.CreatePerson = MUSER;
  246. entity.CreateDateTime = Dates;
  247. entity.MUSER = MUSER;
  248. entity.MUSERName = MUSERNAME;
  249. entity.MTIME = Dates;
  250. entity.WorkPoint = WorkPoint;
  251. entity.ApplyID = "";
  252. entity.ApplyDetailID = "";
  253. entity.ExtensionID = IDD;
  254. var result = MsSqlData.Insert<ICSMOApply>(entity);
  255. if (!result)
  256. {
  257. returnValue = "新增失败";
  258. }
  259. }
  260. else
  261. {
  262. //检验自由项
  263. Colspan = model.ProjectCode + "~" + model.BatchCode + "~" + model.Version
  264. + "~" + model.Brand + "~" + model.cFree1
  265. + "~" + model.cFree2 + "~" + model.cFree3 + "~" + model.cFree4
  266. + "~" + model.cFree5 + "~" + model.cFree6 + "~" + model.cFree7
  267. + "~" + model.cFree8 + "~" + model.cFree9 + "~" + model.cFree10;
  268. sql = @"select ID,Colspan from ICSExtension a
  269. where Colspan='{0}' and WorkPoint='{1}'";
  270. sql = string.Format(sql, Colspan, model.WorkPoint);
  271. var dtt = SqlHelper.CmdExecuteDataTable(sql);
  272. if (dtt.Rows.Count == 0)
  273. {
  274. IDD = Guid.NewGuid().ToString();
  275. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  276. 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}'";
  277. 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);
  278. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  279. {
  280. throw new Exception("自由项添加失败");
  281. }
  282. }
  283. else
  284. {
  285. IDD = dtt.Rows[0]["ID"].ToString();
  286. }
  287. ConvertExt.Mapping<ICSMOApplyEdit, ICSMOApply>(model, entity);
  288. entity.MUSER = MUSER;
  289. entity.MUSERName = MUSERNAME;
  290. entity.MTIME = Dates;
  291. entity.ApplyID = "";
  292. entity.ApplyDetailID = "";
  293. entity.ExtensionID = IDD;
  294. var result = MsSqlData.Update<ICSMOApply>(entity);
  295. if (!result)
  296. {
  297. returnValue = "修改失败";
  298. }
  299. }
  300. }
  301. }
  302. }
  303. catch (Exception ex)
  304. {
  305. returnValue = ex.Message;
  306. }
  307. return returnValue;
  308. }
  309. ///// <summary>
  310. ///// 修改
  311. ///// </summary>
  312. ///// <param name="ICSASN"></param>
  313. ///// <returns></returns>
  314. //public string UpdateICSMOApplyApplyNeg(string ICSASN)
  315. //{
  316. // string msg = "";
  317. // string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOApply/Update";
  318. // string result = HttpPost(APIURL, ICSASN);
  319. // JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  320. // string MessAge = Obj["Message"].ToString();
  321. // string Success = Obj["Success"].ToString();
  322. // if (Success.ToUpper() == "FALSE")
  323. // {
  324. // msg = MessAge;
  325. // }
  326. // return msg;
  327. //}
  328. /// <summary>
  329. /// 创建自增单号
  330. /// </summary>
  331. /// <param name="WorkPoint"></param>
  332. /// <returns></returns>
  333. public string GetOOCode(string WorkPoint)
  334. {
  335. WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  336. string OOCode = string.Empty;
  337. if (!string.IsNullOrEmpty(WorkPoint))
  338. {
  339. OOCode = GetSerialCode(WorkPoint, "ICSMOApply", "ApplyCode", "00", 8);
  340. }
  341. if (!string.IsNullOrWhiteSpace(OOCode))
  342. {
  343. string sqlISHave = @"SELECT ApplyCode FROM ICSMOApply a
  344. WHERE a.ApplyCode = '{0}'";
  345. sqlISHave = string.Format(sqlISHave, OOCode);
  346. DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave);
  347. if (dtIsHave.Rows.Count > 0)
  348. {
  349. throw new Exception("单号已存在!");
  350. }
  351. }
  352. return OOCode;
  353. }
  354. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  355. {
  356. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  357. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  358. return SqlHelper.ExecuteScalar(sql).ToString();
  359. }
  360. public void UpdateOutsourcingOrderApplyNegTemp(string json)
  361. {
  362. var data = json.ToJObject();
  363. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  364. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  365. if (info != null && info.Length > 0)
  366. {
  367. info[0]["ZJID"] = data["ZJID"];
  368. info[0]["InvName"] = data["InvName"];
  369. }
  370. else
  371. {
  372. DataRow newrow = Invmes.NewRow();
  373. newrow["ZJID"] = data["ZJID"];
  374. Invmes.Rows.Add(newrow);
  375. }
  376. }
  377. public DataTable GetICSMOApplyReturnTemporary(string ApplyCode)
  378. {
  379. string sql = @"SELECT a.ID,a.ApplyCode,a.Sequence,a.SourceCode,a.SourceSequence,a.InvCode,a.Quantity,a.Amount,a.IssueQuantity
  380. ,a.WHCode,a.Type,a.Status,a.CreatePerson,a.CreateDateTime,b.InvName
  381. ,a.ApplyID,a.ApplyDetailID,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint
  382. from ICSMOApply a
  383. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  384. where a.ApplyCode ='" + ApplyCode + "' ";
  385. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  386. DataTable dtCloned = table.Clone();
  387. foreach (DataColumn col in dtCloned.Columns)
  388. {
  389. col.DataType = typeof(string);
  390. }
  391. foreach (DataRow row in table.Rows)
  392. {
  393. DataRow newrow = dtCloned.NewRow();
  394. foreach (DataColumn column in dtCloned.Columns)
  395. {
  396. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  397. }
  398. dtCloned.Rows.Add(newrow);
  399. }
  400. if (Invmes.Rows.Count > 0)
  401. {
  402. dtCloned.Merge(Invmes, false);
  403. }
  404. return dtCloned;
  405. }
  406. /// <summary>
  407. /// 接口api解析
  408. /// </summary>
  409. /// <param name="url"></param>
  410. /// <param name="body"></param>
  411. /// <returns></returns>
  412. /// <exception cref="Exception"></exception>
  413. public static string HttpPost(string url, string body)
  414. {
  415. try
  416. {
  417. Encoding encoding = Encoding.UTF8;
  418. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  419. request.Method = "POST";
  420. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  421. request.ContentType = "application/json; charset=utf-8";
  422. byte[] buffer = encoding.GetBytes(body);
  423. request.ContentLength = buffer.Length;
  424. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  425. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  426. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  427. {
  428. return reader.ReadToEnd();
  429. }
  430. }
  431. catch (WebException ex)
  432. {
  433. throw new Exception(ex.Message);
  434. }
  435. }
  436. //领料单
  437. public string SetData_PR(String savePath)
  438. {
  439. //数据获取
  440. try
  441. {
  442. int index = 1;
  443. string msg = "";
  444. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  445. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  446. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  447. DateTime MTime = DateTime.Now;
  448. SqlConnection conn = SqlHelper.GetDataCenterConn();
  449. string sql = "";
  450. string sqlss = "";
  451. int count = 0;
  452. DataTable data = FileToExcel.ExcelToTable(savePath);
  453. var groupedData = from row in data.AsEnumerable()
  454. group row by row.Field<string>("申请单号") into g
  455. select new { Category = g.Key, Values = g.ToList() };
  456. // 输出结果
  457. foreach (var group in groupedData)
  458. {
  459. Console.WriteLine($"Category: {group.Category}");
  460. foreach (DataRow row in group.Values)
  461. {
  462. string IDD=string.Empty;
  463. string ApplyCode = row["申请单号"].ToString();
  464. string Sequence = row["申请单行号"].ToString();
  465. string InvCode = row["助记码"].ToString();
  466. string Quantity = row["数量"].ToString();
  467. string WHCode = row["仓库代码"].ToString();
  468. string EATTRIBUTE3 = row["物料代码"].ToString();
  469. string EATTRIBUTE4 = row["组件"].ToString();
  470. if (ApplyCode == "" || ApplyCode == null)
  471. {
  472. throw new Exception("第 " + index + " 行申请单号不能为空!");
  473. }
  474. if (Sequence == "" || Sequence == null)
  475. {
  476. throw new Exception("第 " + index + " 行申请单行号不能为空!");
  477. }
  478. if (InvCode == "" || InvCode == null)
  479. {
  480. throw new Exception("第 " + index + " 行助记码不能为空!");
  481. }
  482. if (Quantity == "" || Quantity == null)
  483. {
  484. throw new Exception("第 " + index + " 行数量不能为空!");
  485. }
  486. if (WHCode == "" || WHCode == null)
  487. {
  488. throw new Exception("第 " + index + " 行仓库代码不能为空!");
  489. }
  490. if (EATTRIBUTE3 == "" || EATTRIBUTE3 == null)
  491. {
  492. throw new Exception("第 " + index + " 行物料代码不能为空!");
  493. }
  494. string sqls = @"select ApplyCode,Sequence from ICSMOApply where ApplyCode='{0}' and Sequence='{2}' and WorkPoint='{1}'";
  495. sqls = string.Format(sqls, ApplyCode, WorkPoint, Sequence);
  496. DataTable dnum = SqlHelper.CmdExecuteDataTable(sqls);
  497. if (dnum != null && dnum.Rows.Count > 0)
  498. {
  499. throw new Exception("领料单: " + ApplyCode + ",行号: " + Sequence + " 已存在!");
  500. }
  501. else
  502. {
  503. //检验自由项
  504. string Colspan = row["批次"].ToString() + "~" + row["自由项1"].ToString()
  505. + "~" + row["自由项2"].ToString() + "~" + row["自由项3"].ToString() + "~" + row["自由项4"].ToString()
  506. + "~" + row["自由项5"].ToString() + "~" + row["自由项6"].ToString() + "~" + row["自由项7"].ToString()
  507. + "~" + row["自由项8"].ToString() + "~" + row["自由项9"].ToString() + "~" + row["自由项10"].ToString();
  508. sql = @"select ID,Colspan from ICSExtension a
  509. where Colspan='{0}' and WorkPoint='{1}'";
  510. sql = string.Format(sql, Colspan, WorkPoint);
  511. var dtt = SqlHelper.CmdExecuteDataTable(sql);
  512. if (dtt.Rows.Count == 0)
  513. {
  514. IDD = Guid.NewGuid().ToString();
  515. sql = @"Insert into ICSExtension(ID, Colspan, BatchCode, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  516. select '{14}','{0}','{1}',
  517. '{2}','{3}','{4}','{5}',
  518. '{6}','{7}','{8}','{9}','{10}','{11}','{14}','{12}',f.F_RealName,'{13}'from Sys_SRM_User f where f.F_Account='{12}' and f.F_Location='{13}'";
  519. sql = string.Format(sql, Colspan, row["批次"].ToString(), row["自由项1"].ToString(), row["自由项2"].ToString(), row["自由项3"].ToString(), row["自由项4"].ToString(), row["自由项5"].ToString(), row["自由项6"].ToString(), row["自由项7"].ToString(), row["自由项8"].ToString(), row["自由项9"].ToString(), row["自由项10"].ToString(), MUSER, WorkPoint, IDD,MTime);
  520. if (SqlHelper.CmdExecuteNonQueryLi(sql) < 0)
  521. {
  522. throw new Exception("自由项添加失败");
  523. }
  524. }
  525. else
  526. {
  527. IDD = dtt.Rows[0]["ID"].ToString();
  528. }
  529. sqlss += @"Insert INto ICSMOApply
  530. ( ID,ApplyCode,Sequence,SourceCode,SourceSequence,InvCode,Quantity,Amount, IssueQuantity,WHCode,Type,Status,CreatePerson,CreateDateTime,ApplyID,ApplyDetailID,ExtensionID,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE3,EATTRIBUTE4)
  531. Values (newid(),'{0}','{1}','{2}','{3}','{4}',{5},{6},
  532. {7},'{8}','{9}','{10}','{11}',GETDATE(),'{12}','{13}','{14}',
  533. '{11}','{15}','{19}','{16}','{17}','{18}' )";
  534. }
  535. sqlss = string.Format(sqlss, ApplyCode, Sequence, row["来源单据号"].ToString(), row["来源单据行号"].ToString(), InvCode, Quantity, row["辅计量数量"].ToString()==""?0 : Convert.ToDecimal(row["辅计量数量"].ToString()) , row["已发数量"].ToString()==""?0: Convert.ToDecimal(row["已发数量"].ToString()), WHCode, "1", "2",MUSER,"","",IDD,MUSERNAME,WorkPoint, EATTRIBUTE3, EATTRIBUTE4, MTime);
  536. }
  537. }
  538. //foreach (DataRow dr in data.Rows)
  539. //{
  540. // index++;
  541. // var StackCode = "";
  542. // var StackName = "";
  543. // //string GUID = Guid.NewGuid().ToString();
  544. // string KuFang = dr["库房编码"].ToString().Trim().ToUpper();
  545. // string Qu = dr["区"].ToString().Trim().ToUpper();
  546. // string Pai = dr["排"].ToString().Trim().ToUpper();
  547. // string Jia = dr["货架"].ToString().Trim().ToUpper();
  548. // string Ceng = dr["层"].ToString().Trim().ToUpper();
  549. // string Ge = dr["格"].ToString().Trim().ToUpper();
  550. // if (KuFang == "" || KuFang == null)
  551. // {
  552. // throw new Exception("第 " + index + " 行库房编码不能为空!");
  553. // }
  554. // if (Qu == "" && Pai == "" && Jia == "" && Ceng == "" && Ge == "")
  555. // {
  556. // throw new Exception("第 " + index + " 区、排、货架、层、格至少填写一项!");
  557. // }
  558. // string sqlWH = @"select ID from ICSWarehouse where WarehouseCode='{0}' and WorkPoint='{1}'";
  559. // sqlWH = string.Format(sqlWH, KuFang, WorkPoint);
  560. // DataTable dd = SqlHelper.CmdExecuteDataTable(sqlWH);
  561. // if (dd == null || dd.Rows.Count <= 0)
  562. // {
  563. // throw new Exception("库房编码: " + KuFang + " 不存在!");
  564. // }
  565. // string WHID = dd.Rows[0]["ID"].ToString();
  566. // StackCode = KuFang;
  567. // StackName = KuFang + "仓库";
  568. // if (Qu != "")
  569. // {
  570. // StackCode += "-" + Qu;
  571. // StackName += Qu + "区";
  572. // }
  573. // if (Pai != "")
  574. // {
  575. // StackCode += "-" + Pai;
  576. // StackName += Pai + "排";
  577. // }
  578. // if (Jia != "")
  579. // {
  580. // StackCode += "-" + Jia;
  581. // StackName += Jia + "货架";
  582. // }
  583. // if (Ceng != "")
  584. // {
  585. // StackCode += "-" + Ceng;
  586. // StackName += Ceng + "层";
  587. // }
  588. // if (Ge != "")
  589. // {
  590. // StackCode += "-" + Ge;
  591. // StackName += Ge + "格";
  592. // }
  593. // string sqls = @"select LocationCode from ICSLocation where LocationCode='{0}' and WorkPoint='{1}'";
  594. // sqls = string.Format(sqls, StackCode, WorkPoint);
  595. // DataTable dnum = SqlHelper.CmdExecuteDataTable(sqls);
  596. // if (dnum != null && dnum.Rows.Count > 0)
  597. // {
  598. // throw new Exception("库位: " + StackCode + " 已存在!");
  599. // }
  600. // else
  601. // {
  602. // sql += @"Insert INto ICSLocation
  603. // ( ID, LocationCode, LocationName, WHID, MUSER, MUSERName, MTIME, WorkPoint, EATTRIBUTE1, Region, Row, GoodsShelf, Tier, Grid)
  604. // Values (newid(),'{0}','{1}','{2}','{3}','{4}',getdate(),'{5}','','{6}','{7}','{8}','{9}','{10}')";
  605. // }
  606. // sql = string.Format(sql, StackCode, StackName, WHID, MUSER, MUSERNAME, WorkPoint, Qu, Pai, Jia, Ceng, Ge);
  607. //}
  608. count = SqlHelper.CmdExecuteNonQueryLi(sqlss);
  609. if (count > 0)
  610. {
  611. msg = "导入成功";
  612. }
  613. else
  614. {
  615. return "无有效的导入数据。";
  616. }
  617. return msg;
  618. }
  619. catch (Exception ex)
  620. {
  621. return ex.Message;
  622. }
  623. }
  624. /// <summary>
  625. /// 全部导出
  626. /// <returns></returns>
  627. public DataTable GetASNListExport()
  628. {
  629. string sql = @"SELECT a.ApplyCode AS 委外申请单号
  630. ,a.Sequence AS
  631. ,a.SourceCode AS
  632. ,a.SourceSequence AS
  633. ,a.IssueQuantity AS
  634. ,a.Quantity AS
  635. ,a.WHCode AS
  636. ,e.WarehouseName as
  637. ,a.Type AS
  638. ,a.InvCode AS
  639. ,b.InvName AS
  640. ,a.Amount AS
  641. ,a.Status AS
  642. ,a.CreatePerson AS
  643. ,a.CreateDateTime AS
  644. ,a.MUSER AS
  645. ,a.MUSERName AS
  646. ,a.MTIME AS
  647. ,a.WorkPoint AS
  648. from ICSMOApply a
  649. left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint
  650. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  651. left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint";
  652. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  653. return dt;
  654. }
  655. }
  656. }