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

1078 lines
63 KiB

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