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.

552 lines
25 KiB

3 weeks ago
  1. using Newtonsoft.Json.Linq;
  2. using Newtonsoft.Json;
  3. using NFine.Code;
  4. using NFine.Data.Extensions;
  5. using NFine.Domain._03_Entity.SRM;
  6. using NFine.Repository;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Data.Common;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Configuration;
  15. using System.IO;
  16. using System.Net;
  17. using NFine.Application.WMS;
  18. using NFine.Application.Models;
  19. using System.Reflection;
  20. using NFine.Application.Entity;
  21. using NFine.Domain.Entity.SystemSecurity;
  22. using System.Xml;
  23. using System.Collections;
  24. using System.Data.SqlClient;
  25. namespace NFine.Application.KBSWMS
  26. {
  27. public class ICSManufactureReceiveApp : RepositoryFactory<ICSVendor>
  28. {
  29. #region 获取工单主表数据
  30. /// <summary>
  31. /// 获取产品入库单数据
  32. /// </summary>
  33. /// <param name="queryJson"></param>
  34. /// <param name="jqgridparam"></param>
  35. /// <returns></returns>
  36. public DataTable GetManufactureReceive(string queryJson, ref Pagination jqgridparam)
  37. {
  38. DataTable dt = new DataTable();
  39. var queryParam = queryJson.ToJObject();
  40. List<DbParameter> parameter = new List<DbParameter>();
  41. object Figure = GetDecimalDigits();
  42. string wheresql = string.Empty;
  43. if (!string.IsNullOrWhiteSpace(queryJson))
  44. {
  45. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  46. {
  47. wheresql += " and a.RCVCode like '%" + queryParam["POCode"].ToString() + "%' ";
  48. }
  49. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  50. {
  51. wheresql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  52. }
  53. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  54. {
  55. wheresql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  56. }
  57. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  58. {
  59. wheresql += " and d.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  60. }
  61. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  62. {
  63. wheresql += " and b.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  64. }
  65. if (!string.IsNullOrWhiteSpace(queryParam["WHStatus"].ToString()))
  66. {
  67. string WHStatus = queryParam["WHStatus"].ToString();
  68. if (WHStatus == "0")
  69. {
  70. wheresql += " and a.Quantity-ISNULL(a.RCVQuantity,0)>0 ";
  71. }
  72. else
  73. {
  74. wheresql += " and a.Quantity-ISNULL(a.RCVQuantity,0)=0 ";
  75. }
  76. }
  77. }
  78. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  79. {
  80. wheresql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  81. }
  82. #region [SQL]
  83. string sql = $@" SELECT a.ID,a.RCVCode,a.Sequence,a.SourceCode ProductionCode,b.InvCode,b.InvName,b.InvStd,Isnull(a.RCVQuantity,0) RCVQuantity,a.WHCode,a.CreatePerson,a.CreateDateTime,sum(ISNULL(c.Quantity, 0)) BoundQuantity,a.Quantity,case when a.Quantity-ISNULL(a.RCVQuantity,0)=0 then '是' else '否' end IsWH
  84. from ICSManufactureReceive a
  85. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  86. LEFT JOIN ICSManufactureReceiveLot c ON a.SourceCode=c.ProductionCode AND a.RCVCode=c.RCVCode AND a.Sequence=c.RCVSequence AND a.WorkPoint=c.WorkPoint AND a.InvCode=c.InvCode
  87. LEFT JOIN ICSExtension d ON a.ExtensionID=d.ID AND a.WorkPoint=d.WorkPoint
  88. WHERE 1=1 {wheresql}
  89. GROUP BY a.RCVCode,a.Sequence,a.SourceCode,b.InvCode,b.InvName,b.InvStd,a.RCVQuantity,a.WHCode,a.CreatePerson,a.CreateDateTime,a.ID,a.Quantity ";
  90. #endregion
  91. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  92. }
  93. #endregion
  94. #region 获取条码信息
  95. /// <summary>
  96. /// 获取条码信息
  97. /// </summary>
  98. /// <param name="ApplyNegCode"></param>
  99. /// <param name="Sequence"></param>
  100. /// <param name="Type"></param>
  101. /// <param name="isPrint"></param>
  102. /// <param name="jqgridparam"></param>
  103. /// <returns></returns>
  104. public DataTable GetManufactureReceiveLot(string ProductionCode, string WHCode, string InvCode,ref Pagination jqgridparam)
  105. {
  106. DataTable dt = new DataTable();
  107. List<DbParameter> parameter = new List<DbParameter>();
  108. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  109. //多个出库单会有重复数据,需要去重
  110. string sql = $@" SELECT distinct c.ID,c.LotNo,c.Quantity,a.SourceCode ProductionCode,b.InvCode,b.InvName,b.InvStd,c.MUSERName,c.MTIME
  111. FROM ICSManufactureReceive a
  112. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  113. INNER JOIN ICSManufactureReceiveLot c ON a.SourceCode=c.ProductionCode AND a.WorkPoint=c.WorkPoint AND a.InvCode=c.InvCode and IsBind='0'
  114. WHERE a.SourceCode='{ProductionCode}' AND a.WHCode='{WHCode}' and a.InvCode='{InvCode}' and a.WorkPoint='{WorkPoint}' ";
  115. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  116. }
  117. #endregion
  118. #region 入库单绑定条码
  119. /// <summary>
  120. /// 入库单绑定条码
  121. /// </summary>
  122. /// <param name="POCode"></param>
  123. /// <param name="PORow"></param>
  124. /// <param name="keyValue"></param>
  125. /// <returns></returns>
  126. public string BindingLot(string ICSASN)
  127. {
  128. try
  129. {
  130. var moModels = ICSASN.ToJObject();
  131. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  132. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  133. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  134. string ids = moModels["IDs"].ToString();
  135. string RCVCode = moModels["RCVCode"].ToString();
  136. string RCVSequence = moModels["RCVSequence"].ToString();
  137. string sql = $" UPDATE ICSManufactureReceiveLot SET IsBind='1' ,RCVCode='{RCVCode}',RCVSequence='{RCVSequence}' WHERE ID IN({ids.TrimEnd(',')}) and WorkPoint='{WorkPoints}' ";
  138. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  139. return "";
  140. }
  141. catch (Exception ex)
  142. {
  143. return ex.Message;
  144. }
  145. }
  146. #endregion
  147. #region 入库单解绑条码
  148. /// <summary>
  149. /// 入库单解绑条码
  150. /// </summary>
  151. /// <param name="ids"></param>
  152. /// <returns></returns>
  153. public string PostUnBind(string ids)
  154. {
  155. try
  156. {
  157. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  158. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  159. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  160. var idList = JsonConvert.DeserializeObject<List<string>>(ids);
  161. string sqls = string.Empty;
  162. string sql = @"SELECT RCVCode,Sequence FROM ICSManufactureReceive WHERE id IN ('" + string.Join("','", idList) + $"') AND WorkPoint='{WorkPoints}' and Quantity!=isnull(RCVQuantity,0) ";
  163. var dt = SqlHelper.CmdExecuteDataTable(sql);
  164. if (dt.Rows.Count<=0)
  165. {
  166. return "所选的入库单绑定的条码已经入库,操作失败!";
  167. }
  168. for (int i=0;i< dt.Rows.Count;i++)
  169. {
  170. sqls += $"UPDATE a SET a.IsBind='0' ,a.RCVCode=null,a.RCVSequence=null from ICSManufactureReceiveLot a LEFT JOIN ICSWareHouseLotInfo b ON a.LOTNO=b.LOTNO AND a.WorkPoint=b.WorkPoint WHERE a.RCVCode='{dt.Rows[i]["RCVCode"]}' and a.RCVSequence='{dt.Rows[i]["Sequence"]}' and a.WorkPoint='{WorkPoints}' and b.id is null ";
  171. }
  172. int count = SqlHelper.CmdExecuteNonQueryLi(sqls);
  173. return "";
  174. }
  175. catch (Exception ex)
  176. {
  177. return ex.Message;
  178. }
  179. }
  180. #endregion
  181. public object GetDecimalDigits()
  182. {
  183. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  184. try
  185. {
  186. string sql = string.Empty;
  187. sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
  188. object Figure = SqlHelper.ExecuteScalar(sql);
  189. return Figure;
  190. }
  191. catch (Exception ex)
  192. {
  193. throw new Exception(ex.Message.ToString());
  194. }
  195. }
  196. #region 入库单提交过账
  197. /// <summary>
  198. /// 入库单提交过账
  199. /// </summary>
  200. /// <param name="RCVCodes">入库单号</param>
  201. /// <returns></returns>
  202. public string PostExamine(string RCVCodes)
  203. {
  204. try
  205. {
  206. var moModels = RCVCodes.ToList<string>();
  207. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  208. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  209. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  210. if (moModels.Count <= 0)
  211. {
  212. throw new Exception("请选择单据信息!");
  213. }
  214. List<ExamineViewModel> examineViewModels = new List<ExamineViewModel>();
  215. List<DetailEntity> detailEntities = new List<DetailEntity>();
  216. for (int i = 0; i < moModels.Count; i++)
  217. {
  218. //验证入库单是否全部绑定条码
  219. string checksql = $@"SELECT a.RCVCode FROM ICSManufactureReceive a
  220. INNER JOIN (SELECT RCVCode,WorkPoint,InvCode,Sum(Quantity) Quantity FROM ICSManufactureReceiveLot WHERE IsBind = '1' GROUP BY RCVCode,WorkPoint,InvCode ) b ON a.RCVCode = b.RCVCode AND a.WorkPoint = b.WorkPoint AND a.InvCode = b.InvCode
  221. WHERE a.RCVCode = '{moModels[i]}' AND a.Quantity=B.Quantity";
  222. var checkdt = SqlHelper.CmdExecuteDataTable(checksql);
  223. if (checkdt.Rows.Count <= 0)
  224. {
  225. throw new Exception($"单据{moModels[i]}绑定数量小于单据数量,操作失败!");
  226. }
  227. //查询入库条码信息
  228. string sql = $@"SELECT a.LotNo, a.RCVCode, a.RCVSequence, a.Quantity,a.InvCode ,a.LocationCode,c.WarehouseCode
  229. FROM ICSManufactureReceiveLot a
  230. LEFT JOIN ICSLocation b ON a.LocationCode=b.LocationCode AND a.WorkPoint=b.WorkPoint
  231. LEFT JOIN ICSWarehouse c ON b.WHID=c.ID
  232. WHERE a.RCVCode = '{moModels[i]}' AND a.WorkPoint = '{WorkPoints}' ";
  233. var dt = SqlHelper.CmdExecuteDataTable(sql);
  234. if (dt.Rows.Count > 0)
  235. {
  236. for (int j = 0; j < dt.Rows.Count; j++)
  237. {
  238. DetailEntity detailEntity = new DetailEntity();
  239. detailEntity.LotNo = dt.Rows[j]["LotNo"].ToString();
  240. detailEntity.TransCode = dt.Rows[j]["RCVCode"].ToString();
  241. detailEntity.TransSequence = dt.Rows[j]["RCVSequence"].ToString();
  242. detailEntity.Quantity = dt.Rows[j]["Quantity"].ToString();
  243. detailEntity.InvCode = dt.Rows[j]["InvCode"].ToString();
  244. detailEntity.LocationCode = dt.Rows[j]["LocationCode"].ToString();
  245. detailEntity.WarehouseCode = dt.Rows[j]["WarehouseCode"].ToString();
  246. detailEntities.Add(detailEntity);
  247. }
  248. }
  249. }
  250. //根据
  251. var detailEntities1=detailEntities.GroupBy(x => new { x.TransCode, x.TransSequence }).ToList();
  252. detailEntities1.ForEach(infor=>
  253. {
  254. ExamineViewModel examineViewModel = new ExamineViewModel();
  255. examineViewModel.MTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  256. examineViewModel.User = MUSER;
  257. examineViewModel.WorkPoint = WorkPoints;
  258. examineViewModel.TransCode = infor.Key.TransCode;
  259. examineViewModel.TransSequence = infor.Key.TransSequence;
  260. examineViewModel.Detail = infor.ToList();
  261. examineViewModels.Add(examineViewModel);
  262. });
  263. #region 调用PDA入库接口
  264. if (!examineViewModels.IsEmpty())
  265. {
  266. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTStockUp/Create";
  267. var erpinput = JsonConvert.SerializeObject(examineViewModels);
  268. string result1 = HttpPost(APIURL, erpinput);
  269. JObject Obj = (JObject)JsonConvert.DeserializeObject(result1);//或者JObject jo = JObject.Parse(jsonText);
  270. string success = Obj["Success"].ToString();
  271. string message = Obj["Message"].ToString();
  272. if (success.ToUpper() == "FALSE")
  273. {
  274. throw new Exception(message);
  275. }
  276. }
  277. #endregion
  278. return "";
  279. }
  280. catch (Exception ex)
  281. {
  282. return ex.Message;
  283. }
  284. }
  285. #endregion
  286. /// <summary>
  287. /// 删除条码
  288. /// </summary>
  289. /// <param name="keyValue"></param>
  290. /// <returns></returns>
  291. public string DeleteItemLot(string MOCodes)
  292. {
  293. string msg = string.Empty;
  294. try
  295. {
  296. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  297. string sql = $@"SELECT * FROM dbo.ICSMOSubInventoryLot
  298. WHERE MOCode IN ({MOCodes}) and WorkPoint in ('{WorkPoint}') and isnull(EATTRIBUTE1,'') !='' ";
  299. DataTable dtASN = SqlHelper.GetDataTableBySql(sql);
  300. if (dtASN != null && dtASN.Rows.Count > 0)
  301. {
  302. msg = "所选条码已绑定,无法删除!";
  303. return msg;
  304. }
  305. if (string.IsNullOrEmpty(msg))
  306. {
  307. string sqls = $"DELETE FROM ICSMOSubInventoryLot WHERE MOCode in({MOCodes}) AND WorkPoint in ('{WorkPoint}') ";
  308. SqlHelper.CmdExecuteNonQueryLi(sqls);
  309. }
  310. }
  311. catch (Exception ex)
  312. {
  313. return ex.Message;
  314. }
  315. return msg;
  316. }
  317. public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen)
  318. {
  319. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  320. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  321. //return Repository().FindTableBySql(sql.ToString());
  322. return SqlHelper.ExecuteScalar(sql).ToString();
  323. //return DbHelper.ExecuteScalar(CommandType.Text, sql).ToString();
  324. }
  325. public static string HttpPost(string url, string body)
  326. {
  327. try
  328. {
  329. Encoding encoding = Encoding.UTF8;
  330. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  331. request.Method = "POST";
  332. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  333. request.ContentType = "application/json; charset=utf-8";
  334. byte[] buffer = encoding.GetBytes(body);
  335. request.ContentLength = buffer.Length;
  336. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  337. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  338. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  339. {
  340. return reader.ReadToEnd();
  341. }
  342. }
  343. catch (WebException ex)
  344. {
  345. throw new Exception(ex.Message);
  346. }
  347. }
  348. /// <summary>
  349. /// 出库单条码绑定导入
  350. /// </summary>
  351. /// <param name="savePath"></param>
  352. /// <returns></returns>
  353. public string UploadFileBinding(String savePath)
  354. {
  355. //数据获取
  356. try
  357. {
  358. int index = 1;
  359. string msg = "";
  360. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  361. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  362. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  363. string MTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  364. string sql = string.Empty;
  365. SqlConnection conn = SqlHelper.GetDataCenterConn();
  366. int count = 0;
  367. DataTable data = FileToExcel.ExcelToTable(savePath);
  368. var parent = data.DefaultView.ToTable(true, "入库单号", "入库单行号", "生产订单号", "物料编码", "条码", "数量", "库位编码");
  369. parent.PrimaryKey = new DataColumn[] { parent.Columns["column1"], parent.Columns["column2"], parent.Columns["column3"], parent.Columns["column4"], parent.Columns["column5"], parent.Columns["column6"] };
  370. DataTable distinctTable = parent.DefaultView.ToTable(true);
  371. foreach (DataRow distinctds in distinctTable.Rows)
  372. {
  373. string ID = Guid.NewGuid().ToString();
  374. index++;
  375. string RCVCode = distinctds["入库单号"].ToString().Trim();
  376. string RCVSequence = distinctds["入库单行号"].ToString().Trim();
  377. string ProductionCode = distinctds["生产订单号"].ToString().Trim();
  378. string InvCode = distinctds["物料编码"].ToString().Trim();
  379. string LotNo = distinctds["条码"].ToString().Trim();
  380. string Quantity = distinctds["数量"].ToString().Trim();
  381. string LocationCode = distinctds["库位编码"].ToString().Trim();
  382. #region 判断必填项
  383. if (ProductionCode == "" || ProductionCode == null)
  384. {
  385. throw new Exception("第 " + index + " 行生产订单号不能为空!");
  386. }
  387. if (InvCode == "" || InvCode == null)
  388. {
  389. throw new Exception("第 " + index + " 行物料编码不能为空!");
  390. }
  391. if (LotNo == "" || LotNo == null)
  392. {
  393. throw new Exception("第 " + index + " 行条码不能为空!");
  394. }
  395. if (Quantity == "" || Quantity == null)
  396. {
  397. throw new Exception("第 " + index + " 行数量不能为空!");
  398. }
  399. if (LocationCode == "" || LocationCode == null)
  400. {
  401. throw new Exception("第 " + index + " 行库位编码不能为空!");
  402. }
  403. #endregion
  404. sql += $@"
  405. IF NOT EXISTS(SELECT ID FROM ICSLocation where LocationCode='{LocationCode}' and Workpoint='{WorkPoint}')
  406. BEGIN
  407. RAISERROR('{index}{LocationCode}', 16, 1);
  408. RETURN
  409. END
  410. INSERT INTO [dbo].[ICSInventoryLot] ([ID], [LotNo], [InvCode], [ProductDate], [ExpirationDate], [Quantity], [Amount], [ExtensionID], [Type], [PrintTimes], [LastPrintUser], [LastPrintTime], [MUSER], [MUSERName], [MTIME], [WorkPoint]) SELECT NEWID(), N'{LotNo}', N'{InvCode}', '{MTIME}', case when EffectiveEnable='1' THEN DATEADD(day,EffectiveDays,GETDATE()) else '2099-12-31' END, {Quantity}, 0.000000, (SELECT ID FROM ICSExtension WHERE Colspan='~~~~~~~~~~~~~'), N'9', NULL, NULL, NULL, N'{MUSER}', N'{MUSERNAME}', '{MTIME}', N'KC47' FROM ICSInventory WHERE InvCode='{InvCode}' AND WorkPoint='{WorkPoint}' ;
  411. INSERT INTO [dbo].[ICSInventoryLotDetail] ([LotNo], [TransID], [TransCode], [TransSequence], [MUSER], [MUSERName], [MTIME], [WorkPoint]) SELECT N'{LotNo}', ID, MOCode, Sequence,'{MUSER}', N'{MUSERNAME}', '{MTIME}', N'{WorkPoint}' FROM ICSMO WHERE MOCode='{ProductionCode}' AND Sequence='1' AND WorkPoint='{WorkPoint}' ;
  412. INSERT INTO [dbo].[ICSManufactureReceiveLot] ([ID], [ProductionCode], [ProductionSequence], [RCVCode], [RCVSequence], [LotNo], [InvCode], [WarehouseCode], [LocationCode], [Quantity], [Memo], [IsBind], [MUSER], [MUSERName], [MTIME], [WorkPoint]) SELECT NEWID(), N'{ProductionCode}', N'1', N'', N'', N'{LotNo}', N'{InvCode}', a.WarehouseCode, N'{LocationCode}', '{Quantity}', NULL, '0', N'{MUSER}', N'{MUSERNAME}', '{MTIME}', N'{WorkPoint}' FROM ICSWarehouse a
  413. INNER JOIN ICSLocation b ON a.Id=b.WHID AND a.workpoint=b.WorkPoint
  414. where b.LocationCode='{LocationCode}' and a.Workpoint='{WorkPoint}'; ";
  415. if (RCVCode != "" && RCVCode != null && RCVSequence != "" && RCVSequence != null)
  416. {
  417. sql += $@" IF NOT EXISTS(SELECT a.ID FROM ICSManufactureReceive a
  418. INNER JOIN ICSManufactureReceiveLot b ON a.SourceCode = b.ProductionCode AND a.WorkPoint = b.WorkPoint AND a.InvCode = b.InvCode
  419. WHERE a.RCVCode = '{RCVCode}' AND a.InvCode = '{InvCode}' AND b.LOTNO = '{LotNo}' and a.Sequence = '{RCVSequence}' and a.WorkPoint = '{WorkPoint}')
  420. BEGIN
  421. RAISERROR(':{LotNo}:{RCVCode}', 16, 1);
  422. RETURN
  423. END;
  424. UPDATE ICSManufactureReceiveLot SET IsBind = '1', RCVCode = '{RCVCode}', RCVSequence = '1' WHERE LotNo = '{LotNo}' and WorkPoint = '{WorkPoint}';
  425. IF EXISTS(SELECT a.Quantity FROM ICSManufactureReceive a
  426. INNER JOIN ICSManufactureReceiveLot b ON a.SourceCode = b.ProductionCode AND a.WorkPoint = b.WorkPoint AND a.InvCode = b.InvCode
  427. WHERE a.RCVCode = '{RCVCode}' and a.Sequence = '{RCVSequence}' AND a.InvCode = '{InvCode}' AND b.IsBind = '1'
  428. GROUP BY a.Quantity
  429. HAVING sum(b.Quantity) > a.Quantity)
  430. BEGIN
  431. RAISERROR(':{RCVCode}', 16, 1);
  432. RETURN
  433. END; ";
  434. }
  435. }
  436. count = SqlHelper.CmdExecuteNonQueryLi(sql);
  437. if (count > 0)
  438. {
  439. msg = "导入成功";
  440. }
  441. else
  442. {
  443. return "无有效的导入数据。";
  444. }
  445. return msg;
  446. }
  447. catch (Exception ex)
  448. {
  449. return ex.Message;
  450. }
  451. }
  452. }
  453. #region 工单子线实体对象
  454. /// <summary>
  455. /// 新增工单子线实体对象
  456. /// </summary>
  457. public class MOModel
  458. {
  459. /// <summary>
  460. /// 工单编码
  461. /// </summary>
  462. public string MOCode { get; set; }
  463. /// <summary>
  464. /// 行号
  465. /// </summary>
  466. public string Sequence { get; set; }
  467. /// <summary>
  468. /// 物料编码
  469. /// </summary>
  470. public string InvCode { get; set; }
  471. /// <summary>
  472. /// 数量
  473. /// </summary>
  474. public decimal Quantity { get; set; }
  475. /// <summary>
  476. ///
  477. /// </summary>
  478. public string ExtensionID { get; set; }
  479. }
  480. #endregion
  481. }