Esempio n. 1
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;
        }
    }