public void Print() { string tmp = string.Empty; string[] tmpArray; string port = this.txtHotPort.Text.Trim(); for (int i = 0; i < config.Commands.Count; i++) { WindowFormDelegate.SetMainThreadHint(this.lbPrintHint, string.Format("正执行第{0}条命令", i)); //Thread.Sleep(500); tmp = config.Commands[i]; if (tmp.IndexOf("|") != -1) { tmpArray = tmp.Trim().Split('|'); if (tmpArray.Length > 0) { tmp = string.Empty; for (int j = 0; j < tmpArray.Length; j++) { tmp += (char)Convert.ToInt32(tmpArray[j]); } } } if (port.StartsWith("lpt")) { helper.Write(tmp); } else { helper2.Write(tmp); } } }
private void setHint(string msg) { WindowFormDelegate.SetMainThreadHint(this.lbHint, msg); /* * if (lbHint.InvokeRequired) * { * SetMainThreadHintDelegate msgCallback = new SetMainThreadHintDelegate(setHint); * lbHint.Invoke(msgCallback, new object[] { msg }); * } * else * { * lbHint.Text = msg; * } */ }
private void PrintTask2() { while (this.counter < this.stopCounter) { StringBuilder msg = new StringBuilder(); int i = HotPrinterImporter.PrintLine(this.txtPrintContent.Text.Trim(), msg); if (i == 0) { counter++; } WindowFormDelegate.SetMainThreadHint(this.lbHotHint, "正在打印:" + counter.ToString() + "行!"); System.Threading.Thread.Sleep(this.threadSleepTime * 1000); if (this.counter == this.stopCounter) { WindowFormDelegate.SetMainThreadHint(this.lbHotHint, "打印完成:" + counter.ToString() + "行!"); break; } } }
private void setHint(string msg) { WindowFormDelegate.SetMainThreadHint(this.lbPrintHint, msg); }
private void SetReadHint(string msg) { WindowFormDelegate.SetMainThreadHint(this.lbPrintHint, this.lbPrintHint.Text += msg); }
private void BeginMonitor() { int sec = Convert.ToInt32(this.txtTimerSecond.Text.Trim()); int MonitorLineCount = Convert.ToInt32(this.txtMonitorLine.Text.Trim()); int days = Convert.ToInt32(this.txtLogDays.Text.Trim()); string monitorPath = this.txtMonitorPath.Text.Trim(); while (true) { try { DateTime begin = System.DateTime.Now; string path = string.Empty; string bakRestart = string.Empty; string bakNormal = string.Empty; string date = System.DateTime.Now.ToString("yyyyMMdd"); DirectoryInfo dir; if (monitorPath.Length > 0) { dir = new DirectoryInfo(monitorPath); } else { dir = new DirectoryInfo(Application.StartupPath); } FileInfo[] files = dir.GetFiles(); FileInfo fileTemp = null; string olddate = System.DateTime.Now.AddDays(-days).ToString("yyyyMMdd"); for (int i = 0; i < files.Length; i++) { fileTemp = files[i]; if (fileTemp.Name.StartsWith(olddate)) { fileTemp.Delete(); } } if (this.txtMonitorPath.Text.Trim().Length > 0) { path = this.txtMonitorPath.Text.Trim() + "\\" + date + ".txt"; bakRestart = this.txtMonitorPath.Text.Trim() + "\\" + date + "-" + System.DateTime.Now.ToString("HHmmss") + "-restart.txt"; bakNormal = this.txtMonitorPath.Text.Trim() + "\\" + date + "-" + System.DateTime.Now.ToString("HHmmss") + "-normal.txt"; } else { path = date + ".txt"; bakRestart = date + "-" + System.DateTime.Now.ToString("HHmmss") + "-restart.txt"; bakNormal = date + "-" + System.DateTime.Now.ToString("HHmmss") + "-normal.txt"; } FileInfo file = new FileInfo(path); if (file.Exists) { int counter = 0; bool findError = false; using (FileStream file_s = //new FileStream(path, FileMode.Open); File.Open(path, FileMode.Open, FileAccess.Read)) { using (StreamReader sr = new StreamReader(file_s)) //using (StreamReader sr = new StreamReader(path)) { String line; // Read and display lines from the file until the end of // the file is reached. while ((line = sr.ReadLine()) != null) { counter++; WindowFormDelegate.SetMainThreadHint(lbHint, string.Format(HintFormatter, counter, date)); WindowFormDelegate.SetMainThreadHint(lbLogContent, string.Format(HintContentFormatter, line)); if (counter <= LineCounter) { continue; } else { if (line.IndexOf(ErrorString) != -1) { findError = true; this.LineCounter = counter; break; } } } // while(sr.EndOfStream } if (findError) { FT.Commons.Tools.WindowServicesHelper.ForceStop(XServerName); try { file.CopyTo(bakRestart); file.Delete(); this.LineCounter = 0; } catch (Exception ex) { log.Info(bakRestart); log.Info(ex); //MessageBoxHelper.Show(ex.ToString()); } System.Threading.Thread.Sleep(2000); FT.Commons.Tools.WindowServicesHelper.ForceStart(XServerName); } else if (counter > MonitorLineCount) { try { file.CopyTo(bakNormal); file.Delete(); this.LineCounter = 0; } catch (Exception ex) { log.Info(bakNormal); log.Info(ex); //MessageBoxHelper.Show(ex.ToString()); } } } } DateTime end = System.DateTime.Now; TimeSpan ts = end.Subtract(begin); WindowFormDelegate.SetMainThreadHint(lbUseTimes, ts.TotalMilliseconds.ToString()); System.Threading.Thread.Sleep(sec); } catch (Exception ex) { log.Info("大循环异常:" + ex); } } }