华恒Mes鼎捷代码
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.

647 lines
26 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using DevExpress.XtraEditors;
  9. using ICSSoft.Frame.User.BLL;
  10. using ICSSoft.Base.Language.Tool;
  11. using ICSSoft.Base.UserControl.MessageControl;
  12. using System.Data.SqlClient;
  13. using ICSSoft.Base.Config.AppConfig;
  14. using ICSSoft.Base.Report.Filter;
  15. using ICSSoft.Base.Config.DBHelper;
  16. using ICSSoft.Base.UserControl.FormControl;
  17. using ICSSoft.Base.ReferForm.AppReferForm;
  18. using ICSSoft.Base.Lable.PrintTool;
  19. using ICSSoft.Frame.Data.DAL;
  20. using ICSSoft.Frame.Data.BLL;
  21. using ICSSoft.Frame.Data.Entity;
  22. using System.Collections;
  23. using System.Net;
  24. using System.IO;
  25. using Newtonsoft.Json;
  26. using System.Configuration;
  27. using DevExpress.XtraGrid.Columns;
  28. using System.Linq;
  29. using ICSSoft.Frame.Common;
  30. namespace ICSSoft.Frame.APP
  31. {
  32. public partial class FormICSAgvSlOrBackHH : DevExpress.XtraEditors.XtraForm
  33. {
  34. string Lotno;
  35. string Opcode;
  36. string Eqpcode;
  37. Timer T = new Timer();
  38. DataTable TableMain = new DataTable();
  39. DataTable TableSon = new DataTable();
  40. #region 构造函数
  41. public FormICSAgvSlOrBackHH()
  42. {
  43. InitializeComponent();
  44. }
  45. public FormICSAgvSlOrBackHH(String Lotno,string Opcode,string Eqpcode)
  46. {
  47. InitializeComponent();
  48. this.Lotno = Lotno;
  49. this.Opcode = Opcode;
  50. this.Eqpcode = Eqpcode;
  51. }
  52. #endregion
  53. public void LoadUIMes(string Lotno,string Opcode ) {
  54. string sql = @"Select LOTNO,MCODE,A.TRANSNO,B.INVNAME,C.OPCODE,C.OPNAME FROM ICSITEMLot a
  55. Left join ICSINVENTORY b on a.MCODE=b.INVCODE
  56. Left join ICSOP C ON C.OPCODE='{0}'
  57. WHERE A.LotNO='{1}'
  58. ";
  59. sql = string.Format(sql,Opcode,Lotno);
  60. DataSet Set = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql);
  61. DataTable datasource = Set.Tables[0];
  62. TxtLotno.Text = Lotno;
  63. TxtOpcode.Text = Opcode;
  64. TxtOpName.Text = datasource.Rows[0]["OPNAME"].ToString();
  65. TxtMocode.Text = datasource.Rows[0]["TRANSNO"].ToString();
  66. TxtItemcode.Text= datasource.Rows[0]["MCODE"].ToString();
  67. TxtItemName.Text = datasource.Rows[0]["INVNAME"].ToString();
  68. }
  69. public void LoadGridMes() {
  70. StringBuilder logmes = new StringBuilder("");
  71. try
  72. {
  73. TableSon = InitAgvLog().Copy();
  74. var AreaMes = ICSAGVBLL.GetAreaCode("00088", "5", AppConfig.AppConnectString, AppConfig.WorkPointCode);
  75. string sql = @" select vv.define1 from Sys_EnumValues vv
  76. inner join Sys_Enumkey kk on kk.WorkPointCode=vv.WorkPointCode and kk.EnumKey=vv.EnumKey
  77. where kk.enumname='AGV管控'
  78. and vv.EnumText='AGVInventory'
  79. and kk.WorkPointCode ='" + AppConfig.WorkPointCode + "'";
  80. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  81. if (dt == null || dt.Rows.Count == 0)
  82. {
  83. throw new Exception("请联系管理员,在自定义档案中维护信息:AGV管控-AGVInventory");
  84. }
  85. logmes.AppendLine("调用接口:AGVInventory");
  86. string GetInventoryListUrl = dt.Rows[0]["define1"].ToString();
  87. var Detail = new { referCode = Lotno/*, zoneCode = AreaMes.Split('@')[0].Split(':')[0]*/};
  88. var GetInventoryListModel = new { inventoryDetail = Detail, pageSize = "100", pageNum = "1", area = AppConfig.GetDataBaseNameByConnectString(AppConfig.AppConnectString) == "ICSMES_GTSys" ? "GT" : "JJ" };
  89. var StringContent = JsonConvert.SerializeObject(GetInventoryListModel);
  90. logmes.AppendLine("params:" + StringContent + "");
  91. var Rtnstr = WebInvokePost(GetInventoryListUrl, StringContent);
  92. logmes.AppendLine("ReturnMes:" + Rtnstr + "");
  93. ReturnMesInv ReturnMes = JsonConvert.DeserializeObject<ReturnMesInv>(Rtnstr);
  94. if (ReturnMes.code != 200)
  95. throw new Exception(ReturnMes.msg);
  96. else
  97. {
  98. foreach (InventoryDetail inv in ReturnMes.data)
  99. {
  100. DataRow row = TableMain.NewRow();
  101. row["选择"] = "";
  102. row["子件编码"] = inv.materialCode;
  103. row["子件名称"] = inv.materialName;
  104. row["计划数量"] = /*inv.taskQty*/inv.qty;
  105. row["起始点位"] = AreaMes.Split('@')[0];
  106. row["ID"] = inv.id;
  107. row["已领数量"] = TableSon.AsEnumerable().Where(a => a["子件编码"].ToString() == inv.materialCode && a["DetailId"].ToString() == inv.id).Sum(a => Convert.ToDecimal(a["本次数量"]));
  108. TableMain.Rows.Add(row);
  109. }
  110. }
  111. gridControl1.DataSource = TableMain;
  112. gridControl2.DataSource = TableSon;
  113. }
  114. catch (Exception ex)
  115. {
  116. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  117. }
  118. finally {
  119. WriteLogFile(logmes.ToString(), "AGV接口");
  120. }
  121. }
  122. #region 关闭 退出
  123. private void btnClose_Click(object sender, EventArgs e)
  124. {
  125. this.Close();
  126. }
  127. #endregion
  128. #region 移动窗体
  129. private const int WM_NCHITTEST = 0x84;
  130. private const int HTCLIENT = 0x1;
  131. private const int HTCAPTION = 0x2;
  132. //首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
  133. //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
  134. //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
  135. //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
  136. //重写窗体,使窗体可以不通过自带标题栏实现移动
  137. protected override void WndProc(ref Message m)
  138. {
  139. //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
  140. //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
  141. //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
  142. //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
  143. switch (m.Msg)
  144. {
  145. case WM_NCHITTEST:
  146. base.WndProc(ref m);
  147. if ((int)m.Result == HTCLIENT)
  148. m.Result = (IntPtr)HTCAPTION;
  149. return;
  150. }
  151. //拦截双击标题栏、移动窗体的系统消息
  152. if (m.Msg != 0xA3)
  153. {
  154. base.WndProc(ref m);
  155. }
  156. }
  157. #endregion
  158. #region 取消
  159. private void can_Click(object sender, EventArgs e)
  160. {
  161. this.Close();
  162. }
  163. #endregion
  164. #region 页面加载
  165. private void FormICSItenLotAdd_Load(object sender, EventArgs e)
  166. {
  167. foreach (Control contorl in panel1.Controls)
  168. {
  169. if (contorl is TextEdit)
  170. {
  171. (contorl as TextEdit).Properties.ReadOnly = true;
  172. }
  173. }
  174. foreach (GridColumn column in gridViewMain.Columns)
  175. {
  176. TableMain.Columns.Add(new DataColumn(column.FieldName));
  177. }
  178. LoadUIMes(Lotno,Opcode);
  179. InitLocation();
  180. LoadGridMes();
  181. T.Interval = 10000;
  182. T.Tick += delegate(object sender1, EventArgs e1) {
  183. try
  184. {
  185. DataTable LogTable = InitAgvLog();
  186. foreach (DataRow Row in LogTable.Rows) {
  187. var SonRows = TableSon.AsEnumerable().Where(a => a["ID"].ToString()== Row["ID"].ToString()).FirstOrDefault();
  188. if (SonRows==null)
  189. {
  190. DataRow NewRow = TableSon.NewRow();
  191. NewRow.ItemArray = Row.ItemArray;
  192. TableSon.Rows.Add(NewRow);
  193. continue;
  194. }
  195. else {
  196. SonRows["是否到料"] = Row["是否到料"];
  197. SonRows["是否返回"] = Row["是否返回"];
  198. }
  199. }
  200. //foreach (DataRow row in TableMain.Rows)
  201. //{
  202. // row["已领数量"] = TableSon.AsEnumerable().Where(a => a["子件编码"].ToString() == row["子件编码"].ToString() && a["DetailId"].ToString() == row["ID"].ToString()).Sum(a => Convert.ToDecimal(a["本次数量"]));
  203. //}
  204. }
  205. catch (Exception ex)
  206. {
  207. throw ex;
  208. }
  209. };
  210. T.Start();
  211. }
  212. #endregion
  213. private DataTable InitAgvLog()
  214. {
  215. try
  216. {
  217. string sql = @"select A.ID,A.MaterialCode as 子件编码,'' AS 选择,A.IsArrive as 到料状态,A.Mtime as 叫料时间,B.MTIME AS 返回时间,B.ISBACK AS 返回状态,ISNULL(B.QTY,0) AS 本次数量,A.EATTRIBUTE1 AS DetailId,A.LOCATIONCODE as 起始点位,a.QTY,A.Groupid,a.AREA as 区域,a.endlocation as 点位,a.groupid,a.isarrive as 是否到料,a.isback as 是否返回 from ICSAGVTASKLOG a
  218. Left Join ICSAGVTASKLOG b on a.id<>b.id AND B.TaskType='' and a.groupid=b.groupid
  219. where A.Lotno='{0}' and A.opcode='{1}' and A.TaskType=''";
  220. sql = string.Format(sql, Lotno, Opcode);
  221. DataTable Table = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  222. return Table;
  223. }
  224. catch (Exception ex)
  225. {
  226. throw ex;
  227. }
  228. }
  229. public void InitLocation() {
  230. try
  231. {
  232. string sql = @"select a.locationcode as 点位编码,b.LocationName as 点位名称 from IcsEqpWithLocation a left join IcsAGVLocation b on a.locationcode=b.locationcode where eqpcode='{0}'";
  233. sql = string.Format(sql,Eqpcode);
  234. DataTable Table = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  235. LookUpEditLocation.DataSource = Table;
  236. LookUpEditLocation.DisplayMember = "点位编码";
  237. LookUpEditLocation.ValueMember = "点位编码";
  238. LookUpEditLocation.NullText = "";//空时的值
  239. LookUpEditLocation.ImmediatePopup = true;//输入值是否马上弹出窗体
  240. LookUpEditLocation.ValidateOnEnterKey = true;//回车确认
  241. LookUpEditLocation.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard
  242. LookUpEditLocation.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容 //自适应宽度
  243. LookUpEditLocation.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
  244. }
  245. catch (Exception ex)
  246. {
  247. throw ex;
  248. }
  249. }
  250. private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  251. {
  252. if (e.Info.IsRowIndicator && e.RowHandle >= 0)
  253. e.Info.DisplayText = (e.RowHandle + 1).ToString();
  254. }
  255. private void BtnBack_Click(object sender, EventArgs e)
  256. {
  257. try
  258. {
  259. List<ICSAGVTASKLOG> Log_List = new List<ICSAGVTASKLOG>();
  260. List<AGVCreateTaskModel> Task_List = new List<AGVCreateTaskModel>();
  261. for (int i = 0; i < TableSon.Rows.Count; i++)
  262. {
  263. if (TableSon.Rows[i]["选择"].ToString() == "Y")
  264. {
  265. Check("", "料框返回", TableSon.Rows[i]["ID"].ToString());
  266. ICSAGVTASKLOG log = new ICSAGVTASKLOG();
  267. log.ID = AppConfig.GetGuid();
  268. log.Lotno = Lotno;
  269. log.Opcode = Opcode;
  270. log.Itemcode = TxtItemcode.Text;
  271. log.MaterialCode = TableSon.Rows[i]["子件编码"].ToString();
  272. log.LocationCode = TableSon.Rows[i]["点位"].ToString();
  273. log.EndLocation = TableSon.Rows[i]["起始点位"].ToString();
  274. log.Qty =(Decimal?)(TableSon.Rows[i]["本次数量"]);
  275. log.TaskType = "料框返回HH";
  276. log.Mtime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  277. log.MuserName = AppConfig.UserName;
  278. log.IsArrive = false;
  279. log.IsBack = false;
  280. log.GroupID = TableSon.Rows[i]["groupid"].ToString();
  281. Log_List.Add(log);
  282. AGVCreateTaskModel model = new AGVCreateTaskModel();
  283. model.area = log.Area.Split(':')[0];
  284. model.qty =Convert.ToInt32(TableSon.Rows[i]["QTY"].ToString()) -(int)log.Qty;
  285. model.station = log.LocationCode;
  286. model.type = "false";
  287. model.materialCode = log.MaterialCode;
  288. //model.materialName = MainRow["子件名称"].ToString();
  289. model.trackingNumber = Lotno;
  290. Task_List.Add(model);
  291. }
  292. }
  293. if (Log_List.Count <= 0)
  294. throw new Exception("请选择要料框返回的料框!");
  295. string mes = ICSAGVBLL.CreateAGVTaskJJorBack(Task_List, Log_List, AppConfig.AppConnectString, AppConfig.WorkPointCode);
  296. if (string.IsNullOrEmpty(mes))
  297. {
  298. ICSBaseSimpleCode.AppshowMessageBox("料框返回成功!");
  299. LoadGridMes();
  300. }
  301. else
  302. ICSBaseSimpleCode.AppshowMessageBox(mes);
  303. }
  304. catch (Exception ex)
  305. {
  306. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  307. }
  308. }
  309. private void BtnCall_Click(object sender, EventArgs e)
  310. {
  311. try
  312. {
  313. List<ICSAGVTASKLOG> Log_List = new List<ICSAGVTASKLOG>();
  314. List<PointToPointModel> Task_List = new List<PointToPointModel>();
  315. for (int i = 0; i <gridViewMain.RowCount; i++) {
  316. if (gridViewMain.GetRowCellValue(i, ).ToString()== "Y") {
  317. string AgvId = gridViewMain.GetRowCellValue(i,AGVID).ToString();//子件库存查询的接口ID 可能存在多笔相同子件不同料框的情况,需要记录id区分是哪个料框叫的料
  318. Check(AgvId,"叫料");
  319. ICSAGVTASKLOG log = new ICSAGVTASKLOG();
  320. log.ID = AppConfig.GetGuid();
  321. log.Lotno = Lotno;
  322. log.Opcode = Opcode;
  323. log.Itemcode = TxtItemcode.Text;
  324. log.MaterialCode = gridViewMain.GetRowCellValue(i, ).ToString();
  325. log.LocationCode= gridViewMain.GetRowCellValue(i, ).ToString();
  326. log.EndLocation = gridViewMain.GetRowCellValue(i, ).ToString();
  327. log.Qty = Convert.ToDecimal(gridViewMain.GetRowCellValue(i, ).ToString());
  328. log.TaskType = "叫料HH";
  329. log.Mtime =Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  330. log.MuserName = AppConfig.UserName;
  331. log.IsArrive = false;
  332. log.IsBack = false;
  333. log.GroupID= AppConfig.GetGuid(); //叫料,料框返回Goupid是相同的
  334. log.Eattribute1= AgvId;
  335. Log_List.Add(log);
  336. PointToPointModel model = new PointToPointModel();
  337. model.warehouseCode = "KS0001";
  338. model.startingPoint = log.LocationCode;
  339. model.endPoint = log.EndLocation;
  340. Task_List.Add(model);
  341. }
  342. }
  343. if (Log_List.Count <= 0)
  344. throw new Exception("请选择要叫料的物料!");
  345. string mes=ICSAGVBLL.AgvPointToPoint(Task_List, Log_List,AppConfig.AppConnectString,AppConfig.WorkPointCode);
  346. if (string.IsNullOrEmpty(mes))
  347. {
  348. ICSBaseSimpleCode.AppshowMessageBox("叫料成功!");
  349. TableMain.Clear();
  350. TableSon.Clear();
  351. LoadGridMes();
  352. }
  353. else
  354. ICSBaseSimpleCode.AppshowMessageBox(mes);
  355. }
  356. catch (Exception ex)
  357. {
  358. ICSBaseSimpleCode.AppshowMessageBox(ex.Message);
  359. }
  360. }
  361. /// <summary>
  362. ///
  363. /// </summary>
  364. /// <param name="AgvID">主表信息标识</param>
  365. /// <param name="Type">叫料or料框返回</param>
  366. /// <param name="LogID">叫料日志id</param>
  367. private void Check(String AgvID,string Type,params string[] LogID) {
  368. try
  369. {
  370. DataTable LogTable = InitAgvLog();
  371. if (Type == "叫料")
  372. {
  373. DataRow MainRow = TableMain.AsEnumerable().Where(A => A["ID"].ToString() == AgvID).FirstOrDefault();
  374. List<DataRow> CheckRow_List = LogTable.AsEnumerable().Where(a => a["DetailId"].ToString() == AgvID).ToList();
  375. //decimal HasLLQty = CheckRow_List.Sum(a => Convert.ToDecimal(a["本次数量"]));
  376. string LocationCode = MainRow["到料点位"].ToString();
  377. if (CheckRow_List.Where(a => string.IsNullOrEmpty(a["返回时间"].ToString()) == true).Count() > 0)
  378. throw new Exception("ID:" + AgvID + ",已叫料且未料框返回,无法再次叫料!");
  379. if (Convert.ToDecimal(MainRow["计划数量"])<=0)
  380. throw new Exception("ID:" + AgvID + ",库存数量为0,无法再次叫料!");
  381. if(string.IsNullOrEmpty(LocationCode))
  382. throw new Exception("ID:" + AgvID + ",需输入到料点位!");
  383. }
  384. else if (Type == "料框返回") {
  385. var BackRow=LogTable.AsEnumerable().Where(a => a["ID"].ToString() == LogID[0]).FirstOrDefault();
  386. if (!String.IsNullOrEmpty(BackRow["返回时间"].ToString()))
  387. throw new Exception("行标识:" + LogID[0] + ",已执行料框返回完毕,请勿重复操作!");
  388. if(string.IsNullOrEmpty(TableSon.AsEnumerable().Where(A => A["ID"].ToString() == LogID[0]).Select(A => A["OnQty"]).ToString()))
  389. throw new Exception("行标识:" + LogID[0] + ",需要输入本次数量!");
  390. }
  391. }
  392. catch (Exception ex)
  393. {
  394. throw ex;
  395. }
  396. }
  397. public static string WebInvokePost(string url, string JsonData)
  398. {
  399. //构造一个Web请求的对象
  400. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  401. request.Method = "POST";
  402. request.Accept = "text/html, application/xhtml+xml, */*";
  403. request.ContentType = "application/json;charset=utf-8";
  404. var stream=request.GetRequestStream();
  405. byte[] Data = System.Text.Encoding.UTF8.GetBytes(JsonData);
  406. stream.Write(Data, 0, Data.Length);
  407. //获取web请求的响应的内容
  408. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  409. using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
  410. {
  411. return reader.ReadToEnd();
  412. }
  413. }
  414. private void gridViewMain_DoubleClick(object sender, EventArgs e)
  415. {
  416. if (gridViewMain.FocusedRowHandle < 0)
  417. {
  418. return;
  419. }
  420. if (gridViewMain.FocusedColumn ==)
  421. {
  422. if (gridViewMain.GetRowCellValue(gridViewMain.FocusedRowHandle, ).ToString() == "")
  423. {
  424. gridViewMain.SetRowCellValue(gridViewMain.FocusedRowHandle, , "Y");
  425. }
  426. else
  427. {
  428. gridViewMain.SetRowCellValue(gridViewMain.FocusedRowHandle, , "");
  429. }
  430. }
  431. }
  432. private void gridViewSon_DoubleClick(object sender, EventArgs e)
  433. {
  434. if (gridViewSon.FocusedRowHandle < 0)
  435. {
  436. return;
  437. }
  438. if (gridViewSon.FocusedColumn == ColSelect)
  439. {
  440. if (gridViewSon.GetRowCellValue(gridViewSon.FocusedRowHandle, ColSelect).ToString() == "")
  441. {
  442. gridViewSon.SetRowCellValue(gridViewSon.FocusedRowHandle, ColSelect, "Y");
  443. }
  444. else
  445. {
  446. gridViewSon.SetRowCellValue(gridViewSon.FocusedRowHandle, ColSelect, "");
  447. }
  448. }
  449. }
  450. private void TxtOnQty_Click(object sender, EventArgs e)
  451. {
  452. if (!string.IsNullOrEmpty(gridViewSon.GetFocusedRowCellValue().ToString()) && gridViewSon.FocusedColumn == OnQty)
  453. {
  454. TxtOnQty.ReadOnly = true;
  455. OnQty.OptionsColumn.ReadOnly = true;
  456. }
  457. else
  458. {
  459. TxtOnQty.ReadOnly = false;
  460. OnQty.OptionsColumn.ReadOnly = false;
  461. }
  462. }
  463. #region 写入日志
  464. public static void WriteLogFile(string input, string txtName)
  465. {
  466. try
  467. {
  468. string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString() + "\\Log\\";
  469. if (!System.IO.Directory.Exists(logAdress))
  470. {
  471. System.IO.Directory.CreateDirectory(logAdress);//不存在就创建目录
  472. }
  473. string adress = logAdress + txtName;
  474. if (!System.IO.Directory.Exists(adress))
  475. {
  476. System.IO.Directory.CreateDirectory(adress);//不存在就创建目录
  477. }
  478. // string logAdress = ConfigurationManager.AppSettings["logAdress"].ToString();
  479. /**/
  480. ///指定日志文件的目录
  481. string fname = adress + "\\" + "log" + DateTime.Now.ToString("yy-MM-dd") + ".txt";
  482. /**/
  483. ///定义文件信息对象
  484. FileInfo finfo = new FileInfo(fname);
  485. if (!finfo.Exists)
  486. {
  487. FileStream fs;
  488. fs = File.Create(fname);
  489. fs.Close();
  490. finfo = new FileInfo(fname);
  491. }
  492. /**/
  493. ///判断文件是否存在以及是否大于2K
  494. if (finfo.Length > 1024 * 1024 * 10)
  495. {
  496. /**/
  497. ///文件超过10MB则重命名
  498. File.Move(logAdress + "\\Log\\" + txtName + ".txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\Log\\" + txtName + ".txt");
  499. /**/
  500. ///删除该文件
  501. //finfo.Delete();
  502. }
  503. //finfo.AppendText();
  504. /**/
  505. ///创建只写文件流
  506. using (FileStream fs = finfo.OpenWrite())
  507. {
  508. /**/
  509. ///根据上面创建的文件流创建写数据流
  510. StreamWriter w = new StreamWriter(fs);
  511. /**/
  512. ///设置写数据流的起始位置为文件流的末尾
  513. w.BaseStream.Seek(0, SeekOrigin.End);
  514. w.WriteLine("*****************Start*****************");
  515. w.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  516. /**/
  517. ///写入当前系统时间并换行
  518. /**/
  519. ///写入日志内容并换行
  520. w.WriteLine(input);
  521. /**/
  522. ///写入------------------------------------“并换行
  523. w.WriteLine("------------------END------------------------");
  524. /**/
  525. ///清空缓冲区内容,并把缓冲区内容写入基础流
  526. w.Flush();
  527. /**/
  528. ///关闭写数据流
  529. w.Close();
  530. }
  531. }
  532. catch (Exception ex)
  533. { throw ex; }
  534. }
  535. #endregion
  536. private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
  537. {
  538. }
  539. }
  540. }