纽威
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.

1090 lines
63 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  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 System.Net;
  18. using System.IO;
  19. using Newtonsoft.Json.Linq;
  20. using NFine.Domain._03_Entity.WMS;
  21. namespace NFine.Application.WMS
  22. {
  23. public class ICSMTDOCApp : RepositoryFactory<ICSVendor>
  24. {
  25. public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam)
  26. {
  27. DataTable dt = new DataTable();
  28. var queryParam = queryJson.ToJObject();
  29. List<DbParameter> parameter = new List<DbParameter>();
  30. #region [SQL]
  31. string sql = @" SELECT * FROM (select row_number() over(partition by a.MTDOCCode ORDER BY a.CreateDateTime) as row, a.MTDOCCode,a.CreatePerson,a.CreateDateTime,
  32. case when isnull(a.MTDOCQuantity,0)=a.Quantity then '' else '' end Status
  33. ,a.MUSER,a.MUSERName,a.MTIME
  34. from ICSMTDOC a
  35. LEFT JOIN ICSInventoryDetail detail on a.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint ";
  36. sql += " WHERE 1=1";
  37. sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  38. #endregion
  39. #region 获取仓库权限信息
  40. string workpoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  41. string user = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  42. string permission = HelperMethod.GetWarehousePermissions(user, workpoint);
  43. if (!string.IsNullOrWhiteSpace(permission))
  44. {
  45. sql += " and a.WHCode " + permission + " ";
  46. }
  47. #endregion
  48. if (!string.IsNullOrWhiteSpace(queryJson))
  49. {
  50. if (!string.IsNullOrWhiteSpace(queryParam["MTDOCCode"].ToString()))
  51. {
  52. sql += " and a.MTDOCCode like '%" + queryParam["MTDOCCode"].ToString() + "%' ";
  53. }
  54. if (!string.IsNullOrWhiteSpace(queryParam["Area"].ToString()))
  55. {
  56. sql += " and detail.LocationCode='" + queryParam["Area"].ToString() + "'";
  57. }
  58. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  59. {
  60. if (queryParam["ReleaseState"].ToString() == "2")
  61. {
  62. sql += " and isnull(a.MTDOCQuantity,0)=a.Quantity";
  63. }
  64. else
  65. {
  66. sql += " and isnull(a.MTDOCQuantity,0)<>a.Quantity";
  67. }
  68. }
  69. }
  70. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  71. {
  72. sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  73. }
  74. sql += " ) t WHERE t.Row=1";
  75. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  76. }
  77. public DataTable GetSubGridJson(string MTDOCCode)
  78. {
  79. DataTable dt = new DataTable();
  80. //var queryParam = queryJson.ToJObject();
  81. string sql = string.Empty;
  82. List<DbParameter> parameter = new List<DbParameter>();
  83. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  84. sql = @" select a.ID,a.DepCode,d.DepName,a.WHCode,c.WarehouseName,a.Sequence,b.InvCode,b.InvName,a.Quantity,a.Amount,a.MTDOCQuantity,case WHEN a.MTDOCType='1' then '转换前' ELSE '转换后' END as MTDOCType , detail.LocationCode AS Area
  85. from ICSMTDOC a
  86. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  87. left join ICSWarehouse c on a.WHCode=c.WarehouseCode and a.WorkPoint=c.WorkPoint
  88. left join ICSDepartment d on a.DepCode=d.DepCode and a.WorkPoint=d.WorkPoint
  89. LEFT JOIN ICSInventoryDetail detail on b.InvCode=detail.INVCode AND a.WHCode=detail.WHCode AND a.WorkPoint=detail.WorkPoint
  90. WHERE a.MTDOCCode='{0}' and a.WorkPoint in ('{1}') order by a.Sequence ";
  91. sql = string.Format(sql, MTDOCCode, WorkPoint);
  92. return Repository().FindTableBySql(sql.ToString());
  93. }
  94. public DataTable GetRepertory(string LotNo, ref Pagination jqgridparam)
  95. {
  96. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  97. List<DbParameter> parameter = new List<DbParameter>();
  98. DataTable table = new DataTable();
  99. string wherestr = "";
  100. if (!string.IsNullOrEmpty(LotNo))
  101. {
  102. wherestr += " and a.LotNO like '%" + LotNo + "%'";
  103. }
  104. string sql = @"select a.WarehouseCode,a.LotNo,b.Amount,a.InvCode,c.InvName,c.InvDesc,c.InvStd,c.InvUnit,a.Quantity
  105. from ICSWareHouseLotInfo a
  106. inner join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  107. left join ICSInventory c on b.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  108. WHERE a.Quantity>0 and a.WorkPoint = '" + WorkPoint + "'" + wherestr;
  109. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  110. }
  111. public DataTable GetInvcode(string Invcode, ref Pagination jqgridparam)
  112. {
  113. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  114. List<DbParameter> parameter = new List<DbParameter>();
  115. DataTable table = new DataTable();
  116. string wherestr = "";
  117. if (!string.IsNullOrEmpty(Invcode))
  118. {
  119. wherestr += " and InvCode like '%" + Invcode + "%'";
  120. }
  121. string sql = @"select distinct InvCode,InvName,InvStd,InvUnit,InvDesc from dbo.ICSInventory
  122. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  123. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  124. }
  125. public DataTable GetCode(string Type, string Common, ref Pagination jqgridparam)
  126. {
  127. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  128. List<DbParameter> parameter = new List<DbParameter>();
  129. DataTable dt = new DataTable();
  130. DataTable table = new DataTable();
  131. string wherestr = "";
  132. string sql = string.Empty;
  133. if (Type == "1")
  134. {
  135. if (!string.IsNullOrEmpty(Common))
  136. {
  137. wherestr += " and ProjectCode like '%" + Common + "%'";
  138. }
  139. sql = @"select distinct ProjectCode as Code from ICSExtension
  140. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  141. }
  142. if (Type == "2")
  143. {
  144. if (!string.IsNullOrEmpty(Common))
  145. {
  146. wherestr += " and BatchCode like '%" + Common + "%'";
  147. }
  148. sql = @"select distinct BatchCode as Code from ICSExtension
  149. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  150. }
  151. if (Type == "3")
  152. {
  153. if (!string.IsNullOrEmpty(Common))
  154. {
  155. wherestr += " and Version like '%" + Common + "%'";
  156. }
  157. sql = @"select distinct Version as Code from ICSExtension
  158. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  159. }
  160. if (Type == "4")
  161. {
  162. if (!string.IsNullOrEmpty(Common))
  163. {
  164. wherestr += " and Brand like '%" + Common + "%'";
  165. }
  166. sql = @"select distinct Brand as Code from ICSExtension
  167. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  168. }
  169. if (Type == "5")
  170. {
  171. if (!string.IsNullOrEmpty(Common))
  172. {
  173. wherestr += " and cFree1 like '%" + Common + "%'";
  174. }
  175. sql = @"select distinct cFree1 as Code from ICSExtension
  176. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  177. }
  178. if (Type == "6")
  179. {
  180. if (!string.IsNullOrEmpty(Common))
  181. {
  182. wherestr += " and cFree2 like '%" + Common + "%'";
  183. }
  184. sql = @"select distinct cFree2 as Code from ICSExtension
  185. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  186. }
  187. if (Type == "7")
  188. {
  189. if (!string.IsNullOrEmpty(Common))
  190. {
  191. wherestr += " and cFree3 like '%" + Common + "%'";
  192. }
  193. sql = @"select distinct cFree3 as Code from ICSExtension
  194. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  195. }
  196. if (Type == "8")
  197. {
  198. if (!string.IsNullOrEmpty(Common))
  199. {
  200. wherestr += " and cFree4 like '%" + Common + "%'";
  201. }
  202. sql = @"select distinct cFree4 as Code from ICSExtension
  203. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  204. }
  205. if (Type == "9")
  206. {
  207. if (!string.IsNullOrEmpty(Common))
  208. {
  209. wherestr += " and cFree5 like '%" + Common + "%'";
  210. }
  211. sql = @"select distinct cFree5 as Code from ICSExtension
  212. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  213. }
  214. if (Type == "10")
  215. {
  216. if (!string.IsNullOrEmpty(Common))
  217. {
  218. wherestr += " and cFree6 like '%" + Common + "%'";
  219. }
  220. sql = @"select distinct cFree6 as Code from ICSExtension
  221. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  222. }
  223. if (Type == "11")
  224. {
  225. if (!string.IsNullOrEmpty(Common))
  226. {
  227. wherestr += " and cFree7 like '%" + Common + "%'";
  228. }
  229. sql = @"select distinct cFree7 as Code from ICSExtension
  230. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  231. }
  232. if (Type == "12")
  233. {
  234. if (!string.IsNullOrEmpty(Common))
  235. {
  236. wherestr += " and cFree8 like '%" + Common + "%'";
  237. }
  238. sql = @"select distinct cFree8 as Code from ICSExtension
  239. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  240. }
  241. if (Type == "13")
  242. {
  243. if (!string.IsNullOrEmpty(Common))
  244. {
  245. wherestr += " and cFree9 like '%" + Common + "%'";
  246. }
  247. sql = @"select distinct cFree9 as Code from ICSExtension
  248. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  249. }
  250. if (Type == "14")
  251. {
  252. if (!string.IsNullOrEmpty(Common))
  253. {
  254. wherestr += " and cFree10 like '%" + Common + "%'";
  255. }
  256. sql = @"select distinct cFree10 as Code from ICSExtension
  257. WHERE WorkPoint = '" + WorkPoint + "'" + wherestr;
  258. }
  259. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  260. }
  261. //新增形态转换
  262. public string CreateICSMTDOC(string ICSMTDOC, string InvCode, string Memo)
  263. {
  264. string Colspan = "";
  265. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  266. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  267. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  268. string msg = "";
  269. string MTDOCCode = "";
  270. DateTime TimeNow = DateTime.Now;
  271. string sql = string.Empty;
  272. JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC);
  273. int Num = 1;
  274. DataTable dts = new DataTable();
  275. string Time = DateTime.Now.ToString("yyyyMMdd");
  276. string sqlss = @"select max(MTDOCCode) as NewMTDOCCode from ICSMTDOC where substring(MTDOCCode,1,8)='{0}'";
  277. sqlss = string.Format(sqlss, Time);
  278. dts = Repository().FindTableBySql(sqlss.ToString());
  279. if (dts == null || dts.Rows.Count == 0 || dts.Rows[0]["NewMTDOCCode"].ToString() == "")
  280. {
  281. MTDOCCode = Time + "000001";
  282. }
  283. else
  284. {
  285. string NewMTDOCCode = dts.Rows[0]["NewMTDOCCode"].ToString();
  286. int COUNT = Convert.ToInt32(NewMTDOCCode.Substring(8)) + 1;
  287. MTDOCCode = Time + COUNT.ToString().PadLeft(6, '0');
  288. }
  289. Dictionary<string, object> dic = new Dictionary<string, object>();
  290. foreach (var item in res)
  291. {
  292. JObject jo = (JObject)item;
  293. DataTable dt = new DataTable();
  294. string NewLotNo = "";
  295. string LotNo = jo["LotNo"].ToString();
  296. #region 根据原条码查询并创建新条码
  297. string sqls = @"select max(LotNo) as NewLotNo from ICSInventoryLot where EATTRIBUTE1='{0}' ";
  298. sqls = string.Format(sqls, LotNo);
  299. dt = Repository().FindTableBySql(sqls.ToString());
  300. if (dt == null || dt.Rows.Count == 0 || dt.Rows[0]["NewLotNo"].ToString() == "")
  301. {
  302. NewLotNo = LotNo + "-1";
  303. }
  304. else
  305. {
  306. string newLotNO = dt.Rows[0]["NewLotNo"].ToString();
  307. int COUNT = Convert.ToInt32(newLotNO.Substring(newLotNO.LastIndexOf('-') + 1)) + 1;
  308. NewLotNo = LotNo + "-" + COUNT.ToString();
  309. }
  310. #endregion
  311. #region 查询并插入Extension
  312. string sqloldLotNo = string.Format(@"select a.ProjectCode,a.BatchCode,a.Version,a.Brand,a.cFree1,a.cFree2,a.cFree3,a.cFree4,a.cFree5,a.cFree6,a.cFree7,a.cFree8,a.cFree9,a.cFree10 from ICSExtension a inner join dbo.ICSInventoryLot b on a.ID=b.ExtensionID and a.WorkPoint=b.WorkPoint where b.LotNo='{0}'", LotNo);
  313. DataTable oldLotNo = SqlHelper.GetDataTableBySql(sqloldLotNo);
  314. string oProjectCode = oldLotNo.Rows[0]["ProjectCode"].ToString();
  315. string oBatchCode = oldLotNo.Rows[0]["BatchCode"].ToString();
  316. string oVersion = oldLotNo.Rows[0]["Version"].ToString();
  317. string oBrand = oldLotNo.Rows[0]["Brand"].ToString();
  318. string ocFree1 = oldLotNo.Rows[0]["cFree1"].ToString();
  319. string ocFree2 = oldLotNo.Rows[0]["cFree2"].ToString();
  320. string ocFree3 = oldLotNo.Rows[0]["cFree3"].ToString();
  321. string ocFree4 = oldLotNo.Rows[0]["cFree4"].ToString();
  322. string ocFree5 = oldLotNo.Rows[0]["cFree5"].ToString();
  323. string ocFree6 = oldLotNo.Rows[0]["cFree6"].ToString();
  324. string ocFree7 = oldLotNo.Rows[0]["cFree7"].ToString();
  325. string ocFree8 = oldLotNo.Rows[0]["cFree8"].ToString();
  326. string ocFree9 = oldLotNo.Rows[0]["cFree9"].ToString();
  327. string ocFree10 = oldLotNo.Rows[0]["cFree10"].ToString();
  328. if (jo["FlagProjectCode"].ToString() != "" && jo["FlagProjectCode"].ToString() == "1")
  329. {
  330. oProjectCode = jo["ProjectCode"].ToString();
  331. }
  332. if (jo["FlagBatchCode"].ToString() != "" && jo["FlagBatchCode"].ToString() == "1")
  333. {
  334. oBatchCode = jo["BatchCode"].ToString();
  335. }
  336. if (jo["FlagVersion"].ToString() != "" && jo["FlagVersion"].ToString() == "1")
  337. {
  338. oVersion = jo["Version"].ToString();
  339. }
  340. if (jo["FlagBrand"].ToString() != "" && jo["FlagBrand"].ToString() == "1")
  341. {
  342. oBrand = jo["Brand"].ToString();
  343. }
  344. if (jo["FlagcFree1"].ToString() != "" && jo["FlagcFree1"].ToString() == "1")
  345. {
  346. ocFree1 = jo["cFree1"].ToString();
  347. }
  348. if (jo["FlagcFree2"].ToString() != "" && jo["FlagcFree2"].ToString() == "1")
  349. {
  350. ocFree2 = jo["cFree2"].ToString();
  351. }
  352. if (jo["FlagcFree3"].ToString() != "" && jo["FlagcFree3"].ToString() == "1")
  353. {
  354. ocFree3 = jo["cFree3"].ToString();
  355. }
  356. if (jo["FlagcFree4"].ToString() != "" && jo["FlagcFree4"].ToString() == "1")
  357. {
  358. ocFree4 = jo["cFree4"].ToString();
  359. }
  360. if (jo["FlagcFree5"].ToString() != "" && jo["FlagcFree5"].ToString() == "1")
  361. {
  362. ocFree5 = jo["cFree5"].ToString();
  363. }
  364. if (jo["FlagcFree6"].ToString() != "" && jo["FlagcFree6"].ToString() == "1")
  365. {
  366. ocFree6 = jo["cFree6"].ToString();
  367. }
  368. if (jo["FlagcFree7"].ToString() != "" && jo["FlagcFree7"].ToString() == "1")
  369. {
  370. ocFree7 = jo["cFree7"].ToString();
  371. }
  372. if (jo["FlagcFree8"].ToString() != "" && jo["FlagcFree8"].ToString() == "1")
  373. {
  374. ocFree8 = jo["cFree8"].ToString();
  375. }
  376. if (jo["FlagcFree9"].ToString() != "" && jo["FlagcFree9"].ToString() == "1")
  377. {
  378. ocFree9 = jo["cFree9"].ToString();
  379. }
  380. if (jo["FlagcFree10"].ToString() != "" && jo["FlagcFree10"].ToString() == "1")
  381. {
  382. ocFree10 = jo["cFree10"].ToString();
  383. }
  384. //Colspan = jo["ProjectCode"].ToString() + "~" + jo["BatchCode"].ToString() + "~" + jo["Version"].ToString() + "~" + jo["Brand"].ToString() + "~" + jo["cFree1"].ToString() + "~" + jo["cFree2"].ToString() + "~" + jo["cFree3"].ToString() + "~" + jo["cFree4"].ToString() + "~" + jo["cFree5"].ToString() + "~" + jo["cFree6"].ToString() + "~" + jo["cFree7"].ToString() + "~" + jo["cFree8"].ToString() + "~" + jo["cFree9"].ToString() + "~" + jo["cFree10"].ToString();
  385. Colspan = oProjectCode + "~" + oBatchCode + "~" + oVersion + "~" + oBrand + "~" + ocFree1 + "~" + ocFree2 + "~" + ocFree3 + "~" + ocFree4 + "~" + ocFree5 + "~" + ocFree6 + "~" + ocFree7 + "~" + ocFree8 + "~" + ocFree9 + "~" + ocFree10;
  386. string sqlsss = string.Format(@"select ID from ICSExtension where Colspan='{0}'", Colspan);
  387. object ExtensionID = SqlHelper.ExecuteScalar(sqlsss);
  388. if (ExtensionID == null)
  389. {
  390. if (dic.ContainsKey(Colspan))
  391. {
  392. ExtensionID = dic[Colspan];
  393. }
  394. else
  395. {
  396. ExtensionID = Guid.NewGuid();
  397. sql += string.Format(@"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  398. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  399. ExtensionID, Colspan, oProjectCode, oBatchCode, oVersion, oBrand, ocFree1, ocFree2, ocFree3, ocFree4, ocFree5, ocFree6, ocFree7, ocFree8, ocFree9, ocFree10,
  400. MUSER, MUSERNAME, WorkPoint);
  401. dic.Add(Colspan, ExtensionID);
  402. }
  403. }
  404. #endregion
  405. string sqloldInvcode = string.Format(@"select InvCode from dbo.ICSInventoryLot where LotNo='{0}'", LotNo);
  406. object OldInvcode = SqlHelper.ExecuteScalar(sqloldInvcode);
  407. if (jo["FlagInvCode"].ToString() != "" && jo["FlagInvCode"].ToString() == "1")
  408. {
  409. OldInvcode = InvCode;
  410. }
  411. //老
  412. sql += @"INSERT INTO dbo.ICSMTDOC
  413. ( ID ,MTDOCCode,WHCode ,Sequence ,InvCode,Quantity,Amount,MTDOCQuantity,MTDOCType,Memo,Status,CreatePerson,
  414. CreateDateTime,MTDOCID,MTDOCDetailID,ExtensionID,MUSER,MUSERName ,MTIME ,WorkPoint )
  415. select NEWID(),'{0}','{1}','{2}','{15}','{4}','{5}','{6}','1','{7}','1','{8}','{16}',newid(),newid(),ExtensionID,'{10}','{11}','{16}','{12}' from ICSInventoryLot
  416. where LotNo='{3}'
  417. ";
  418. //新
  419. sql += @"INSERT INTO dbo.ICSMTDOC
  420. ( ID ,MTDOCCode,WHCode ,Sequence ,InvCode,Quantity,Amount,MTDOCQuantity,MTDOCType,Memo,Status,CreatePerson,
  421. CreateDateTime,MTDOCID,MTDOCDetailID,ExtensionID,MUSER,MUSERName ,MTIME ,WorkPoint )
  422. values(NEWID(),'{0}','{1}','{14}','{15}','{4}','{5}','{6}','2','{7}','1','{8}','{16}',newid(),newid(),'{9}','{10}','{11}','{16}','{12}')";
  423. //新增条码
  424. sql += @"INSERT into ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  425. select newid(),'{13}','{15}',ProductDate,ExpirationDate,Quantity,Amount,'{9}','102',MUSER,MUSERName,MTIME,WorkPoint,'{3}' from ICSInventoryLot
  426. where LotNo='{3}'";
  427. //新增条码关联
  428. sql += @" INSERT into ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  429. select '{13}',TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint from ICSInventoryLotDetail
  430. where LotNo='{3}'";
  431. sql = string.Format(sql, MTDOCCode, jo["WHCode"].ToString(), Num++, jo["LotNo"].ToString(), jo["Quantity"].ToString(), jo["Amount"].ToString(), jo["MTDOCQuantity"].ToString(), Memo, MUSER, ExtensionID, MUSER, MUSERNAME, WorkPoint, NewLotNo, Num++, OldInvcode, TimeNow);
  432. }
  433. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  434. {
  435. msg = "";
  436. }
  437. else
  438. {
  439. msg = "形态转换失败!";
  440. }
  441. return msg;
  442. }
  443. //审核(原逻辑)
  444. // public string ICSMTDOCAudit(string MTDOCCode)
  445. // {
  446. // string msg = "";
  447. // string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  448. // string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  449. // string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  450. // DateTime TimeNow = DateTime.Now;
  451. // string sql = string.Empty;
  452. // string sqlAsn = @" select LotNo from ICSMTDOC where MTDOCCode='{0}' and MTDOCType='2'";
  453. // sqlAsn = string.Format(sqlAsn, MTDOCCode);
  454. // DataTable dt = Repository().FindTableBySql(sqlAsn.ToString());
  455. // string Identification = Guid.NewGuid().ToString();
  456. // for (int i = 0; i < dt.Rows.Count; i++)
  457. // {
  458. // string NewLotNo = dt.Rows[i]["LotNo"].ToString();
  459. // string sqlAsnD = @"select EATTRIBUTE1,InvCode from dbo.ICSInventoryLot where LotNo='{0}' ";
  460. // sqlAsnD = string.Format(sqlAsnD, NewLotNo);
  461. // DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  462. // string OldLotNo = dtD.Rows[0]["EATTRIBUTE1"].ToString();
  463. // string NewInvCode = dtD.Rows[0]["InvCode"].ToString();
  464. // //修改形态表状态
  465. // sql += @"UPDATE ICSMTDOC set Status='2',MTIME='" + TimeNow + "',MUSER ='" + MUSER + "',MUSERName='" + MUSERNAME + "' WHERE MTDOCCode='" + MTDOCCode + "' and WorkPoint='" + WorkPoint + "'";
  466. // //加入一条老条码的出库记录
  467. // sql += @"INSERT into ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,FromWarehouseCode,FromLocationCode,
  468. // Quantity,Lock,TransType,BusinessCode,
  469. // MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  470. // select newid(),'" + Identification + "',d.MTDOCCode,d.Sequence, a.LotNo,a.InvCode,a.WarehouseCode,a.LocationCode,a.Quantity,'0' ,'10','35','" + MUSER + @"','" + MUSERNAME + @"','" + TimeNow + @"',a.WorkPoint,''
  471. // from ICSWareHouseLotInfo a
  472. // left join dbo.ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  473. // left join dbo.ICSInventoryLotDetail c on b.LotNo=c.LotNo and b.WorkPoint=c.WorkPoint
  474. // left join dbo.ICSMTDOC d on a.LotNo=d.LotNo and d.WorkPoint=c.WorkPoint
  475. // where a.LotNo='" + OldLotNo + "' and a.WorkPoint='" + WorkPoint + "'";
  476. // //新条码加入库存表
  477. // sql += @"INSERT into ICSWareHouseLotInfo(ID,LotNo,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  478. // select newid(),'" + NewLotNo + @"',a.WarehouseCode,a.LocationCode,'" + NewInvCode + @"',a.Quantity,a.InDate,a.LockQuantity,'" + MUSER + @"','" + MUSERNAME + @"','" + TimeNow + @"',a.WorkPoint,a.EATTRIBUTE1 from ICSWareHouseLotInfo a left join dbo.ICSInventoryLot b on a.LotNo=b.EATTRIBUTE1 and a.WorkPoint=b.WorkPoint
  479. // where a.LotNo='" + OldLotNo + "'";
  480. // //修改老条码库存
  481. // sql += @"UPDATE ICSWareHouseLotInfo set Quantity=0,MTIME='" + TimeNow + "',MUSER='" + MUSER + "',MUSERName='" + MUSERNAME + "' WHERE LotNo='" + OldLotNo + "'";
  482. // //库存记录加入新条码记录
  483. // sql += @"INSERT into ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,ToWarehouseCode,ToLocationCode,
  484. // Quantity,Lock,TransType,BusinessCode,
  485. // MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  486. // select newid(),'" + Identification + "',d.MTDOCCode,d.Sequence, a.LotNo,a.InvCode,a.WarehouseCode,a.LocationCode,a.Quantity,'0' ,'10','36','" + MUSER + @"','" + MUSERNAME + @"','" + TimeNow + @"',a.WorkPoint,''
  487. // from ICSWareHouseLotInfo a
  488. // left join dbo.ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  489. // left join dbo.ICSInventoryLotDetail c on b.LotNo=c.LotNo and b.WorkPoint=c.WorkPoint
  490. // left join dbo.ICSMTDOC d on a.LotNo=d.LotNo and d.WorkPoint=c.WorkPoint
  491. // where a.LotNo='" + NewLotNo + "' and a.WorkPoint='" + WorkPoint + "'";
  492. // }
  493. // sql += @" select isnull(a.DepCode,'')+a.WHCode+a.MUSER as Costre , isnull(a.DepCode,'') as DepCode,a.WHCode as InWhCode, (row_number() over(order by cast(a.Sequence as int) ,a.WHCode,b.InvCode)-1)/2+1 as GroupNO ,
  494. // a.WHCode as OutWhCode,row_number() over(order by cast(a.Sequence as int) ,a.WHCode,b.InvCode) as Sequence,b.InvCode,d.Name as [Type] ,a.WHCode as WHCode,
  495. // a.Quantity as Quantity ,a.Amount,a.MUSER as [User],a.WorkPoint,
  496. // isnull(c.BatchCode,'') as BatchCode ,isnull(c.ProjectCode,'') as ProjectCode,isnull(c.Version,'') as Version,isnull(c.Brand,'') as Brand,isnull(c.cFree1,'') as cFree1,isnull(c.cFree2,'') as cFree2,isnull(c.cFree3,'') as cFree3,isnull(c.cFree4,'') as cFree4,isnull(c.cFree5,'') as cFree5,isnull(c.cFree6,'') as cFree6,
  497. // isnull(c.cFree7,'') as cFree7,isnull(c.cFree8,'') as cFree8,isnull(c.cFree9,'') as cFree9,isnull(c.cFree10,'') as cFree10
  498. //INTO #TempERP
  499. // from ICSMTDOC a
  500. // left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  501. // left join ICSExtension c on a.ExtensionID=c.ID and a.WorkPoint=c.WorkPoint
  502. // left join ICSType d on d.TableCode='ICSMTDOC' and d.ColumnCode='MTDOCType' and d.Code=a.MTDOCType
  503. // where a.MTDOCCode='{0}' and a.WorkPoint='{1}'
  504. // select distinct Costre, DepCode,InWhCode,OutWhCode,[User],getdate() as MTime,WorkPoint FROM #TempERP
  505. // select Costre, Sequence,GroupNO,[Type],InvCode,WHCode,BatchCode,ProjectCode,Quantity,Amount,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  506. // DROP TABLE #TempERP";
  507. // sql = string.Format(sql, MTDOCCode, WorkPoint);
  508. // msg = CmdExecuteData(sql, MTDOCCode, Identification);
  509. // return msg;
  510. // }
  511. //形态转换审核传输SAP(正常情况是PDA扫码审核,但是因为形态转换单据是整单审核,创建单子时超库存建单子会导致SAP删除部分形态转换单,导致PDA无法整单扫码转换,因此增加此入口)
  512. //已经扫码完毕但是没有传输SAP的形态转换单在此传输SAP
  513. public string ICSMTDOCAudit(string MTDOCCode)
  514. {
  515. //上传ERP
  516. try
  517. {
  518. #region SAP(三层结构)
  519. string IsSuccess = "";
  520. string ErrorMessage = "";
  521. string sql = $@" select Distinct A.MTDOCCode,A.WorkPoint from ICSMTDOC A
  522. where A.MTDOCCode='{MTDOCCode}' AND A.MTDOCType='2' ";
  523. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  524. if (dt.Rows.Count > 1)
  525. {
  526. throw new Exception("单次提交只允许一张单据,请勿多单据同时提交!");//单据查询失败
  527. }
  528. for (int i = 0; i < dt.Rows.Count; i++)
  529. {
  530. string chksql = @"select SUM(Quantity) AS Quantity,SUM(MTDOCQuantity) AS MTDOCQuantity from ICSMTDOC
  531. where MTDOCCode='{0}' and WorkPoint='{1}'
  532. GROUP BY MTDOCCode,WorkPoint";
  533. chksql = string.Format(chksql, dt.Rows[i]["MTDOCCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  534. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  535. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["MTDOCQuantity"]))
  536. {
  537. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  538. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  539. Info.NEWID = Guid.NewGuid().ToString();
  540. Info.DANJU = dt.Rows[i]["MTDOCCode"].ToString();
  541. Info.STATE = "0";
  542. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  543. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  544. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  545. sql = @"select Distinct A.MTDOCCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.MTDOCQuantity
  546. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSMTDOC A
  547. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  548. WHERE MTDOCCode='{0}' AND A.WorkPoint='{1}'";
  549. sql = string.Format(sql, dt.Rows[i]["MTDOCCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  550. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  551. foreach (DataRow dr in Sapdt.Rows)
  552. {
  553. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["MTDOCQuantity"].ToString()))
  554. {
  555. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  556. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  557. Item.DANJU = dr["MTDOCCode"].ToString();
  558. Item.POSNR = dr["SAPSequence"].ToString();
  559. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  560. ItemList.Add(Item);
  561. if (dr["BatchCode"].ToString() != "")
  562. {
  563. ItemLine.DANJU = dr["MTDOCCode"].ToString();
  564. ItemLine.POSNR = dr["SAPSequence"].ToString();
  565. ItemLine.MATNR = dr["InvCode"].ToString();
  566. ItemLine.GERNR = dr["BatchCode"].ToString();
  567. ItemLineList.Add(ItemLine);
  568. }
  569. }
  570. }
  571. if (ItemList.Count > 0)
  572. {
  573. Info.Z_ITEM = ItemList.ToArray();
  574. if (ItemLineList.Count > 0)
  575. {
  576. Info.Z_GERNR = ItemLineList.ToArray();
  577. }
  578. else
  579. {
  580. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  581. }
  582. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  583. result = Client.CallZWMS_SK_WS_PZ(Info);
  584. if (result.Z_NULL == "N")
  585. {
  586. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  587. {
  588. IsSuccess = "N";
  589. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  590. }
  591. }
  592. }
  593. }
  594. }
  595. if (IsSuccess == "N")
  596. {
  597. throw new Exception(ErrorMessage);
  598. }
  599. #endregion
  600. return ErrorMessage;
  601. }
  602. catch (Exception ex)
  603. {
  604. throw new Exception(ex.Message);//单据查询失败
  605. }
  606. }
  607. public string CmdExecuteData(string sql, string MTDOCCode, string Identification)
  608. {
  609. string msg = "";
  610. try
  611. {
  612. string connString = SqlHelper.DataCenterConnString;
  613. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  614. conn.Open();
  615. SqlTransaction sqlTran = conn.BeginTransaction();
  616. SqlCommand cmd = new SqlCommand();
  617. cmd.Transaction = sqlTran;
  618. cmd.Connection = conn;
  619. try
  620. {
  621. DataSet DSet = SqlCommandHelper.SQlReturnDataSet(sql, cmd);
  622. string Inputstr = SqlHelper.DataSetToJson(DSet, "details", "Costre");
  623. string APIURL = ConfigurationManager.ConnectionStrings["ERPAPIURL"].ConnectionString + "MorphologicalTransformationDoc/Create";
  624. string result = HttpPost(APIURL, Inputstr);
  625. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  626. string MessAge = Obj["Message"].ToString();
  627. string Success = Obj["Success"].ToString();
  628. string ERPSql = "";
  629. if (Success.ToUpper() == "FALSE")
  630. {
  631. throw new Exception(MessAge);
  632. }
  633. else
  634. {
  635. try
  636. {
  637. JArray res = (JArray)JsonConvert.DeserializeObject(Obj["Data"].ToString());
  638. foreach (var item in res)
  639. {
  640. JObject jo = (JObject)item;
  641. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  642. foreach (var detail in resdetail)
  643. {
  644. JObject det = (JObject)detail;
  645. ERPSql += @"UPDATE a set ERPID='{3}',ERPDetailID='{4}',ERPCode='{5}',ERPSequence='{6}',ERPUpload='1'
  646. from ICSWareHouseLotInfoLog a
  647. inner join ICSMTDOC b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  648. where b.MTDOCCode='{0}' and b.Sequence='{1}' and a.Identification='{2}'";
  649. ERPSql += @" update ICSMTDOC set MTDOCID='{3}',MTDOCDetailID='{4}' where MTDOCCode='{0}' and Sequence='{1}'";
  650. ERPSql = string.Format(ERPSql, MTDOCCode, det["Sequence"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["MTCode"].ToString(), det["Sequence"].ToString());
  651. }
  652. }
  653. SqlCommandHelper.CmdExecuteNonQuery(ERPSql, cmd);
  654. }
  655. catch (Exception ex)
  656. {
  657. msg = ex.Message;
  658. }
  659. }
  660. cmd.Transaction.Commit();
  661. //return dt;
  662. }
  663. catch (Exception ex)
  664. {
  665. cmd.Transaction.Rollback();
  666. msg = ex.Message;
  667. }
  668. finally
  669. {
  670. if (conn.State == ConnectionState.Open)
  671. {
  672. conn.Close();
  673. }
  674. conn.Dispose();
  675. }
  676. }
  677. catch (Exception ex)
  678. {
  679. msg = ex.Message;
  680. }
  681. return msg;
  682. }
  683. public static string HttpPost(string url, string body)
  684. {
  685. try
  686. {
  687. Encoding encoding = Encoding.UTF8;
  688. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  689. request.Method = "POST";
  690. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  691. request.ContentType = "application/json; charset=utf-8";
  692. byte[] buffer = encoding.GetBytes(body);
  693. request.ContentLength = buffer.Length;
  694. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  695. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  696. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  697. {
  698. return reader.ReadToEnd();
  699. }
  700. }
  701. catch (WebException ex)
  702. {
  703. throw new Exception(ex.Message);
  704. }
  705. }
  706. //形态转换导入
  707. public string ToLead(String savePath, string Year)
  708. {
  709. //数据获取
  710. try
  711. {
  712. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  713. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  714. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  715. SqlConnection conn = SqlHelper.GetDataCenterConn();
  716. DataTable data = FileToExcel.ExcelToTable(savePath);
  717. int index = 1;
  718. string Time = DateTime.Now.ToString("yyyyMMdd");
  719. string MTDOCCode = "";
  720. string Memo = "";
  721. decimal Amount = 0;
  722. DateTime TimeNow = DateTime.Now;
  723. int Num = 1;
  724. DateTime time = DateTime.Now;
  725. string sql = string.Empty;
  726. string sqltxt = string.Empty;
  727. sql = string.Format(@"SELECT a.LotNo, a.InvCode, b.ProjectCode, b.BatchCode, b.Version, b.Brand, b.cFree1, b.cFree2, b.cFree3, b.cFree4, b.cFree5, b.cFree6, b.cFree7, b.cFree8, b.cFree9, b.cFree10 FROM ICSInventoryLot AS a LEFT JOIN ICSExtension AS b ON a.ExtensionID = b.ID AND a.WorkPoint = b.WorkPoint where a.WorkPoint ='{0}' ", WorkPoint);
  728. sql += string.Format(@"select LotNo,InvCode from ICSInventoryLot where WorkPoint ='{0}' ", WorkPoint);
  729. sql += string.Format(@"select a.LotNo,a.WarehouseCode,a.InvCode,a.Quantity,b.Amount from ICSWareHouseLotInfo a left JOIN ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint where a.WorkPoint ='{0}' ", WorkPoint);
  730. sql += string.Format(@"select max(MTDOCCode) as NewMTDOCCode from ICSMTDOC where substring(MTDOCCode,1,8)='{0}'", Time);
  731. DataSet ds = SqlHelper.GetDataSetBySql(sql);
  732. if (data != null && data.Rows.Count > 0)
  733. {
  734. foreach (DataRow dr in data.Rows)
  735. {
  736. index++;
  737. #region 获取数据及卡控
  738. string LotNo = dr["条码"].ToString();
  739. string FrontInvCode = dr["转换前料号"].ToString();
  740. string LaterInvCode = dr["转换后料号"].ToString();
  741. string FrontProjectCode = string.Empty;
  742. string LaterProjectCode = string.Empty;
  743. string FrontBatchCode = string.Empty;
  744. string LaterBatchCode = string.Empty;
  745. string FrontVersion = string.Empty;
  746. string LaterVersion = string.Empty;
  747. string FrontBrand = string.Empty;
  748. string LaterBrand = string.Empty;
  749. string FrontcFree1 = string.Empty;
  750. string LatercFree1 = string.Empty;
  751. string FrontcFree2 = string.Empty;
  752. string LatercFree2 = string.Empty;
  753. string FrontcFree3 = string.Empty;
  754. string LatercFree3 = string.Empty;
  755. string FrontcFree4 = string.Empty;
  756. string LatercFree4 = string.Empty;
  757. string FrontcFree5 = string.Empty;
  758. string LatercFree5 = string.Empty;
  759. string FrontcFree6 = string.Empty;
  760. string LatercFree6 = string.Empty;
  761. string FrontcFree7 = string.Empty;
  762. string LatercFree7 = string.Empty;
  763. string FrontcFree8 = string.Empty;
  764. string LatercFree8 = string.Empty;
  765. string FrontcFree9 = string.Empty;
  766. string LatercFree9 = string.Empty;
  767. string FrontcFree10 = string.Empty;
  768. string LatercFree10 = string.Empty;
  769. if (data.Columns.Contains("转换前项目号")) { FrontProjectCode = dr["转换前项目号"].ToString(); }
  770. if (data.Columns.Contains("转换后项目号")) { LaterProjectCode = dr["转换后项目号"].ToString(); }
  771. if (data.Columns.Contains("转换前批次")) { FrontBatchCode = dr["转换前批次"].ToString(); }
  772. if (data.Columns.Contains("转换后批次")) { FrontBatchCode = dr["转换后批次"].ToString(); }
  773. if (data.Columns.Contains("转换前版本")) { FrontVersion = dr["转换前版本"].ToString(); }
  774. if (data.Columns.Contains("转换后版本")) { LaterVersion = dr["转换后版本"].ToString(); }
  775. if (data.Columns.Contains("转换前厂牌")) { FrontBrand = dr["转换前厂牌"].ToString(); }
  776. if (data.Columns.Contains("转换后厂牌")) { LaterBrand = dr["转换后厂牌"].ToString(); }
  777. if (data.Columns.Contains("转换前自由项1")) { FrontcFree1 = dr["转换前自由项1"].ToString(); }
  778. if (data.Columns.Contains("转换后自由项1")) { LatercFree1 = dr["转换后自由项1"].ToString(); }
  779. if (data.Columns.Contains("转换前自由项2")) { FrontcFree2 = dr["转换前自由项2"].ToString(); }
  780. if (data.Columns.Contains("转换后自由项2")) { LatercFree2 = dr["转换后自由项2"].ToString(); }
  781. if (data.Columns.Contains("转换前自由项3")) { FrontcFree3 = dr["转换前自由项3"].ToString(); }
  782. if (data.Columns.Contains("转换后自由项3")) { LatercFree3 = dr["转换后自由项3"].ToString(); }
  783. if (data.Columns.Contains("转换前自由项4")) { FrontcFree4 = dr["转换前自由项4"].ToString(); }
  784. if (data.Columns.Contains("转换后自由项4")) { LatercFree4 = dr["转换后自由项4"].ToString(); }
  785. if (data.Columns.Contains("转换前自由项5")) { FrontcFree5 = dr["转换前自由项5"].ToString(); }
  786. if (data.Columns.Contains("转换后自由项5")) { LatercFree5 = dr["转换后自由项5"].ToString(); }
  787. if (data.Columns.Contains("转换前自由项6")) { FrontcFree6 = dr["转换前自由项6"].ToString(); }
  788. if (data.Columns.Contains("转换后自由项6")) { LatercFree6 = dr["转换后自由项6"].ToString(); }
  789. if (data.Columns.Contains("转换前自由项7")) { FrontcFree7 = dr["转换前自由项7"].ToString(); }
  790. if (data.Columns.Contains("转换后自由项7")) { LatercFree7 = dr["转换后自由项7"].ToString(); }
  791. if (data.Columns.Contains("转换前自由项8")) { FrontcFree8 = dr["转换前自由项8"].ToString(); }
  792. if (data.Columns.Contains("转换后自由项8")) { LatercFree8 = dr["转换后自由项8"].ToString(); }
  793. if (data.Columns.Contains("转换前自由项9")) { FrontcFree9 = dr["转换前自由项9"].ToString(); }
  794. if (data.Columns.Contains("转换后自由项9")) { LatercFree9 = dr["转换后自由项9"].ToString(); }
  795. if (data.Columns.Contains("转换前自由项10")) { FrontcFree10 = dr["转换前自由项10"].ToString(); }
  796. if (data.Columns.Contains("转换后自由项10")) { LatercFree10 = dr["转换后自由项10"].ToString(); }
  797. string FrontColspan = FrontProjectCode + "~" + FrontBatchCode + "~" + FrontVersion + "~" + FrontBrand + "~" + FrontcFree1 + "~" + FrontcFree2 + "~" + FrontcFree3 + "~" + FrontcFree4 + "~" + FrontcFree5 + "~" + FrontcFree6 + "~" + FrontcFree7 + "~" + FrontcFree8 + "~" + FrontcFree9 + "~" + FrontcFree10;
  798. string LaterColspan = LaterProjectCode + "~" + LaterBatchCode + "~" + LaterVersion + "~" + LaterBrand + "~" + LatercFree1 + "~" + LatercFree2 + "~" + LatercFree3 + "~" + LatercFree4 + "~" + LatercFree5 + "~" + LatercFree6 + "~" + LatercFree7 + "~" + LatercFree8 + "~" + LatercFree9 + "~" + LatercFree10;
  799. //if (LotNo == null || LotNo == "")
  800. //{
  801. // throw new Exception("第 " + index + " 行,请输入条码!");
  802. //}
  803. if (!string.IsNullOrEmpty(FrontInvCode))
  804. {
  805. if (string.IsNullOrEmpty(LaterInvCode))
  806. {
  807. throw new Exception("第 " + index + " 行,已输入转换前料号,请输入转换后料号!");
  808. }
  809. }
  810. else if (!string.IsNullOrEmpty(LaterInvCode))
  811. {
  812. if (string.IsNullOrEmpty(FrontInvCode))
  813. {
  814. throw new Exception("第 " + index + " 行,已输入转换后料号,请输入转换前料号!");
  815. }
  816. }
  817. var LotNoResult = ds.Tables[2].Select(string.Format(" LotNo='{0}'", LotNo));
  818. if (LotNoResult == null || LotNoResult.Length <= 0)
  819. {
  820. throw new Exception("第 " + index + " 行,条码:" + LotNo + "未查询到库存信息!");
  821. }
  822. var FrontInvCodeResult = ds.Tables[2].Select(string.Format("InvCode='{0}' and LotNo='{1}'", FrontInvCode, LotNo));
  823. if (FrontInvCodeResult == null || FrontInvCodeResult.Length <= 0)
  824. {
  825. throw new Exception("第 " + index + " 行,转换前料号:" + FrontInvCode + " 与条码对应信息不符!");
  826. }
  827. if (!string.IsNullOrEmpty(FrontProjectCode) || !string.IsNullOrEmpty(LaterProjectCode))
  828. {
  829. var ProjectCodeResult = ds.Tables[0].Select(string.Format("ProjectCode='{0}' and LotNo='{1}'", FrontProjectCode, LotNo));
  830. if (ProjectCodeResult == null || ProjectCodeResult.Length <= 0)
  831. {
  832. throw new Exception("第 " + index + " 行,转换前项目号:" + FrontProjectCode + " 与条码对应信息不符合!");
  833. }
  834. }
  835. if (!string.IsNullOrEmpty(FrontBatchCode) || !string.IsNullOrEmpty(LaterBatchCode))
  836. {
  837. var BatchCodeResult = ds.Tables[0].Select(string.Format("BatchCode='{0}' and LotNo='{1}'", FrontBatchCode, LotNo));
  838. if (BatchCodeResult == null || BatchCodeResult.Length <= 0)
  839. {
  840. throw new Exception("第 " + index + " 行,转换前批次:" + FrontBatchCode + " 与条码对应信息不符合!");
  841. }
  842. }
  843. if (!string.IsNullOrEmpty(FrontVersion) || !string.IsNullOrEmpty(LaterVersion))
  844. {
  845. var VersionResult = ds.Tables[0].Select(string.Format("Version='{0}' and LotNo='{1}'", FrontVersion, LotNo));
  846. if (VersionResult == null || VersionResult.Length <= 0)
  847. {
  848. throw new Exception("第 " + index + " 行,转换前版本:" + FrontVersion + " 与条码对应信息不符合!");
  849. }
  850. }
  851. if (!string.IsNullOrEmpty(FrontBrand) || !string.IsNullOrEmpty(LaterBrand))
  852. {
  853. var BrandResult = ds.Tables[0].Select(string.Format("Brand='{0}' and LotNo='{1}'", FrontBrand, LotNo));
  854. if (BrandResult == null || BrandResult.Length <= 0)
  855. {
  856. throw new Exception("第 " + index + " 行,转换前厂牌:" + FrontBrand + " 与条码对应信息不符合!");
  857. }
  858. }
  859. if (!string.IsNullOrEmpty(FrontcFree1) || !string.IsNullOrEmpty(LatercFree1))
  860. {
  861. var cFree1Result = ds.Tables[0].Select(string.Format("cFree1='{0}' and LotNo='{1}'", FrontcFree1, LotNo));
  862. if (cFree1Result == null || cFree1Result.Length <= 0)
  863. {
  864. throw new Exception("第 " + index + " 行,转换前自由项1:" + FrontcFree1 + " 与条码对应信息不符合!");
  865. }
  866. }
  867. if (!string.IsNullOrEmpty(FrontcFree2) || !string.IsNullOrEmpty(LatercFree2))
  868. {
  869. var cFree2Result = ds.Tables[0].Select(string.Format("cFree2='{0}' and LotNo='{1}'", FrontcFree2, LotNo));
  870. if (cFree2Result == null || cFree2Result.Length <= 0)
  871. {
  872. throw new Exception("第 " + index + " 行,转换前自由项2:" + FrontcFree2 + " 与条码对应信息不符合!");
  873. }
  874. }
  875. if (!string.IsNullOrEmpty(FrontcFree3) || !string.IsNullOrEmpty(LatercFree3))
  876. {
  877. var cFree3Result = ds.Tables[0].Select(string.Format("cFree3='{0}' and LotNo='{1}'", FrontcFree3, LotNo));
  878. if (cFree3Result == null || cFree3Result.Length <= 0)
  879. {
  880. throw new Exception("第 " + index + " 行,转换前自由项3:" + FrontcFree3 + " 与条码对应信息不符合!");
  881. }
  882. }
  883. if (!string.IsNullOrEmpty(FrontcFree4) || !string.IsNullOrEmpty(LatercFree4))
  884. {
  885. var cFree4Result = ds.Tables[0].Select(string.Format("cFree4='{0}' and LotNo='{1}'", FrontcFree4, LotNo));
  886. if (cFree4Result == null || cFree4Result.Length <= 0)
  887. {
  888. throw new Exception("第 " + index + " 行,转换前自由项4:" + FrontcFree4 + " 与条码对应信息不符合!");
  889. }
  890. }
  891. if (!string.IsNullOrEmpty(FrontcFree5) || !string.IsNullOrEmpty(LatercFree5))
  892. {
  893. var cFree5Result = ds.Tables[0].Select(string.Format("cFree5='{0}' and LotNo='{1}'", FrontcFree5, LotNo));
  894. if (cFree5Result == null || cFree5Result.Length <= 0)
  895. {
  896. throw new Exception("第 " + index + " 行,转换前自由项5:" + FrontcFree5 + " 与条码对应信息不符合!");
  897. }
  898. }
  899. if (!string.IsNullOrEmpty(FrontcFree6) || !string.IsNullOrEmpty(LatercFree6))
  900. {
  901. var cFree6Result = ds.Tables[0].Select(string.Format("cFree6='{0}' and LotNo='{1}'", FrontcFree6, LotNo));
  902. if (cFree6Result == null || cFree6Result.Length <= 0)
  903. {
  904. throw new Exception("第 " + index + " 行,转换前自由项6:" + FrontcFree6 + " 与条码对应信息不符合!");
  905. }
  906. }
  907. if (!string.IsNullOrEmpty(FrontcFree7) || !string.IsNullOrEmpty(LatercFree7))
  908. {
  909. var cFree7Result = ds.Tables[0].Select(string.Format("cFree7='{0}' and LotNo='{1}'", FrontcFree7, LotNo));
  910. if (cFree7Result == null || cFree7Result.Length <= 0)
  911. {
  912. throw new Exception("第 " + index + " 行,转换前自由项7:" + FrontcFree7 + " 与条码对应信息不符合!");
  913. }
  914. }
  915. if (!string.IsNullOrEmpty(FrontcFree8) || !string.IsNullOrEmpty(LatercFree8))
  916. {
  917. var cFree8Result = ds.Tables[0].Select(string.Format("cFree8='{0}' and LotNo='{1}'", FrontcFree8, LotNo));
  918. if (cFree8Result == null || cFree8Result.Length <= 0)
  919. {
  920. throw new Exception("第 " + index + " 行,转换前自由项8:" + FrontcFree8 + " 与条码对应信息不符合!");
  921. }
  922. }
  923. if (!string.IsNullOrEmpty(FrontcFree9) || !string.IsNullOrEmpty(LatercFree9))
  924. {
  925. var cFree9Result = ds.Tables[0].Select(string.Format("cFree9='{0}' and LotNo='{1}'", FrontcFree9, LotNo));
  926. if (cFree9Result == null || cFree9Result.Length <= 0)
  927. {
  928. throw new Exception("第 " + index + " 行,转换前自由项9:" + FrontcFree9 + " 与条码对应信息不符合!");
  929. }
  930. }
  931. if (!string.IsNullOrEmpty(FrontcFree10) || !string.IsNullOrEmpty(LatercFree10))
  932. {
  933. var cFree10Result = ds.Tables[0].Select(string.Format("cFree10='{0}' and LotNo='{1}'", FrontcFree10, LotNo));
  934. if (cFree10Result == null || cFree10Result.Length <= 0)
  935. {
  936. throw new Exception("第 " + index + " 行,转换前自由项10:" + FrontcFree10 + " 与条码对应信息不符合!");
  937. }
  938. }
  939. #endregion
  940. if (ds.Tables[3] == null || ds.Tables[3].Rows.Count == 0 || ds.Tables[3].Rows[0]["NewMTDOCCode"].ToString() == "")
  941. {
  942. MTDOCCode = Time + "000001";
  943. }
  944. else
  945. {
  946. string NewMTDOCCode = ds.Tables[3].Rows[0]["NewMTDOCCode"].ToString();
  947. int COUNT = Convert.ToInt32(NewMTDOCCode.Substring(8)) + 1;
  948. MTDOCCode = Time + COUNT.ToString().PadLeft(6, '0');
  949. }
  950. string NewLotNo = "";
  951. string sqls = @"select max(LotNo) as NewLotNo from ICSInventoryLot where EATTRIBUTE1='{0}' ";
  952. sqls = string.Format(sqls, LotNo);
  953. DataTable dt = Repository().FindTableBySql(sqls.ToString());
  954. if (dt == null || dt.Rows.Count == 0 || dt.Rows[0]["NewLotNo"].ToString() == "")
  955. {
  956. NewLotNo = LotNo + "-1";
  957. }
  958. else
  959. {
  960. string newLotNO = dt.Rows[0]["NewLotNo"].ToString();
  961. int COUNT = Convert.ToInt32(newLotNO.Substring(newLotNO.LastIndexOf('-') + 1)) + 1;
  962. NewLotNo = LotNo + "-" + COUNT.ToString();
  963. }
  964. var info = ds.Tables[2].Select(string.Format(" LotNo='{0}'", LotNo));
  965. if (!string.IsNullOrEmpty(info[0]["Amount"].ToString()))
  966. {
  967. Amount = Convert.ToDecimal(info[0]["Amount"].ToString());
  968. }
  969. string sqlsss = string.Format(@"select ID from ICSExtension where Colspan='{0}'", LaterColspan);
  970. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  971. if (ExtensionID == null)
  972. {
  973. ExtensionID = Guid.NewGuid();
  974. sqltxt += string.Format(@"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  975. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  976. ExtensionID, LaterColspan, LaterProjectCode, LaterBatchCode, LaterVersion, LaterBrand, LatercFree1, LatercFree2, LatercFree3, LatercFree4, LatercFree5, LatercFree6, LatercFree7, LatercFree8, FrontcFree9, LatercFree10,
  977. MUSER, MUSERNAME, WorkPoint);
  978. }
  979. //老
  980. sqltxt += @"INSERT INTO dbo.ICSMTDOC
  981. ( ID ,MTDOCCode,WHCode ,Sequence ,LotNo,Quantity,Amount,MTDOCQuantity,MTDOCType,Memo,Status,CreatePerson,
  982. CreateDateTime,MTDOCID,MTDOCDetailID,ExtensionID,MUSER,MUSERName ,MTIME ,WorkPoint )
  983. values(NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}','1','{7}','1','{8}','{16}',newid(),newid(),'{9}','{10}','{11}','{16}','{12}')";
  984. //新
  985. sqltxt += @"INSERT INTO dbo.ICSMTDOC
  986. ( ID ,MTDOCCode,WHCode ,Sequence ,LotNo,Quantity,Amount,MTDOCQuantity,MTDOCType,Memo,Status,CreatePerson,
  987. CreateDateTime,MTDOCID,MTDOCDetailID,ExtensionID,MUSER,MUSERName ,MTIME ,WorkPoint )
  988. values(NEWID(),'{0}','{1}','{14}','{13}','{4}','{5}','{6}','2','{7}','1','{8}','{16}',newid(),newid(),'{9}','{10}','{11}','{16}','{12}')";
  989. //新增条码
  990. sqltxt += @"INSERT into ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  991. select newid(),'{13}','{15}',ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,'102',MUSER,MUSERName,MTIME,WorkPoint,'{3}' from ICSInventoryLot
  992. where LotNo='{3}'";
  993. //新增条码关联
  994. sqltxt += @" INSERT into ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  995. select '{13}',TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint from ICSInventoryLotDetail
  996. where LotNo='{3}'";
  997. sqltxt = string.Format(sqltxt, MTDOCCode, info[0]["WarehouseCode"].ToString(), Num++, info[0]["LotNo"].ToString(), info[0]["Quantity"].ToString(), Amount, info[0]["Quantity"].ToString(), Memo, MUSER, ExtensionID, MUSER, MUSERNAME, WorkPoint, NewLotNo, Num++, info[0]["InvCode"].ToString(), TimeNow);
  998. }
  999. SqlHelper.CmdExecuteNonQueryLi(sqltxt);
  1000. }
  1001. else
  1002. {
  1003. return "无有效的导入数据。";
  1004. }
  1005. return "true";
  1006. }
  1007. catch (Exception ex)
  1008. {
  1009. return ex.Message;
  1010. }
  1011. }
  1012. public string GetNewid()
  1013. {
  1014. string sql = "select newid() AS ID";
  1015. return Repository().FindTableBySql(sql, null).Rows[0]["ID"].ToString();
  1016. }
  1017. }
  1018. }