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.

561 lines
20 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Text;
  6. using NFine.Code;
  7. using NFine.Repository;
  8. using System.Data.Common;
  9. using NFine.Domain._03_Entity.SRM;
  10. using Newtonsoft.Json;
  11. using System.Configuration;
  12. using System.Net;
  13. using System.IO;
  14. using Newtonsoft.Json.Linq;
  15. using System.Linq;
  16. namespace NFine.Application.OMAY
  17. {
  18. public class OMAYApsApp : RepositoryFactory<ICSVendor>
  19. {
  20. public DataTable GetGridJsonChengPing(string queryJson, ref Pagination jqgridparam)
  21. {
  22. DataTable dt = new DataTable();
  23. var queryParam = queryJson.ToJObject();
  24. List<DbParameter> parameter = new List<DbParameter>();
  25. //object Figure = GetDecimalDigits();
  26. #region [SQL]
  27. string sql = @" select
  28. a.*
  29. from
  30. (
  31. select '' isSelect
  32. ,a.ID
  33. ,a.EATTRIBUTE5 as PreOrderNo --
  34. ,a.EATTRIBUTE6 as BusinessName --
  35. ,a.MOCode
  36. ,a.Sequence MoSeq
  37. ,a.MODetailID
  38. ,a.EATTRIBUTE1 MoTypeValue
  39. ,a.DepCode
  40. ,b.DepName --
  41. ,a.CreateDateTime --
  42. ,a.EATTRIBUTE3 PackageAsk --
  43. ,a.EATTRIBUTE4 SpecialAsk--
  44. ,a.EATTRIBUTE2 Useage--
  45. ,a.InvCode ItemCode
  46. ,c.EATTRIBUTE2 ItemAddCode
  47. ,c.InvName ItemName
  48. ,c.InvStd ItemStd
  49. ,c.InvUnit ItemUnit
  50. ,a.Amount
  51. ,CONVERT(varchar(10), a.StartDate,120) StartDate
  52. ,CONVERT(varchar(10), a.DueDate,120) DueDate
  53. ,case when a.PlanStartDate is null then CONVERT(varchar(10), a.StartDate,120)
  54. else CONVERT(varchar(10), a.PlanStartDate,120) end as PlanStartDate
  55. ,case when a.PlanEndDate is null then CONVERT(varchar(10), a.DueDate,120)
  56. else CONVERT(varchar(10), a.PlanEndDate,120) end as PlanEndDate
  57. ,a.ApsOrderDate
  58. ,a.APSStatus
  59. ,a.OrderStatus
  60. from ICSMO a with(nolock)
  61. left join ICSDepartment b with(nolock) on a.DepCode=b.DepCode
  62. left join ICSInventory c with(nolock) on a.InvCode=c.InvCode
  63. where 1=1
  64. <1>
  65. --order by a.CreateDateTime desc
  66. ) a
  67. where 1=1
  68. ";
  69. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  70. //sql = string.Format(sql, Figure);
  71. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  72. #endregion
  73. if (!string.IsNullOrWhiteSpace(queryJson))
  74. {
  75. if (!string.IsNullOrWhiteSpace(queryParam["ItemCode"].ToString()))
  76. {
  77. sql += " and a.ItemCode like '%" + queryParam["ItemCode"].ToString() + "%' ";
  78. }
  79. if (!string.IsNullOrWhiteSpace(queryParam["ItemName"].ToString()))
  80. {
  81. sql += " and a.ItemName like '%" + queryParam["ItemName"].ToString() + "%' ";
  82. }
  83. var ssName1 = queryParam["SSName"].ToString();
  84. var ssName2 = queryParam["SSName2"].ToString();
  85. if (string.IsNullOrEmpty(ssName1) && string.IsNullOrEmpty(ssName2))
  86. {
  87. sql = sql.Replace("<1>", "and a.APSStatus is null ");
  88. }
  89. else
  90. {
  91. if (!string.IsNullOrEmpty(ssName1) && !string.IsNullOrEmpty(ssName2))
  92. {
  93. sql += " and a.DepName ='" + ssName1 + "' and a.APSStatus='Y' ";
  94. sql = sql.Replace("<1>", " ");
  95. }
  96. if (!string.IsNullOrEmpty(ssName1))
  97. {
  98. sql += " and a.DepName ='" + ssName1 + "' and a.APSStatus='Y' ";
  99. sql = sql.Replace("<1>", " ");
  100. }
  101. if (!string.IsNullOrEmpty(ssName2))
  102. {
  103. sql += " and a.DepName ='" + ssName2 + "' ";
  104. sql = sql.Replace("<1>", " and a.APSStatus is null ");
  105. }
  106. }
  107. if (!string.IsNullOrWhiteSpace(queryParam["MoCode"].ToString()))
  108. {
  109. sql += " and a.MOCode like '%" + queryParam["MoCode"].ToString() + "%' ";
  110. }
  111. if (!string.IsNullOrWhiteSpace(queryParam["OrderStatus"].ToString()))
  112. {
  113. sql += " and a.OrderStatus = '" + queryParam["OrderStatus"].ToString() + "' ";
  114. }
  115. else
  116. {
  117. sql += " and (a.OrderStatus is null or a.OrderStatus='')";
  118. }
  119. }
  120. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  121. //{
  122. // sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  123. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  124. //}
  125. //else
  126. //{
  127. // sql = sql.Replace("{0}", "");
  128. //}
  129. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  130. //{
  131. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  132. //}
  133. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  134. }
  135. public string UpdateMoOrderStatus(string keyValue)
  136. {
  137. string returnValue = string.Empty;
  138. try
  139. {
  140. var queryParam = keyValue.ToJObject();
  141. var ids = queryParam["ids"].ToString().Split(',');
  142. if (ids.Length == 0)
  143. {
  144. throw new Exception("编号获取失败");
  145. }
  146. var orderStatus = queryParam["orderStatus"].ToString();
  147. //orderStatus = orderStatus == "" ? null : orderStatus;
  148. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  149. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  150. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  151. var sql = @"update ICSMO set OrderStatus ='{3}',MTIME=GETDATE(),MUSER='{0}',WorkPoint='{1}' where ID in ('{2}') ";
  152. sql = string.Format(sql, MUSER, WorkPoint, string.Join("','", ids),orderStatus);
  153. var rows = SqlHelper.CmdExecuteNonQueryLi(sql) > 0;
  154. if (!rows)
  155. {
  156. throw new Exception("修改失败");
  157. }
  158. }
  159. catch (Exception ex)
  160. {
  161. throw new Exception(ex.Message);
  162. }
  163. return returnValue;
  164. }
  165. public string GetOrgAName()
  166. {
  167. string returnValue = string.Empty;
  168. string sql = @"select
  169. b.F_FullName as OrgName
  170. ,b.F_EnCode as OrgCode
  171. ,a.*
  172. from [dbo].[Sys_SRM_Role] a
  173. left join Sys_SRM_Organize b on a.F_OrganizeId=b.F_Id
  174. where 1=1
  175. and a.F_EnCode='{0}'
  176. ";
  177. sql = string.Format(sql, NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode);
  178. var dt = Repository().FindDataSetBySql(sql.ToString()).Tables[0];
  179. if (dt == null || dt.Rows.Count == 0)
  180. {
  181. return returnValue;
  182. }
  183. returnValue = dt.Rows[0]["OrgName"].ToStringExt();
  184. return returnValue;
  185. }
  186. public string UpdateMoPlan2(string keyValue)
  187. {
  188. string returnValue = string.Empty;
  189. var queryParam = keyValue.ToJObject();
  190. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  191. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  192. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  193. string sql = string.Empty;
  194. sql = @"
  195. UPDATE dbo.ICSMO set MTIME=GETDATE(),MUSER='{0}',WorkPoint='{1}'
  196. <1>
  197. <2>
  198. <3>
  199. WHERE ID in ('{2}')";
  200. var ids = queryParam["ids"].ToString().Split(',');
  201. sql = string.Format(sql, MUSER, WorkPoint, string.Join("','", ids));
  202. if (!string.IsNullOrEmpty(queryParam["orderDate"].ToString()))
  203. {
  204. sql = sql.Replace("<1>", ",ApsOrderDate='" + queryParam["orderDate"].ToString() + "'");
  205. }
  206. if (!string.IsNullOrEmpty(queryParam["planStartDate"].ToString()))
  207. {
  208. sql = sql.Replace("<2>", ",planStartDate='" + queryParam["planStartDate"].ToString() + "'");
  209. }
  210. if (!string.IsNullOrEmpty(queryParam["planEndDate"].ToString()))
  211. {
  212. sql = sql.Replace("<3>", ",planEndDate='" + queryParam["planEndDate"].ToString() + "'");
  213. }
  214. var rows = SqlHelper.CmdExecuteNonQueryLi(sql) > 0;
  215. if (!rows)
  216. {
  217. throw new Exception("修改失败");
  218. }
  219. return returnValue;
  220. }
  221. public string UpdateMoPlan(string keyValue)
  222. {
  223. string returnValue = string.Empty;
  224. var queryParam = keyValue.ToJObject();
  225. var isCanUpdateStatus = queryParam["isCanUpdateStatus"].ToBool();
  226. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  227. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  228. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  229. string sql = string.Empty;
  230. sql = @"
  231. declare @DepCode nvarchar(100)
  232. select @DepCode= DepCode from ICSDepartment
  233. where DepName='{0}'
  234. --select @DepCode
  235. UPDATE dbo.ICSMO set DepCode=@DepCode, MTIME=GETDATE(),MUSER='{1}',WorkPoint='{2}',APSStatus='Y' <1> <2> <3> WHERE ID in ('{3}')";
  236. var ids = queryParam["ids"].ToString().Split(',');
  237. string APIURL = ConfigurationManager.ConnectionStrings["ERPAPIURL"].ConnectionString + "MOHKWam/Update";
  238. var planStartDate = queryParam["planStartDate"].ToStringExt();
  239. var planEndDate = queryParam["planEndDate"].ToStringExt();
  240. sql = string.Format(sql, queryParam["line"].ToString(), MUSER, WorkPoint, string.Join("','", ids), queryParam["orderDate"].ToString());
  241. if (!string.IsNullOrEmpty(queryParam["orderDate"].ToString()))
  242. {
  243. sql = sql.Replace("<1>", ",ApsOrderDate='" + queryParam["orderDate"].ToString() + "' ");
  244. }
  245. else
  246. {
  247. sql = sql.Replace("<1>", ",ApsOrderDate=getdate()");
  248. }
  249. if (!string.IsNullOrEmpty(planStartDate))
  250. {
  251. sql = sql.Replace("<2>", ",PlanStartDate='" + planStartDate + "'");
  252. }
  253. else
  254. {
  255. sql = sql.Replace("<2>", " ,PlanStartDate=StartDate");
  256. }
  257. if (!string.IsNullOrEmpty(planEndDate))
  258. {
  259. sql = sql.Replace("<3>", ",PlanEndDate='" + planEndDate + "'");
  260. }
  261. else
  262. {
  263. sql = sql.Replace("<3>", " ,PlanEndDate=DueDate");
  264. }
  265. //string sql11 = @"select a.* from ICSMO a where a.ID in ('0')";
  266. //sql11 = string.Format(sql11, string.Join("','", ids));
  267. //var dt11 = Repository().FindDataSetBySql(sql11.ToString()).Tables[0];
  268. //if (dt11 == null || dt11.Rows.Count == 0)
  269. //{
  270. // throw new Exception("获取工单数据失败");
  271. //}
  272. //foreach (DataRow item in dt11.Rows)
  273. //{
  274. //}
  275. try
  276. {
  277. string sql3 = @"
  278. declare @DepCode nvarchar(100)
  279. select @DepCode= DepCode from ICSDepartment
  280. where DepName='{0}'
  281. select @DepCode as DepCode ";
  282. sql3 = string.Format(sql3, queryParam["line"].ToString());
  283. var dt5 = Repository().FindDataSetBySql(sql3.ToString()).Tables[0];
  284. if (dt5 == null || dt5.Rows.Count == 0)
  285. {
  286. throw new Exception("当前部门获取失败");
  287. }
  288. var deptCode = dt5.Rows[0]["DepCode"].ToString();
  289. if (!isCanUpdateStatus)
  290. {
  291. sql = sql.Replace(",APSStatus='Y'", " ");
  292. //var rows2 = SqlHelper.CmdExecuteNonQueryLi(sql) > 0;
  293. //if (!rows2)
  294. //{
  295. // throw new Exception("修改失败");
  296. //}
  297. //return returnValue;
  298. }
  299. string objsql = @"
  300. declare @WorkPointCode varchar(100)
  301. select @WorkPointCode=WorkPointCode from Sys_WorkPoint
  302. select
  303. @WorkPointCode as WorkPoint
  304. ,a.MODetailID as MoDid
  305. ,CONVERT(varchar(10), a.StartDate,120) StartDate
  306. ,CONVERT(varchar(10), a.DueDate,120) DueDate
  307. ,a.DepCode cDept
  308. from ICSMO a with(nolock)
  309. where a.ID in ('{0}')
  310. ";
  311. objsql = string.Format(objsql, string.Join("','", ids));
  312. var dt = Repository().FindDataSetBySql(objsql.ToString()).Tables[0];
  313. if (dt == null || dt.Rows.Count == 0)
  314. {
  315. return returnValue;
  316. }
  317. List<object> objList = new List<object>();
  318. foreach (DataRow item in dt.Rows)
  319. {
  320. if (!string.IsNullOrEmpty(planStartDate))
  321. {
  322. }
  323. object obj = new
  324. {
  325. WorkPoint = item["WorkPoint"].ToString(),
  326. MoDid = item["MoDid"].ToString(),
  327. StartDate = string.IsNullOrEmpty(planStartDate) ? item["StartDate"].ToString() : planStartDate,
  328. DueDate = string.IsNullOrEmpty(planEndDate) ? item["DueDate"].ToString() : planEndDate,
  329. cDept = deptCode,
  330. };
  331. objList.Add(obj);
  332. }
  333. var result = HttpMethods.Post<ResultDto>(APIURL, objList).Result;
  334. if (!result.Success)
  335. {
  336. return result.Message;
  337. }
  338. var rows = SqlHelper.CmdExecuteNonQueryLi(sql) > 0;
  339. if (!rows)
  340. {
  341. throw new Exception("修改失败");
  342. }
  343. }
  344. catch (Exception ex)
  345. {
  346. returnValue = ex.Message;
  347. }
  348. return returnValue;
  349. }
  350. public DataTable GetApsPlanSelectSubItemList(string ids, ref Pagination pagination)
  351. {
  352. DataTable dt = new DataTable();
  353. // var queryParam = queryJson.ToJObject();
  354. List<DbParameter> parameter = new List<DbParameter>();
  355. //object Figure = GetDecimalDigits();
  356. #region [SQL]
  357. string sql = @"select
  358. a.SubItemCode,a.SubItemName,a.SubItemStd,a.InvUnit,a.AmountUnit
  359. ,sum( a.Quantity) Quantity
  360. ,sum( a.Amount) Amount
  361. ,max(a.ID) ID
  362. from
  363. (
  364. select 0 Code
  365. --a.*
  366. ,a.ID
  367. ,c.InvCode SubItemCode
  368. ,c.InvName SubItemName
  369. ,c.InvStd SubItemStd
  370. ,a.Quantity --
  371. ,c.InvUnit --
  372. ,a.Amount --
  373. ,c.AmountUnit --
  374. from ICSMOPick a with(nolock)
  375. left join ICSMO b with(nolock) on a.MODetailID=b.MODetailID
  376. left join ICSInventory c with(nolock) on a.InvCode =c.InvCode
  377. where 1=1
  378. <1>
  379. and a.EATTRIBUTE1=0
  380. ) a
  381. group by a.SubItemCode,a.SubItemName,a.SubItemStd,a.InvUnit,a.AmountUnit
  382. order by a.SubItemCode,a.SubItemName,a.SubItemStd
  383. ";
  384. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  385. var list = ids.Split(',');
  386. sql = sql.Replace("<1>", " and b.ID in ('" + string.Join("','", list) + "')");
  387. //sql = sql.Replace("<2>", "and b.Sequence=" + moSeq + "");
  388. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  389. #endregion
  390. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  391. //{
  392. // sql = sql.Replace("<3>", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  393. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  394. //}
  395. //else
  396. //{
  397. // sql = sql.Replace("<3>", "");
  398. //}
  399. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  400. //{
  401. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  402. //}
  403. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  404. }
  405. public DataTable GetApsPlanSubGridJsonList(string moCode, int moSeq, ref Pagination pagination)
  406. {
  407. DataTable dt = new DataTable();
  408. // var queryParam = queryJson.ToJObject();
  409. List<DbParameter> parameter = new List<DbParameter>();
  410. //object Figure = GetDecimalDigits();
  411. #region [SQL]
  412. string sql = @"select 0 Code
  413. --a.*
  414. ,a.ID
  415. ,a.Sequence SubSeq
  416. ,c.InvCode SubItemCode
  417. ,c.InvName SubItemName
  418. --,c.ClassCode
  419. --,c.ClassName
  420. ,c.InvStd SubItemDtd
  421. ,convert(nvarchar(100), floor (isnull( a.EATTRIBUTE3,0) *100)) +'%' as Rate --
  422. ,a.Quantity --
  423. ,c.InvUnit --
  424. ,a.Amount --
  425. ,c.AmountUnit --
  426. from ICSMOPick a with(nolock)
  427. left join ICSMO b with(nolock) on a.MODetailID=b.MODetailID
  428. left join ICSInventory c with(nolock) on a.InvCode =c.InvCode and a.WorkPoint=c.WorkPoint
  429. where 1=1
  430. <1>
  431. <2>
  432. and a.EATTRIBUTE1=0
  433. --and left( c.ClassCode,2)='01'
  434. order by a.Sequence
  435. ";
  436. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  437. sql = sql.Replace("<1>", "and b.MOCode='" + moCode + "'");
  438. sql = sql.Replace("<2>", "and b.Sequence=" + moSeq + "");
  439. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  440. #endregion
  441. //if (!string.IsNullOrWhiteSpace(queryJson))
  442. //{
  443. // if (!string.IsNullOrWhiteSpace(queryParam["ItemCode"].ToString()))
  444. // {
  445. // sql += " and a.ItemCode like '%" + queryParam["ItemCode"].ToString() + "%' ";
  446. // }
  447. // if (!string.IsNullOrWhiteSpace(queryParam["ItemName"].ToString()))
  448. // {
  449. // sql += " and a.ItemName like '%" + queryParam["ItemName"].ToString() + "%' ";
  450. // }
  451. // //if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  452. // //{
  453. // // sql += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  454. // //}
  455. // //if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  456. // //{
  457. // // sql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  458. // //}
  459. // //if (!string.IsNullOrWhiteSpace(queryParam["SelGDLX"].ToString()))
  460. // //{
  461. // // sql += " and a.MOType like '%" + queryParam["SelGDLX"].ToString() + "%' ";
  462. // //}
  463. // //if (!string.IsNullOrWhiteSpace(queryParam["POStatus"].ToString()))
  464. // //{
  465. // // string POStatus = queryParam["POStatus"].ToString();
  466. // // if (POStatus == "0")
  467. // // {
  468. // // //sql += " and a.Quantity=ISNULL(c.LotQty,0)";
  469. // // }
  470. // // else if (POStatus == "1")
  471. // // {
  472. // // sql += " and ISNULL(c.LOTQTY,0)>=a.Quantity";
  473. // // }
  474. // // else
  475. // // {
  476. // // sql += " and ISNULL(c.LOTQTY,0)<a.Quantity";
  477. // // }
  478. // //}
  479. //}
  480. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  481. //{
  482. // sql = sql.Replace("<3>", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  483. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  484. //}
  485. //else
  486. //{
  487. // sql = sql.Replace("<3>", "");
  488. //}
  489. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  490. //{
  491. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  492. //}
  493. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  494. }
  495. }
  496. }