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.

1221 lines
73 KiB

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