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.

250 lines
9.6 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. 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 DataTable GetCCL7(string Type, string Group, string TimeFrom, string TimeArrive)
  58. {
  59. string sqlwhere = string.Empty;
  60. string sql = @" select
  61. cast( isnull( sum(isnull(e.RowCC,0)),0) as decimal(18,2))
  62. from dbo.ICSMO a
  63. inner join dbo.ICSDepartment d on a.DepCode=d.DepCode
  64. inner join ( select a.MOCode,a.Sequence,a.WorkPoint, e.EATTRIBUTE5,e.EATTRIBUTE1,case when e.EATTRIBUTE3='' then isnull(b.Quantity,0) /isnull(e.EATTRIBUTE1,1)*e.EATTRIBUTE5/1000 else isnull( isnull(b.Quantity,0),0)/1000 end as RowCC from dbo.ICSMO a
  65. inner join dbo.ICSWareHouseLotInfoLog b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and b.BusinessCode='17'
  66. inner join dbo.ICSInventory e on a.InvCode=e.InvCode and a.WorkPoint=e.WorkPoint
  67. inner join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  68. where c.MUSERName= '" + Type + Group + "' {0} )e on a.MOCode = e.MOCode and a.Sequence = e.Sequence and a.WorkPoint = e.WorkPoint where d.DepName = '" + Type + "' ";
  69. if (!string.IsNullOrWhiteSpace(TimeFrom))
  70. {
  71. sqlwhere += "and left(b.MTIME,7)>='" + TimeFrom + "'";
  72. }
  73. if (!string.IsNullOrWhiteSpace(TimeArrive))
  74. {
  75. sqlwhere += "and left(b.MTIME,7)<='" + TimeArrive + "'";
  76. }
  77. sql = string.Format(sql, sqlwhere);
  78. return Repository().FindTableBySql(sql.ToString());
  79. }
  80. public string CreateKPIMaintain(string keyValue)
  81. {
  82. var queryParam = keyValue.ToJObject();
  83. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  84. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  85. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  86. string msg = "";
  87. string sql = string.Empty;
  88. sql = @"IF EXISTS(SELECT * FROM dbo.ICSKPIMaintain
  89. where Team = '{0}' and Date='{1}' and WorkPoint='{5}')
  90. BEGIN
  91. RAISERROR(':{0},{1}!',16,1);
  92. RETURN
  93. END
  94. INSERT INTO dbo.ICSKPIMaintain
  95. ( ID ,Team,Date,Metrics ,Picking ,CreatePerson,CreateDate,MUSER,MTIME,WorkPoint )
  96. Values(NEWID(),'{0}','{1}','{2}','{3}','{4}',GETDATE(),'{4}',GETDATE(),'{5}')
  97. ";
  98. sql = string.Format(sql, queryParam["Team"].ToString(), queryParam["Date"].ToString(), queryParam["Metrics"].ToString(), queryParam["Picking"].ToString(), MUSER, WorkPoint);
  99. try
  100. {
  101. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  102. {
  103. }
  104. else
  105. {
  106. msg = "新增失败";
  107. }
  108. }
  109. catch (Exception ex)
  110. {
  111. msg = ex.Message;
  112. }
  113. return msg;
  114. }
  115. public string UpdateKPIMaintain(string keyValue)
  116. {
  117. var queryParam = keyValue.ToJObject();
  118. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  119. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  120. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  121. string msg = "";
  122. string sql = string.Empty;
  123. sql = @"UPDATE dbo.ICSKPIMaintain set Team = '{0}',Date='{1}',Metrics='{2}',Picking='{3}',MTIME=GETDATE(),MUSER='{4}',WorkPoint='{5}' WHERE ID='{6}'";
  124. sql = string.Format(sql, queryParam["Team"].ToString(), queryParam["Date"].ToString(), queryParam["Metrics"].ToString(), queryParam["Picking"].ToString(), MUSER, WorkPoint, queryParam["ID"].ToString());
  125. try
  126. {
  127. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  128. {
  129. }
  130. else
  131. {
  132. msg = "修改失败";
  133. }
  134. }
  135. catch (Exception ex)
  136. {
  137. msg = ex.Message;
  138. }
  139. return msg;
  140. }
  141. public string DeleteOMAYMaintain(string keyValue)
  142. {
  143. //站点信息
  144. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  145. string msg = "";
  146. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  147. string sql = string.Empty;
  148. sql = string.Format(@"DELETE FROM dbo.ICSKPIMaintain WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  149. try
  150. {
  151. SqlHelper.ExecuteNonQuery(sql);
  152. }
  153. catch (Exception ex)
  154. {
  155. msg = ex.Message;
  156. }
  157. return msg;
  158. }
  159. public DataTable GetZB(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 ( 'L1'),('L2'), ( 'L3'), ('L4'),('L5'), ('L6');
  166. select a.Team as Team,
  167. sum(case when b.Metrics='' then 0 else cast(b.Metrics as decimal(18,2)) end )as Metrics
  168. from #TempTable a left join ICSKPIMaintain b on a.Team=SUBSTRING(b.Team, 1, 2) {0}
  169. group by a.Team
  170. drop table #TempTable";
  171. if (!string.IsNullOrWhiteSpace(TimeFrom))
  172. {
  173. Condition += "and b.Date>='"+ TimeFrom + "'";
  174. }
  175. if (!string.IsNullOrWhiteSpace(TimeArrive))
  176. {
  177. Condition += "and b.Date<='" + TimeArrive + "'";
  178. }
  179. sql= string.Format(sql, Condition);
  180. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  181. return dt;
  182. }
  183. public DataTable GetYFFJ(string TimeFrom, string TimeArrive)
  184. {
  185. var Condition = "";
  186. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  187. string sql = @" CREATE TABLE #TempTable(Team VARCHAR(50))
  188. INSERT INTO #TempTable ( Team)
  189. VALUES ( 'L1A'),( 'L1B'),( 'L2A'),( 'L2B'),( 'L3A'),( 'L3B'), ( 'L4A'),( 'L4B'), ( 'L5A'),( 'L5B'),( 'L6A'),( 'L6B')
  190. select a.Team as Team,
  191. sum(case when b.Picking='' then 0 else cast(b.Picking as decimal(18,2)) end) as Picking
  192. from #TempTable a left join ICSKPIMaintain b on a.Team=b.Team {0}
  193. group by a.Team
  194. drop table #TempTable";
  195. if (!string.IsNullOrWhiteSpace(TimeFrom))
  196. {
  197. Condition += "and b.Date>='" + TimeFrom + "'";
  198. }
  199. if (!string.IsNullOrWhiteSpace(TimeArrive))
  200. {
  201. Condition += "and b.Date<='" + TimeArrive + "'";
  202. }
  203. sql = string.Format(sql, Condition);
  204. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  205. return dt;
  206. }
  207. }
  208. }