示例#1
0
 /// <summary>
 /// 新增字段
 /// </summary>
 /// <returns></returns>
 public ActionResult AddFields()
 {
     try
     {
         UserEntity   uInfo     = ViewData["Account"] as UserEntity;
         FieldsEntity entityAdd = new FieldsEntity();
         entityAdd.TabId           = int.Parse(Request["TabId"]);
         entityAdd.FieldName       = Request["FieldName"].Trim();
         entityAdd.FieldViewName   = Request["FieldViewName"].Trim();
         entityAdd.FieldDataTypeId = int.Parse(Request["FieldDataTypeId"]);
         entityAdd.IsActive        = bool.Parse(Request["IsActive"]);
         entityAdd.IsSearch        = bool.Parse(Request["IsSearch"]);
         entityAdd.CreateBy        = uInfo.AccountName;
         entityAdd.CreateTime      = DateTime.Now;
         entityAdd.UpdateBy        = uInfo.AccountName;
         entityAdd.UpdateTime      = DateTime.Now;
         entityAdd.Sort            = int.Parse(Request["Sort"]);
         bool ExistsFieldName     = new FieldsBLL().ExistsFieldName(entityAdd.FieldName, entityAdd.TabId);
         bool ExistsFieldViewName = new FieldsBLL().ExistsFieldViewName(entityAdd.FieldViewName, entityAdd.TabId);
         if (ExistsFieldName)
         {
             return(Content("{\"msg\":\"添加失败,字段名已存在!\",\"success\":false}"));
         }
         else if (ExistsFieldViewName)
         {
             return(Content("{\"msg\":\"添加失败,字段显示名已存在!\",\"success\":false}"));
         }
         else
         {
             int entityId = new FieldsBLL().Add(entityAdd);
             if (entityId > 0)
             {
                 //新增数据库表字段 获取表信息
                 TableEntity    tabEntity      = new TableBLL().GetModel(entityAdd.TabId);
                 DataTypeEntity dataTypeEntity = new DataTypeBLL().GetModel(entityAdd.FieldDataTypeId);
                 string         dbTabName      = "tb_" + tabEntity.TabName;
                 if (Comm.AddTabField(dbTabName, entityAdd.FieldName, dataTypeEntity.DataType))
                 {
                     return(Content("{\"msg\":\"添加成功!\",\"success\":true}"));
                 }
                 else
                 {
                     return(Content("{\"msg\":\"添加失败!\",\"success\":false}"));
                 }
             }
             else
             {
                 return(Content("{\"msg\":\"添加失败!\",\"success\":false}"));
             }
         }
     }
     catch (Exception ex)
     {
         return(Content("{\"msg\":\"添加失败," + ex.Message + "\",\"success\":false}"));
     }
 }