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.

1248 lines
74 KiB

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