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

947 lines
55 KiB

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