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.

324 lines
14 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
9 months ago
9 months ago
9 months ago
10 months ago
9 months ago
9 months ago
10 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months 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 = @"
  22. // select isnull((b.YLTR-aaa.TL),0) as YLTR,b.PCLRK from(
  23. // select
  24. //cast( 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)/1000 as decimal(18,2)) as YLTR ,
  25. //cast(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)/1000 as decimal(18,2)) as PCLRK
  26. // from dbo.ICSMO a
  27. // left join dbo.ICSMOPick b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  28. // inner join dbo.ICSWareHouseLotInfoLog c on a.MOCode=c.TransCode and a.Sequence+'~'+b.Sequence=c.TransSequence and c.EATTRIBUTE1<>'1'
  29. // inner join dbo.ICSDepartment d on a.DepCode=d.DepCode
  30. //where 1=1 and isnull(a.EATTRIBUTE7,'')<>'1' {0})b
  31. // left join
  32. // (select
  33. //isnull(sum(isnull(c.Quantity,0)),0)/1000 as TL
  34. // from dbo.ICSMO a
  35. // left join dbo.ICSMOPick b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  36. // inner join dbo.ICSWareHouseLotInfoLog c on a.MOCode=c.TransCode and a.Sequence+'~'+b.Sequence=c.TransSequence and c.EATTRIBUTE1<>'1' and c.BusinessCode='16-1'
  37. // inner join dbo.ICSDepartment d on a.DepCode=d.DepCode
  38. // where SUBSTRING(b.InvCode, 1, 2) IN ('01','04','05') and isnull(a.EATTRIBUTE7,'')<>'1' {0}) aaa on 1=1";
  39. string sql = @"select isnull((b.YLTR-aaa.TL),0) as YLTR from(
  40. select
  41. cast(sum(isnull(c.Quantity,0)) /1000 as decimal(18,2)) as YLTR
  42. from
  43. ICSWareHouseLotInfoLog c
  44. left JOIN ICSMO a ON c.TransCode=a.MOCode AND SUBSTRING(c.TransSequence, 1, CHARINDEX('~', c.TransSequence) - 1)=a.Sequence and c.WorkPoint=a.WorkPoint
  45. where c.BusinessCode='13' and SUBSTRING(c.InvCode, 1, 2) IN ('01','04','05')
  46. and isnull( a.EATTRIBUTE7,'')<>'1' and c.EATTRIBUTE1<>'1' {0})b
  47. left join
  48. (select
  49. isnull(sum(isnull(c.Quantity,0)),0)/1000 as TL
  50. from
  51. ICSWareHouseLotInfoLog c
  52. left JOIN ICSMO a ON c.TransCode=a.MOCode and
  53. (case when c.TransSequence like '%~%'
  54. then SUBSTRING(c.TransSequence, 1, CHARINDEX('~', c.TransSequence) - 1)
  55. else c.TransSequence end )=a.Sequence
  56. and c.WorkPoint=a.WorkPoint
  57. where c.BusinessCode='16-1'
  58. and isnull( a.EATTRIBUTE7,'')<>'1' and isnull(c.EATTRIBUTE1,'')<>'1'
  59. and SUBSTRING(c.InvCode, 1, 2) IN ('01','04','05') {0}) aaa on 1=1
  60. ";
  61. string where = "and LEFT(c.MUSERName,2) = '" + Type + "' and c.MUSERName = '" + Type + Group + "'";
  62. if (!string.IsNullOrWhiteSpace(TimeFrom))
  63. {
  64. where += "and left(c.MTIME,7)>='" + TimeFrom + "'";
  65. }
  66. if (!string.IsNullOrWhiteSpace(TimeArrive))
  67. {
  68. where += "and left(c.MTIME,7)<='" + TimeArrive + "'";
  69. }
  70. sql = string.Format(sql, where);
  71. return Repository().FindTableBySql(sql.ToString());
  72. }
  73. public DataTable GetYLAndPCLRK(string Type, string Group, string TimeFrom, string TimeArrive)
  74. {
  75. string sql = @" select cast (isnull(sum(a.Quantity),0)/1000 as decimal(18,2))as PCLRK
  76. from dbo.ICSInventoryLot a
  77. inner join dbo.ICSWareHouseLotInfo b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  78. --inner join dbo.ICSWareHouseLotInfoLog c on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  79. where a.Type='19'
  80. and a.MUSERName= '" + Type + Group + "' ";
  81. if (!string.IsNullOrWhiteSpace(TimeFrom))
  82. {
  83. sql += "and left(b.MTIME,7)>='" + TimeFrom + "'";
  84. }
  85. if (!string.IsNullOrWhiteSpace(TimeArrive))
  86. {
  87. sql += "and left(b.MTIME,7)<='" + TimeArrive + "'";
  88. }
  89. return Repository().FindTableBySql(sql.ToString());
  90. }
  91. public DataTable GetCC(string Type, string Group, string TimeFrom, string TimeArrive)
  92. {
  93. //string sql = @" select cast( isnull( sum(isnull(b.Quantity,0)),0)/1000 as decimal(18,2)) as CC
  94. // from dbo.ICSMO a
  95. //inner join dbo.ICSWareHouseLotInfoLog b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and b.BusinessCode='17' and b.EATTRIBUTE1<>'1'
  96. // inner join dbo.ICSDepartment d on a.DepCode=d.DepCode
  97. // inner join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  98. // where isnull(a.EATTRIBUTE7,'')<>'1' and LEFT(c.MUSERName,2)='" + Type + "' and c.MUSERName= '" + Type + Group + "' ";
  99. string sql = @" select cast( isnull( sum(isnull(b.Quantity,0)),0)/1000 as decimal(18,2)) as CC
  100. from
  101. dbo.ICSWareHouseLotInfoLog b
  102. left JOIN ICSMO a on a.MOCode=b.TransCode and a.Sequence=b.TransSequence
  103. left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and b.WorkPoint=c.WorkPoint
  104. where isnull(a.EATTRIBUTE7,'')<>'1' and b.BusinessCode='17' and b.EATTRIBUTE1<>'1' and LEFT(c.MUSERName,2)='" + Type + "' and c.MUSERName= '" + Type + Group + "' ";
  105. if (!string.IsNullOrWhiteSpace(TimeFrom))
  106. {
  107. sql += "and left(b.MTIME,7)>='" + TimeFrom + "'";
  108. }
  109. if (!string.IsNullOrWhiteSpace(TimeArrive))
  110. {
  111. sql += "and left(b.MTIME,7)<='" + TimeArrive + "'";
  112. }
  113. return Repository().FindTableBySql(sql.ToString());
  114. }
  115. public DataTable GetCCL7(string Type, string Group, string TimeFrom, string TimeArrive)
  116. {
  117. string sqlwhere = string.Empty;
  118. // string sql = @" select
  119. //cast( isnull( sum(isnull(e.RowCC,0)),0) as decimal(18,2)) as CC
  120. // from dbo.ICSMO a
  121. // left join dbo.ICSDepartment d on a.DepCode=d.DepCode
  122. // 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
  123. //inner join dbo.ICSWareHouseLotInfoLog b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and b.BusinessCode='17'
  124. // inner join dbo.ICSInventory e on a.InvCode=e.InvCode and a.WorkPoint=e.WorkPoint
  125. // inner join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.WorkPoint=c.WorkPoint
  126. // where isnull(a.EATTRIBUTE7,'')<>'1' and 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 + "' ";
  127. string sql = @" select
  128. cast( isnull( sum(isnull(e.RowCC,0)),0) as decimal(18,2)) as CC
  129. from
  130. (select a.MOCode,a.Sequence,a.WorkPoint, e.EATTRIBUTE5,e.EATTRIBUTE1,
  131. 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
  132. dbo.ICSWareHouseLotInfoLog b
  133. left JOIN ICSMO a on a.MOCode=b.TransCode and a.Sequence=b.TransSequence
  134. left join dbo.ICSInventory e on b.InvCode=e.InvCode and b.WorkPoint=e.WorkPoint
  135. left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and b.WorkPoint=c.WorkPoint
  136. where isnull(a.EATTRIBUTE7,'')<>'1' and c.MUSERName= '" + Type + Group + "' and b.BusinessCode='17' {0} ) e ";
  137. if (!string.IsNullOrWhiteSpace(TimeFrom))
  138. {
  139. sqlwhere += "and left(b.MTIME,7)>='" + TimeFrom + "'";
  140. }
  141. if (!string.IsNullOrWhiteSpace(TimeArrive))
  142. {
  143. sqlwhere += "and left(b.MTIME,7)<='" + TimeArrive + "'";
  144. }
  145. sql = string.Format(sql, sqlwhere);
  146. return Repository().FindTableBySql(sql.ToString());
  147. }
  148. public string CreateKPIMaintain(string keyValue)
  149. {
  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 msg = "";
  155. string sql = string.Empty;
  156. sql = @"IF EXISTS(SELECT * FROM dbo.ICSKPIMaintain
  157. where Team = '{0}' and Date='{1}' and WorkPoint='{5}')
  158. BEGIN
  159. RAISERROR(':{0},{1}!',16,1);
  160. RETURN
  161. END
  162. INSERT INTO dbo.ICSKPIMaintain
  163. ( ID ,Team,Date,Metrics ,Picking ,CreatePerson,CreateDate,MUSER,MTIME,WorkPoint )
  164. Values(NEWID(),'{0}','{1}','{2}','{3}','{4}',GETDATE(),'{4}',GETDATE(),'{5}')
  165. ";
  166. sql = string.Format(sql, queryParam["Team"].ToString(), queryParam["Date"].ToString(), queryParam["Metrics"].ToString(), queryParam["Picking"].ToString(), MUSER, WorkPoint);
  167. try
  168. {
  169. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  170. {
  171. }
  172. else
  173. {
  174. msg = "新增失败";
  175. }
  176. }
  177. catch (Exception ex)
  178. {
  179. msg = ex.Message;
  180. }
  181. return msg;
  182. }
  183. public string UpdateKPIMaintain(string keyValue)
  184. {
  185. var queryParam = keyValue.ToJObject();
  186. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  187. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  188. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  189. string msg = "";
  190. string sql = string.Empty;
  191. sql = @"UPDATE dbo.ICSKPIMaintain set Team = '{0}',Date='{1}',Metrics='{2}',Picking='{3}',MTIME=GETDATE(),MUSER='{4}',WorkPoint='{5}' WHERE ID='{6}'";
  192. sql = string.Format(sql, queryParam["Team"].ToString(), queryParam["Date"].ToString(), queryParam["Metrics"].ToString(), queryParam["Picking"].ToString(), MUSER, WorkPoint, queryParam["ID"].ToString());
  193. try
  194. {
  195. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  196. {
  197. }
  198. else
  199. {
  200. msg = "修改失败";
  201. }
  202. }
  203. catch (Exception ex)
  204. {
  205. msg = ex.Message;
  206. }
  207. return msg;
  208. }
  209. public string DeleteOMAYMaintain(string keyValue)
  210. {
  211. //站点信息
  212. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  213. string msg = "";
  214. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  215. string sql = string.Empty;
  216. sql = string.Format(@"DELETE FROM dbo.ICSKPIMaintain WHERE ID IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  217. try
  218. {
  219. SqlHelper.ExecuteNonQuery(sql);
  220. }
  221. catch (Exception ex)
  222. {
  223. msg = ex.Message;
  224. }
  225. return msg;
  226. }
  227. public DataTable GetZB(string TimeFrom, string TimeArrive)
  228. {
  229. var Condition = "";
  230. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  231. string sql = @"CREATE TABLE #TempTable(Team VARCHAR(50))
  232. INSERT INTO #TempTable ( Team)
  233. VALUES ( 'L1'),('L2'), ( 'L3'), ('L4'),('L5'), ('L6');
  234. select a.Team as Team,
  235. sum(case when b.Metrics='' then 0 else cast(b.Metrics as decimal(18,2)) end )as Metrics
  236. from #TempTable a left join ICSKPIMaintain b on a.Team=SUBSTRING(b.Team, 1, 2) {0}
  237. group by a.Team
  238. drop table #TempTable";
  239. if (!string.IsNullOrWhiteSpace(TimeFrom))
  240. {
  241. Condition += "and b.Date>='"+ TimeFrom + "'";
  242. }
  243. if (!string.IsNullOrWhiteSpace(TimeArrive))
  244. {
  245. Condition += "and b.Date<='" + TimeArrive + "'";
  246. }
  247. sql= string.Format(sql, Condition);
  248. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  249. return dt;
  250. }
  251. public DataTable GetYFFJ(string TimeFrom, string TimeArrive)
  252. {
  253. var Condition = "";
  254. string WorkPoints = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  255. string sql = @" CREATE TABLE #TempTable(Team VARCHAR(50))
  256. INSERT INTO #TempTable ( Team)
  257. VALUES ( 'L1A'),( 'L1B'),( 'L2A'),( 'L2B'),( 'L3A'),( 'L3B'), ( 'L4A'),( 'L4B'), ( 'L5A'),( 'L5B'),( 'L6A'),( 'L6B')
  258. select a.Team as Team,
  259. sum(case when b.Picking='' then 0 else cast(b.Picking as decimal(18,2)) end) as Picking
  260. from #TempTable a left join ICSKPIMaintain b on a.Team=b.Team {0}
  261. group by a.Team
  262. drop table #TempTable";
  263. if (!string.IsNullOrWhiteSpace(TimeFrom))
  264. {
  265. Condition += "and b.Date>='" + TimeFrom + "'";
  266. }
  267. if (!string.IsNullOrWhiteSpace(TimeArrive))
  268. {
  269. Condition += "and b.Date<='" + TimeArrive + "'";
  270. }
  271. sql = string.Format(sql, Condition);
  272. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  273. return dt;
  274. }
  275. }
  276. }