示例#1
0
    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();
        }
    }
示例#2
0
    protected void DelGridCommand(Object sender, DataGridCommandEventArgs e)
    {
        string connectionString = ConfigurationSettings.AppSettings["fleetnetbaseConnectionString"];
        DataBlock dataBlock = new DataBlock(connectionString, ConfigurationManager.AppSettings["language"]);
        List<int> dataBlockIds = new List<int>();
        int cardType;
        Status.Text = "";
        try
        {
            if (((ImageButton)e.CommandSource).CommandName == "RemoveData")
            {
                DeleteStructure delStr = new DeleteStructure();
                int rightIdToDelete = -1;
                delStr.name = e.Item.Cells[3].Text;
                delStr.createTime = e.Item.Cells[6].Text;
                delStr.recordsCount = int.Parse(e.Item.Cells[5].Text);
                dataBlockIds = dataBlock.GetDataBlockIdByRecordsCount(delStr.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 == delStr.name)
                            {
                                rightIdToDelete = blockId;
                                break;
                            }
                        }
                        //Обязательно сделать проверку, по дате добавления...(будет не лишним по-любому!)
                    }
                    else
                        throw new Exception("Нет доступа к информации(или нет данных для удаления)");
                if (rightIdToDelete != -1)
                {
                    dataBlock = new DataBlock(connectionString, rightIdToDelete, ConfigurationManager.AppSettings["language"]);
                    dataBlock.DeleteDataBlockAndRecords();
                    LoadAllDeleteLists();
                }
                else throw new Exception("Не найдена запись для удаления");
            }
        }
        catch (Exception ex)
        {
            Status.Text = ex.Message;
        }
    }
示例#3
0
    public static bool RemoveItemUnparsedDataBlocks(String DataBlockID)
    {
        try
        {
            int dataBlockID = int.Parse(DataBlockID);
            string connectionString = ConfigurationManager.AppSettings["fleetnetbaseConnectionString"];
            DataBlock dataBlock = new DataBlock(connectionString, dataBlockID, ConfigurationManager.AppSettings["language"]);
            dataBlock.DeleteDataBlockAndRecords();

            dataBlock.CloseConnection();

            return true;
        }
        catch (Exception ex)
        {
            throw ex;
            //return false;
        }
    }