protected void AddGridCommand(object sender, DataGridCommandEventArgs e) { string connectionString = ConfigurationSettings.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); List<int> dataBlockIds = new List<int>(); int orgId = Convert.ToInt32(Session["CURRENT_ORG_ID"]); Status.Text = ""; DriverPreviewButtonsPanel.Visible = false; VehiclePreviewButtonsPanel.Visible = false; FilesPreviewDataGrid.DataSource = null; FilesPreviewDataGrid.DataBind(); try { if (e.CommandName == "ViewData") { if (Session["DeleteCommmand"] == "ViewDriversFile") { int tableIndex = Convert.ToInt32(e.Item.Cells[2].Text) - 1; int cardId = Convert.ToInt32(DriversSelectTree.SelectedValue); List<Driver> driversStructureList = new List<Driver>(); dataBlock.OpenConnection(); driversStructureList = LoadAllDriversLists(cardId); dataBlockIds.Add(driversStructureList[tableIndex].DataBlockId); onlyForInternal.Value = driversStructureList[tableIndex].DataBlockId.ToString(); if (driversStructureList[tableIndex].CardTypeName != "Plf") { DriverPreviewButtonsPanel.Visible = true; Driver_FileContents(null, null); } else { PLFUnit.PLFUnitClass plf = new PLFUnit.PLFUnitClass(); plf.Records = dataBlock.plfUnitInfo.Get_Records(dataBlockIds, cardId); FilesPreviewDataGrid.DataSource = PlfReportsDataTables.PLF_Data(plf.Records); FilesPreviewDataGrid.DataBind(); FilesPreviewPanel.Visible = true; } ShowDriversStatisticsForOneFile(sender, e); dataBlock.CloseConnection(); } if (Session["DeleteCommmand"] == "ViewVehiclesFile") { int tableIndex = Convert.ToInt32(e.Item.Cells[2].Text) - 1; int cardId = Convert.ToInt32(VehiclesSelectTree.SelectedValue); List<int> cardDataBlockIds = new List<int>(); dataBlock.OpenConnection(); cardDataBlockIds = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardId); dataBlockIds.Add(cardDataBlockIds[tableIndex]); onlyForInternal.Value = cardDataBlockIds[tableIndex].ToString(); dataBlock.CloseConnection(); VehiclePreviewButtonsPanel.Visible = true; Vehicles_FileContents(null, null); ShowVehiclesStatistics(null, null); } } else if (Session["DeleteCommmand"].ToString() == "RemoveParsedData") { DelGridCommand(sender, e); } else if (Session["DeleteCommmand"].ToString() == "RemoveUnparsedData") { int number = Convert.ToInt32(e.Item.Cells[2].Text); dataBlockIds = dataBlock.GetAllUnparsedDataBlockIDs(orgId); int dataBlockId = dataBlockIds[number - 1]; dataBlock = new DataBlock(connectionString, dataBlockId, ConfigurationManager.AppSettings["language"]); dataBlock.DeleteDataBlockAndRecords(); LoadAllLists(); } else if (Session["DeleteCommmand"].ToString() == "RemoveDriversFile") { int rightIdToDelete = -1; string name = e.Item.Cells[3].Text; int recordsCount = int.Parse(e.Item.Cells[7].Text); dataBlockIds = dataBlock.GetDataBlockIdByRecordsCount(recordsCount); if (dataBlockIds.Count == 1) rightIdToDelete = dataBlockIds[0]; else if (dataBlockIds.Count > 1) { string nameTemp; foreach (int blockId in dataBlockIds) { nameTemp = dataBlock.GetDriversNameOrVehiclesNumberByBlockId(blockId); if (nameTemp == name) { rightIdToDelete = blockId; break; } } } else throw new Exception("Нет доступа к информации(или нет данных для удаления)"); if (rightIdToDelete != -1) { dataBlock = new DataBlock(connectionString, rightIdToDelete, ConfigurationManager.AppSettings["language"]); dataBlock.DeleteDataBlockAndRecords(); ManagmentLoadedInfo_SelectedNodeChanged(null, null); } } else if (Session["DeleteCommmand"].ToString() == "RecoverDriversFile") { int tableIndex = Convert.ToInt32(e.Item.Cells[2].Text) - 1; int cardId = Convert.ToInt32(UserFileRecover_TreeView.SelectedValue); List<int> filesIds = new List<int>(); dataBlock.OpenConnection(); filesIds = dataBlock.cardsTable.GetAllDataBlockIds_byCardId(cardId); int dataBlockId = filesIds[tableIndex]; onlyForInternal.Value = dataBlockId.ToString(); byte[] fileBytes = dataBlock.GetDataBlock_BytesArray(dataBlockId); string fileName = dataBlock.GetDataBlock_FileName(dataBlockId); dataBlock.CloseConnection(); Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=" + fileName); Response.AddHeader("Content-Length", fileBytes.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.OutputStream.Write(fileBytes, 0, fileBytes.Length); Response.End(); Page.ClientScript.RegisterStartupScript(this.GetType(), "submit", "javascript:document.form1.submit()", true); } } catch (Exception ex) { Status.Text = ex.Message; StatusUpdatePanel.Update(); } finally { ModalPopupExtender1.Hide(); } }
public static bool ParseDataBlocks(String OrgID, String UserName) { string connectionString = ConfigurationManager.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); PLFUnit.PLFUnitClass plfForXml = new PLFUnit.PLFUnitClass(); List<int> dataBlockIDs = new List<int>(); int filesCounter = 0; object parsedObject; try { dataBlock.OpenConnection(); dataBlock.OpenTransaction(); int userId = dataBlock.usersTable.Get_UserID_byName(UserName); int orgId = int.Parse(OrgID); dataBlockIDs = dataBlock.GetAllUnparsedDataBlockIDs(orgId); if (dataBlockIDs.Count == 0) { return true; } string output = ""; foreach (int blockId in dataBlockIDs) { dataBlock.SetDataBlockIdForParse(blockId); dataBlock.SetOrgIdForParse(orgId); string state = dataBlock.GetDataBlockState(blockId); if (state.Equals("Not parsed")) { output = HttpContext.Current.Server.MapPath("~/XML_PLF") + "\\"; parsedObject = dataBlock.ParseRecords(true, output, userId); filesCounter++; } } dataBlock.CommitTransaction(); dataBlock.CloseConnection(); return true; } catch (Exception ex) { dataBlock.RollbackConnection(); dataBlock.CloseConnection(); throw ex; //return false; } }
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(); } }
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; } }
protected void Parse_Click(object Sender, EventArgs e) { string connectionString = ConfigurationSettings.AppSettings["fleetnetbaseConnectionString"]; DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]); PLFUnit.PLFUnitClass plfForXml = new PLFUnit.PLFUnitClass(); List<int> dataBlockIDs = new List<int>(); int cardType = 0; int filesCounter = 0; object parsedObject; try { dataBlock.OpenConnection(); dataBlock.OpenTransaction(); int userId = dataBlock.usersTable.Get_UserID_byName(User.Identity.Name); int orgId = Convert.ToInt32(Session["CURRENT_ORG_ID"]); dataBlockIDs = dataBlock.GetAllUnparsedDataBlockIDs(orgId); if (dataBlockIDs.Count == 0) throw new Exception("Отсутствуют данные для разбора."); string output = ""; foreach (int blockId in dataBlockIDs) { dataBlock.SetDataBlockIdForParse(blockId); dataBlock.SetOrgIdForParse(orgId); //dataBlock = new DataBlock(connectionString, blockId, ConfigurationManager.AppSettings["language"], orgId); if (dataBlock.GetDataBlockState(blockId) == "Not parsed") { output = Server.MapPath("~/XML_PLF") + "\\"; parsedObject = dataBlock.ParseRecords(true, output, userId); filesCounter++; } else continue; } dataBlock.CommitTransaction(); dataBlock.CloseConnection(); LoadAllLists(); if (filesCounter > 0) Status.Text = "Файлы разобраны успешно! Разобрано " + filesCounter.ToString() + " файлов."; else Status.Text = "Не разобрано ни одного файла."; } catch (Exception ex) { dataBlock.RollbackConnection(); dataBlock.CloseConnection(); LoadAllLists(); Status.Text = "Ошибка: " + ex.Message; } finally { StatusUpdatePanel.Update(); ModalPopupExtender1.Hide(); } }