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.

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