private void btnSave_Click(object sender, EventArgs e) { if (grdAnswer.Rows.Count == 0) { return; } DialogResult Ans = dlgSave.ShowDialog(); if (Ans == DialogResult.Cancel) { return; } PrintReport printReport = new PrintReport(dlgSave.FileName, grdAnswer); if (!printReport.SaveFromGrid()) { lblMessage.ForeColor = Color.Red; lblMessage.Text = printReport.ErrorMessage; } else { lblMessage.ForeColor = Color.Green; lblMessage.Text = "Сохранено в " + dlgSave.FileName; Ans = MessageBox.Show("Открыть сохраненный файл?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (Ans == DialogResult.No) { return; } string tmpMsg = CommonFunctions.OpenFile(dlgSave.FileName); if (tmpMsg != string.Empty) { lblMessage.ForeColor = Color.Red; lblMessage.Text = tmpMsg; } } }
private void GetData() { IPGeoinfo GeoInfo = null; SendStatus(BatchFinderStatus.Working, "Получаю список IP..."); string[] IPs = GetAllIPs(); if (IPs == null) { SendStatus(BatchFinderStatus.Error, ErrorMessage); return; } SendStatus(BatchFinderStatus.Working, "Подготавливаю данные..."); if (!string.IsNullOrEmpty(SxPath)) //открываем базу SxGeo { GeoInfo = new IPGeoinfo(SxPath); if (!GeoInfo.Open()) { ErrorMessage = GeoInfo.ErrorMessage; SendStatus(BatchFinderStatus.Error, ErrorMessage); return; } } //объект для отчета PrintReport Log = new PrintReport(OutputFile); //добавляем строку с полями string stFields = ""; if (GeoInfo != null) { stFields = GeoInfo.GetDescriptions(ColData); } if (AllTorData) { stFields = stFields + ";" + ColData.GetDesription("In_Tor") + ";" + CSVLoader.GetDescriptions(ColData); } else { stFields = stFields + ";" + ColData.GetDesription("In_Tor"); } Log.ReportAdd(stFields); //начинаем обработку IP int Count = IPs.Length; int Current = 0; int ErrCount = 0; if (GeoInfo != null) { GeoInfo.PrepareBatch(); } //обрабатываем IP foreach (string IP in IPs) { //прибавили счетчик, послали статус, подготовили буфер Current++; SendStatus(BatchFinderStatus.Working, "IP " + Current.ToString() + "/" + Count.ToString()); string buf = string.Empty; string sxinfo = string.Empty; //информация SxGeo if (GeoInfo != null) { sxinfo = GeoInfo.GetDataString(IP); } //информация Tor List <string> listTor = CSVLoader.FindList(IP); if (listTor == null) //ошибка { SendStatus(BatchFinderStatus.Error, CSVLoader.ErrorMessage); ErrCount++; buf = sxinfo + ";" + CSVLoader.ErrorMessage; Log.ReportAdd(buf); } else { if (listTor.Count == 0) //не нашли { buf = sxinfo + ";Not found in TOR"; Log.ReportAdd(buf); } else { string found = ";Found (" + listTor.Count.ToString() + ")"; if (!AllTorData) //полная информация не нужна { buf = sxinfo + found; Log.ReportAdd(buf); } else //нужна полная информация по tor-ноде(ам) { int torI = 0; foreach (string node in listTor) { torI++; buf = sxinfo + found + " #" + torI + ";" + node; Log.ReportAdd(buf); } } } } //конец обработки IP } //конец цикла обработки всех IP //сохраняем отчет if (!Log.ReportSave(OutputFile)) { ErrorMessage = Log.ErrorMessage; SendStatus(BatchFinderStatus.Error, "Ошибка сохранения отчета: " + ErrorMessage); return; } if (ErrCount != 0) { ErrorMessage = "При обработке адресов произошли ошибки."; SendStatus(BatchFinderStatus.Error, ErrorMessage); } else { SendStatus(BatchFinderStatus.Complete, "Отчет успешно сохранен."); } }