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.

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