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

964 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
3 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
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. #region 根据原条码查询并创建新条码
  272. string sqls = @"select max(LotNo) as NewLotNo from ICSInventoryLot where EATTRIBUTE1='{0}' ";
  273. sqls = string.Format(sqls, LotNo);
  274. dt = Repository().FindTableBySql(sqls.ToString());
  275. if (dt == null || dt.Rows.Count == 0 || dt.Rows[0]["NewLotNo"].ToString() == "")
  276. {
  277. NewLotNo = LotNo + "-1";
  278. }
  279. else
  280. {
  281. string newLotNO = dt.Rows[0]["NewLotNo"].ToString();
  282. int COUNT = Convert.ToInt32(newLotNO.Substring(newLotNO.LastIndexOf('-') + 1)) + 1;
  283. NewLotNo= LotNo + "-" + COUNT.ToString();
  284. }
  285. #endregion
  286. #region 查询并插入Extension
  287. 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);
  288. DataTable oldLotNo = SqlHelper.GetDataTableBySql(sqloldLotNo);
  289. string oProjectCode = oldLotNo.Rows[0]["ProjectCode"].ToString();
  290. string oBatchCode = oldLotNo.Rows[0]["BatchCode"].ToString();
  291. string oVersion = oldLotNo.Rows[0]["Version"].ToString();
  292. string oBrand = oldLotNo.Rows[0]["Brand"].ToString();
  293. string ocFree1 = oldLotNo.Rows[0]["cFree1"].ToString();
  294. string ocFree2 = oldLotNo.Rows[0]["cFree2"].ToString();
  295. string ocFree3 = oldLotNo.Rows[0]["cFree3"].ToString();
  296. string ocFree4 = oldLotNo.Rows[0]["cFree4"].ToString();
  297. string ocFree5 = oldLotNo.Rows[0]["cFree5"].ToString();
  298. string ocFree6 = oldLotNo.Rows[0]["cFree6"].ToString();
  299. string ocFree7 = oldLotNo.Rows[0]["cFree7"].ToString();
  300. string ocFree8 = oldLotNo.Rows[0]["cFree8"].ToString();
  301. string ocFree9 = oldLotNo.Rows[0]["cFree9"].ToString();
  302. string ocFree10 = oldLotNo.Rows[0]["cFree10"].ToString();
  303. if (jo["FlagProjectCode"].ToString()!=""&& jo["FlagProjectCode"].ToString()=="1")
  304. {
  305. oProjectCode = jo["ProjectCode"].ToString();
  306. }
  307. if (jo["FlagBatchCode"].ToString() != "" && jo["FlagBatchCode"].ToString() == "1")
  308. {
  309. oBatchCode = jo["BatchCode"].ToString();
  310. }
  311. if (jo["FlagVersion"].ToString() != "" && jo["FlagVersion"].ToString() == "1")
  312. {
  313. oVersion = jo["Version"].ToString();
  314. }
  315. if (jo["FlagBrand"].ToString() != "" && jo["FlagBrand"].ToString() == "1")
  316. {
  317. oBrand = jo["Brand"].ToString();
  318. }
  319. if (jo["FlagcFree1"].ToString() != "" && jo["FlagcFree1"].ToString() == "1")
  320. {
  321. ocFree1 = jo["cFree1"].ToString();
  322. }
  323. if (jo["FlagcFree2"].ToString() != "" && jo["FlagcFree2"].ToString() == "1")
  324. {
  325. ocFree2 = jo["cFree2"].ToString();
  326. }
  327. if (jo["FlagcFree3"].ToString() != "" && jo["FlagcFree3"].ToString() == "1")
  328. {
  329. ocFree3 = jo["cFree3"].ToString();
  330. }
  331. if (jo["FlagcFree4"].ToString() != "" && jo["FlagcFree4"].ToString() == "1")
  332. {
  333. ocFree4 = jo["cFree4"].ToString();
  334. }
  335. if (jo["FlagcFree5"].ToString() != "" && jo["FlagcFree5"].ToString() == "1")
  336. {
  337. ocFree5 = jo["cFree5"].ToString();
  338. }
  339. if (jo["FlagcFree6"].ToString() != "" && jo["FlagcFree6"].ToString() == "1")
  340. {
  341. ocFree6 = jo["cFree6"].ToString();
  342. }
  343. if (jo["FlagcFree7"].ToString() != "" && jo["FlagcFree7"].ToString() == "1")
  344. {
  345. ocFree7 = jo["cFree7"].ToString();
  346. }
  347. if (jo["FlagcFree8"].ToString() != "" && jo["FlagcFree8"].ToString() == "1")
  348. {
  349. ocFree8 = jo["cFree8"].ToString();
  350. }
  351. if (jo["FlagcFree9"].ToString() != "" && jo["FlagcFree9"].ToString() == "1")
  352. {
  353. ocFree9 = jo["cFree9"].ToString();
  354. }
  355. if (jo["FlagcFree10"].ToString() != "" && jo["FlagcFree10"].ToString() == "1")
  356. {
  357. ocFree10 = jo["cFree10"].ToString();
  358. }
  359. //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();
  360. Colspan = oProjectCode + "~" + oBatchCode + "~" + oVersion + "~" + oBrand + "~" + ocFree1 + "~" + ocFree2 + "~" + ocFree3 + "~" + ocFree4 + "~" + ocFree5+ "~" + ocFree6+ "~" + ocFree7+ "~" + ocFree8+ "~" + ocFree9+ "~" + ocFree10;
  361. string sqlsss = string.Format(@"select ID from ICSExtension where Colspan='{0}'", Colspan);
  362. object ExtensionID = SqlHelper.ExecuteScalar(sqlsss);
  363. if (ExtensionID == null)
  364. {
  365. if (dic.ContainsKey(Colspan))
  366. {
  367. ExtensionID = dic[Colspan];
  368. }
  369. else
  370. {
  371. ExtensionID = Guid.NewGuid();
  372. 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)
  373. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  374. ExtensionID, Colspan, oProjectCode, oBatchCode, oVersion, oBrand, ocFree1, ocFree2, ocFree3, ocFree4, ocFree5, ocFree6, ocFree7, ocFree8, ocFree9, ocFree10,
  375. MUSER, MUSERNAME, WorkPoint);
  376. dic.Add(Colspan, ExtensionID);
  377. }
  378. }
  379. #endregion
  380. string sqloldInvcode = string.Format(@"select InvCode from dbo.ICSInventoryLot where LotNo='{0}'", LotNo);
  381. object OldInvcode = SqlHelper.ExecuteScalar(sqloldInvcode);
  382. if (jo["FlagInvCode"].ToString() != "" && jo["FlagInvCode"].ToString() == "1")
  383. {
  384. OldInvcode = InvCode;
  385. }
  386. //老
  387. sql += @"INSERT INTO dbo.ICSMTDOC
  388. ( ID ,MTDOCCode,WHCode ,Sequence ,InvCode,Quantity,Amount,MTDOCQuantity,MTDOCType,Memo,Status,CreatePerson,
  389. CreateDateTime,MTDOCID,MTDOCDetailID,ExtensionID,MUSER,MUSERName ,MTIME ,WorkPoint )
  390. select NEWID(),'{0}','{1}','{2}','{15}','{4}','{5}','{6}','1','{7}','1','{8}','{16}',newid(),newid(),ExtensionID,'{10}','{11}','{16}','{12}' from ICSInventoryLot
  391. where LotNo='{3}'
  392. ";
  393. //新
  394. sql += @"INSERT INTO dbo.ICSMTDOC
  395. ( ID ,MTDOCCode,WHCode ,Sequence ,InvCode,Quantity,Amount,MTDOCQuantity,MTDOCType,Memo,Status,CreatePerson,
  396. CreateDateTime,MTDOCID,MTDOCDetailID,ExtensionID,MUSER,MUSERName ,MTIME ,WorkPoint )
  397. values(NEWID(),'{0}','{1}','{14}','{15}','{4}','{5}','{6}','2','{7}','1','{8}','{16}',newid(),newid(),'{9}','{10}','{11}','{16}','{12}')";
  398. //新增条码
  399. sql += @"INSERT into ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  400. select newid(),'{13}','{15}',ProductDate,ExpirationDate,Quantity,Amount,'{9}','102',MUSER,MUSERName,MTIME,WorkPoint,'{3}' from ICSInventoryLot
  401. where LotNo='{3}'";
  402. //新增条码关联
  403. sql+= @" INSERT into ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  404. select '{13}',TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint from ICSInventoryLotDetail
  405. where LotNo='{3}'";
  406. 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);
  407. }
  408. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  409. {
  410. msg ="";
  411. }
  412. else
  413. {
  414. msg = "形态转换失败!";
  415. }
  416. return msg;
  417. }
  418. //审核
  419. public string ICSMTDOCAudit(string MTDOCCode)
  420. {
  421. string msg = "";
  422. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  423. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  424. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  425. DateTime TimeNow = DateTime.Now;
  426. string sql = string.Empty;
  427. string sqlAsn = @" select LotNo from ICSMTDOC where MTDOCCode='{0}' and MTDOCType='2'";
  428. sqlAsn = string.Format(sqlAsn, MTDOCCode);
  429. DataTable dt = Repository().FindTableBySql(sqlAsn.ToString());
  430. string Identification = Guid.NewGuid().ToString();
  431. for (int i = 0; i < dt.Rows.Count; i++)
  432. {
  433. string NewLotNo = dt.Rows[i]["LotNo"].ToString();
  434. string sqlAsnD = @"select EATTRIBUTE1,InvCode from dbo.ICSInventoryLot where LotNo='{0}' ";
  435. sqlAsnD = string.Format(sqlAsnD, NewLotNo);
  436. DataTable dtD = Repository().FindTableBySql(sqlAsnD.ToString());
  437. string OldLotNo = dtD.Rows[0]["EATTRIBUTE1"].ToString();
  438. string NewInvCode = dtD.Rows[0]["InvCode"].ToString();
  439. //修改形态表状态
  440. sql += @"UPDATE ICSMTDOC set Status='2',MTIME='" + TimeNow + "',MUSER ='" + MUSER + "',MUSERName='" + MUSERNAME + "' WHERE MTDOCCode='" + MTDOCCode + "' and WorkPoint='" + WorkPoint + "'";
  441. //加入一条老条码的出库记录
  442. sql += @"INSERT into ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,FromWarehouseCode,FromLocationCode,
  443. Quantity,Lock,TransType,BusinessCode,
  444. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  445. 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,''
  446. from ICSWareHouseLotInfo a
  447. left join dbo.ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  448. left join dbo.ICSInventoryLotDetail c on b.LotNo=c.LotNo and b.WorkPoint=c.WorkPoint
  449. left join dbo.ICSMTDOC d on a.LotNo=d.LotNo and d.WorkPoint=c.WorkPoint
  450. where a.LotNo='" + OldLotNo + "' and a.WorkPoint='" + WorkPoint + "'";
  451. //新条码加入库存表
  452. sql += @"INSERT into ICSWareHouseLotInfo(ID,LotNo,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  453. 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
  454. where a.LotNo='" + OldLotNo + "'";
  455. //修改老条码库存
  456. sql += @"UPDATE ICSWareHouseLotInfo set Quantity=0,MTIME='" + TimeNow + "',MUSER='" + MUSER + "',MUSERName='" + MUSERNAME + "' WHERE LotNo='" + OldLotNo + "'";
  457. //库存记录加入新条码记录
  458. sql += @"INSERT into ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,ToWarehouseCode,ToLocationCode,
  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','36','" + 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='" + NewLotNo + "' and a.WorkPoint='" + WorkPoint + "'";
  467. }
  468. 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 ,
  469. 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,
  470. a.Quantity as Quantity ,a.Amount,a.MUSER as [User],a.WorkPoint,
  471. 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,
  472. isnull(c.cFree7,'') as cFree7,isnull(c.cFree8,'') as cFree8,isnull(c.cFree9,'') as cFree9,isnull(c.cFree10,'') as cFree10
  473. INTO #TempERP
  474. from ICSMTDOC a
  475. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  476. left join ICSExtension c on a.ExtensionID=c.ID and a.WorkPoint=c.WorkPoint
  477. left join ICSType d on d.TableCode='ICSMTDOC' and d.ColumnCode='MTDOCType' and d.Code=a.MTDOCType
  478. where a.MTDOCCode='{0}' and a.WorkPoint='{1}'
  479. select distinct Costre, DepCode,InWhCode,OutWhCode,[User],getdate() as MTime,WorkPoint FROM #TempERP
  480. 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
  481. DROP TABLE #TempERP";
  482. sql = string.Format(sql, MTDOCCode, WorkPoint);
  483. msg= CmdExecuteData(sql, MTDOCCode, Identification);
  484. return msg;
  485. }
  486. public string CmdExecuteData(string sql,string MTDOCCode,string Identification)
  487. {
  488. string msg = "";
  489. try
  490. {
  491. string connString = SqlHelper.DataCenterConnString;
  492. SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
  493. conn.Open();
  494. SqlTransaction sqlTran = conn.BeginTransaction();
  495. SqlCommand cmd = new SqlCommand();
  496. cmd.Transaction = sqlTran;
  497. cmd.Connection = conn;
  498. try
  499. {
  500. DataSet DSet = SqlCommandHelper.SQlReturnDataSet(sql, cmd);
  501. string Inputstr = SqlHelper.DataSetToJson(DSet, "details", "Costre");
  502. string APIURL = ConfigurationManager.ConnectionStrings["ERPAPIURL"].ConnectionString + "MorphologicalTransformationDoc/Create";
  503. string result = HttpPost(APIURL, Inputstr);
  504. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  505. string MessAge = Obj["Message"].ToString();
  506. string Success = Obj["Success"].ToString();
  507. string ERPSql = "";
  508. if (Success.ToUpper() == "FALSE")
  509. {
  510. throw new Exception(MessAge);
  511. }
  512. else
  513. {
  514. try
  515. {
  516. JArray res = (JArray)JsonConvert.DeserializeObject(Obj["Data"].ToString());
  517. foreach (var item in res)
  518. {
  519. JObject jo = (JObject)item;
  520. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  521. foreach (var detail in resdetail)
  522. {
  523. JObject det = (JObject)detail;
  524. ERPSql += @"UPDATE a set ERPID='{3}',ERPDetailID='{4}',ERPCode='{5}',ERPSequence='{6}',ERPUpload='1'
  525. from ICSWareHouseLotInfoLog a
  526. inner join ICSMTDOC b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  527. where b.MTDOCCode='{0}' and b.Sequence='{1}' and a.Identification='{2}'";
  528. ERPSql += @" update ICSMTDOC set MTDOCID='{3}',MTDOCDetailID='{4}' where MTDOCCode='{0}' and Sequence='{1}'";
  529. ERPSql = string.Format(ERPSql, MTDOCCode, det["Sequence"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["MTCode"].ToString() , det["Sequence"].ToString());
  530. }
  531. }
  532. SqlCommandHelper.CmdExecuteNonQuery(ERPSql, cmd);
  533. }
  534. catch (Exception ex)
  535. {
  536. msg = ex.Message;
  537. }
  538. }
  539. cmd.Transaction.Commit();
  540. //return dt;
  541. }
  542. catch (Exception ex)
  543. {
  544. cmd.Transaction.Rollback();
  545. msg = ex.Message;
  546. }
  547. finally
  548. {
  549. if (conn.State == ConnectionState.Open)
  550. {
  551. conn.Close();
  552. }
  553. conn.Dispose();
  554. }
  555. }
  556. catch (Exception ex)
  557. {
  558. msg = ex.Message;
  559. }
  560. return msg;
  561. }
  562. public static string HttpPost(string url, string body)
  563. {
  564. try
  565. {
  566. Encoding encoding = Encoding.UTF8;
  567. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  568. request.Method = "POST";
  569. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  570. request.ContentType = "application/json; charset=utf-8";
  571. byte[] buffer = encoding.GetBytes(body);
  572. request.ContentLength = buffer.Length;
  573. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  574. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  575. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  576. {
  577. return reader.ReadToEnd();
  578. }
  579. }
  580. catch (WebException ex)
  581. {
  582. throw new Exception(ex.Message);
  583. }
  584. }
  585. //形态转换导入
  586. public string ToLead(String savePath, string Year)
  587. {
  588. //数据获取
  589. try
  590. {
  591. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  592. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  593. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  594. SqlConnection conn = SqlHelper.GetDataCenterConn();
  595. DataTable data = FileToExcel.ExcelToTable(savePath);
  596. int index = 1;
  597. string Time = DateTime.Now.ToString("yyyyMMdd");
  598. string MTDOCCode = "";
  599. string Memo = "";
  600. decimal Amount = 0;
  601. DateTime TimeNow = DateTime.Now;
  602. int Num = 1;
  603. DateTime time = DateTime.Now;
  604. string sql = string.Empty;
  605. string sqltxt = string.Empty;
  606. 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);
  607. sql += string.Format(@"select LotNo,InvCode from ICSInventoryLot where WorkPoint ='{0}' ", WorkPoint);
  608. 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);
  609. sql += string.Format(@"select max(MTDOCCode) as NewMTDOCCode from ICSMTDOC where substring(MTDOCCode,1,8)='{0}'", Time);
  610. DataSet ds = SqlHelper.GetDataSetBySql(sql);
  611. if (data != null && data.Rows.Count > 0)
  612. {
  613. foreach (DataRow dr in data.Rows)
  614. {
  615. index++;
  616. #region 获取数据及卡控
  617. string LotNo = dr["条码"].ToString();
  618. string FrontInvCode = dr["转换前料号"].ToString();
  619. string LaterInvCode = dr["转换后料号"].ToString();
  620. string FrontProjectCode = string.Empty;
  621. string LaterProjectCode = string.Empty;
  622. string FrontBatchCode = string.Empty;
  623. string LaterBatchCode = string.Empty;
  624. string FrontVersion = string.Empty;
  625. string LaterVersion = string.Empty;
  626. string FrontBrand = string.Empty;
  627. string LaterBrand = string.Empty;
  628. string FrontcFree1 = string.Empty;
  629. string LatercFree1 = string.Empty;
  630. string FrontcFree2 = string.Empty;
  631. string LatercFree2 = string.Empty;
  632. string FrontcFree3 = string.Empty;
  633. string LatercFree3 = string.Empty;
  634. string FrontcFree4 = string.Empty;
  635. string LatercFree4 = string.Empty;
  636. string FrontcFree5 = string.Empty;
  637. string LatercFree5 = string.Empty;
  638. string FrontcFree6 = string.Empty;
  639. string LatercFree6 = string.Empty;
  640. string FrontcFree7 = string.Empty;
  641. string LatercFree7 = string.Empty;
  642. string FrontcFree8 = string.Empty;
  643. string LatercFree8 = string.Empty;
  644. string FrontcFree9 = string.Empty;
  645. string LatercFree9 = string.Empty;
  646. string FrontcFree10 = string.Empty;
  647. string LatercFree10 = string.Empty;
  648. if (data.Columns.Contains("转换前项目号")) { FrontProjectCode = dr["转换前项目号"].ToString(); }
  649. if (data.Columns.Contains("转换后项目号")) { LaterProjectCode = dr["转换后项目号"].ToString(); }
  650. if (data.Columns.Contains("转换前批次")) { FrontBatchCode = dr["转换前批次"].ToString(); }
  651. if (data.Columns.Contains("转换后批次")) { FrontBatchCode = dr["转换后批次"].ToString(); }
  652. if (data.Columns.Contains("转换前版本")) { FrontVersion = dr["转换前版本"].ToString(); }
  653. if (data.Columns.Contains("转换后版本")) { LaterVersion = dr["转换后版本"].ToString(); }
  654. if (data.Columns.Contains("转换前厂牌")) { FrontBrand = dr["转换前厂牌"].ToString(); }
  655. if (data.Columns.Contains("转换后厂牌")) { LaterBrand = dr["转换后厂牌"].ToString(); }
  656. if (data.Columns.Contains("转换前自由项1")) { FrontcFree1 = dr["转换前自由项1"].ToString(); }
  657. if (data.Columns.Contains("转换后自由项1")) { LatercFree1 = dr["转换后自由项1"].ToString(); }
  658. if (data.Columns.Contains("转换前自由项2")) { FrontcFree2 = dr["转换前自由项2"].ToString(); }
  659. if (data.Columns.Contains("转换后自由项2")) { LatercFree2 = dr["转换后自由项2"].ToString(); }
  660. if (data.Columns.Contains("转换前自由项3")) { FrontcFree3 = dr["转换前自由项3"].ToString(); }
  661. if (data.Columns.Contains("转换后自由项3")) { LatercFree3 = dr["转换后自由项3"].ToString(); }
  662. if (data.Columns.Contains("转换前自由项4")) { FrontcFree4 = dr["转换前自由项4"].ToString(); }
  663. if (data.Columns.Contains("转换后自由项4")) { LatercFree4 = dr["转换后自由项4"].ToString(); }
  664. if (data.Columns.Contains("转换前自由项5")) { FrontcFree5 = dr["转换前自由项5"].ToString(); }
  665. if (data.Columns.Contains("转换后自由项5")) { LatercFree5 = dr["转换后自由项5"].ToString(); }
  666. if (data.Columns.Contains("转换前自由项6")) { FrontcFree6 = dr["转换前自由项6"].ToString(); }
  667. if (data.Columns.Contains("转换后自由项6")) { LatercFree6 = dr["转换后自由项6"].ToString(); }
  668. if (data.Columns.Contains("转换前自由项7")) { FrontcFree7 = dr["转换前自由项7"].ToString(); }
  669. if (data.Columns.Contains("转换后自由项7")) { LatercFree7 = dr["转换后自由项7"].ToString(); }
  670. if (data.Columns.Contains("转换前自由项8")) { FrontcFree8 = dr["转换前自由项8"].ToString(); }
  671. if (data.Columns.Contains("转换后自由项8")) { LatercFree8 = dr["转换后自由项8"].ToString(); }
  672. if (data.Columns.Contains("转换前自由项9")) { FrontcFree9 = dr["转换前自由项9"].ToString(); }
  673. if (data.Columns.Contains("转换后自由项9")) { LatercFree9 = dr["转换后自由项9"].ToString(); }
  674. if (data.Columns.Contains("转换前自由项10")) { FrontcFree10 = dr["转换前自由项10"].ToString(); }
  675. if (data.Columns.Contains("转换后自由项10")) { LatercFree10 = dr["转换后自由项10"].ToString(); }
  676. string FrontColspan = FrontProjectCode + "~" + FrontBatchCode + "~" + FrontVersion + "~" + FrontBrand + "~" + FrontcFree1 + "~" + FrontcFree2 + "~" + FrontcFree3 + "~" + FrontcFree4 + "~" + FrontcFree5 + "~" + FrontcFree6 + "~" + FrontcFree7 + "~" + FrontcFree8 + "~" + FrontcFree9 + "~" + FrontcFree10;
  677. string LaterColspan = LaterProjectCode + "~" + LaterBatchCode + "~" + LaterVersion + "~" + LaterBrand + "~" + LatercFree1 + "~" + LatercFree2 + "~" + LatercFree3 + "~" + LatercFree4 + "~" + LatercFree5 + "~" + LatercFree6 + "~" + LatercFree7 + "~" + LatercFree8 + "~" + LatercFree9 + "~" + LatercFree10;
  678. //if (LotNo == null || LotNo == "")
  679. //{
  680. // throw new Exception("第 " + index + " 行,请输入条码!");
  681. //}
  682. if (!string.IsNullOrEmpty(FrontInvCode))
  683. {
  684. if (string.IsNullOrEmpty(LaterInvCode))
  685. {
  686. throw new Exception("第 " + index + " 行,已输入转换前料号,请输入转换后料号!");
  687. }
  688. }
  689. else if (!string.IsNullOrEmpty(LaterInvCode))
  690. {
  691. if (string.IsNullOrEmpty(FrontInvCode))
  692. {
  693. throw new Exception("第 " + index + " 行,已输入转换后料号,请输入转换前料号!");
  694. }
  695. }
  696. var LotNoResult = ds.Tables[2].Select(string.Format(" LotNo='{0}'", LotNo));
  697. if (LotNoResult == null || LotNoResult.Length <= 0)
  698. {
  699. throw new Exception("第 " + index + " 行,条码:" + LotNo + "未查询到库存信息!");
  700. }
  701. var FrontInvCodeResult = ds.Tables[2].Select(string.Format("InvCode='{0}' and LotNo='{1}'", FrontInvCode, LotNo));
  702. if (FrontInvCodeResult == null || FrontInvCodeResult.Length <= 0)
  703. {
  704. throw new Exception("第 " + index + " 行,转换前料号:" + FrontInvCode + " 与条码对应信息不符!");
  705. }
  706. if (!string.IsNullOrEmpty(FrontProjectCode) || !string.IsNullOrEmpty(LaterProjectCode))
  707. {
  708. var ProjectCodeResult = ds.Tables[0].Select(string.Format("ProjectCode='{0}' and LotNo='{1}'", FrontProjectCode, LotNo));
  709. if (ProjectCodeResult == null || ProjectCodeResult.Length <= 0)
  710. {
  711. throw new Exception("第 " + index + " 行,转换前项目号:" + FrontProjectCode + " 与条码对应信息不符合!");
  712. }
  713. }
  714. if (!string.IsNullOrEmpty(FrontBatchCode) || !string.IsNullOrEmpty(LaterBatchCode))
  715. {
  716. var BatchCodeResult = ds.Tables[0].Select(string.Format("BatchCode='{0}' and LotNo='{1}'", FrontBatchCode, LotNo));
  717. if (BatchCodeResult == null || BatchCodeResult.Length <= 0)
  718. {
  719. throw new Exception("第 " + index + " 行,转换前批次:" + FrontBatchCode + " 与条码对应信息不符合!");
  720. }
  721. }
  722. if (!string.IsNullOrEmpty(FrontVersion) || !string.IsNullOrEmpty(LaterVersion))
  723. {
  724. var VersionResult = ds.Tables[0].Select(string.Format("Version='{0}' and LotNo='{1}'", FrontVersion, LotNo));
  725. if (VersionResult == null || VersionResult.Length <= 0)
  726. {
  727. throw new Exception("第 " + index + " 行,转换前版本:" + FrontVersion + " 与条码对应信息不符合!");
  728. }
  729. }
  730. if (!string.IsNullOrEmpty(FrontBrand) || !string.IsNullOrEmpty(LaterBrand))
  731. {
  732. var BrandResult = ds.Tables[0].Select(string.Format("Brand='{0}' and LotNo='{1}'", FrontBrand, LotNo));
  733. if (BrandResult == null || BrandResult.Length <= 0)
  734. {
  735. throw new Exception("第 " + index + " 行,转换前厂牌:" + FrontBrand + " 与条码对应信息不符合!");
  736. }
  737. }
  738. if (!string.IsNullOrEmpty(FrontcFree1) || !string.IsNullOrEmpty(LatercFree1))
  739. {
  740. var cFree1Result = ds.Tables[0].Select(string.Format("cFree1='{0}' and LotNo='{1}'", FrontcFree1, LotNo));
  741. if (cFree1Result == null || cFree1Result.Length <= 0)
  742. {
  743. throw new Exception("第 " + index + " 行,转换前自由项1:" + FrontcFree1 + " 与条码对应信息不符合!");
  744. }
  745. }
  746. if (!string.IsNullOrEmpty(FrontcFree2) || !string.IsNullOrEmpty(LatercFree2))
  747. {
  748. var cFree2Result = ds.Tables[0].Select(string.Format("cFree2='{0}' and LotNo='{1}'", FrontcFree2, LotNo));
  749. if (cFree2Result == null || cFree2Result.Length <= 0)
  750. {
  751. throw new Exception("第 " + index + " 行,转换前自由项2:" + FrontcFree2 + " 与条码对应信息不符合!");
  752. }
  753. }
  754. if (!string.IsNullOrEmpty(FrontcFree3) || !string.IsNullOrEmpty(LatercFree3))
  755. {
  756. var cFree3Result = ds.Tables[0].Select(string.Format("cFree3='{0}' and LotNo='{1}'", FrontcFree3, LotNo));
  757. if (cFree3Result == null || cFree3Result.Length <= 0)
  758. {
  759. throw new Exception("第 " + index + " 行,转换前自由项3:" + FrontcFree3 + " 与条码对应信息不符合!");
  760. }
  761. }
  762. if (!string.IsNullOrEmpty(FrontcFree4) || !string.IsNullOrEmpty(LatercFree4))
  763. {
  764. var cFree4Result = ds.Tables[0].Select(string.Format("cFree4='{0}' and LotNo='{1}'", FrontcFree4, LotNo));
  765. if (cFree4Result == null || cFree4Result.Length <= 0)
  766. {
  767. throw new Exception("第 " + index + " 行,转换前自由项4:" + FrontcFree4 + " 与条码对应信息不符合!");
  768. }
  769. }
  770. if (!string.IsNullOrEmpty(FrontcFree5) || !string.IsNullOrEmpty(LatercFree5))
  771. {
  772. var cFree5Result = ds.Tables[0].Select(string.Format("cFree5='{0}' and LotNo='{1}'", FrontcFree5, LotNo));
  773. if (cFree5Result == null || cFree5Result.Length <= 0)
  774. {
  775. throw new Exception("第 " + index + " 行,转换前自由项5:" + FrontcFree5 + " 与条码对应信息不符合!");
  776. }
  777. }
  778. if (!string.IsNullOrEmpty(FrontcFree6) || !string.IsNullOrEmpty(LatercFree6))
  779. {
  780. var cFree6Result = ds.Tables[0].Select(string.Format("cFree6='{0}' and LotNo='{1}'", FrontcFree6, LotNo));
  781. if (cFree6Result == null || cFree6Result.Length <= 0)
  782. {
  783. throw new Exception("第 " + index + " 行,转换前自由项6:" + FrontcFree6 + " 与条码对应信息不符合!");
  784. }
  785. }
  786. if (!string.IsNullOrEmpty(FrontcFree7) || !string.IsNullOrEmpty(LatercFree7))
  787. {
  788. var cFree7Result = ds.Tables[0].Select(string.Format("cFree7='{0}' and LotNo='{1}'", FrontcFree7, LotNo));
  789. if (cFree7Result == null || cFree7Result.Length <= 0)
  790. {
  791. throw new Exception("第 " + index + " 行,转换前自由项7:" + FrontcFree7 + " 与条码对应信息不符合!");
  792. }
  793. }
  794. if (!string.IsNullOrEmpty(FrontcFree8) || !string.IsNullOrEmpty(LatercFree8))
  795. {
  796. var cFree8Result = ds.Tables[0].Select(string.Format("cFree8='{0}' and LotNo='{1}'", FrontcFree8, LotNo));
  797. if (cFree8Result == null || cFree8Result.Length <= 0)
  798. {
  799. throw new Exception("第 " + index + " 行,转换前自由项8:" + FrontcFree8 + " 与条码对应信息不符合!");
  800. }
  801. }
  802. if (!string.IsNullOrEmpty(FrontcFree9) || !string.IsNullOrEmpty(LatercFree9))
  803. {
  804. var cFree9Result = ds.Tables[0].Select(string.Format("cFree9='{0}' and LotNo='{1}'", FrontcFree9, LotNo));
  805. if (cFree9Result == null || cFree9Result.Length <= 0)
  806. {
  807. throw new Exception("第 " + index + " 行,转换前自由项9:" + FrontcFree9 + " 与条码对应信息不符合!");
  808. }
  809. }
  810. if (!string.IsNullOrEmpty(FrontcFree10) || !string.IsNullOrEmpty(LatercFree10))
  811. {
  812. var cFree10Result = ds.Tables[0].Select(string.Format("cFree10='{0}' and LotNo='{1}'", FrontcFree10, LotNo));
  813. if (cFree10Result == null || cFree10Result.Length <= 0)
  814. {
  815. throw new Exception("第 " + index + " 行,转换前自由项10:" + FrontcFree10 + " 与条码对应信息不符合!");
  816. }
  817. }
  818. #endregion
  819. if (ds.Tables[3] == null || ds.Tables[3].Rows.Count == 0 || ds.Tables[3].Rows[0]["NewMTDOCCode"].ToString() == "")
  820. {
  821. MTDOCCode = Time + "000001";
  822. }
  823. else
  824. {
  825. string NewMTDOCCode = ds.Tables[3].Rows[0]["NewMTDOCCode"].ToString();
  826. int COUNT = Convert.ToInt32(NewMTDOCCode.Substring(8)) + 1;
  827. MTDOCCode = Time + COUNT.ToString().PadLeft(6, '0');
  828. }
  829. string NewLotNo = "";
  830. string sqls = @"select max(LotNo) as NewLotNo from ICSInventoryLot where EATTRIBUTE1='{0}' ";
  831. sqls = string.Format(sqls, LotNo);
  832. DataTable dt = Repository().FindTableBySql(sqls.ToString());
  833. if (dt == null || dt.Rows.Count == 0 || dt.Rows[0]["NewLotNo"].ToString() == "")
  834. {
  835. NewLotNo = LotNo + "-1";
  836. }
  837. else
  838. {
  839. string newLotNO = dt.Rows[0]["NewLotNo"].ToString();
  840. int COUNT = Convert.ToInt32(newLotNO.Substring(newLotNO.LastIndexOf('-') + 1)) + 1;
  841. NewLotNo = LotNo + "-" + COUNT.ToString();
  842. }
  843. var info = ds.Tables[2].Select(string.Format(" LotNo='{0}'", LotNo));
  844. if (!string.IsNullOrEmpty(info[0]["Amount"].ToString()))
  845. {
  846. Amount = Convert.ToDecimal(info[0]["Amount"].ToString());
  847. }
  848. string sqlsss = string.Format(@"select ID from ICSExtension where Colspan='{0}'", LaterColspan);
  849. object ExtensionID = SqlHelper.ExecuteScalar(sqls);
  850. if (ExtensionID == null)
  851. {
  852. ExtensionID = Guid.NewGuid();
  853. 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)
  854. Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}',getdate(),'{16}','{17}','{18}' )",
  855. ExtensionID, LaterColspan, LaterProjectCode, LaterBatchCode, LaterVersion, LaterBrand, LatercFree1, LatercFree2, LatercFree3, LatercFree4, LatercFree5, LatercFree6, LatercFree7, LatercFree8, FrontcFree9, LatercFree10,
  856. MUSER, MUSERNAME, WorkPoint);
  857. }
  858. //老
  859. sqltxt += @"INSERT INTO dbo.ICSMTDOC
  860. ( ID ,MTDOCCode,WHCode ,Sequence ,LotNo,Quantity,Amount,MTDOCQuantity,MTDOCType,Memo,Status,CreatePerson,
  861. CreateDateTime,MTDOCID,MTDOCDetailID,ExtensionID,MUSER,MUSERName ,MTIME ,WorkPoint )
  862. values(NEWID(),'{0}','{1}','{2}','{3}','{4}','{5}','{6}','1','{7}','1','{8}','{16}',newid(),newid(),'{9}','{10}','{11}','{16}','{12}')";
  863. //新
  864. sqltxt += @"INSERT INTO dbo.ICSMTDOC
  865. ( ID ,MTDOCCode,WHCode ,Sequence ,LotNo,Quantity,Amount,MTDOCQuantity,MTDOCType,Memo,Status,CreatePerson,
  866. CreateDateTime,MTDOCID,MTDOCDetailID,ExtensionID,MUSER,MUSERName ,MTIME ,WorkPoint )
  867. values(NEWID(),'{0}','{1}','{14}','{13}','{4}','{5}','{6}','2','{7}','1','{8}','{16}',newid(),newid(),'{9}','{10}','{11}','{16}','{12}')";
  868. //新增条码
  869. sqltxt += @"INSERT into ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  870. select newid(),'{13}','{15}',ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,'102',MUSER,MUSERName,MTIME,WorkPoint,'{3}' from ICSInventoryLot
  871. where LotNo='{3}'";
  872. //新增条码关联
  873. sqltxt += @" INSERT into ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
  874. select '{13}',TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint from ICSInventoryLotDetail
  875. where LotNo='{3}'";
  876. 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);
  877. }
  878. SqlHelper.CmdExecuteNonQueryLi(sqltxt);
  879. }
  880. else
  881. {
  882. return "无有效的导入数据。";
  883. }
  884. return "true";
  885. }
  886. catch (Exception ex)
  887. {
  888. return ex.Message;
  889. }
  890. }
  891. public string GetNewid()
  892. {
  893. string sql = "select newid() AS ID";
  894. return Repository().FindTableBySql(sql, null).Rows[0]["ID"].ToString();
  895. }
  896. }
  897. }