Exemplo n.º 1
0
    /// <summary>
    /// Updating row in the grid
    /// </summary>
    /// <param name="sender">Grid View</param>
    /// <param name="e">Event args</param>
    void grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        // extract and store input values in the collection
        StringCollection updateValues = new StringCollection();

        foreach (DataControlFieldCell cel in grid.Rows[e.RowIndex].Controls)
        {
            foreach (Control ctl in cel.Controls)
            {
                if (ctl.GetType().Name == "TextBox")
                {
                    TextBox txt = (TextBox)ctl;
                    updateValues.Add(txt.Text);
                }
            }
        }

        int paramIndex = ParameterValueIndex(sender, e.RowIndex);

        for (int i = 0; i < _settings.Parameters.Count; i++)
        {
            string parName = _settings.Parameters[i].Name;
            if (_settings.IsRequiredParameter(parName) && string.IsNullOrEmpty(updateValues[i]))
            {
                // throw error if required field is empty
                ErrorMsg.InnerHtml = "\"" + _settings.GetLabel(parName) + "\" is a required field";
                ErrorMsg.Visible   = true;
                e.Cancel           = true;
                return;
            }
            else if (parName == _settings.KeyField && _settings.IsKeyValueExists(updateValues[i]))
            {
                // check if key value was changed; if not, it's ok to update
                if (!_settings.IsOldValue(parName, updateValues[i], paramIndex))
                {
                    // trying to update key field with value that already exists
                    ErrorMsg.InnerHtml = "\"" + updateValues[i] + "\" is already exists";
                    ErrorMsg.Visible   = true;
                    e.Cancel           = true;
                    return;
                }
            }
            else
            {
                _settings.Parameters[i].Values[paramIndex] = updateValues[i];
            }
        }

        ExtensionManager.SaveSettings(_extensionName, _settings);
        Response.Redirect(Request.RawUrl);
    }
Exemplo n.º 2
0
        /// <summary>
        /// The init custom filters.
        /// </summary>
        private static void InitCustomFilters()
        {
            var settings = new ExtensionSettings("BeCustomFilters");

            settings.AddParameter("FullName", "Name", 100, true, true);
            settings.AddParameter("Name");
            settings.AddParameter("Checked");
            settings.AddParameter("Cought");
            settings.AddParameter("Reported");
            settings.AddParameter("Priority");

            customFilters = ExtensionManager.InitSettings("MetaExtension", settings);
            if (customFilters == null)
            {
                return;
            }

            var dt             = customFilters.GetDataTable();
            var codeAssemblies = Utils.CodeAssemblies();

            foreach (var type in
                     codeAssemblies.Cast <Assembly>().Select(a => a.GetTypes()).SelectMany(
                         types => (from type in types
                                   where type.GetInterface("BlogEngine.Core.ICustomFilter") != null
                                   let found = dt.Rows.Cast <DataRow>().Any(row => row[0].ToString() == type.Name)
                                               where !found
                                               select type)))
            {
                // if new filter found in the assembly, add it to settings
                if (!customFilters.IsKeyValueExists(type.FullName))
                {
                    customFilters.AddValues(new[] { type.FullName, type.Name, "0", "0", "0", "0" });
                    ExtensionManager.SaveSettings("MetaExtension", customFilters);
                }
            }
        }