Beispiel #1
0
    private void SetTheValue()
    {
        // Get binding object
        BaseInfo bindingObj = CMSObjectHelper.GetObject(BindingObjectType);

        // Build where condition (select only bindings of the current site)
        string where = bindingObj.TypeInfo.SiteIDColumn + "=" + SiteID;

        // Initialize selector from retrieved data
        DataSet ds = bindingObj.Generalized.GetData(null, where, null, 0, null, false);

        currentValues = TextHelper.Join(";", SystemDataHelper.GetStringValues(ds.Tables[0], bindingObj.TypeInfo.ParentIDColumn));
        if (!RequestHelper.IsPostBack())
        {
            Value = currentValues;
        }
    }
    /// <summary>
    /// Fills dropdown list with column names
    /// </summary>
    protected void SetupControl()
    {
        drpColumn.Items.Clear();

        // Get object by object type
        GeneralizedInfo generalObject = CMSObjectHelper.GetObject(ObjectType);

        if (generalObject != null)
        {
            FormInfo fi = FormHelper.GetFormInfo(generalObject.ObjectClassName, false);
            if (fi != null)
            {
                // Get fields except the primary key
                var fields = fi.GetFields(true, ShowAllColumns).Where(f => !f.PrimaryKey);

                // Sort fields by visibility and caption or name
                fields = fields.OrderByDescending(f => f.Visible).ThenBy(f => UseColumnCaption ? (string.IsNullOrEmpty(f.Caption) ? f.Name : f.Caption) : f.Name);

                foreach (FormFieldInfo field in fields)
                {
                    if (UseColumnCaption && !String.IsNullOrEmpty(field.Caption))
                    {
                        drpColumn.Items.Add(new ListItem(field.Caption, field.Name));
                    }
                    else
                    {
                        drpColumn.Items.Add(field.Name);
                    }
                }
            }
        }

        if (selectedColumn != String.Empty)
        {
            // Select selected column
            ListItem item = drpColumn.Items.FindByValue(ValidationHelper.GetString(selectedColumn, String.Empty));
            if (item != null)
            {
                item.Selected = true;
            }
        }
    }
Beispiel #3
0
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        GeneralizedInfo parentObject = CMSObjectHelper.GetObject(currentObject.ParentObjectType);

        // Check if object or parent are site related
        if (((parentObject != null) && (parentObject.SiteIDColumn != TypeInfo.COLUMN_NAME_UNKNOWN)) || (currentObject.SiteIDColumn != TypeInfo.COLUMN_NAME_UNKNOWN))
        {
            // Initialize site selector
            siteSelector.Reload(false);
            siteSelector.PostbackOnDropDownChange = true;
            siteSelector.DropDownSingleSelect.SelectedIndexChanged += new EventHandler(DropDownSingleSelect_SelectedIndexChanged);

            // Check if global is allowed else select current site
            if (((parentObject != null) && parentObject.TypeInfo.SupportsGlobalObjects) || (currentObject.TypeInfo.SupportsGlobalObjects))
            {
                siteSelector.AllowGlobal = true;
            }
            else
            {
                if (!URLHelper.IsPostback())
                {
                    siteSelector.Value = CMSContext.CurrentSiteID;
                }
            }
        }
        else
        {
            plcSite.Visible = false;
        }

        if ((parentObject != null) && (parentObject.SiteIDColumn != TypeInfo.COLUMN_NAME_UNKNOWN))
        {
            // Get site where condition
            parentSelector.WhereCondition = siteSelector.GetSiteWhereCondition(parentObject.SiteIDColumn);
            parentSelector.Reload(true);
        }
    }
