Пример #1
0
        protected void btnok_Click(object sender, System.EventArgs e)
        {
            if (base.Action.Equals(ActionType.Add.ToString()) && !base.IsAuthorizedOp(ActionType.Add.ToString()))
            {
                base.ShowMsg("Không có thẩm quyền");
            }
            else if (base.Action.Equals(ActionType.Modify.ToString()) && !base.IsAuthorizedOp(ActionType.Modify.ToString()))
            {
                base.ShowMsg("Không có thẩm quyền");
            }
            else
            {
                SettingInfo settingInfo = new SettingInfo();
                if (base.IsEdit)
                {
                    settingInfo = SettingProvider.GetEntityById(base.OpID);
                }
                settingInfo.KeyName = WebUtils.GetString(this.TextBox1.Text);
                settingInfo.CateID  = ((this.cate == null) ? 0 : this.cate.AutoID);
                settingInfo.KeyDesc = WebUtils.GetString(this.TextBox3.Text);
                if (settingInfo.CateID == 0)
                {
                    base.ShowMsg("Chọn phân loại Cấu hình");
                }
                else if (string.IsNullOrEmpty(settingInfo.KeyName))
                {
                    base.ShowMsg("Cấu hình tên chủ chốt không thể để trống");
                }
                else if (string.IsNullOrEmpty(settingInfo.KeyDesc))
                {
                    base.ShowMsg("Tên hiển thị không thể để trống");
                }
                else
                {
                    settingInfo.DataLength   = WebUtils.GetInt(this.ExtTextBox5.Text, 50);
                    settingInfo.ControlType  = this.DropDownList5.SelectedValue;
                    settingInfo.DefaultValue = WebUtils.GetString(this.TextBox6.Text);
                    SinGooCMS.Control.FieldSetting fieldSetting = new SinGooCMS.Control.FieldSetting();
                    fieldSetting.ControlWidth  = WebUtils.GetInt(this.ExtTextBox1.Text);
                    fieldSetting.ControlHeight = WebUtils.GetInt(this.ExtTextBox2.Text);
                    fieldSetting.TextMode      = this.ExtRadioButtonList3.SelectedValue;
                    fieldSetting.IsDataType    = settingInfo.ControlType.Equals(FieldType.DateTimeType);
                    fieldSetting.DataFormat    = WebUtils.GetString(this.ExtTextBox4.Text);
                    FieldType fieldType = (FieldType)System.Enum.Parse(typeof(FieldType), settingInfo.ControlType);
                    switch (fieldType)
                    {
                    case FieldType.MultipleTextType:
                    case FieldType.MultipleHtmlType:
                        settingInfo.DataType = "ntext";
                        break;

                    default:
                        if (fieldType != FieldType.DateTimeType)
                        {
                            settingInfo.DataType   = "nvarchar";
                            settingInfo.DataLength = WebUtils.GetInt(this.ExtTextBox5.Text, 50);
                        }
                        else
                        {
                            settingInfo.DataType = "datetime";
                        }
                        break;
                    }
                    fieldSetting.DataFrom = this.ExtDropDownList6.SelectedValue;
                    string dataFrom = fieldSetting.DataFrom;
                    if (dataFrom != null)
                    {
                        if (!(dataFrom == "Text"))
                        {
                            if (!(dataFrom == "DataDictionary"))
                            {
                                if (!(dataFrom == "SQLQuery"))
                                {
                                    if (dataFrom == "AjaxData")
                                    {
                                        fieldSetting.DataSource = WebUtils.GetString(this.ExtTextBox11.Text);
                                    }
                                }
                                else
                                {
                                    fieldSetting.DataSource = WebUtils.GetString(this.ExtTextBox9.Text);
                                }
                            }
                            else
                            {
                                fieldSetting.DataSource = WebUtils.GetString(this.ExtTextBox8.Text);
                            }
                        }
                        else
                        {
                            fieldSetting.DataSource = this.ExtTextBox7.Text;
                        }
                    }
                    settingInfo.Setting  = XmlSerializerUtils.Serialize <SinGooCMS.Control.FieldSetting>(fieldSetting);
                    settingInfo.IsUsing  = this.CheckBox7.Checked;
                    settingInfo.IsSystem = false;
                    settingInfo.Sort     = 9999;
                    if (base.Action.Equals(ActionType.Add.ToString()))
                    {
                        if (SettingProvider.ExistsByName(settingInfo.KeyName))
                        {
                            base.ShowMsg("Cấu hình tùy chỉnh cùng tên đã tồn tại");
                            return;
                        }
                        settingInfo.AutoTimeStamp = System.DateTime.Now;
                        if (SettingProvider.Add(settingInfo) > 0)
                        {
                            CacheUtils.Del("JsonLeeCMS_CacheForGetSetting");
                            CacheUtils.Del("JsonLeeCMS_CacheForSETTINGDIRECTORY");
                            PageBase.log.AddEvent(base.LoginAccount.AccountName, "Thêm cấu hình tùy chỉnh [" + settingInfo.KeyDesc + "] thành công");
                            base.Response.Redirect(string.Concat(new object[]
                            {
                                "CustomSetting.aspx?CatalogID=",
                                base.CurrentCatalogID,
                                "&Module=",
                                base.CurrentModuleCode,
                                "&cateid=",
                                this.cate.AutoID,
                                "&action=View"
                            }));
                        }
                        else
                        {
                            base.ShowMsg("Thêm cấu hình tùy chỉnh thất bại");
                        }
                    }
                    if (base.Action.Equals(ActionType.Modify.ToString()))
                    {
                        if (SettingProvider.Update(settingInfo))
                        {
                            CacheUtils.Del("JsonLeeCMS_CacheForGetSetting");
                            CacheUtils.Del("JsonLeeCMS_CacheForSETTINGDIRECTORY");
                            PageBase.log.AddEvent(base.LoginAccount.AccountName, "Sửa đổi các cấu hình tùy chỉnh [" + settingInfo.KeyDesc + "] thành công");
                            base.Response.Redirect(string.Concat(new object[]
                            {
                                "CustomSetting.aspx?CatalogID=",
                                base.CurrentCatalogID,
                                "&Module=",
                                base.CurrentModuleCode,
                                "&cateid=",
                                this.cate.AutoID,
                                "&action=View"
                            }));
                        }
                        else
                        {
                            base.ShowMsg("Sửa đổi các cấu hình tùy chỉnh thất bại");
                        }
                    }
                }
            }
        }