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.

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