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.

224 lines
8.1 KiB

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. namespace NFine.Application.OMAY
  16. {
  17. public class OMAYApp : RepositoryFactory<ICSVendor>
  18. {
  19. public DataTable GetYLAndPC(string Type ,string Group, string TimeFrom, string TimeArrive)
  20. {
  21. string sql = @" select
  22. isnull( sum( case when c.BusinessCode='13' and SUBSTRING(b.InvCode, 1, 2) IN ('01','04','05') then cast(isnull(c.Quantity,0)/1000 as decimal(18,2)) else 0 end ),0) as YLTR ,
  23. isnull( sum( case when c.BusinessCode='50' and b.EATTRIBUTE1='1' and SUBSTRING(b.InvCode, 1, 2) IN ('05') then cast( isnull(c.Quantity,0)/1000 as decimal(18,2)) else 0 end) ,0)as PCLRK
  24. from dbo.ICSMO a
  25. inner join dbo.ICSMOPick b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  26. inner join dbo.ICSWareHouseLotInfoLog c on a.MOCode=c.TransCode and a.Sequence+'~'+b.Sequence=c.TransSequence
  27. inner join dbo.ICSDepartment d on a.DepCode=d.DepCode
  28. where d.DepName = '" + Type + "' and c.MUSERName= '" + Type + Group + "' ";
  29. if (!string.IsNullOrWhiteSpace(TimeFrom))
  30. {
  31. sql += "and left(c.MTIME,7)>='" + TimeFrom + "'";
  32. }
  33. if (!string.IsNullOrWhiteSpace(TimeArrive))
  34. {
  35. sql += "and left(c.MTIME,7)<='" + TimeArrive + "'";
  36. }
  37. return Repository().FindTableBySql(sql.ToString());
  38. }
  39. public DataTable GetCC(string Type, string Group, string TimeFrom, string TimeArrive)
  40. {
  41. string sql = @" select cast( isnull( sum(isnull(b.Quantity,0)),0)/1000 as decimal(18,2)) as CC
  42. from dbo.ICSMO a
  43. inner join dbo.ICSWareHouseLotInfoLog b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and b.BusinessCode='17'
  44. inner join dbo.ICSDepartment d on a.DepCode=d.DepCode
  45. inner join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  46. where d.DepName = '" + Type + "' and c.MUSERName= '" + Type + Group + "' ";
  47. if (!string.IsNullOrWhiteSpace(TimeFrom))
  48. {
  49. sql += "and left(b.MTIME,7)>='" + TimeFrom + "'";
  50. }
  51. if (!string.IsNullOrWhiteSpace(TimeArrive))
  52. {
  53. sql += "and left(b.MTIME,7)<='" + TimeArrive + "'";
  54. }
  55. return Repository().FindTableBySql(sql.ToString());
  56. }
  57. public string CreateKPIMaintain(string keyValue)
  58. {
  59. var queryParam = keyValue.ToJObject();
  60. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  61. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  62. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  63. string msg = "";
  64. string sql = string.Empty;
  65. sql = @"IF EXISTS(SELECT * FROM dbo.ICSKPIMaintain
  66. where Team = '{0}' and Date='{1}' and WorkPoint='{5}')
  67. BEGIN
  68. RAISERROR(':{0},{1}!',16,1);
  69. RETURN
  70. END
  71. INSERT INTO dbo.ICSKPIMaintain
  72. ( ID ,Team,Date,Metrics ,Picking ,CreatePerson,CreateDate,MUSER,MTIME,WorkPoint )
  73. Values(NEWID(),'{0}','{1}','{2}','{3}','{4}',GETDATE(),'{4}',GETDATE(),'{5}')
  74. ";
  75. sql = string.Format(sql, queryParam["Team"].ToString(), queryParam["Date"].ToString(), queryParam["Metrics"].ToString(), queryParam["Picking"].ToString(), MUSER, WorkPoint);
  76. try
  77. {
  78. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  79. {
  80. }
  81. else
  82. {
  83. msg = "新增失败";
  84. }
  85. }
  86. catch (Exception ex)
  87. {
  88. msg = ex.Message;
  89. }
  90. return msg;
  91. }
  92. public string UpdateKPIMaintain(string keyValue)
  93. {
  94. var queryParam = keyValue.ToJObject();
  95. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  96. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  97. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  98. string msg = "";
  99. string sql = string.Empty;
  100. sql = @"UPDATE dbo.ICSKPIMaintain set Team = '{0}',Date='{1}',Metrics='{2}',Picking='{3}',MTIME=GETDATE(),MUSER='{4}',WorkPoint='{5}' WHERE ID='{6}'";
  101. sql = string.Format(sql, queryParam["Team"].ToString(), queryParam["Date"].ToString(), queryParam["Metrics"].ToString(), queryParam["Picking"].ToString(), MUSER, WorkPoint, queryParam["ID"].ToString());
  102. try
  103. {
  104. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  105. {
  106. }
  107. else
  108. {
  109. msg = "修改失败";
  110. }
  111. }
  112. catch (Exception ex)
  113. {
  114. msg = ex.Message;
  115. }
  116. return msg;
  117. }
  118. public string DeleteOMAYMaintain(string keyValue)
  119. {
  120. //站点信息
  121. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  122. string msg = "";
  123. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  124. string sql = string.Empty;
  125. sql = string.Format(@"DELETE FROM dbo.ICSKPIMaintain WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  126. try
  127. {
  128. SqlHelper.ExecuteNonQuery(sql);
  129. }
  130. catch (Exception ex)
  131. {
  132. msg = ex.Message;
  133. }
  134. return msg;
  135. }
  136. public DataTable GetZB(string TimeFrom, string TimeArrive)
  137. {
  138. var Condition = "";
  139. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  140. string sql = @"CREATE TABLE #TempTable(Team VARCHAR(50))
  141. INSERT INTO #TempTable ( Team)
  142. VALUES ( 'L1'),('L2'), ( 'L3'), ('L4'),('L5'), ('L6');
  143. select a.Team as Team, isnull(sum(cast(b.Metrics as decimal)),0) as Metrics
  144. from #TempTable a left join ICSKPIMaintain b on a.Team=SUBSTRING(b.Team, 1, 2) {0}
  145. group by a.Team
  146. drop table #TempTable";
  147. if (!string.IsNullOrWhiteSpace(TimeFrom))
  148. {
  149. Condition += "and b.Date>='"+ TimeFrom + "'";
  150. }
  151. if (!string.IsNullOrWhiteSpace(TimeArrive))
  152. {
  153. Condition += "and b.Date<='" + TimeArrive + "'";
  154. }
  155. sql= string.Format(sql, Condition);
  156. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  157. return dt;
  158. }
  159. public DataTable GetYFFJ(string TimeFrom, string TimeArrive)
  160. {
  161. var Condition = "";
  162. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  163. string sql = @"CREATE TABLE #TempTable(Team VARCHAR(50))
  164. INSERT INTO #TempTable ( Team)
  165. VALUES ( 'L1A'),( 'L1B'),( 'L2A'),( 'L2B'),( 'L3A'),( 'L3B'), ( 'L4A'),( 'L4B'), ( 'L5A'),( 'L5B'),( 'L6A'),( 'L6B')
  166. select a.Team as Team,isnull(cast(b.Picking as decimal),0) as Picking
  167. from #TempTable a left join ICSKPIMaintain b on a.Team=b.Team {0}
  168. drop table #TempTable";
  169. if (!string.IsNullOrWhiteSpace(TimeFrom))
  170. {
  171. Condition += "and b.Date>='" + TimeFrom + "'";
  172. }
  173. if (!string.IsNullOrWhiteSpace(TimeArrive))
  174. {
  175. Condition += "and b.Date<='" + TimeArrive + "'";
  176. }
  177. sql = string.Format(sql, Condition);
  178. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  179. return dt;
  180. }
  181. }
  182. }