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.

460 lines
16 KiB

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