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

836 lines
49 KiB

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