纽威
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.

470 lines
24 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
  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. namespace NFine.Application.WMS
  13. {
  14. public class WatchPanelApp : RepositoryFactory<ModuleEntity>
  15. {
  16. string workpoint = ConfigurationManager.ConnectionStrings["WorkPointCode"].ConnectionString;
  17. private static string U9IP = ConfigurationManager.ConnectionStrings["U9connstr"].ConnectionString;
  18. private static string StratTimecfg = ConfigurationManager.ConnectionStrings["StratTime"].ConnectionString;
  19. private static string EndTimecfg = ConfigurationManager.ConnectionStrings["EndTime"].ConnectionString;
  20. private static string advDays = ConfigurationManager.ConnectionStrings["advDays"].ConnectionString;
  21. string StratTime = DateTime.Parse(DateTime.Now.AddDays(-1).ToString()).ToString("yyyy-MM-dd") + ' ' + StratTimecfg;
  22. string EndTime = DateTime.Parse(DateTime.Now.ToString()).ToString("yyyy-MM-dd") + ' ' + EndTimecfg;
  23. //private string ERPName = U9IP.Substring(U9IP.IndexOf("Server=") + 7, 9) + "." + U9IP.Substring(U9IP.IndexOf("Catalog=") + 8, 7);
  24. //string dsaq = ConfigurationManager.ConnectionStrings["advDays"].ConnectionString;
  25. private static string conbegin = "Data Source=";
  26. private static int end = U9IP.IndexOf(";Uid=");
  27. private static string ERPName = "[" + U9IP.Substring(conbegin.Length, end - conbegin.Length).Replace(";Database=", "].");
  28. private static string ERPName1 = ERPName.Split('.')[ERPName.Split('.').Length - 1];
  29. string EndTime2 = "";
  30. //到货明细
  31. public DataTable GetList1(string queryJson, ref Pagination jqgridparam)
  32. {
  33. var queryParam = queryJson.ToJObject();
  34. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  35. List<DbParameter> parameter = new List<DbParameter>();
  36. string SqlText = @"
  37. select * from (
  38. SELECT *,
  39. - ,
  40. CASE WHEN -> 0 THEN '' WHEN > 0 THEN '' ELSE '' END
  41. FROM (
  42. SELECT dd.orderno ,dd.itemcode ,dd.planqty ,inv.invname ,
  43. isnull((
  44. SELECT SUM (lotqty)
  45. FROM icsitemlot lot
  46. WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  47. AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint),0) ,
  48. isnull((
  49. SELECT SUM (lotqty)
  50. FROM icsitemlot lot
  51. WHERE lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  52. AND isnull(IQCStatus,'') !='' AND cc.workpoint=lot.workpoint
  53. AND NOT EXISTS (
  54. SELECT 1 FROM ICSWareHouseLotInfo info
  55. WHERE info.lotno=lot.lotno AND info.workpoint=lot.workpoint)),0)
  56. FROM ICSINVReceipt cc
  57. LEFT JOIN ICSINVReceiptDetail dd ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  58. LEFT JOIN ICSINVENTORY inv ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  59. WHERE cc.mtime >=DATEADD(week, -1,getdate())
  60. and cc.workpoint='" + workpoint + @"'
  61. ) ff ) gg
  62. ";
  63. DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "WMSconnstr", parameter.ToArray(), ref jqgridparam);
  64. return dt;
  65. }
  66. //来料不合格明细
  67. public DataTable GetList2(string queryJson, ref Pagination jqgridparam)
  68. {
  69. var queryParam = queryJson.ToJObject();
  70. OperatorModel oo = NFine.Code.OperatorProvider.Provider.GetCurrent();
  71. List<DbParameter> parameter = new List<DbParameter>();
  72. string SqlText = @"
  73. select * from (
  74. SELECT cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,
  75. sum(lot.lotqty) ,kk.CKITEMDESC
  76. FROM ICSINVReceipt cc
  77. LEFT JOIN ICSINVReceiptDetail dd ON cc.ReceiptNO=dd.ReceiptNO AND dd.workpoint=cc.workpoint
  78. LEFT JOIN ICSINVENTORY inv ON inv.invcode=dd.itemcode AND dd.workpoint=inv.workpoint
  79. left join icsitemlot lot on lot.TransNO=dd.ReceiptNO AND lot.TransLine=dd.ReceiptLine
  80. AND cc.workpoint=lot.workpoint
  81. left join (select * from (select ROW_NUMBER()over(partition by LOTNO order by mtime desc,id ) rowId,lotno ,errdata ,CKITEMDESC
  82. from ICSIQCErrList ck where workpoint='" + workpoint + @"' ) as AuctionRecords
  83. where rowId=1) kk on kk.lotno=lot.lotno
  84. WHERE 1=1
  85. and cc.mtime >=DATEADD(MONTH, -1,getdate())
  86. and kk.errdata=''
  87. and cc.workpoint='" + workpoint + @"'
  88. group by cc.receiptNo ,dd.orderno ,dd.itemcode , inv.invname ,kk.CKITEMDESC ) jj
  89. ";
  90. DataTable dt = Repository().FindTablePageBySql_Other(SqlText, "WMSconnstr", parameter.ToArray(), ref jqgridparam);
  91. return dt;
  92. }
  93. public DataTable GetWIPDATA()
  94. {
  95. List<DbParameter> parameter = new List<DbParameter>();
  96. string SqlText = @"
  97. select distinct mo.mocode ,mo.moseq ,mo.itemcode ,inv.invname ,
  98. mo.moplanqty ,sim.MUSERName ,sim.opcode
  99. ,row_number() over (partition by mo.mocode ,mo.moseq , sim.MUSERName ,sim.opcode order by sim.mtime desc,sim.id desc) rn
  100. from icsmo mo
  101. left join ICSITEMLot lot on lot.transno =mo.mocode and lot.TransLine=mo.moseq and lot.workpoint =mo.workpoint
  102. left join ICSLOTSIMULATION sim on mo.WorkPoint=sim.WorkPoint and sim.lotno=lot.lotno
  103. left join ICSINVENTORY inv on inv.invcode=mo.itemcode and inv.workpoint=mo.workpoint
  104. where sim.mtime>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'
  105. and mo.WorkPoint='" + workpoint + @"'
  106. ";
  107. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  108. //测试
  109. for (int i = 0; i < 20; i++)
  110. {
  111. DataRow newRow;
  112. newRow = dt.NewRow();
  113. newRow["生产订单号"] = "MO-0001"+i.ToString();
  114. newRow["行号"] = "22";
  115. dt.Rows.Add(newRow);
  116. }
  117. return dt;
  118. }
  119. //车间人员信息
  120. public DataTable GetWIPUser()
  121. {
  122. List<DbParameter> parameter = new List<DbParameter>();
  123. string SqlText = @"
  124. select distinct mo.mocode ,mo.moseq ,mo.itemcode ,inv.invname ,
  125. mo.moplanqty ,sim.MUSERName ,sim.opcode
  126. ,row_number() over (partition by mo.mocode ,mo.moseq , sim.MUSERName ,sim.opcode order by sim.mtime desc,sim.id desc) rn
  127. from icsmo mo
  128. left join ICSITEMLot lot on lot.transno =mo.mocode and lot.TransLine=mo.moseq and lot.workpoint =mo.workpoint
  129. left join ICSLOTSIMULATION sim on mo.WorkPoint=sim.WorkPoint and sim.lotno=lot.lotno
  130. left join ICSINVENTORY inv on inv.invcode=mo.itemcode and inv.workpoint=mo.workpoint
  131. where sim.mtime>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'
  132. and mo.WorkPoint='" + workpoint + @"'
  133. ";
  134. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  135. //测试
  136. for (int i = 0; i < 20; i++)
  137. {
  138. DataRow newRow;
  139. newRow = dt.NewRow();
  140. newRow["生产订单号"] = "MO-0001" + i.ToString();
  141. newRow["行号"] = "22";
  142. dt.Rows.Add(newRow);
  143. }
  144. return dt;
  145. }
  146. //收料信息
  147. public DataTable GetWIPRCV()
  148. {
  149. List<DbParameter> parameter = new List<DbParameter>();
  150. string SqlText = @"
  151. select B.CreatedOn ,A.DescFlexField_PrivateDescSeg1 ,A.DocNO ,B.DocLineNo
  152. ,ISNULL(B.QCBillNo,'') AS ,CASE WHEN A.Status='0' THEN '' WHEN A.Status='2' THEN '' WHEN A.Status='3' THEN '' ELSE '' END AS
  153. ,A.Supplier_ShortName ,A.DescFlexField_PubDescSeg13 ,B.ItemInfo_ItemCode
  154. ,B.ItemInfo_ItemName ,C.INVSTD ,C.INVUOM ,B.ArriveQtyTU ,B.QualifiedQtyTU
  155. ,case when B.Status='5' then B.QualifiedQtyTU When B.Status='5' AND ISNULL(B.QCBillNo,'')='' then B.QualifiedQtyTU ELSE 0 end as U9已上架数量
  156. ,ISNULL(F.QTY,0) AS WMS已上架数量,B.ArriveQtyTU-ISNULL(F.QTY,0) AS WMS未上架数量,E.Name
  157. from
  158. {0}.DBO.PM_Receivement A
  159. LEFT JOIN (SELECT a.ID,b.CreatedOn,b.DocLineNo,b.QCBillNo,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,b.ItemInfo_ItemID,b.WhMan
  160. ,sum(b.ArriveQtyTU) ArriveQtyTU,SUM(b.QualifiedQtyTU) QualifiedQtyTU,b.Status
  161. from {0}.DBO.PM_Receivement a LEFT JOIN {0}.DBO.PM_RcvLine b on b.Receivement=a.ID
  162. where (SplitFlag=0 OR SplitFlag=2)
  163. GROUP BY a.ID,b.CreatedOn,b.DocLineNo,b.QCBillNo,b.ItemInfo_ItemCode,b.ItemInfo_ItemName,b.ItemInfo_ItemID,b.WhMan,b.Status ) B
  164. ON B.ID=A.ID
  165. LEFT JOIN ICSINVENTORY C on C.ID=B.ItemInfo_ItemID
  166. LEFT JOIN {0}.DBO.CBO_Operators_trl E on E.ID=B.WhMan
  167. LEFT JOIN (SELECT ASN.STNO,ASN.ITEMCODE,SUM(ISNULL(WHLOT.LotQty,0)) AS QTY FROM ICSASNDETAIL ASN
  168. LEFT JOIN ICSITEMLot LOT ON LOT.LotNO=ASN.LOTNO AND LOT.WorkPoint=ASN.WorkPoint
  169. LEFT JOIN ICSWareHouseLotInfo WHLOT ON WHLOT.LotNO=LOT.LotNO AND WHLOT.WorkPoint=LOT.WorkPoint
  170. GROUP BY ASN.STNO,ASN.ITEMCODE) F ON F.STNO=A.DescFlexField_PrivateDescSeg1 AND F.ITEMCODE=B.ItemInfo_ItemCode
  171. where 1=1 and B.CreatedOn>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'
  172. order by B.CreatedOn";
  173. SqlText = string.Format(SqlText, ERPName, workpoint);
  174. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  175. return dt;
  176. }
  177. //收料图表
  178. public DataTable GetWIPRCVChart()
  179. {
  180. List<DbParameter> parameter = new List<DbParameter>();
  181. string SqlText = @"
  182. SELECT top 1 (SELECT COUNT(ID) FROM {0}.DBO.PM_RcvLine
  183. where (SplitFlag=0 OR SplitFlag=2)
  184. and CreatedOn>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00' and status<>'5') as U9dk,
  185. (SELECT COUNT(ID) FROM {0}.DBO.PM_RcvLine
  186. where (SplitFlag=0 OR SplitFlag=2)
  187. and CreatedOn>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00' and status='5') as U9gb
  188. from {0}.DBO.PM_RcvLine";
  189. SqlText = string.Format(SqlText, ERPName, workpoint);
  190. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  191. return dt;
  192. }
  193. //发料信息
  194. public DataTable GetMaterialPick()
  195. {
  196. List<DbParameter> parameter = new List<DbParameter>();
  197. string SqlText = $@" SELECT
  198. a.ApplyCode,
  199. A.Sequence,
  200. a.SAPSequence,
  201. a.InvCode,
  202. c.LotNo,
  203. c.Quantity,
  204. e.StartLocation,
  205. e.EndLocation
  206. -- e.TaskCode
  207. FROM
  208. ICSMOApply a
  209. -- INNER JOIN ICSContainerReceiptsNumber b ON a.ApplyCode= b.TransCode
  210. INNER JOIN ICSWareHouseLotInfoLog c ON a.ApplyCode= c.TransCode AND
  211. c.BusinessCode= '15'
  212. AND a.Sequence= c.TransSequence
  213. INNER JOIN ( SELECT DISTINCT e.StartLocation,e.EndLocation FROM
  214. ICSForkLiftTaskLog e WHERE e.EndLocation is not null AND e.EndLocation!='' ) e ON c.FromLocationCode= e.StartLocation
  215. WHERE
  216. a.WorkPoint='1701'";
  217. //if (!string.IsNullOrWhiteSpace(StratTime))
  218. //{
  219. // SqlText += " and a.CreatedOn>'" + StratTime + "'";
  220. //}
  221. //if (!string.IsNullOrWhiteSpace(EndTime))
  222. //{
  223. // SqlText += " and a.CreatedOn<'" + EndTime + "'";
  224. //}
  225. if (!string.IsNullOrWhiteSpace(advDays))
  226. {
  227. SqlText += @" and a.MTIME>CAST(CAST(DATEADD(day, -" + advDays + @", GETDATE()) as date) as varchar(10)) + ' 00:00:00'
  228. and a.MTIME<=CAST(CAST(GETDATE() as date) as varchar(10)) + ' 23:59:59'";
  229. }
  230. if (string.IsNullOrWhiteSpace(StratTime) && string.IsNullOrWhiteSpace(EndTime) && string.IsNullOrWhiteSpace(advDays))
  231. {
  232. SqlText += @" and a.MTIME>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'
  233. and a.MTIME<=CAST(CAST(GETDATE() as date) as varchar(10)) + ' 23:59:59'";
  234. }
  235. SqlText += @"order by a.MTIME ";
  236. //SqlText = string.Format(SqlText, ERPName, workpoint);
  237. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  238. return dt;
  239. }
  240. //发料图表
  241. public DataTable GetMaterialPickChart()
  242. {
  243. List<DbParameter> parameter = new List<DbParameter>();
  244. string SqlText = @" SELECT top 1
  245. (SELECT COUNT(*) from {0}.DBO.MO_MO a
  246. where a.CreatedOn>CAST(CAST(DATEADD(day, -{2}, GETDATE()) as date) as varchar(10)) + ' 00:00:00')-
  247. (SELECT COUNT(*) from {0}.DBO.MO_MO a
  248. LEFT JOIN (SELECT DISTINCT COUNT(VouchRow) ,MOCode from ICSMaterialPick GROUP BY MOCode) b on a.DocNo=b.MOCode
  249. LEFT JOIN (SELECT DISTINCT COUNT(VouchRow) ,MOCode from ICSMaterialPick where Quantity<=HasQuantity GROUP BY MOCode) c on a.DocNo=c.MOCode
  250. where a.CreatedOn>CAST(CAST(DATEADD(day, -{2}, GETDATE()) as date) as varchar(10)) + ' 00:00:00' and b.=c.)
  251. as ,
  252. (SELECT COUNT(*) from {0}.DBO.MO_MO a
  253. LEFT JOIN (SELECT DISTINCT COUNT(VouchRow) ,MOCode from ICSMaterialPick GROUP BY MOCode) b on a.DocNo=b.MOCode
  254. LEFT JOIN (SELECT DISTINCT COUNT(VouchRow) ,MOCode from ICSMaterialPick where Quantity<=HasQuantity GROUP BY MOCode) c on a.DocNo=c.MOCode
  255. where a.CreatedOn>CAST(CAST(DATEADD(day, -{2}, GETDATE()) as date) as varchar(10)) + ' 00:00:00' and b.=c.) as
  256. from {0}.DBO.MO_MO";
  257. SqlText = string.Format(SqlText, ERPName, workpoint, advDays);
  258. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  259. return dt;
  260. }
  261. //发货信息
  262. public DataTable GetSo()
  263. {
  264. List<DbParameter> parameter = new List<DbParameter>();
  265. string SqlText = @"
  266. SELECT DISTINCT a1.CreatedOn ,A1.BusinessDate ,A1.DocNo ,A2.DocLineNo ,A5.Code ,A6.NameCombineName ,
  267. A5.SPECS ,A10.Name ,ISNULL(A2.ShipQtyInvAmount, 0) ,ISNULL(so.HasQuantity, 0) ,ISNULL(A2.ShipQtyInvAmount,0)-isnull(so.HasQuantity, 0) WMS未发数量
  268. from {0}.DBO.SM_Ship A1
  269. LEFT JOIN {0}.dbo.SM_ShipLine A2 ON A2.Ship=A1.ID
  270. LEFT JOIN {0}.dbo.SM_ShipLine_Trl A3 ON A2.ID=A3.ID AND A3.SysMLFlag='zh-CN'
  271. LEFT JOIN {0}.dbo.CBO_ItemMaster A5 ON A2.ItemInfo_ItemID=A5.ID
  272. LEFT JOIN {0}.dbo.CBO_ItemMaster_Trl A6 ON A6.ID = A5.ID AND A6.SysMLFlag='zh-CN'
  273. LEFT JOIN {0}.dbo.CBO_Wh A7 ON A2.WH=A7.ID
  274. LEFT JOIN {0}.dbo.CBO_Wh_Trl A8 ON A8.ID = A7.ID AND A8.SysMLFlag='zh-CN'
  275. LEFT JOIN {0}.dbo.Base_UOM A9 ON A2.PriceUOM=A9.ID
  276. LEFT JOIN {0}.dbo.Base_UOM_Trl A10 ON A10.ID = A9.ID AND A10.SysMLFlag='zh-CN'
  277. LEFT JOIN ICSSODispatch so on A1.DocNo=so.DispatchCode AND A2.DocLineNo=so.DispatchRow
  278. where 1=1 AND ISNULL(A2.WH,'')!=''";
  279. if (!string.IsNullOrWhiteSpace(StratTime))
  280. {
  281. SqlText += " and a1.CreatedOn>'" + StratTime + "'";
  282. }
  283. if (!string.IsNullOrWhiteSpace(EndTime))
  284. {
  285. SqlText += " and a1.CreatedOn<'" + EndTime + "'";
  286. }
  287. if (string.IsNullOrWhiteSpace(StratTime) && string.IsNullOrWhiteSpace(EndTime) && !string.IsNullOrWhiteSpace(advDays))
  288. {
  289. SqlText += " and a1.CreatedOn>CAST(CAST(DATEADD(day, -" + advDays + ", GETDATE()) as date) as varchar(10)) + ' 00:00:00'";
  290. }
  291. if (string.IsNullOrWhiteSpace(StratTime) && string.IsNullOrWhiteSpace(EndTime) && string.IsNullOrWhiteSpace(advDays))
  292. {
  293. SqlText += " and a1.CreatedOn>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'";
  294. }
  295. SqlText += @"order by a1.CreatedOn ";
  296. SqlText = string.Format(SqlText, ERPName, workpoint);
  297. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  298. return dt;
  299. }
  300. //工单欠料信息
  301. public DataTable GetOwe()
  302. {
  303. List<DbParameter> parameter = new List<DbParameter>();
  304. string SqlText = @" SELECT a.DocNo U9工单,a.startDate 开工日期,BItem.Code 母件料号,BItem.Name 母件名称,BItem.SPECS 母件规格,A.ProductQty 工单数量,
  305. UOM.Name ,cBItem.Code ,cBItem.Name ,cBItem.SPECS ,--b.id,c.id,d.MO,
  306. b.ActualReqQty,c.IssuedQty,d.qty,
  307. ISNULL(b.ActualReqQty, 0)-ISNULL(c.IssuedQty, 0)+ISNULL(d.qty, 0) as
  308. from {0}.DBO.MO_MO a
  309. LEFT JOIN {0}.DBO.CBO_ItemMaster BItem on BItem.ID=a.ItemMaster
  310. LEFT JOIN {0}.DBO.Base_UOM_Trl UOM ON UOM.ID = BItem.InventoryUOM
  311. LEFT JOIN {0}.DBO.MO_MoPickList b on a.ID=B.MO
  312. LEFT JOIN {0}.DBO.CBO_ItemMaster cBItem on b.ItemMaster=cBItem.ID
  313. LEFT JOIN {0}.DBO.MO_IssueDocLine c on a.ID=c.MO and b.ItemMaster=c.Item
  314. LEFT JOIN (SELECT b.MO,b.IssuedQty as qty,b.Item from {0}.DBO.mo_IssueDoc a
  315. INNER JOIN {0}.DBO.MO_IssueDocLine b on a.ID=b.IssueDoc
  316. INNER JOIN {0}.DBO.MO_IssueDocLine c on b.SourceIssueDocLine=c.ID
  317. where a.IssueType='1' ) d on a.ID=d.MO and b.ItemMaster=d.Item
  318. where a.DocState<>3 ";
  319. //if (!string.IsNullOrWhiteSpace(StratTime))
  320. //{
  321. // SqlText += " and a.CreatedOn>'" + StratTime + "'";
  322. //}
  323. //if (!string.IsNullOrWhiteSpace(EndTime))
  324. //{
  325. // SqlText += " and a.CreatedOn<'" + EndTime + "'";
  326. //}
  327. if (!string.IsNullOrWhiteSpace(advDays))
  328. {
  329. SqlText += @" and a.startDate>CAST(CAST(DATEADD(day, -" + advDays + @", GETDATE()) as date) as varchar(10)) + ' 00:00:00'
  330. and a.startDate<=CAST(CAST(GETDATE() as date) as varchar(10)) + ' 23:59:59'";
  331. }
  332. if (string.IsNullOrWhiteSpace(StratTime) && string.IsNullOrWhiteSpace(EndTime) && string.IsNullOrWhiteSpace(advDays))
  333. {
  334. SqlText += @" and a.startDate>CAST(CAST(GETDATE() as date) as varchar(10)) + ' 00:00:00'
  335. and a.startDate<=CAST(CAST(GETDATE() as date) as varchar(10)) + ' 23:59:59'";
  336. }
  337. SqlText += @"order by a.startDate ";
  338. SqlText = string.Format(SqlText, ERPName, workpoint);
  339. DataTable dt = Repository().GetDataTableBySql_Other(SqlText, "WMSconnstr", null);
  340. return dt;
  341. }
  342. public static void WriteLogFile(string input, string txtName)
  343. {
  344. try
  345. {
  346. string logAdress = "C:\\看板日志" + "\\";
  347. if (!System.IO.Directory.Exists(logAdress))
  348. {
  349. System.IO.Directory.CreateDirectory(logAdress);//不存在就创建目录
  350. }
  351. string adress = logAdress + txtName;
  352. if (!System.IO.Directory.Exists(adress))
  353. {
  354. System.IO.Directory.CreateDirectory(adress);//不存在就创建目录
  355. }
  356. // string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString();
  357. /**/
  358. ///指定日志文件的目录
  359. string fname = adress + "\\" + "log" + DateTime.Now.ToString("yy-MM-dd") + ".txt";
  360. /**/
  361. ///定义文件信息对象
  362. FileInfo finfo = new FileInfo(fname);
  363. if (!finfo.Exists)
  364. {
  365. FileStream fs;
  366. fs = File.Create(fname);
  367. fs.Close();
  368. finfo = new FileInfo(fname);
  369. }
  370. /**/
  371. ///判断文件是否存在以及是否大于2K
  372. if (finfo.Length > 1024 * 1024 * 10)
  373. {
  374. /**/
  375. ///文件超过10MB则重命名
  376. File.Move(logAdress + "\\Log\\" + txtName + ".txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\Log\\" + txtName + ".txt");
  377. /**/
  378. ///删除该文件
  379. //finfo.Delete();
  380. }
  381. //finfo.AppendText();
  382. /**/
  383. ///创建只写文件流
  384. using (FileStream fs = finfo.OpenWrite())
  385. {
  386. /**/
  387. ///根据上面创建的文件流创建写数据流
  388. StreamWriter w = new StreamWriter(fs);
  389. /**/
  390. ///设置写数据流的起始位置为文件流的末尾
  391. ///设置写数据流的起始位置为文件流的末尾
  392. w.BaseStream.Seek(0, SeekOrigin.End);
  393. w.WriteLine("*****************Start*****************");
  394. w.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  395. /**/
  396. ///写入当前系统时间并换行
  397. /**/
  398. ///写入日志内容并换行
  399. w.WriteLine(input);
  400. /**/
  401. ///写入------------------------------------“并换行
  402. w.WriteLine("------------------END------------------------");
  403. /**/
  404. ///清空缓冲区内容,并把缓冲区内容写入基础流
  405. w.Flush();
  406. /**/
  407. ///关闭写数据流
  408. w.Close();
  409. }
  410. }
  411. catch (Exception ex)
  412. { }
  413. }
  414. }
  415. }