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

957 lines
56 KiB

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