Beispiel #4
0
    /// <summary>
    /// Initialize filter controls.
    /// </summary>
    private void SetupControl()
    {
        if ((Parameters != null) && (Parameters["ObjectType"] != null))
        {
            // Get current object
            currentObject = CMSObjectHelper.GetObject(ValidationHelper.GetString(Parameters["ObjectType"], String.Empty));

            // Check if object is not null and has parent object
            if ((currentObject != null) && !String.IsNullOrEmpty(currentObject.ParentObjectType))
            {
                lblParent.ResourceString = "objecttype." + currentObject.ParentObjectType.Replace(".", "_");

                // Set parent object selector properties
                parentSelector.ObjectType = currentObject.ParentObjectType;
                parentSelector.DropDownSingleSelect.AutoPostBack = true;
                parentSelector.OnSelectionChanged += new EventHandler(parentSelector_OnSelectionChanged);
            }
            else
            {
                plcParentObject.Visible = false;
            }
        }
    }
    /// <summary>
    /// Compare DataSets.
    /// </summary>
    /// <param name="ds">Original DataSet</param>
    /// <param name="compareDs">DataSet to compare</param>
    private void CompareDataSets(DataSet ds, DataSet compareDs)
    {
        Table = new Table();
        SetTable(Table);
        Table.CssClass += " NoSideBorders";

        // Ensure same tables in DataSets
        EnsureSameTables(ds, compareDs);
        EnsureSameTables(compareDs, ds);

        // Prepare list of tables
        SortedDictionary <string, string> tables = new SortedDictionary <string, string>();

        foreach (DataTable dt in ds.Tables)
        {
            string excludedTableNames = (ExcludedTableNames != null) ? ";" + ExcludedTableNames.Trim(';').ToLowerCSafe() + ";" : "";
            string tableName          = dt.TableName;
            if (!DataHelper.DataSourceIsEmpty(ds.Tables[tableName]) || !DataHelper.DataSourceIsEmpty(CompareDataSet.Tables[tableName]))
            {
                if (!excludedTableNames.Contains(";" + tableName.ToLowerCSafe() + ";"))
                {
                    tables.Add(GetString("ObjectType." + tableName), tableName);
                }
            }
        }

        // Generate the tables
        foreach (string tableName in tables.Values)
        {
            DataTable dt        = ds.Tables[tableName].Copy();
            DataTable dtCompare = CompareDataSet.Tables[tableName].Copy();

            if (dt.PrimaryKey.Length <= 0)
            {
                continue;
            }

            // Add table heading
            if ((tables.Count > 1) || (ds.Tables.Count > 1))
            {
                AddTableHeaderRow(Table, GetTableHeaderText(dt), ((Table.Rows.Count > 0) ? "TableSeparator " : "") + "NoSideBorders");
            }

            while (dt.Rows.Count > 0 || dtCompare.Rows.Count > 0)
            {
                // Add table header row
                TableCell labelCell = new TableHeaderCell();
                labelCell.Text = GetString("General.FieldName");
                TableCell valueCell = new TableHeaderCell();
                valueCell.Text = GetString("General.Value");
                TableCell valueCompare = new TableHeaderCell();
                valueCompare.Text = GetString("General.Value");

                AddRow(Table, labelCell, valueCell, valueCompare, "UniGridHead", false);

                DataRow srcDr = null;
                DataRow dstDr = null;

                if ((tables.Count == 1) && (dt.Rows.Count == 1) && (dtCompare.Rows.Count == 1))
                {
                    srcDr = dt.Rows[0];
                    dstDr = dtCompare.Rows[0];
                }
                else
                {
                    if (!DataHelper.DataSourceIsEmpty(dt))
                    {
                        srcDr = dt.Rows[0];
                        dstDr = dtCompare.Rows.Find(GetPrimaryColumnsValue(dt, srcDr));
                    }
                    else
                    {
                        dstDr = dtCompare.Rows[0];
                        srcDr = dt.Rows.Find(GetPrimaryColumnsValue(dtCompare, dstDr));
                    }

                    // If match not find, try to find in guid column
                    if ((srcDr == null) || (dstDr == null))
                    {
                        DataTable dtToSearch = null;
                        DataRow   drTocheck  = null;

                        if (srcDr == null)
                        {
                            dtToSearch = dt;
                            drTocheck  = dstDr;
                        }
                        else
                        {
                            dtToSearch = dtCompare;
                            drTocheck  = srcDr;
                        }


                        GeneralizedInfo infoObj = CMSObjectHelper.GetObject(drTocheck, dt.TableName.Replace("_", "."));
                        if ((infoObj != null) && ((infoObj.CodeNameColumn != TypeInfo.COLUMN_NAME_UNKNOWN) || (infoObj.GUIDColumn != TypeInfo.COLUMN_NAME_UNKNOWN)))
                        {
                            DataRow[] rows = dtToSearch.Select(infoObj.CodeNameColumn + "='" + drTocheck[infoObj.CodeNameColumn] + "'");
                            if (rows.Length > 0)
                            {
                                if (srcDr == null)
                                {
                                    srcDr = rows[0];
                                }
                                else
                                {
                                    dstDr = rows[0];
                                }
                            }
                            else
                            {
                                rows = dtToSearch.Select(infoObj.GUIDColumn + "='" + drTocheck[infoObj.GUIDColumn] + "'");
                                if (rows.Length > 0)
                                {
                                    if (srcDr == null)
                                    {
                                        srcDr = rows[0];
                                    }
                                    else
                                    {
                                        dstDr = rows[0];
                                    }
                                }
                            }
                        }
                    }
                }

                // Add values
                bool even = false;
                foreach (DataColumn dc in dt.Columns)
                {
                    // Get content values
                    string fieldContent        = GetRowColumnContent(srcDr, dc, true);
                    string fieldCompareContent = GetRowColumnContent(dstDr, dc, true);

                    if (ShowAllFields || !String.IsNullOrEmpty(fieldContent) || !String.IsNullOrEmpty(fieldCompareContent))
                    {
                        // Initialize comparators
                        TextComparison comparefirst = new TextComparison();
                        comparefirst.SynchronizedScrolling = false;
                        comparefirst.ComparisonMode        = TextComparisonModeEnum.PlainTextWithoutFormating;
                        comparefirst.EnsureHTMLLineEndings = true;

                        TextComparison comparesecond = new TextComparison();
                        comparesecond.SynchronizedScrolling = false;
                        comparesecond.RenderingMode         = TextComparisonTypeEnum.DestinationText;
                        comparesecond.EnsureHTMLLineEndings = true;

                        comparefirst.PairedControl = comparesecond;

                        // Set comparator content
                        comparefirst.SourceText      = fieldContent;
                        comparefirst.DestinationText = fieldCompareContent;

                        // Create set of cells
                        labelCell      = new TableCell();
                        labelCell.Text = "<strong>" + dc.ColumnName + "</strong>";
                        valueCell      = new TableCell();
                        valueCell.Controls.Add(comparefirst);
                        valueCompare = new TableCell();
                        valueCompare.Controls.Add(comparesecond);

                        // Add comparison row
                        AddRow(Table, labelCell, valueCell, valueCompare, null, even);
                        even = !even;
                    }
                }

                // Remove rows from tables
                if (srcDr != null)
                {
                    dt.Rows.Remove(srcDr);
                }
                if (dstDr != null)
                {
                    dtCompare.Rows.Remove(dstDr);
                }

                if (dt.Rows.Count > 0 || dtCompare.Rows.Count > 0)
                {
                    TableCell emptyCell = new TableCell();
                    emptyCell.Text = "&nbsp;";
                    AddRow(Table, emptyCell, null, null, "TableSeparator", false);
                    even = false;
                }
            }
        }
        plcContent.Controls.Add(Table);
    }
