金豪看板
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.

419 lines
14 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using NFine.Code;
  2. using NFine.Domain.Entity.SystemManage;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.Common;
  6. using NFine.Repository;
  7. using System.Text;
  8. using System;
  9. using System.Configuration;
  10. using NFine.Data;
  11. using System.IO;
  12. using Newtonsoft.Json;
  13. using NFine.Domain._02_ViewModel;
  14. using NFine.Data.Extensions;
  15. using Newtonsoft.Json.Linq;
  16. namespace NFine.Application.SRM
  17. {
  18. public class WatchPanelApp : RepositoryFactory<ModuleEntity>
  19. {
  20. //十天生产订单开工&生产汇总
  21. public DataTable GetList1()
  22. {
  23. string ORGCode = ConfigurationManager.ConnectionStrings["ORGCode"].ConnectionString;
  24. List<DbParameter> parameter = new List<DbParameter>();
  25. string SqlText = @"
  26. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempdatePerr'))
  27. drop table #TempdatePerr
  28. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOWIPQty'))
  29. drop table #TempMOWIPQty
  30. declare @DateTimeZZ datetime=CONVERT(varchar(10),dateadd(day,-20, getdate()), 21) + ' 00:00:00'
  31. select *
  32. into #TempMOWIPQty
  33. from (
  34. select mo.StartDate ,mo.docno, min(rr.CompleteDate) ,
  35. case when mo.ClosedOn is not null and min(rr.CompleteDate) is not null then mo.ClosedOn
  36. else (case when min(rr.CompleteDate) is not null then getdate() else null end) end
  37. ,case when mo.ClosedOn is not null then mo.ClosedOn
  38. else getdate() end
  39. from mo_mo mo with(nolock)
  40. left join base_organization oo with(nolock) on mo.org=oo.id
  41. left join MO_CompleteRpt rr with(nolock) on rr.mo=mo.id
  42. where mo.DocState in (2,3) and oo.code='" + ORGCode + @"'
  43. group by mo.docno, mo.StartDate , mo.ClosedOn
  44. ) lll
  45. where (<=@DateTimeZZ and >=@DateTimeZZ )
  46. or (<=@DateTimeZZ and >=@DateTimeZZ )
  47. or >=@DateTimeZZ
  48. or >=@DateTimeZZ
  49. select convert(varchar(10),DATEADD(day,number*-1,getdate()) ,21) AS
  50. into #TempdatePerr
  51. from master.dbo.spt_values
  52. where type='p'
  53. AND number<=20
  54. and number>=0
  55. order by 1 desc
  56. select substring(,6,5) ,isnull(,0) ,isnull(,0) from (
  57. select aa.,
  58. row_number() over ( order by aa. desc) rn ,
  59. (select count(1) from #TempMOWIPQty bb where bb.<=aa.
  60. and bb.>=aa.) ,
  61. (select count(1) from #TempMOWIPQty bb where bb.<=aa.
  62. and bb.>=aa.)
  63. from #TempdatePerr aa
  64. ) kk
  65. where kk.rn <=10
  66. order by
  67. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempdatePerr'))
  68. drop table #TempdatePerr
  69. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempMOWIPQty'))
  70. drop table #TempMOWIPQty
  71. ";
  72. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "U9connstr", null);
  73. return dt;
  74. }
  75. //定子/转子生产明细
  76. public DataTable GetList2(string ttype)
  77. {
  78. string ORGCode = ConfigurationManager.ConnectionStrings["ORGCode"].ConnectionString;
  79. List<DbParameter> parameter = new List<DbParameter>();
  80. string SqlText = @"
  81. select row_number() over ( order by mo.docno ) ,
  82. mo.docno ,mo.productqty ,mo.TotalCompleteQty ,ii.code ,
  83. ii.name ,ii.SPECS ,mo.DescFlexField_PrivateDescSeg2 ,mo.DescFlexField_PrivateDescSeg3 ,
  84. mo.DescFlexField_PrivateDescSeg1
  85. from mo_mo mo with(nolock)
  86. left join base_organization oo with(nolock) on mo.org=oo.id
  87. left join CBO_ItemMaster ii with(nolock) on ii.id=mo.itemmaster
  88. where mo.DocState in (2,3)
  89. and mo.StartDate<=CONVERT(varchar(10), GETDATE(), 21) + ' 23:59:59'
  90. and case when mo.ClosedOn is not null then mo.ClosedOn else getdate() end >=CONVERT(varchar(10), GETDATE(), 21) + ' 00:00:00'
  91. and ii.name like '%" + ttype + @"%' and oo.code='" + ORGCode + @"'
  92. ";
  93. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "U9connstr", null);
  94. return dt;
  95. }
  96. //收货
  97. public DataTable GetList3()
  98. {
  99. string ORGCode = ConfigurationManager.ConnectionStrings["ORGCode"].ConnectionString;
  100. List<DbParameter> parameter = new List<DbParameter>();
  101. string SqlText = @"
  102. select po.docno ,pol.doclineno ,ii.code ,
  103. ii.name ,ii.specs ,posl.ReqQtyTU-isnull(posl.TotalRecievedQtyTU,0)
  104. from dbo. PM_POShipLine POsL WITH(NOLOCK)
  105. left join pm_poline pol with(nolock) on POsL.poline=pol.id
  106. left join PM_PurchaseOrder po with(nolock) on po.id=pol.PurchaseOrder
  107. left join CBO_ItemMaster ii with(nolock) on ii.id=pol.iteminfo_itemid
  108. left join base_organization oo with(nolock) on oo.id=POsL.CurrentOrg
  109. where 1= 1
  110. and oo.code='" + ORGCode + @"'
  111. and pol.status in (2 )
  112. and POsL.DeliveryDate >=CONVERT(varchar(10), GETDATE(), 21) + ' 00:00:00'
  113. order by 1,2
  114. ";
  115. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "U9connstr", null);
  116. return dt;
  117. }
  118. //收货比例
  119. public DataTable GetList5()
  120. {
  121. string ORGCode = ConfigurationManager.ConnectionStrings["ORGCode"].ConnectionString;
  122. List<DbParameter> parameter = new List<DbParameter>();
  123. string SqlText = @"
  124. select isnull(sum(),0) ,isnull(sum(),0)-isnull(sum(),0) ,
  125. isnull(sum(),0) , case when isnull(sum(),0)=0 then 0 else
  126. Convert(decimal(18,2),isnull(sum(),0)/ sum() *100.0 ) end
  127. from (
  128. select posl.ReqQtyTU ,posl.TotalRecievedQtyTU
  129. from dbo. PM_POShipLine POsL WITH(NOLOCK)
  130. left join pm_poline pol with(nolock) on POsL.poline=pol.id
  131. left join PM_PurchaseOrder po with(nolock) on po.id=pol.PurchaseOrder
  132. left join base_organization oo with(nolock) on oo.id=POsL.CurrentOrg
  133. where 1= 1
  134. and oo.code='" + ORGCode + @"'
  135. and pol.status in (2,3,4,5)
  136. and POsL.DeliveryDate >=CONVERT(varchar(10), GETDATE(), 21) + ' 00:00:00'
  137. ) ll
  138. ";
  139. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "U9connstr", null);
  140. return dt;
  141. }
  142. //出货
  143. public DataTable GetList4()
  144. {
  145. string ORGCode = ConfigurationManager.ConnectionStrings["ORGCode"].ConnectionString;
  146. List<DbParameter> parameter = new List<DbParameter>();
  147. string SqlText = @"
  148. select ss.docno ,line.doclineno ,ii.code ,
  149. ii.name ,ii.specs ,line.ShipQtyTUAmount
  150. from sm_ship ss with(nolock)
  151. inner join sm_shipline line with(nolock) on ss.id=line.ship
  152. left join CBO_ItemMaster ii with(nolock) on ii.id=line.iteminfo_itemid
  153. left join base_organization oo with(nolock) on oo.id=line.Org
  154. where line.status!=3
  155. and oo.code='" + ORGCode + @"'
  156. and line.createdon >=CONVERT(varchar(10), GETDATE(), 21) + ' 00:00:00'
  157. ";
  158. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "U9connstr", null);
  159. return dt;
  160. }
  161. //出货比例
  162. public DataTable GetList6()
  163. {
  164. string ORGCode = ConfigurationManager.ConnectionStrings["ORGCode"].ConnectionString;
  165. List<DbParameter> parameter = new List<DbParameter>();
  166. string SqlText = @"
  167. select isnull(sum(),0) ,isnull(sum(),0)-isnull(sum(),0) ,
  168. isnull(sum(),0) , case when isnull(sum(),0)=0 then 0 else
  169. Convert(decimal(18,2),isnull(sum(),0)/ sum() *100.0 ) end
  170. from (
  171. select line.ShipQtyTUAmount ,case when
  172. line.status=3 then line.ShipQtyTUAmount else 0 end
  173. from sm_ship ss with(nolock)
  174. inner join sm_shipline line with(nolock) on ss.id=line.ship
  175. left join CBO_ItemMaster ii with(nolock) on ii.id=line.iteminfo_itemid
  176. left join base_organization oo with(nolock) on oo.id=line.Org
  177. where oo.code='" + ORGCode + @"'
  178. and line.createdon >=CONVERT(varchar(10), GETDATE(), 21) + ' 00:00:00'
  179. ) jjj
  180. ";
  181. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "U9connstr", null);
  182. return dt;
  183. }
  184. //设备开机率
  185. public DataTable GetList7()
  186. {
  187. List<DbParameter> parameter = new List<DbParameter>();
  188. string SqlText = @"
  189. SELECT ZQTY,QTY,
  190. case WHEN ZQTY=0 THEN 0 ELSE Convert(decimal(18,0),QTY/ZQTY*100) end EQPRATE
  191. FROM (select ISNULL((
  192. select count(1) from device_data with(nolock) where created_at>=CONVERT(varchar(10), GETDATE(), 21) + ' 00:00:00'),0) QTY,
  193. ISNULL( (select count(1) from devices with(nolock) ),0) ZQTY
  194. ) KKK
  195. ";
  196. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "connstr", null);
  197. return dt;
  198. }
  199. public static void WriteLogFile(string input, string txtName)
  200. {
  201. try
  202. {
  203. string logAdress = "C:\\看板日志" + "\\";
  204. if (!System.IO.Directory.Exists(logAdress))
  205. {
  206. System.IO.Directory.CreateDirectory(logAdress);//不存在就创建目录
  207. }
  208. string adress = logAdress + txtName;
  209. if (!System.IO.Directory.Exists(adress))
  210. {
  211. System.IO.Directory.CreateDirectory(adress);//不存在就创建目录
  212. }
  213. // string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString();
  214. /**/
  215. ///指定日志文件的目录
  216. string fname = adress + "\\" + "log" + DateTime.Now.ToString("yy-MM-dd") + ".txt";
  217. /**/
  218. ///定义文件信息对象
  219. FileInfo finfo = new FileInfo(fname);
  220. if (!finfo.Exists)
  221. {
  222. FileStream fs;
  223. fs = File.Create(fname);
  224. fs.Close();
  225. finfo = new FileInfo(fname);
  226. }
  227. /**/
  228. ///判断文件是否存在以及是否大于2K
  229. if (finfo.Length > 1024 * 1024 * 10)
  230. {
  231. /**/
  232. ///文件超过10MB则重命名
  233. File.Move(logAdress + "\\Log\\" + txtName + ".txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\Log\\" + txtName + ".txt");
  234. /**/
  235. ///删除该文件
  236. //finfo.Delete();
  237. }
  238. //finfo.AppendText();
  239. /**/
  240. ///创建只写文件流
  241. using (FileStream fs = finfo.OpenWrite())
  242. {
  243. /**/
  244. ///根据上面创建的文件流创建写数据流
  245. StreamWriter w = new StreamWriter(fs);
  246. /**/
  247. ///设置写数据流的起始位置为文件流的末尾
  248. ///设置写数据流的起始位置为文件流的末尾
  249. w.BaseStream.Seek(0, SeekOrigin.End);
  250. w.WriteLine("*****************Start*****************");
  251. w.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  252. /**/
  253. ///写入当前系统时间并换行
  254. /**/
  255. ///写入日志内容并换行
  256. w.WriteLine(input);
  257. /**/
  258. ///写入------------------------------------“并换行
  259. w.WriteLine("------------------END------------------------");
  260. /**/
  261. ///清空缓冲区内容,并把缓冲区内容写入基础流
  262. w.Flush();
  263. /**/
  264. ///关闭写数据流
  265. w.Close();
  266. }
  267. }
  268. catch (Exception ex)
  269. { }
  270. }
  271. public string ConvertDataTableToJson(DataTable dt)
  272. {
  273. StringBuilder sbs = new StringBuilder();
  274. if (dt.Rows.Count > 0)//如果有记录
  275. {
  276. sbs.Append("{'" + dt.TableName + "':[");
  277. string str = "";
  278. foreach (DataRow dr in dt.Rows)//开始拼
  279. {
  280. string result = "";
  281. foreach (DataColumn dc in dt.Columns)
  282. {
  283. result += string.Format(",'{0}':'{1}'",
  284. dc.ColumnName, dr[dc.ColumnName]);
  285. }
  286. result = result.Substring(1);
  287. result = ",{" + result + "}";
  288. str += result;
  289. }
  290. str = str.Substring(1);
  291. sbs.Append(str);
  292. sbs.Append("]}");
  293. }
  294. else//如果没有记录
  295. {
  296. sbs.Append("");
  297. }
  298. return sbs.ToString();
  299. }
  300. }
  301. }