Exemplo n.º 1
0
    private DataTable FillTable(BXIBlockTypeCollection collection, List<string> visibleColumnsList)
    {
        if (collection == null)
            collection = new BXIBlockTypeCollection();

        DataTable result = new DataTable();

        result.Columns.Add("TypeId", typeof(int));
        result.Columns.Add("Name", typeof(string));
        result.Columns.Add("Sort", typeof(int));
        result.Columns.Add("HaveSections", typeof(string));

        foreach (BXIBlockType t in collection)
        {
            DataRow r = result.NewRow();
            r["TypeId"] = t.Id;
            r["Name"] = t.Translations[BXLoc.CurrentLocale].Name;
            r["Sort"] = t.Sort;
            r["HaveSections"] = (t.HaveSections ? GetMessage("Kernel.Yes") : GetMessage("Kernel.No"));
            result.Rows.Add(r);
        }

        return result;
    }
Exemplo n.º 2
0
    protected void GridView1_Delete(object sender, BXDeleteEventArgs e)
    {
        BXGridView grid = (BXGridView)sender;
        try
        {
            BXIBlockTypeCollection elements;
            if (e.Keys != null) //Delete one element
            {
                elements = new BXIBlockTypeCollection();

                int typeId;
                Int32.TryParse(e.Keys["TypeId"].ToString(), out typeId);

                if (typeId <= 0)
                    throw new PublicException(GetMessageRaw("Error.CodeOfTypeIsNotFound"));

                BXIBlockType elem = BXIBlockType.GetById(typeId);
                if (elem == null)
                    throw new PublicException(GetMessageRaw("Exception.TypeIsNotFound"));
                elements.Add(elem);

            }
            else //All elements
            {
                elements = BXIBlockType.GetList(new BXFilter(MakeCurrentFilter(), BXIBlockType.Fields), null);
            }
            int iblocksCount;
            int delErrorCount = 0;
            string elemName;
            foreach (BXIBlockType element in elements)
            {
                if (element == null)
                    throw new PublicException(GetMessageRaw("Exception.ElementIsNotFound"));

                if (!currentUserCanModifyType)
                    throw new PublicException(GetMessageRaw("Exception.YouDontHaveRightsToDeleteThisRecord"));

                iblocksCount = BXIBlock.Count(new BXFilter(new BXFilterItem(BXIBlock.Fields.Type.ID, BXSqlFilterOperators.Equal, element.Id)));
                elemName = element.Translations[BXLoc.CurrentLocale].Name;
                if (iblocksCount > 0)
                {
                    delErrorCount++;
                    errorMessage.AddErrorText(String.Format(GetMessageRaw("Exception.IBlockTypeContainsIBlocks"),BXTextEncoder.HtmlTextEncoder.Decode(elemName) ));
                }
                else
                {

                    //throw new PublicException(GetMessageRaw("Exception.AnErrorHasOccurredWhileDeletingElement"));
                    //successMessage.AddErrorText(String.Format("\"{0}\"", BXTextEncoder.HtmlTextEncoder.Decode(element.Translations[BXLoc.CurrentLocale].Name)));
                    BXIBlockType.Delete(element.Id);
                    deletedList.Append(String.Format("<li>\"{0}\"</li>",elemName ));
                    e.DeletedCount++;
                }
            }
            if (delErrorCount == 0)
                successMessage.Visible = true;
        }
        catch (Exception ex)
        {
            ProcessException(ex, errorMessage.AddErrorText);

        }
        
        grid.MarkAsChanged();
    }