Пример #1
0
        private void dg_update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            int     ItemID  = int.Parse(e.Item.Cells[0].Text);
            TextBox tb      = (TextBox)e.Item.FindControl("tbName");
            int     _weight = 0;
            TextBox tbW     = (TextBox)e.Item.FindControl("tbWeight");

            if (tbW != null && tbW.Text.Length > 0)
            {
                _weight = int.Parse(tbW.Text);
            }
            if (tb != null)
            {
                try
                {
                    if (ItemID > 0)
                    {
                        Dictionaries.UpdateItem(ItemID, tb.Text, _weight, (DictionaryTypes)iDictionaryType);
                    }
                    else
                    {
                        Dictionaries.AddItem(tb.Text, _weight, (DictionaryTypes)iDictionaryType);
                    }
                }
                catch (SqlException ex)
                {
                    if (ex.Number == 2627)                      // Violation of UNIQUE KEY
                    {
                        lblError.Visible = true;
                        lblError.Text    = LocRM.GetString("Duplication") + "<br>";
                    }
                }
            }

            dgDic.EditItemIndex = -1;
            BindDG();
        }
Пример #2
0
        private void dg_update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            string dictionaryName = ddDictionaries.SelectedItem.Value;

            if (dictionaryName == ListManager.ListTypeEnumName)
            {
                MetaFieldType mft = Mediachase.Ibn.Core.MetaDataWrapper.GetEnumByName(dictionaryName);

                int ItemId = int.Parse(e.CommandArgument.ToString());

                TextBox      tb      = (TextBox)e.Item.FindControl("txtName");
                DropDownList ddl     = (DropDownList)e.Item.FindControl("ddlOrder");
                int          OrderId = int.Parse(ddl.SelectedValue);

                if (tb != null && tb.Text.Trim() != String.Empty)
                {
                    if (ItemId > 0)
                    {
                        MetaEnum.UpdateItem(mft, ItemId, tb.Text.Trim(), OrderId);
                    }
                    else
                    {
                        MetaEnum.AddItem(mft, tb.Text.Trim(), OrderId);
                    }
                }
                dgEnum.EditItemIndex = -1;
            }
            else
            {
                int             ItemID  = int.Parse(e.Item.Cells[0].Text);
                DictionaryTypes dic     = (DictionaryTypes)Enum.Parse(typeof(DictionaryTypes), ddDictionaries.SelectedItem.Value);
                TextBox         tb      = (TextBox)e.Item.FindControl("tbName");
                int             _weight = 0;
                TextBox         tbW     = (TextBox)e.Item.FindControl("tbWeight");
                if (tbW != null && tbW.Text.Length > 0)
                {
                    _weight = int.Parse(tbW.Text);
                }
                if (tb != null)
                {
                    try
                    {
                        if (ItemID > 0)
                        {
                            Dictionaries.UpdateItem(ItemID, tb.Text, _weight, dic);
                        }
                        else
                        {
                            Dictionaries.AddItem(tb.Text, _weight, dic);
                        }
                    }
                    catch (SqlException ex)
                    {
                        if (ex.Number == 2627)                          // Violation of UNIQUE KEY
                        {
                            lblError.Visible = true;
                            lblError.Text    = "<br><br>" + LocRM.GetString("Duplication");
                        }
                    }
                }
                dgDic.EditItemIndex = -1;
            }

            BindDG();
        }