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.

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