Exemplo n.º 1
0
        protected void EBtnSubmit_Click(object sender, EventArgs e)
        {
            if (!this.Page.IsValid)
            {
                return;
            }
            int modelId = BasePage.RequestInt32("ModelID");
            IList <FieldInfo> fieldList = EasyOne.CommonModel.Field.GetFieldList(modelId);
            int orderId = 0;

            foreach (FieldInfo info in fieldList)
            {
                if (info.OrderId > orderId)
                {
                    orderId = info.OrderId;
                }
            }
            orderId++;
            FieldInfo fieldInfo = new FieldInfo();

            fieldInfo.Id          = DataSecurity.FilterBadChar(this.TxtFieldName.Text.Trim());
            fieldInfo.FieldName   = DataSecurity.FilterBadChar(this.TxtFieldName.Text.Trim());
            fieldInfo.FieldAlias  = this.TxtFieldAliax.Text.Trim();
            fieldInfo.Description = this.TxtDescription.Text.Trim();
            fieldInfo.Tips        = this.TxtTips.Text;
            fieldInfo.EnableNull  = DataConverter.CBoolean(this.RadlEnableNull.SelectedValue);
            fieldInfo.FieldType   = (FieldType)Enum.Parse(typeof(FieldType), this.HdnFieldType.Value);
            fieldInfo.CopyToSettings(this.GetSettingsByFieldType((FieldType)Enum.Parse(typeof(FieldType), this.HdnFieldType.Value)));
            fieldInfo.OrderId  = orderId;
            fieldInfo.Disabled = false;
            fieldInfo.EnableShowOnSearchForm = DataConverter.CBoolean(this.RadlEnableShowOnSearchForm.SelectedValue);
            fieldInfo.DefaultValue           = this.GetDefaultValue((FieldType)Enum.Parse(typeof(FieldType), this.HdnFieldType.Value));
            DataActionState unknown = DataActionState.Unknown;
            string          str     = null;

            if ((fieldInfo.FieldType == FieldType.FileType) && DataConverter.CBoolean(fieldInfo.Settings[3]))
            {
                if (string.IsNullOrEmpty(fieldInfo.Settings[4]))
                {
                    AdminPage.WriteErrMsg("<li>记录文件大小字段名不能为空!</li>");
                }
                if (string.Compare(fieldInfo.Settings[4], fieldInfo.FieldName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    AdminPage.WriteErrMsg("<li>保存文件大小的字段名不能与主字段名重复!</li>");
                }
            }
            string str2 = this.ViewState["action"].ToString();

            if (str2 != null)
            {
                if (!(str2 == "Add"))
                {
                    if (str2 == "Copy")
                    {
                        fieldInfo.FieldLevel = 1;
                        unknown = EasyOne.CommonModel.Field.Add(fieldInfo, modelId);
                        str     = "复制";
                        goto Label_035A;
                    }
                }
                else
                {
                    str = "添加";
                    fieldInfo.FieldLevel = 1;
                    unknown = EasyOne.CommonModel.Field.Add(fieldInfo, modelId);
                    if (unknown == DataActionState.Successed)
                    {
                        UserPermissions.AddFieldPermission(this.EChkGroupList.SelectList(), modelId, fieldInfo.FieldName, OperateCode.ContentFieldInput, 1);
                        RolePermissions.AddFieldPermissionToRoles(this.EChkRoleList.SelectList(), modelId, fieldInfo.FieldName, OperateCode.ContentFieldInput);
                    }
                    goto Label_035A;
                }
            }
            str = "修改";
            fieldInfo.FieldLevel = DataConverter.CLng(this.HdnFieldLevel.Value);
            fieldInfo.OrderId    = DataConverter.CLng(this.HdnOrderId.Value);
            fieldInfo.Disabled   = DataConverter.CBoolean(this.HdnDisabled.Value);
            unknown = EasyOne.CommonModel.Field.Update(fieldInfo, modelId);
            if (unknown == DataActionState.Successed)
            {
                UserPermissions.AddFieldPermission(this.EChkGroupList.SelectList(), modelId, fieldInfo.FieldName, OperateCode.ContentFieldInput, 1);
                RolePermissions.AddFieldPermissionToRoles(this.EChkRoleList.SelectList(), modelId, fieldInfo.FieldName, OperateCode.ContentFieldInput);
            }
Label_035A:
            switch (unknown)
            {
            case DataActionState.Successed:
                AdminPage.WriteSuccessMsg("<li>字段" + str + "成功!</li>", string.Concat(new object[] { "FieldManage.aspx?ModelType=", BasePage.RequestInt32("ModelType").ToString(), "&ModelID=", modelId, "&ModelName=", HttpUtility.UrlEncode(this.m_ModelName) }));
                return;

            case DataActionState.Exist:
                AdminPage.WriteErrMsg("<li>该模型下已经存在此字段,请指定其它的字段!</li>");
                return;

            case DataActionState.Unknown:
                AdminPage.WriteErrMsg("<li>对不起,字段" + str + "失败!</li>");
                return;

            default:
                return;
            }
        }