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.

1073 lines
63 KiB

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