protected void Page_Load(object sender, EventArgs e) { string Type=Request.Form.Get("type"); //Section "Восстановить у пользователя" if (Type == DOWNLOAD_FILE_RECOVER_USER) { if (Request.Form.Get("dataBlockId") != null) { int dataBlockId = Convert.ToInt32(Request.Form.Get("dataBlockId")); string connectionString = ConfigurationManager.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); dataBlock.OpenConnection(); byte[] fileBytes = dataBlock.GetDataBlock_BytesArray(dataBlockId); string fileName = dataBlock.GetDataBlock_FileName(dataBlockId); dataBlock.CloseConnection(); Response.Clear(); Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", fileName)); Response.AddHeader("Content-Length", fileBytes.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.OutputStream.Write(fileBytes, 0, fileBytes.Length); Response.End(); return; } } //Section "PLF Файлы" if (Type == GET_PLF_REPORT) { string CardID=Request.Form.Get("CardID"); string PLFID=Request.Form.Get("PLFID"); string UserName = Request.Form.Get("UserName"); string Format = Request.Form.Get("Format"); string ReportType = Request.Form.Get("ReportType"); if (string.IsNullOrEmpty(ReportType)) { ReportType = "Полный отчет"; } int dataBlockId = int.Parse(PLFID); List<int> dataBlockIDS = new List<int>(); dataBlockIDS.Add(dataBlockId); int cardID = int.Parse(CardID); string connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"]; BLL.DataBlock dataBlock = new BLL.DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); dataBlock.OpenConnection(); DateTime from = new DateTime(); from = dataBlock.plfUnitInfo.Get_START_PERIOD(dataBlockId); DateTime to = new DateTime(); to = dataBlock.plfUnitInfo.Get_END_PERIOD(dataBlockId); string vehicle = dataBlock.plfUnitInfo.Get_VEHICLE(dataBlockId); string deviceID = dataBlock.plfUnitInfo.Get_ID_DEVICE(dataBlockId); DataSet dataset = new DataSet(); int userId = dataBlock.usersTable.Get_UserID_byName(UserName); List<PLFUnit.PLFRecord> records = new List<PLFUnit.PLFRecord>(); dataset = ReportDataSetLoader.Get_PLF_ALLData(dataBlockIDS, new DateTime(from.Year, from.Month, from.Day), new DateTime(to.Year, to.Month, to.Day), cardID, userId, ref records); dataBlock.CloseConnection(); //gets table PlfHeader_1 DataTable dt = dataset.Tables[0]; //gets the first row DataRow dr = dt.Rows[0]; string driverName = dr["Имя водителя"].ToString(); //load needed template string path = HttpContext.Current.Server.MapPath("~/templates_plf") + "\\"; XtraReport report = new XtraReport(); report.LoadLayout(path + ReportType+".repx"); report.DataSource = dataset; MemoryStream reportStream = new MemoryStream(); switch (Format) { case "html": report.ExportToHtml(reportStream); break; case "pdf": report.ExportToPdf(reportStream); break; case "rtf": report.ExportToRtf(reportStream); break; case "png": report.ExportToImage(reportStream,ImageFormat.Png); break; } Response.Clear(); Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + driverName + " " + new DateTime(from.Year, from.Month, from.Day).ToString("dd_MM_yyyy") + "-" + new DateTime(to.Year, to.Month, to.Day).ToString("dd_MM_yyyy") + "." + Format)); Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString()); Response.ContentType = "application/octet-stream"; Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length); Response.End(); return; } if (Type == GET_PLF_REPORT_FOR_PERIOD) { string CardID = Request.Form.Get("CardID"); string StartDate = Request.Form.Get("StartDate"); string EndDate = Request.Form.Get("EndDate"); string UserName = Request.Form.Get("UserName"); string Format = Request.Form.Get("Format"); string ReportType = Request.Form.Get("ReportType"); if (string.IsNullOrEmpty(ReportType)) { ReportType = "Полный отчет"; } int cardID = int.Parse(CardID); string connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"]; BLL.DataBlock dataBlock = new BLL.DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); dataBlock.OpenConnection(); DateTime from = DateTime.Parse(StartDate); DateTime to = DateTime.Parse(EndDate); DataSet dataset = new DataSet(); List<int> dataBlockIDS = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardID); int userId = dataBlock.usersTable.Get_UserID_byName(UserName); List<PLFUnit.PLFRecord> records = new List<PLFUnit.PLFRecord>(); dataset = ReportDataSetLoader.Get_PLF_ALLData(dataBlockIDS, new DateTime(from.Year, from.Month, from.Day), new DateTime(to.Year, to.Month, to.Day), cardID, userId, ref records); dataBlock.CloseConnection(); //gets table PlfHeader_1 DataTable dt = dataset.Tables[0]; //gets the first row DataRow dr = dt.Rows[0]; string driverName = dr["Имя водителя"].ToString(); //load needed template string path = HttpContext.Current.Server.MapPath("~/templates_plf") + "\\"; XtraReport report = new XtraReport(); report.LoadLayout(path + ReportType + ".repx"); report.DataSource = dataset; MemoryStream reportStream = new MemoryStream(); switch (Format) { case "html": report.ExportToHtml(reportStream); break; case "pdf": report.ExportToPdf(reportStream); break; case "rtf": report.ExportToRtf(reportStream); break; case "png": report.ExportToImage(reportStream, ImageFormat.Png); break; } Response.Clear(); Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + driverName + " " + new DateTime(from.Year, from.Month, from.Day).ToString("dd_MM_yyyy") + "-" + new DateTime(to.Year, to.Month, to.Day).ToString("dd_MM_yyyy") + "." + Format)); Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString()); Response.ContentType = "application/octet-stream"; Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length); Response.End(); return; } //Section "Транспортные средства" if (Type == GET_DDD_REPORT) { string DataBlockID = Request.Form.Get("DataBlockID"); string UserName = Request.Form.Get("UserName"); string Format = Request.Form.Get("Format"); string ReportType = Request.Form.Get("ReportType"); if (string.IsNullOrEmpty(ReportType)) { ReportType = "Полный отчет"; } int dataBlockId = int.Parse(DataBlockID); List<int> dataBlockIDS = new List<int>(); dataBlockIDS.Add(dataBlockId); string connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); dataBlock.OpenConnection(); DataSet dataset = new DataSet(); string VIN = dataBlock.vehicleUnitInfo.Get_VehicleOverview_IdentificationNumber(dataBlockId).ToString(); string RegNumb = dataBlock.vehicleUnitInfo.Get_VehicleOverview_RegistrationIdentification(dataBlockId).vehicleRegistrationNumber.ToString(); int vehicleId = dataBlock.vehiclesTables.GetVehicleId_byVinRegNumbers(VIN, RegNumb); List<DateTime> vehsCardPeriod = dataBlock.vehicleUnitInfo.Get_StartEndPeriod(dataBlockId); int userId = dataBlock.usersTable.Get_UserID_byName(UserName); dataset = ReportDataSetLoader.Get_Vehicle_ALLDate(vehicleId, dataBlockIDS, vehsCardPeriod[0], vehsCardPeriod[1], userId); dataBlock.CloseConnection(); //load needed template string path = HttpContext.Current.Server.MapPath("~/templates_ddd") + "\\"; XtraReport report = new XtraReport(); report.LoadLayout(path + ReportType + ".repx"); report.DataSource = dataset; MemoryStream reportStream = new MemoryStream(); switch (Format) { case "html": report.ExportToHtml(reportStream); break; case "pdf": report.ExportToPdf(reportStream); break; case "rtf": report.ExportToRtf(reportStream); break; case "png": report.ExportToImage(reportStream, ImageFormat.Png); break; } Response.Clear(); Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + VIN + "_" + RegNumb + " " + vehsCardPeriod[0].ToString("dd_MM_yyyy") + "-" + vehsCardPeriod[1].ToString("dd_MM_yyyy") + "." + Format)); Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString()); Response.ContentType = "application/octet-stream"; Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length); Response.End(); return; } //Section "Транспортные средства" if (Type == GET_DDD_REPORT_FOR_PERIOD) { string CardID = Request.Form.Get("CardID"); string StartDate = Request.Form.Get("StartDate"); string EndDate = Request.Form.Get("EndDate"); string UserName = Request.Form.Get("UserName"); string Format = Request.Form.Get("Format"); string ReportType = Request.Form.Get("ReportType"); if (string.IsNullOrEmpty(ReportType)) { ReportType = "Полный отчет"; } string connectionString = System.Configuration.ConfigurationManager.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); dataBlock.OpenConnection(); DataSet dataset = new DataSet(); int cardId = int.Parse(CardID); string VIN = dataBlock.vehiclesTables.GetVehicleVin(cardId); string RegNumb = dataBlock.vehiclesTables.GetVehicleGOSNUM(cardId); int vehicleId = dataBlock.vehiclesTables.GetVehicle_byCardId(cardId); List<int> dataBlockIDS = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardId); int userId = dataBlock.usersTable.Get_UserID_byName(UserName); DateTime from = DateTime.Parse(StartDate); DateTime to = DateTime.Parse(EndDate); dataset = ReportDataSetLoader.Get_Vehicle_ALLDate(vehicleId, dataBlockIDS, from, to, userId); dataBlock.CloseConnection(); //load needed template string path = HttpContext.Current.Server.MapPath("~/templates_ddd") + "\\"; XtraReport report = new XtraReport(); report.LoadLayout(path + ReportType + ".repx"); report.DataSource = dataset; MemoryStream reportStream = new MemoryStream(); switch (Format) { case "html": report.ExportToHtml(reportStream); break; case "pdf": report.ExportToPdf(reportStream); break; case "rtf": report.ExportToRtf(reportStream); break; case "png": report.ExportToImage(reportStream, ImageFormat.Png); break; } Response.Clear(); Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Отчет " + VIN + "_" + RegNumb + " " + from.ToString("dd_MM_yyyy") + "-" + to.ToString("dd_MM_yyyy") + "." + Format)); Response.AddHeader("Content-Length", reportStream.GetBuffer().Length.ToString()); Response.ContentType = "application/octet-stream"; Response.OutputStream.Write(reportStream.GetBuffer(), 0, reportStream.GetBuffer().Length); Response.End(); return; } }
public static List<DataBlockID> GetUnparsedDataBlocks(String OrgID) { try { string connectionString = ConfigurationManager.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); int orgId = Convert.ToInt32(OrgID); List<DataBlockID> dataBlockIDList = new List<DataBlockID>(); DataBlockID dataBlockIDItem; List<int> dataBlockIDs = new List<int>(); int number = 0; dataBlock.OpenConnection(); dataBlockIDs = dataBlock.GetAllUnparsedDataBlockIDs(orgId); foreach (int id in dataBlockIDs) { number++; dataBlockIDItem = new DataBlockID(); dataBlockIDItem.ID = id; dataBlockIDItem.Number = number; dataBlockIDItem.Name = dataBlock.GetDataBlock_FileName(id); dataBlockIDItem.State = dataBlock.GetDataBlockState(id); dataBlockIDItem.ByteSize = Convert.ToInt32(dataBlock.GetDataBlock_BytesCount(id)); dataBlockIDList.Add(dataBlockIDItem); } dataBlock.CloseConnection(); return dataBlockIDList; } catch (Exception ex) { throw ex; //return null; } }
private List<AddStructure> LoadAllLists() { string connectionString = ConfigurationSettings.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); try { int orgId = Convert.ToInt32(Session["CURRENT_ORG_ID"]); List<AddStructure> addStructureList = new List<AddStructure>(); int i = 0; AddStructure addStructureTemp; List<int> dataBlockIds = new List<int>(); dataBlock.OpenConnection(); dataBlockIds = dataBlock.GetAllUnparsedDataBlockIDs(orgId); foreach (int dataBlockId in dataBlockIds) { i++; addStructureTemp = new AddStructure(); addStructureTemp.dataBlockId = dataBlockId; addStructureTemp.number = i; addStructureTemp.name = dataBlock.GetDataBlock_FileName(dataBlockId); addStructureTemp.state = dataBlock.GetDataBlockState(dataBlockId); addStructureTemp.byteSize = Convert.ToInt32(dataBlock.GetDataBlock_BytesCount(dataBlockId)); addStructureList.Add(addStructureTemp); } if (dataBlockIds.Count == 0) { Parse_Button.Enabled = false; Status.Text = "Нет записей для отображения"; } else { Parse_Button.Enabled = true; Status.Text = ""; } AddGrid.DataSource = CreateDataSource(addStructureList); AddGrid.DataBind(); SetDelColVisible(true); setParseButtonVisible(true); dataBlock.CloseConnection(); return addStructureList; } catch (Exception ex) { dataBlock.CloseConnection(); Status.Text = "Произошла ошибка: " + ex.Message; return null; } finally { StatusUpdatePanel.Update(); } }
DataTable CreateVehiclesInfoSource(List<int> dataBlocksIds, DataBlock dataBlock) { DataTable dt = new DataTable(); DataRow dr; dt.Columns.Add(new DataColumn("#", typeof(int))); dt.Columns.Add(new DataColumn("Имя файла", typeof(string))); dt.Columns.Add(new DataColumn("Тип карты", typeof(string))); dt.Columns.Add(new DataColumn("Период С", typeof(string))); dt.Columns.Add(new DataColumn("По", typeof(string))); dt.Columns.Add(new DataColumn("Кол-во записей", typeof(int))); dt.Columns.Add(new DataColumn("Дата разбора", typeof(string))); int i = 1; List<DateTime> startEnd = new List<DateTime>(); foreach (int id in dataBlocksIds) { dr = dt.NewRow(); dr["#"] = i++; dr["имя файла"] = dataBlock.GetDataBlock_FileName(id); dr["Тип карты"] = dataBlock.GetCardTypeName(id); startEnd = dataBlock.vehicleUnitInfo.Get_StartEndPeriod(id); dr["Период С"] = startEnd[0].ToLongDateString(); dr["По"] = startEnd[1].ToLongDateString(); dr["Кол-во записей"] = dataBlock.GetDataBlock_RecorsCount(id); dr["Дата разбора"] = dataBlock.GetDataBlock_EDate(id); dt.Rows.Add(dr); } return dt; }
private static List<Driver> LoadAllDriversLists(int cardId) { List<Driver> driversStructureList = new List<Driver>(); int number = 0; string connectionString = ConfigurationManager.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); Driver driversStructureTemp; List<int> dataBlockIds = new List<int>(); try { dataBlock.OpenConnection(); dataBlockIds = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardId); int cardType; List<DateTime> startEnd = new List<DateTime>(); foreach (int dataBlockId in dataBlockIds) { number++; driversStructureTemp = new Driver(); driversStructureTemp.DataBlockId = dataBlockId; driversStructureTemp.Number = number; driversStructureTemp.Name = dataBlock.GetDataBlock_FileName(dataBlockId); driversStructureTemp.RecordsCount = dataBlock.GetDataBlock_RecorsCount(dataBlockId); driversStructureTemp.CreationTime = dataBlock.GetDataBlock_EDate(dataBlockId); cardType = dataBlock.GetDataBlock_CardType(dataBlockId); driversStructureTemp.CardTypeName = dataBlock.GetCardTypeName(dataBlockId); if (cardType == 0) { startEnd = dataBlock.cardUnitInfo.Get_StartEndPeriod(dataBlockId); driversStructureTemp.setFromDate(startEnd[0]); driversStructureTemp.setToDate(startEnd[1]); } else if (cardType == 2) { driversStructureTemp.setFromDate(dataBlock.plfUnitInfo.Get_START_PERIOD(dataBlockId)); driversStructureTemp.setToDate(dataBlock.plfUnitInfo.Get_END_PERIOD(dataBlockId)); } else { driversStructureTemp.setFromDate(new DateTime()); driversStructureTemp.setToDate(new DateTime()); } driversStructureList.Add(driversStructureTemp); } dataBlock.CloseConnection(); return driversStructureList; } catch (Exception ex) { dataBlock.CloseConnection(); return null; } }
public static List<VehiclesTreeItem> GetVehiclesTree(String OrgID) { string connectionString = ConfigurationManager.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); int orgId = Convert.ToInt32(OrgID); dataBlock.OpenConnection(); List<int> cardsList = dataBlock.cardsTable.GetAllCardIds(orgId, dataBlock.cardsTable.vehicleCardTypeId); List<VehiclesTreeItem> vehicles = new List<VehiclesTreeItem>(); foreach (int cardId in cardsList) { string name = dataBlock.cardsTable.GetCardName(cardId); int vehicleId = dataBlock.vehiclesTables.GetVehicle_byCardId(cardId); string vehicleVin = dataBlock.vehiclesTables.GetVehicleVin(vehicleId); VehiclesTreeItem vehiclesTreeItem = new VehiclesTreeItem(); vehiclesTreeItem.Name=name; vehiclesTreeItem.VehicleID = vehicleId; vehiclesTreeItem.VehicleVin = vehicleVin; vehiclesTreeItem.Files = new List<VehiclesTreeFileItem>(); List<int> vehDataBlocks = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardId); foreach (int dataBlockId in vehDataBlocks) { List<DateTime> vehsCardPeriod = dataBlock.vehicleUnitInfo.Get_StartEndPeriod(dataBlockId); string fileName=dataBlock.GetDataBlock_FileName(dataBlockId); VehiclesTreeFileItem vehiclesTreeFileItem = new VehiclesTreeFileItem(); vehiclesTreeFileItem.DataBlockID = dataBlockId; vehiclesTreeFileItem.FileName= dataBlock.GetDataBlock_FileName(dataBlockId); vehiclesTreeFileItem.VehicleCardPeriodBegin = vehsCardPeriod[0].ToShortDateString(); vehiclesTreeFileItem.VehicleCardPeriodEnd = vehsCardPeriod[1].ToShortDateString(); vehiclesTreeItem.Files.Add(vehiclesTreeFileItem); } vehicles.Add(vehiclesTreeItem); } dataBlock.vehiclesTables.CloseConnection(); return vehicles; }