public static void SetPrinterInformation(IndexQuery iq) { RequestState state = new RequestState(); PrinterInformation printer = new PrinterInformation(); printer.StoreNo = iq.StoreNo; printer.StoreRegion = iq.StoreRegion; printer.StoreType = iq.StoreType; printer.PrinterType = iq.PrinterType; printer.TonerType = iq.TonerType; state.Host = Common.GetStoreHost(iq.StoreNo); state.Host.PrinterIP = iq.PrinterIP; state.Printer = printer; state.IsIndexQuery = true; try { if (new Ping().Send(state.Host.PrinterIP).Status == IPStatus.Success) { BeginResponse(state); } else { indexCount++; state.Printer.PrinterStatus = "打印机无法连接"; state.Printer.TonerStatus = "打印机无法连接"; state.Printer.PrinterNetwork = "Down"; state.Printer.Date = DateTime.Now.ToString(); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": 打印机无法连接"); } } catch (System.Exception ex) { indexCount++; state.Printer.PrinterStatus = ex.Message; state.Printer.TonerStatus = ex.Message; state.Printer.PrinterNetwork = "Down"; state.Printer.Date = DateTime.Now.ToString(); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": " + ex.Message.ToString()); } while (true) { if (indexCount == 1) { iq.PrinterNetwork = state.Printer.PrinterNetwork; iq.PrinterStatus = state.Printer.PrinterStatus; iq.TonerStatus = state.Printer.TonerStatus; break; } } }
private static void GetPrinterStatus(RequestState state, Pattern pat) { string printerStatus, tonerStatus, percent = string.Empty; int ps, pe, ts, te; string html = state.Host.Html; PrinterInformation printer = state.Printer; try { printerStatus = html.Substring(html.IndexOf(pat.SearchString1)).Replace(" ", " "); tonerStatus = printerStatus.Substring(printerStatus.IndexOf(pat.SearchString2, pat.SearchStartIndex)); if (!String.IsNullOrEmpty(pat.SearchString3)) { int idx = tonerStatus.IndexOf(pat.SearchString3) == -1 ? tonerStatus.IndexOf(pat.SearchString3N) : tonerStatus.IndexOf(pat.SearchString3); percent = tonerStatus.Substring(idx); } ps = printerStatus.IndexOf(pat.Anchor1); pe = printerStatus.IndexOf(pat.Anchor2); printer.PrinterStatus = printerStatus.Substring(ps + pat.Anchor1.Length, pe - ps - pat.Anchor1.Length).Trim().Replace("<br>", ""); ts = tonerStatus.IndexOf(pat.Anchor3); te = tonerStatus.IndexOf(pat.Anchor4); printer.TonerStatus = tonerStatus.Substring(ts + pat.Anchor3.Length, te - ts - pat.Anchor3.Length).Trim().Replace(pat.ReplaceString, pat.ReplaceString + " "); if (!string.IsNullOrEmpty(pat.SearchString3) && !string.IsNullOrEmpty(pat.Anchor5) && !string.IsNullOrEmpty(pat.Anchor6)) { int idxs, idxe; idxs = percent.IndexOf(pat.Anchor5); idxe = percent.IndexOf(pat.Anchor6); percent = " " + percent.Substring(idxs + pat.Anchor5.Length, idxe - idxs - pat.Anchor5.Length).Trim(); printer.TonerStatus += percent; } printer.PrinterNetwork = "Up"; } catch (System.Exception ex) { printer.PrinterStatus = ex.Message.ToString(); printer.TonerStatus = ex.Message.ToString(); printer.PrinterNetwork = "Down"; } }
private static ArrayList GetData(PrinterCondition pc) { ArrayList list = new ArrayList(); DataSet ds = SqlHelper.GetPrinterInformation(pc); int count = ds.Tables[0].Rows.Count; for (int i = 0; i < count; i++) { PrinterInformation printer = new PrinterInformation(); printer.StoreNo = ds.Tables[0].Rows[i]["storeNo"].ToString(); printer.StoreRegion = ds.Tables[0].Rows[i]["storeRegion"].ToString(); printer.StoreType = ds.Tables[0].Rows[i]["storeType"].ToString(); printer.PrinterStatus = ds.Tables[0].Rows[i]["printerStatus"].ToString(); printer.TonerStatus = ds.Tables[0].Rows[i]["tonerStatus"].ToString(); printer.PrinterType = ds.Tables[0].Rows[i]["printerType"].ToString(); printer.TonerType = ds.Tables[0].Rows[i]["tonerType"].ToString(); printer.Date = ds.Tables[0].Rows[i]["date"].ToString(); printer.PrinterNetwork = ds.Tables[0].Rows[i]["printerNetwork"].ToString(); list.Add(printer); } return list; }
public static void DoGetPrinterInfomationTask() { PrinterList = new List <PrinterInformation>(); DataSet ds = SqlHelper.GetNonHKStoreInformation(); storeCount = ds.Tables[0].Rows.Count; Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < storeCount; i++) { RequestState state = new RequestState(); PrinterInformation printer = new PrinterInformation(); printer.StoreNo = ds.Tables[0].Rows[i]["storeNo"].ToString(); printer.StoreRegion = ds.Tables[0].Rows[i]["storeRegion"].ToString(); printer.StoreType = ds.Tables[0].Rows[i]["storeType"].ToString(); printer.PrinterType = ds.Tables[0].Rows[i]["printerType"].ToString(); printer.TonerType = ds.Tables[0].Rows[i]["tonerType"].ToString(); state.Host = Common.GetStoreHost(printer.StoreNo); state.Host.PrinterIP = ds.Tables[0].Rows[i]["printerIP"].ToString(); // IP设置为门店维护的IP state.IsIndexQuery = false; state.Printer = printer; try { if (new Ping().Send(state.Host.PrinterIP).Status == IPStatus.Success) { BeginResponse(state); } else { count++; state.Printer.PrinterStatus = "打印机无法连接"; state.Printer.TonerStatus = "打印机无法连接"; state.Printer.PrinterNetwork = "Down"; state.Printer.Date = DateTime.Now.ToString(); PrinterList.Add(state.Printer); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": 打印机无法连接"); } } catch (System.Exception ex) { count++; state.Printer.PrinterStatus = ex.Message; state.Printer.TonerStatus = ex.Message; state.Printer.PrinterNetwork = "Down"; state.Printer.Date = DateTime.Now.ToString(); PrinterList.Add(state.Printer); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": " + ex.Message.ToString()); continue; } } while (true) { if (count == storeCount) { string[] clist = { "storeNo", "storeRegion", "storeType", "printerNetwork", "printerStatus", "tonerStatus", "printerType", "tonerType", "date" }; DataTable dt = new DataTable(); foreach (string colname in clist) { dt.Columns.Add(colname); } int rowsCount = PrinterList.Count; for (int i = 0; i < rowsCount; i++) { DataRow row = dt.NewRow(); row["storeNo"] = PrinterList[i].StoreNo; row["storeRegion"] = PrinterList[i].StoreRegion; row["storeType"] = PrinterList[i].StoreType; row["printerNetwork"] = PrinterList[i].PrinterNetwork; row["printerStatus"] = PrinterList[i].PrinterStatus; row["tonerStatus"] = PrinterList[i].TonerStatus; row["printerType"] = PrinterList[i].PrinterType; row["tonerType"] = PrinterList[i].TonerType; row["date"] = PrinterList[i].Date; dt.Rows.Add(row); } SqlHelper.DelCurDatePrinterInformation(); SqlHelper.CommonBulkInsert(dt, "PrinterInformation"); sw.Stop(); double ms = sw.ElapsedMilliseconds / 1000.0; Console.WriteLine("耗时: " + ms.ToString() + " 秒"); break; } } }
public static void SetPrinterInformation(IndexQuery iq) { RequestState state = new RequestState(); PrinterInformation printer = new PrinterInformation(); printer.StoreNo = iq.StoreNo; printer.StoreRegion = iq.StoreRegion; printer.StoreType = iq.StoreType; printer.PrinterType = iq.PrinterType; printer.TonerType = iq.TonerType; state.Host = Common.GetStoreHost(iq.StoreNo); state.Host.PrinterIP = iq.PrinterIP; state.Printer = printer; state.IsIndexQuery = true; try { if (new Ping().Send(state.Host.PrinterIP).Status == IPStatus.Success) { BeginResponse(state); } else { indexCount++; state.Printer.PrinterStatus = "打印机无法连接"; state.Printer.TonerStatus = "打印机无法连接"; state.Printer.PrinterNetwork = "Down"; state.Printer.Date = DateTime.Now.ToString(); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": 打印机无法连接"); } } catch (System.Exception ex) { indexCount++; state.Printer.PrinterStatus = ex.Message; state.Printer.TonerStatus = ex.Message; state.Printer.PrinterNetwork = "Down"; state.Printer.Date = DateTime.Now.ToString(); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": " + ex.Message.ToString()); } while (true) { if (indexCount == 1) { iq.PrinterNetwork = state.Printer.PrinterNetwork; iq.PrinterStatus = state.Printer.PrinterStatus; iq.TonerStatus = state.Printer.TonerStatus; break; } } }
public static void DoGetPrinterInfomationTask() { PrinterList = new List<PrinterInformation>(); DataSet ds = SqlHelper.GetNonHKStoreInformation(); storeCount = ds.Tables[0].Rows.Count; Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < storeCount; i++) { RequestState state = new RequestState(); PrinterInformation printer = new PrinterInformation(); printer.StoreNo = ds.Tables[0].Rows[i]["storeNo"].ToString(); printer.StoreRegion = ds.Tables[0].Rows[i]["storeRegion"].ToString(); printer.StoreType = ds.Tables[0].Rows[i]["storeType"].ToString(); printer.PrinterType = ds.Tables[0].Rows[i]["printerType"].ToString(); printer.TonerType = ds.Tables[0].Rows[i]["tonerType"].ToString(); state.Host = Common.GetStoreHost(printer.StoreNo); state.Host.PrinterIP = ds.Tables[0].Rows[i]["printerIP"].ToString(); // IP设置为门店维护的IP state.IsIndexQuery = false; state.Printer = printer; try { if (new Ping().Send(state.Host.PrinterIP).Status == IPStatus.Success) { BeginResponse(state); } else { count++; state.Printer.PrinterStatus = "打印机无法连接"; state.Printer.TonerStatus = "打印机无法连接"; state.Printer.PrinterNetwork = "Down"; state.Printer.Date = DateTime.Now.ToString(); PrinterList.Add(state.Printer); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": 打印机无法连接"); } } catch (System.Exception ex) { count++; state.Printer.PrinterStatus = ex.Message; state.Printer.TonerStatus = ex.Message; state.Printer.PrinterNetwork = "Down"; state.Printer.Date = DateTime.Now.ToString(); PrinterList.Add(state.Printer); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": " + ex.Message.ToString()); continue; } } while (true) { if (count == storeCount) { string[] clist = { "storeNo", "storeRegion", "storeType", "printerNetwork", "printerStatus", "tonerStatus", "printerType", "tonerType", "date" }; DataTable dt = new DataTable(); foreach (string colname in clist) { dt.Columns.Add(colname); } int rowsCount = PrinterList.Count; for (int i = 0; i < rowsCount; i++) { DataRow row = dt.NewRow(); row["storeNo"] = PrinterList[i].StoreNo; row["storeRegion"] = PrinterList[i].StoreRegion; row["storeType"] = PrinterList[i].StoreType; row["printerNetwork"] = PrinterList[i].PrinterNetwork; row["printerStatus"] = PrinterList[i].PrinterStatus; row["tonerStatus"] = PrinterList[i].TonerStatus; row["printerType"] = PrinterList[i].PrinterType; row["tonerType"] = PrinterList[i].TonerType; row["date"] = PrinterList[i].Date; dt.Rows.Add(row); } SqlHelper.DelCurDatePrinterInformation(); SqlHelper.CommonBulkInsert(dt, "PrinterInformation"); sw.Stop(); double ms = sw.ElapsedMilliseconds / 1000.0; Console.WriteLine("耗时: " + ms.ToString() + " 秒"); break; } } }