/// <summary>
        /// 人员管理
        /// </summary>
        /// <returns></returns>
        public ActionResult SystemUserEdit(SystemUser model)
        {
            AjaxReturnData result    = new AjaxReturnData();
            int            EditCount = 0;

            if (model.ObjectId == "" || model.ObjectId == null)
            {
                //新增
                model.ObjectId = Guid.NewGuid().ToString();

                EditCount = _systemUser.Insert <SystemUser>(model);
            }
            else
            {
                Dictionary <string, object> param = new Dictionary <string, object>();
                param.Add("ObjectId", model.ObjectId);
                //修改
                EditCount = _systemUser.UpdateTable <SystemUser>(model, param);
            }
            if (EditCount > 0)
            {
                result.States  = true;
                result.Message = "成功.";
            }
            else
            {
                result.States  = false;
                result.Message = "失败.";
            }

            return(AjaxJson(result));
        }
        /// <summary>
        /// 编辑数据字典
        /// </summary>
        /// <returns></returns>
        public ActionResult EditDataDictionary(S_DataDictionary model)
        {
            AjaxReturnData result    = new AjaxReturnData();
            int            EditCount = 0;

            if (model.TaskID == "" || model.TaskID == null)
            {
                //新增
                model.TaskID = Guid.NewGuid().ToString();

                EditCount = _dataDictionaryService.Insert <S_DataDictionary>(model, ConfigurationManager.AppSettings["SqlConnectionKey_OADB"]);
            }
            else
            {
                Dictionary <string, object> param = new Dictionary <string, object>();
                param.Add("TaskID", model.TaskID);
                //修改
                EditCount = _dataDictionaryService.UpdateTable <S_DataDictionary>(model, param, ConfigurationManager.AppSettings["SqlConnectionKey_OADB"]);
            }
            if (EditCount > 0)
            {
                result.States  = true;
                result.Message = "成功.";
            }
            else
            {
                result.States  = false;
                result.Message = "失败.";
            }

            return(AjaxJson(result));
        }
        /// <summary>
        /// 添加权限
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult EditAuthority(Authority model)
        {
            AjaxReturnData result = new AjaxReturnData();

            int EditCount = 0;


            if (string.IsNullOrEmpty(model.ObjectId))
            {
                //新增
                model.ObjectId = Guid.NewGuid().ToString();

                EditCount = _authority.Insert <Authority>(model);
            }
            else
            {
                Dictionary <string, object> param = new Dictionary <string, object>();
                param.Add("ObjectId", model.ObjectId);
                //修改
                EditCount = _authority.UpdateTable <Authority>(model, param);
            }


            if (EditCount < 0)
            {
                result.States = false;
            }

            return(AjaxJson(result));
        }
        /// <summary>
        /// 编辑流程模板配置
        /// </summary>
        /// <param name="Action"></param>
        /// <param name="ObjectID"></param>
        /// <param name="ProcessParentId"></param>
        /// <param name="ProcessName"></param>
        /// <param name="ProcessCode"></param>
        /// <returns></returns>
        public ActionResult EditWorkflowTemplate(int Action, string ObjectID, string ProcessParentId, string ProcessName, string ProcessCode)
        {
            AjaxReturnData result    = new AjaxReturnData();
            int            EditCount = 0;

            if (Convert.ToInt32(EditType.增加) == Action)
            {
                //新增
                OT_WorkflowTemplate model = new OT_WorkflowTemplate();
                model.ObjectID       = ObjectID;
                model.ParentObjectID = ProcessParentId;
                model.WorkflowCode   = ProcessCode;
                model.ProcessName    = ProcessName;
                model.Content        = WorkflowHelper.CreateDefaultContent(ProcessCode);
                EditCount            = _workflowTemplateService.Insert <OT_WorkflowTemplate>(model);
            }
            else if (Convert.ToInt32(EditType.修改) == Action)
            {
            }
            if (EditCount > 0)
            {
                result.States  = true;
                result.Message = "成功.";
            }
            else
            {
                result.States  = false;
                result.Message = "失败.";
            }

            return(AjaxJson(result));
        }
        /// <summary>
        /// 删除流程
        /// </summary>
        /// <param name="WorkFlowCode"></param>
        /// <returns></returns>
        public ActionResult DeleteProcess(string WorkflowCode)
        {
            AjaxReturnData result  = new AjaxReturnData();
            List <string>  sqlList = new List <string>();

            sqlList.Add(string.Format("delete from OT_BizObjectSchema where SchemaCode='{0}'", WorkflowCode));         //删除保存的数据模型
            sqlList.Add(string.Format("delete from OT_BizObjectSchemaDraft where SchemaCode='{0}'", WorkflowCode));    //删除发布的数据模型
            sqlList.Add(string.Format("delete from OT_WorkflowTemplate where WorkflowCode='{0}'", WorkflowCode));      //删除流程模板
            sqlList.Add(string.Format("delete from OT_WorkflowTemplateDraft where WorkflowCode='{0}'", WorkflowCode)); //删除流程模板
            sqlList.Add(string.Format(@"if exists (select 1  from  sysobjects  
                                        where  id = object_id('I_{0}')   and   type = 'U')   
                                        drop table I_{0}", WorkflowCode));                                             //删除数据表
            int successCount = DapperHelper.CreateInstance().TransAction(sqlList);

            if (successCount > 0)
            {
                result.Message = "删除成功.";
            }
            else
            {
                result.States       = false;
                result.ErrorMessage = "删除失败.";
            }

            return(AjaxJson(result));
        }
Beispiel #6
0
        public ActionResult Login(string Account, string Password)
        {
            AjaxReturnData result = new AjaxReturnData();

            //登录
            result.States = false;
            //登录
            List <SystemUser> list = DapperHelper.CreateInstance().SimpleQuery <SystemUser>(@"select * from SystemUser where Account='" + Account + "'");

            if (list.Count > 0)
            {
                if (list[0].Password == Password)
                {
                    result.States = true;
                    CookieHelper.SetCookie("systemUserName", list[0].UserName, DateTime.Now.AddDays(1));
                    CookieHelper.SetCookie("systemUserAccount", list[0].Account, DateTime.Now.AddDays(1));
                    CookieHelper.SetCookie("systemUserObjectId", list[0].ObjectId, DateTime.Now.AddDays(1));
                    result.Data = list[0];
                }
            }

            if (!result.States)
            {
                result.Message = "账号密码不正确.";
            }
            //else
            //{
            //    Response.Redirect(HttpUtility.UrlDecode(Request.Params["ReturnUrl"]));
            //}
            return(AjaxJson(result));
        }
        /// <summary>
        /// 人员选择
        /// </summary>
        /// <returns></returns>
        public ActionResult SelectSystemUser()
        {
            AjaxReturnData result = new AjaxReturnData();

            List <SystemUser> list = _systemUser.SelectData <SystemUser>("select  * from SystemUser");

            result.Data = list;

            return(AjaxJson(result));
        }
        /// <summary>
        /// 获取角色配置的人员
        /// </summary>
        /// <param name="ObjectId">角色ObjectId</param>
        /// <returns></returns>
        public ActionResult GetRoleUsers(string objectId)
        {
            AjaxReturnData result = new AjaxReturnData();


            List <RoleRelationship> list = _roleRelationship.SelectData <RoleRelationship>("select * from RoleRelationship where RoleObjectId='" + objectId + "'");

            result.Data = list;

            return(AjaxJson(result));
        }
        /// <summary>
        /// 增加主表数据字段
        /// </summary>
        /// <param name="FieldJArray">主表字段数组</param>
        /// <param name="Model">主表数据模型</param>
        /// <param name="AddTarget">新增目标字段</param>
        /// <param name="Service">数据保存服务</param>
        /// <returns></returns>
        public static AjaxReturnData AddMainTableField(string AddTarget, JArray FieldJArray, OT_BizObjectSchema Model, IOT_BizObjectSchemaService Service)
        {
            AjaxReturnData result = new AjaxReturnData();

            result.States = true;

            bool hasField = false;

            JArray newField = JArray.Parse(AddTarget);

            foreach (JObject item in FieldJArray)
            {
                if (item["FieldCode"] + string.Empty == newField[0]["FieldCode"] + string.Empty)
                {
                    hasField = true;
                }
            }

            if (hasField)
            {
                result.States = false;

                result.ErrorMessage = "已存在相同编码";
            }
            else
            {
                FieldJArray.Add(newField[0]);

                Model.Content = FieldJArray.ToString();

                int updateCount = Service.UpdateTable <OT_BizObjectSchema>(Model);

                if (updateCount > 0)
                {
                    result.Message = "更新成功.";
                }
                else
                {
                    result.States = false;

                    result.ErrorMessage = "更新失败.";
                }
            }

            return(result);
        }
        /// <summary>
        /// 编辑菜单页面保存事件
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult SubmitMenuEdit(Sys_Menu model)
        {
            AjaxReturnData result = new AjaxReturnData();

            if (model.pk_Menu == 0)
            {
                //新增
                string maxPk_MenuSql = "select max(pk_Menu)+1 as pk_Menu from Sys_Menu";
                int    pk_Menu       = DapperHelper.CreateInstance().ExecuteScalar(maxPk_MenuSql);
                model.pk_Menu = pk_Menu;
                int insertCount = _sys_MenuService.Insert <Sys_Menu>(model);
                if (insertCount > 0)
                {
                    result.States  = true;
                    result.Message = "新增数据成功.";
                }
                else
                {
                    result.States  = false;
                    result.Message = "新增数据失败.";
                }
            }
            else
            {
                //修改
                Dictionary <string, object> param = new Dictionary <string, object>();
                param.Add("pk_Menu", model.pk_Menu);
                int updateCount = _sys_MenuService.UpdateTable <Sys_Menu>(model, param);
                if (updateCount > 0)
                {
                    result.States  = true;
                    result.Message = "修改数据成功.";
                }
                else
                {
                    result.States  = false;
                    result.Message = "修改数据失败.";
                }
            }
            CacheHelper.Remove("webRootMenuList");
            return(AjaxJson(result));
        }
        /// <summary>
        /// 获取角色
        /// </summary>
        /// <param name="ObjectId">角色ObjectId</param>
        /// <returns></returns>
        public ActionResult GetRoleLists(string roleName = "", int pageIndex = 1)
        {
            AjaxReturnData result     = new AjaxReturnData();
            int            pageSize   = 15;
            int            totalCount = 0;

            List <SystemRole> list = new List <SystemRole>();

            if (string.IsNullOrEmpty(roleName))
            {
                list.AddRange(_systemRole.SimplePageQuery <SystemRole>(pageSize, pageIndex, "RoleName", out totalCount, "select * from SystemRole"));
            }
            else
            {
                list.AddRange(_systemRole.SimplePageQuery <SystemRole>(pageSize, pageIndex, "RoleName", out totalCount, "select * from SystemRole where RoleName like '%" + roleName + "%'"));
            }

            result.Data = new { TotalPage = Math.Ceiling(Convert.ToDecimal(totalCount / pageSize)) + totalCount % pageSize != 0 ? 1 : 0, List = list };

            return(AjaxJson(result));
        }
        /// <summary>
        /// 修改权限角色
        /// </summary>
        /// <param name="objectId"></param>
        /// <param name="roleNames"></param>
        /// <param name="roleObjectIds"></param>
        /// <returns></returns>
        public ActionResult EditAuthRole(string objectId, string roleNames, string roleObjectIds)
        {
            AjaxReturnData result = new AjaxReturnData();

            Authority model = new Authority();

            model = _authority.SelectData <Authority>("select * from Authority where ObjectId='" + objectId + "'")[0];

            model.RoleNames = roleNames;

            model.RoleObjectIds = roleObjectIds;

            int count = _authority.UpdateTable <Authority>(model);

            if (count <= 0)
            {
                result.States = false;
            }

            return(AjaxJson(result));
        }
        /// <summary>
        /// 编辑菜单页面保存事件
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult DeleteMenu(string pk_Menu)
        {
            AjaxReturnData result             = new AjaxReturnData();
            Dictionary <string, object> param = new Dictionary <string, object>();

            param.Add("pk_Menu", pk_Menu);
            int deleteCount = _sys_MenuService.DeleteSigerData <Sys_Menu>(param);

            if (deleteCount > 0)
            {
                result.States  = true;
                result.Message = "删除数据成功.";
            }
            else
            {
                result.States  = false;
                result.Message = "删除数据失败.";
            }
            CacheHelper.Remove("webRootMenuList");
            return(AjaxJson(result));
        }
Beispiel #14
0
        /// <summary>
        /// 一对多查询
        /// </summary>
        /// <returns></returns>
        public ActionResult OneToManyQuery()
        {
            IDbConnection connection = new SqlConnection("Data Source=.;Initial Catalog=DataMip;Integrated Security=True;MultipleActiveResultSets=True");

            var sql    = @"select c.CustomerID, c.CustomerName,c.Mobile,c.Address,c.Email,p.ProductID,p.ProductName,p.ProductDesc from Customers c left join OrderGoods o on c.CustomerID=o.CustomerID left join Product p on  p.ProductID=o.ProductID";
            var lookUp = new Dictionary <int, Customers>();
            List <Customers> customerList = new List <Customers>();
            List <Product>   productList  = new List <Product>();
            List <Customers> resultList   = new List <Customers>();

            customerList = connection.Query <Customers, Product, Customers>(sql, (customer, product) =>
            {
                Customers c;
                if (!lookUp.TryGetValue(customer.CustomerID, out c))
                {
                    lookUp.Add(customer.CustomerID, c = customer);
                }
                Product p;
                p = product;
                //productList.Add(p);
                c.Products.Add(p);
                return(customer);
            }, splitOn: "ProductID").ToList();

            var result = connection.Query(sql);

            resultList.AddRange(lookUp.Values);


            //resultList = DapperHelper.OneToManyQuery<Customers, Product>(sql, "ProductID", "CustomerID");


            ViewData["Result"] = resultList;
            AjaxReturnData returnData = new AjaxReturnData();

            returnData.States = true;
            returnData.Data   = resultList;
            return(AjaxJson(returnData));
            //return View();
        }
        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult AuthorityDelete(Authority model)
        {
            AjaxReturnData result             = new AjaxReturnData();
            int            EditCount          = 0;
            Dictionary <string, object> param = new Dictionary <string, object>();

            param.Add("ObjectId", model.ObjectId);

            EditCount = _authority.DeleteSigerData <Authority>(param);

            if (EditCount > 0)
            {
                result.States  = true;
                result.Message = "成功.";
            }
            else
            {
                result.States  = false;
                result.Message = "失败.";
            }

            return(AjaxJson(result));
        }
        /// <summary>
        /// 编辑数据字典
        /// </summary>
        /// <returns></returns>
        public ActionResult DeleteDictionary(string taskID)
        {
            AjaxReturnData result    = new AjaxReturnData();
            int            EditCount = 0;

            Dictionary <string, object> param = new Dictionary <string, object>();

            param.Add("TaskID", taskID);
            EditCount = _dataDictionaryService.DeleteSigerData <S_DataDictionary>(param, ConfigurationManager.AppSettings["SqlConnectionKey_OADB"]);

            if (EditCount > 0)
            {
                result.States  = true;
                result.Message = "成功.";
            }
            else
            {
                result.States  = false;
                result.Message = "失败.";
            }

            return(AjaxJson(result));
        }
        /// <summary>
        /// 角色管理
        /// </summary>
        /// <returns></returns>
        public ActionResult SystemRoleDelete(string objectId)
        {
            AjaxReturnData result             = new AjaxReturnData();
            int            EditCount          = 0;
            Dictionary <string, object> param = new Dictionary <string, object>();

            param.Add("ObjectId", objectId);

            EditCount = _systemRole.DeleteSigerData <SystemRole>(param);

            if (EditCount > 0)
            {
                result.States  = true;
                result.Message = "成功.";
            }
            else
            {
                result.States  = false;
                result.Message = "失败.";
            }

            return(AjaxJson(result));
        }
        /// <summary>
        /// 保存数据模型字段
        /// </summary>
        /// <param name="FiledListString"></param>
        /// <returns></returns>
        public ActionResult SaveObjectSchema(string FieldListString, string WorkFlowCode)
        {
            AjaxReturnData result = new AjaxReturnData();

            #region 保存数据模型字段

            List <OT_BizObjectSchema> list = _bizObjectSchemaService.SelectData <OT_BizObjectSchema>("select * from OT_BizObjectSchema where SchemaCode='" + WorkFlowCode + "'");

            if (list.Count > 0)
            {
                OT_BizObjectSchema model = list[0];

                JArray Fields = JArray.Parse(model.Content);

                JArray newField = JArray.Parse(FieldListString);

                bool hasField = false;

                if (!Convert.ToBoolean(newField[0]["IsSonTable"] + string.Empty))
                {
                    //非子表数据
                    foreach (JObject item in Fields)
                    {
                        if (item["FieldCode"] + string.Empty == newField[0]["FieldCode"] + string.Empty)
                        {
                            hasField = true;
                        }
                    }

                    if (hasField)
                    {
                        result.States = false;

                        result.ErrorMessage = "已存在相同编码";
                    }
                    else
                    {
                        Fields.Add(newField[0]);

                        model.Content = Fields.ToString();

                        int updateCount = _bizObjectSchemaService.UpdateTable <OT_BizObjectSchema>(model);

                        if (updateCount > 0)
                        {
                            result.Message = "更新成功.";
                        }
                        else
                        {
                            result.States = false;

                            result.ErrorMessage = "更新失败.";
                        }
                    }
                }
                else
                {
                    //子表数据
                    foreach (JObject item in Fields)
                    {
                        if (item["ObjectId"] + string.Empty == newField[0]["ParentProperty"] + string.Empty)
                        {
                            foreach (JObject children in JArray.Parse(item["children"] + string.Empty))
                            {
                                if (children["FieldCode"] + string.Empty == newField[0]["FieldCode"] + string.Empty)
                                {
                                    hasField = true;
                                }
                            }
                            if (hasField)
                            {
                                result.States = false;

                                result.ErrorMessage = "已存在相同编码";
                            }
                            else
                            {
                                JArray children = JArray.Parse(item["children"] + string.Empty);

                                children.Add(newField[0]);

                                item["children"] = children;

                                model.Content = Fields.ToString();

                                int updateCount = _bizObjectSchemaService.UpdateTable <OT_BizObjectSchema>(model);

                                if (updateCount > 0)
                                {
                                    result.Message = "更新成功.";
                                }
                                else
                                {
                                    result.States = false;

                                    result.ErrorMessage = "更新失败.";
                                }
                            }
                            break;
                        }
                    }
                }
            }
            else
            {
                OT_BizObjectSchema model = new OT_BizObjectSchema();
                model.ObjectID     = Guid.NewGuid().ToString();
                model.SchemaCode   = WorkFlowCode;
                model.Content      = FieldListString;
                model.DisplayName  = "数据模型";
                model.CreatedTime  = DateTime.Now;
                model.ModifiedTime = DateTime.Now;
                int insertCount = _bizObjectSchemaService.Insert <OT_BizObjectSchema>(model);
                if (insertCount > 0)
                {
                    result.Message = "保存成功.";
                }
                else
                {
                    result.States = false;

                    result.ErrorMessage = "保存数据失败.";
                }
            }

            #endregion
            return(AjaxJson(result));
        }
        /// <summary>
        /// 删除表数据字段
        /// </summary>
        /// <param name="ObjectId">被删除字段ObjectId</param>
        /// <param name="FieldJArray">主表字段数组</param>
        /// <param name="Model">主表数据模型</param>
        /// <param name="Service">数据保存服务</param>
        /// <returns></returns>
        public static AjaxReturnData DeleteTableField(string MainTableCode, string ObjectId, bool IsSonTable, string ParentProperty, JArray FieldJArray, OT_BizObjectSchema Model, IOT_BizObjectSchemaService Service)
        {
            string dbConnectionKey = string.Format("Data Source = {0}; Initial Catalog = {1}; User Id = {2}; Password = {3} ", ConfigurationManager.AppSettings["DataSource"], string.IsNullOrEmpty(Model.DbName) ? "ProcDB" : Model.DbName, ConfigurationManager.AppSettings["UserId"], ConfigurationManager.AppSettings["Password"]);

            AjaxReturnData result = new AjaxReturnData();

            result.States = true;

            if (IsSonTable)
            {
                foreach (var item in FieldJArray)
                {
                    if (item["ObjectId"] + string.Empty == ParentProperty + string.Empty)
                    {
                        foreach (JObject childItem in (JArray)item["children"])
                        {
                            if (childItem["ObjectId"] + string.Empty == ObjectId + string.Empty)
                            {
                                if ((bool)childItem["IsPublished"] == true)
                                {
                                    if (((JArray)item["children"]).Count == 1)
                                    {
                                        #region  除数据表
                                        string deleteTableFieldSql = "drop table C_" + item["FieldCode"];
                                        DapperHelper.CreateInstance(dbConnectionKey).ExecuteNoneQuery(deleteTableFieldSql);
                                        #endregion
                                        FieldJArray.Remove(item);
                                    }
                                    else
                                    {
                                        #region  除数据表字段
                                        int hasField = DapperHelper.CreateInstance(dbConnectionKey).ExecuteScalar("select   COUNT(*)   from   syscolumns   where   id=object_id('C_" + MainTableCode + "')   and   name='" + item["FieldCode"].ToString() + "' ");
                                        if (hasField > 0)
                                        {
                                            string deleteTableFieldSql = "alter table C_" + item["FieldCode"] + " drop column  [" + childItem["FieldCode"].ToString() + "]";
                                            DapperHelper.CreateInstance(dbConnectionKey).ExecuteNoneQuery(deleteTableFieldSql);
                                        }

                                        #endregion
                                    }
                                }

                                ((JArray)item["children"]).Remove(childItem);

                                break;
                            }
                        }
                        break;
                    }
                }
            }
            else
            {
                foreach (JObject item in FieldJArray)
                {
                    if (item["ObjectId"] + string.Empty == ObjectId + string.Empty)
                    {
                        if ((bool)item["IsPublished"] == true)
                        {
                            if (item["LogicType"] + string.Empty == "BizObjectArray")
                            {
                                //子表
                                #region  除数据表
                                string deleteTableFieldSql = "drop table C_" + item["FieldCode"];
                                DapperHelper.CreateInstance(dbConnectionKey).ExecuteNoneQuery(deleteTableFieldSql);
                                #endregion
                            }
                            else
                            {
                                #region  除数据表字段
                                int hasField = DapperHelper.CreateInstance(dbConnectionKey).ExecuteScalar("select   COUNT(*)   from   syscolumns   where   id=object_id('I_" + MainTableCode + "')   and   name='" + item["FieldCode"].ToString() + "' ");
                                if (hasField > 0)
                                {
                                    string deleteTableFieldSql = "alter table I_" + MainTableCode + " drop column  [" + item["FieldCode"].ToString() + "]";
                                    DapperHelper.CreateInstance(dbConnectionKey).ExecuteNoneQuery(deleteTableFieldSql);
                                }

                                #endregion
                            }
                        }


                        FieldJArray.Remove(item);

                        break;
                    }
                }
            }

            Model.Content = FieldJArray.ToString();

            int updateCount = Service.UpdateTable <OT_BizObjectSchema>(Model);

            if (updateCount > 0)
            {
                result.Message = "更新成功.";
            }
            else
            {
                result.States = false;

                result.ErrorMessage = "更新失败.";
            }


            return(result);
        }
        /// <summary>
        /// 添加角色人员
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public ActionResult AddRoleUsers(List <RoleRelationship> array, string roleObjectId)
        {
            AjaxReturnData result = new AjaxReturnData();

            List <RoleRelationship> list = _roleRelationship.SelectData <RoleRelationship>("select * from RoleRelationship where RoleObjectId='" + roleObjectId + "'");

            int deleteCount = 0;
            int insertCount = 0;

            if (array != null)
            {
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        if (array.Find(c => c.UserObjectId == item.UserObjectId) != null)
                        {
                            array.Remove(array.Find(c => c.UserObjectId == item.UserObjectId));
                        }
                        else
                        {
                            //删除
                            Dictionary <string, Object> param = new Dictionary <string, Object>();
                            param.Add("ObjectId", item.ObjectId);
                            deleteCount = _roleRelationship.DeleteSigerData <RoleRelationship>(param);
                        }
                    }
                }

                foreach (var item in array)
                {
                    item.ObjectId = Guid.NewGuid() + String.Empty;
                }
                insertCount = _roleRelationship.InsertBatch <RoleRelationship>(array);
            }
            else
            {
                {
                    foreach (var item in list)
                    {
                        //删除
                        Dictionary <string, Object> param = new Dictionary <string, Object>();
                        param.Add("ObjectId", item.ObjectId);
                        deleteCount = _roleRelationship.DeleteSigerData <RoleRelationship>(param);
                    }
                }
            }


            if (insertCount > 0 || deleteCount > 0)
            {
                result.States  = true;
                result.Message = "成功.";
            }
            else
            {
                result.States  = false;
                result.Message = "失败.";
            }

            return(AjaxJson(result));
        }
        /// <summary>
        /// 添加子表数据字段
        /// </summary>
        /// <param name="FieldJArray">主表字段数组</param>
        /// <param name="Model">主表数据模型</param>
        /// <param name="AddTarget">新增目标字段</param>
        /// <param name="Service">数据保存服务</param>
        /// <returns></returns>
        public static AjaxReturnData AddSonTableField(string AddTarget, JArray FieldJArray, OT_BizObjectSchema Model, IOT_BizObjectSchemaService Service)
        {
            AjaxReturnData result = new AjaxReturnData();

            result.States = true;

            bool hasField = false;

            JArray newField = JArray.Parse(AddTarget);

            foreach (JObject item in FieldJArray)
            {
                if (item["ObjectId"] + string.Empty == newField[0]["ParentProperty"] + string.Empty)
                {
                    item["IsPublished"] = false;

                    if (!string.IsNullOrEmpty(item["children"] + string.Empty))
                    {
                        foreach (JObject children in JArray.Parse(item["children"] + string.Empty))
                        {
                            if (children["FieldCode"] + string.Empty == newField[0]["FieldCode"] + string.Empty)
                            {
                                hasField = true;
                            }
                        }
                        if (hasField)
                        {
                            result.States = false;

                            result.ErrorMessage = "已存在相同编码";
                        }
                        else
                        {
                            JArray children = JArray.Parse(item["children"] + string.Empty);

                            children.Add(newField[0]);

                            item["children"] = children;

                            Model.Content = FieldJArray.ToString();

                            int updateCount = Service.UpdateTable <OT_BizObjectSchema>(Model);

                            if (updateCount > 0)
                            {
                                result.Message = "更新成功.";
                            }
                            else
                            {
                                result.States = false;

                                result.ErrorMessage = "更新失败.";
                            }
                        }
                    }
                    else
                    {
                        //添加第一个子表数据
                        JArray children = new JArray();

                        children.Add(newField[0]);

                        item["children"] = children;

                        Model.Content = FieldJArray.ToString();

                        int updateCount = Service.UpdateTable <OT_BizObjectSchema>(Model);

                        if (updateCount > 0)
                        {
                            result.Message = "更新成功.";
                        }
                        else
                        {
                            result.States = false;

                            result.ErrorMessage = "更新失败.";
                        }
                    }
                    break;
                }
            }

            return(result);
        }
        /// <summary>
        /// 发布数据模型
        /// </summary>
        /// <param name="FieldListString"></param>
        /// <param name="WorkFlowCode"></param>
        /// <returns></returns>
        public ActionResult PublishObjectSchema(string FieldListString, string WorkFlowCode)
        {
            AjaxReturnData result           = new AjaxReturnData();
            JArray         ObjectSchemaList = JArray.Parse(FieldListString);
            //已保存的数据模型
            OT_BizObjectSchema model = new OT_BizObjectSchema();

            model = _bizObjectSchemaService.SelectData <OT_BizObjectSchema>("select * from OT_BizObjectSchema where SchemaCode='" + WorkFlowCode + "'")[0];

            string hasTableSql   = "select count(*) from sysobjects where id = object_id('Work6-OA.dbo.I_" + WorkFlowCode + "')";
            int    hasTableCount = DapperHelper.CreateInstance().ExecuteScalar(hasTableSql);

            if (hasTableCount > 0)
            {
                //已经发布过的数据模型
            }
            else
            {
                StringBuilder FieldSql = new StringBuilder();
                //未发布
                foreach (JObject item in ObjectSchemaList)
                {
                    if (item["LogicType"] + string.Empty != "BizObjectArray")
                    {
                        //非子表
                        FieldSql.Append(item["FieldCode"] + string.Empty);
                        switch (item["LogicType"] + string.Empty)
                        {
                        case "ShortString":
                        case "SingleParticipant":
                            FieldSql.Append(" varchar(255),");
                            break;

                        case "DateTime":
                            FieldSql.Append(" datetime,");
                            break;

                        default:
                            break;
                        }
                    }

                    //改变发布状态
                    item["IsPublished"] = true;
                }

                string CreateTableSql = string.Format(@"CREATE TABLE I_{1} 
                                            (ObjectId char(36) ,
                                            Name nvarchar(255) ,
                                            CreatedBy varchar(255),
                                            CreatedByParentId varchar(255),
                                            ModifiedBy varchar(255),
                                            CreatedTime datetime,
                                            ModifiedTime datetime,
                                            RunningInstanceId varchar(255),
                                            {0}
                                            PRIMARY KEY (ObjectId)
                                            )", FieldSql.ToString(), WorkFlowCode);



                #region 发布数据模型字段


                OT_BizObjectSchemaDraft publishModel = new OT_BizObjectSchemaDraft();

                model.Content      = ObjectSchemaList.ToString();
                model.ModifiedTime = DateTime.Now;

                publishModel.ObjectID     = Guid.NewGuid().ToString();
                publishModel.SchemaCode   = WorkFlowCode;
                publishModel.Content      = ObjectSchemaList.ToString();
                publishModel.DisplayName  = "数据模型";
                publishModel.CreatedTime  = DateTime.Now;
                publishModel.ModifiedTime = DateTime.Now;
                //事务处理
                using (IDbConnection dbConnection = new SqlConnection(BaseApplication.DefaultSqlConnectionKey))
                {
                    dbConnection.Open();
                    IDbTransaction transaction = dbConnection.BeginTransaction();
                    try
                    {
                        DapperHelper.CreateInstance().ExecuteNoneQuery(CreateTableSql); //创建数据表
                        int insertCount = _bizObjectSchemaDraftService.Insert <OT_BizObjectSchemaDraft>(publishModel);
                        int updateCount = _bizObjectSchemaService.UpdateTable <OT_BizObjectSchema>(model);
                        if (insertCount > 0 && updateCount > 0)
                        {
                            result.Message = "发布成功";
                        }

                        transaction.Commit();
                    }
                    catch (Exception exception)
                    {
                        result.ErrorMessage = exception.ToString();
                        transaction.Rollback();
                    }
                }

                #endregion
            }

            return(AjaxJson(result));
        }