Beispiel #6
0
    protected void usObjects_OnSelectionChanged(object sender, EventArgs e)
    {
        // Get new selection from selector
        string newValues = ValidationHelper.GetString(usObjects.Value, null);

        // Compare with previous selection and get items to remove
        string items = DataHelper.GetNewItemsInList(newValues, currentValues);

        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            // Remove items from site
            foreach (string item in newItems)
            {
                // Get identifier of parent object
                int parentId = ValidationHelper.GetInteger(item, 0);

                // Get binding object based on type
                BaseInfo bindingObj = CMSObjectHelper.GetObject(BindingObjectType);

                // Initialize values of removed object to allow recognition
                bindingObj.SetValue(bindingObj.TypeInfo.SiteIDColumn, SiteID);
                bindingObj.SetValue(bindingObj.TypeInfo.ParentIDColumn, parentId);

                // Get existing object if binding object has identifying column
                if (bindingObj.TypeInfo.IDColumn != TypeInfo.COLUMN_NAME_UNKNOWN)
                {
                    bindingObj = bindingObj.Generalized.GetExisting();
                }

                // Delete the binding
                bindingObj.Generalized.DeleteObject();
            }
        }


        // Compare with previous selection and get items to add
        items = DataHelper.GetNewItemsInList(currentValues, newValues);
        if (!String.IsNullOrEmpty(items))
        {
            string[] newItems = items.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            // Add all new items to site
            foreach (string item in newItems)
            {
                // Get identifier of parent object
                int parentId = ValidationHelper.GetInteger(item, 0);

                // Get binding object based on type
                BaseInfo bindingObj = CMSObjectHelper.GetObject(BindingObjectType);

                // Initialize values
                bindingObj.SetValue(bindingObj.TypeInfo.SiteIDColumn, SiteID);
                bindingObj.SetValue(bindingObj.TypeInfo.ParentIDColumn, parentId);

                // Insert new object
                bindingObj.Generalized.SetObject();
            }
        }

        ShowChangesSaved();
    }
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        filteredControl = FilteredControl as CMSUserControl;

        siteSelector.DropDownSingleSelect.AutoPostBack = true;
        siteSelector.UniSelector.OnSelectionChanged   += Site_Changed;
        siteSelector.UniSelector.DialogWindowName      = "SiteSelectionDialog";
        siteSelector.IsLiveSite = IsLiveSite;

        // All cultures field in cultures mode
        switch (FilterMode)
        {
        case "cultures":
        {
            siteSelector.AllowEmpty = false;
            siteSelector.AllowAll   = false;
            siteSelector.UniSelector.SpecialFields = new string[, ] {
                { ResHelper.GetString("general.allcultures"), string.Empty }
            };
        }
        break;

        case "role":
        {
            siteSelector.AllowEmpty  = false;
            siteSelector.AllowAll    = false;
            siteSelector.AllowGlobal = true;
        }
        break;

        case "user":
        {
            siteSelector.AllowAll   = true;
            siteSelector.AllowEmpty = false;
        }
        break;

        case "notificationtemplate":
        {
            siteSelector.AllowEmpty = false;
            siteSelector.AllowAll   = false;
        }
        break;

        case "notificationtemplateglobal":
        {
            siteSelector.AllowEmpty = false;
            siteSelector.AllowAll   = false;
            siteSelector.UniSelector.SpecialFields = new string[, ] {
                { ResHelper.GetString("general.global"), "" }
            };
        }
        break;

        case "department":
        {
            siteSelector.AllowEmpty  = false;
            siteSelector.AllowAll    = false;
            siteSelector.AllowGlobal = true;
        }
        break;

        default:
        {
            if ((Parameters != null) && (Parameters["ObjectType"] != null))
            {
                // Get object type
                GeneralizedInfo currentObject = CMSObjectHelper.GetObject(ValidationHelper.GetString(Parameters["ObjectType"], String.Empty));
                if (currentObject != null)
                {
                    // Show global value if supports global objects
                    if (currentObject.TypeInfo.SupportsGlobalObjects)
                    {
                        siteSelector.AllowGlobal = true;
                    }
                    siteSelector.AllowAll   = false;
                    siteSelector.AllowEmpty = false;
                    siteSelector.Value      = CMSContext.CurrentSiteID;
                }
            }
            else
            {
                // Use default settings
                siteSelector.AllowAll   = true;
                siteSelector.AllowEmpty = false;
                plcLabel.Visible        = false;
            }
        }
        break;
        }

        // Set initial filter value
        if (!RequestHelper.IsPostBack())
        {
            if (filteredControl != null)
            {
                int defaultValue = ValidationHelper.GetInteger(filteredControl.GetValue("DefaultFilterValue"), 0);

                if (defaultValue > 0)
                {
                    siteSelector.UniSelector.Value = defaultValue;
                    WhereCondition = GenerateWhereCondition(defaultValue);
                }
            }
        }
    }