Beispiel #1
0
        public ActionResult Save(int?verId)
        {
            if (verId.HasValue)
            {
                ViewBag.products = ListToSelect(ProductVerService.GetList().Select(o => new SelectListItem()
                {
                    Text = "(" + o.ProductId + ")" + o.SysName, Value = o.ProductId.ToString()
                }), emptyTitle: "请选择");
            }
            else
            {
                ViewBag.products = ListToSelect(ProductPublishVerService.GetProductVers().Select(o => new SelectListItem()
                {
                    Text = "(" + o.ProductId + ")" + o.SysName, Value = o.ProductId.ToString()
                }), emptyTitle: "请选择");
            }
            ProductPublishVer ver = verId.HasValue ?ProductPublishVerService.Get(verId.Value):new ProductPublishVer();

            return(View(ver));
        }
Beispiel #2
0
        public OpResult UpdateData()
        {
            ProductPublishVer ver = null;

            try
            {
                using (TransactionScope tran = new TransactionScope())
                {
                    ver = PublishVerService.UpdatePublish(0, 1, CurrentUser.FullName);
                    if (ver.ProductModuleVer != null)
                    {
                        var menus  = new List <SysMenus>();
                        var limits = new List <SysLimits>();
                        ver.ProductModuleVer.ProductMenuLimits.Each(o =>
                        {
                            switch (o.Type)
                            {
                            case 1:
                                menus.Add(new SysMenus()
                                {
                                    MenuId = o.MenuId, PMenuId = o.PMenuId, SortOrder = o.SortOrder, Status = o.Status, Title = o.Title, URL = o.Url
                                });
                                break;

                            case 3:
                                limits.Add(new SysLimits()
                                {
                                    LimitId = o.MenuId, PLimitId = o.PMenuId, SortOrder = o.SortOrder, Status = o.Status, Title = o.Title
                                });
                                break;

                            default:
                                break;
                            }
                        });
                        if (menus.Any())
                        {
                            var list = MenuRepository.GetQuery().ToList();
                            MenuRepository.RemoveRange(list);
                            MenuRepository.AddRange(menus);
                        }
                        if (limits.Any())
                        {
                            LimitRepository.RemoveRange(LimitRepository.GetQuery().ToList());
                            LimitRepository.AddRange(limits);
                        }
                    }
                    if (ver.ProductRoleVer != null)
                    {
                        var roles = new List <SysRoles>();
                        ver.ProductRoleVer.ProductRoles.Each(o =>
                        {
                            var role          = new SysRoles();
                            role.CreateDT     = DateTime.Now;
                            role.CreateUID    = CurrentUser.UID;
                            role.RoleId       = o.RoleId.GetValueOrDefault();
                            role.Title        = o.Title;
                            role.Limitids     = o.Limitids;
                            role.Type         = 0;
                            role.Status       = true;
                            role.UpdateDT     = role.CreateDT;
                            role.UpdateUID    = role.CreateUID;
                            role.SysRoleDatas = new List <SysRoleData>();
                            o.ProductRoleDatas.Each(i =>
                            {
                                role.SysRoleDatas.Add(new SysRoleData()
                                {
                                    HasSelected = i.HasSelected,
                                    MenuId      = i.MenuId,
                                    PMenuId     = i.PMenuId,
                                    SortOrder   = i.SortOrder
                                });
                            });
                            roles.Add(role);
                        });
                        if (roles.Any())
                        {
                            var list = RoleRepository.GetQuery(o => o.Type == 0).Include(o => o.SysRoleDatas).ToList();
                            roles.Each(o => {
                                var r = list.FirstOrDefault(i => i.RoleId == o.RoleId);
                                if (r != null)
                                {
                                    o.DeptId = r.DeptId;
                                    if (!r.Memo.IsNullOrEmpty())
                                    {
                                        o.Memo = r.Memo;
                                    }
                                    o.Status    = r.Status;
                                    o.CreateDT  = r.CreateDT;
                                    o.CreateUID = r.CreateUID;
                                }
                            });
                            RoleDataRepository.RemoveRange(list.SelectMany(o => o.SysRoleDatas).ToList());
                            RoleRepository.RemoveRange(list);
                            RoleRepository.AddRange(roles);
                        }
                    }
                    if (ver.ProductDictionaryVer != null)
                    {
                        var dicts = new List <SysDataDictionary>();
                        ver.ProductDictionaryVer.ProductDictionaryDatas.Each(o =>
                        {
                            dicts.Add(new SysDataDictionary()
                            {
                                CreateDT  = DateTime.Now,
                                CreateUID = CurrentUser.UID,
                                Depth     = o.Depth,
                                DicPSN    = o.DicPSN,
                                DicSN     = o.DicSN,
                                HasChild  = o.HasChild,
                                SortOrder = o.SortOrder,
                                Status    = Convert.ToBoolean(o.Status),
                                Title     = o.Title
                            });
                        });
                        if (dicts.Any())
                        {
                            var list = DictRepository.GetQuery().ToList();
                            DictRepository.RemoveRange(list);
                            DictRepository.AddRange(dicts);
                        }
                    }
                    var sqls = new Dictionary <int, string>();
                    var db   = new DBFramework.DBHelper();
                    if (ver.ProductDataVer != null)
                    {
                        ver.ProductDataVer.ProductDataSqls.OrderBy(o => o.RunSort).Each(o =>
                        {
                            sqls[o.MenuId] = o.RunSql;
                        });
                        foreach (var de in sqls)
                        {
                            try
                            {
                                db.ExecuteNonQueryText(de.Value, null);
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("更新初始化数据失败!MenuId:" + de.Key + ";" + LogEngine.ToInnerException(ex).Message);
                            }
                        }
                        sqls.Clear();
                    }
                    ver.ProductPublishSqls.OrderBy(o => o.RunSort).Each(o =>
                    {
                        sqls[o.MenuId] = o.RunSql;
                    });
                    foreach (var de in sqls)
                    {
                        try
                        {
                            db.ExecuteNonQueryText(de.Value, null);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("历史数据处理失败!MenuId:" + de.Key + ";" + LogEngine.ToInnerException(ex).Message);
                        }
                    }
                    tran.Complete();
                }
            }catch (Exception e)
            {
                LogEngine.WriteError(e);
                if (ver != null)
                {
                    PublishVerService.AddUpdateLog(ver.PublishId, 0, false, LogEngine.ToInnerException(e).Message, CurrentUser.FullName);
                }
                return(OpResult.Fail());
            }
            return(OpResult.Success());
        }
        public ActionResult UpdateData()
        {
            ProductPublishVer ver = null;

            using (var client = new ServiceReference1.Service1Client())
            {
                try
                {
                    //TransactionOptions options=new TransactionOptions();
                    //options.IsolationLevel=IsolationLevel.Serializable;
                    //options.Timeout = new TimeSpan(0, 0, 60);
                    using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required))
                    {
                        ver = client.UpdatePublish(CommonService.CompanyId, 2, Sys.CurrentUser.FullName);
                        #region 菜单和权限
                        if (ver.ProductModuleVerk__BackingField != null)
                        {
                            var menus  = new List <SysMenus>();
                            var limits = new List <SysLimits>();
                            ver.ProductModuleVerk__BackingField.ProductMenuLimitsk__BackingField.Each(o =>
                            {
                                switch (o.Typek__BackingField)
                                {
                                case 1:
                                    menus.Add(new SysMenus()
                                    {
                                        MenuId = o.MenuIdk__BackingField, PMenuId = o.PMenuIdk__BackingField, SortOrder = o.SortOrderk__BackingField, Status = o.Statusk__BackingField, Title = o.Titlek__BackingField, URL = o.Urlk__BackingField, CompanyId = CommonService.CompanyId
                                    });
                                    break;

                                case 3:
                                    limits.Add(new SysLimits()
                                    {
                                        LimitId = o.MenuIdk__BackingField, PLimitId = o.PMenuIdk__BackingField, SortOrder = o.SortOrderk__BackingField, Status = Convert.ToInt16(o.Statusk__BackingField), Title = o.Titlek__BackingField, CompanyId = CommonService.CompanyId
                                    });
                                    break;

                                default:
                                    break;
                                }
                            });
                            if (menus.Any())
                            {
                                var list = SysMenuBLL.FindList(o => o.CompanyId == CommonService.CompanyId);
                                SysMenuBLL.Delete(list);
                                SysMenuBLL.AddRange(menus);
                            }
                            if (limits.Any())
                            {
                                var list = SysLimitsBLL.FindList(o => o.CompanyId == CommonService.CompanyId);
                                SysLimitsBLL.Delete(list);
                                SysLimitsBLL.AddRange(limits);
                            }
                        }
                        #endregion
                        #region 角色
                        if (ver.ProductRoleVerk__BackingField != null)
                        {
                            var roles       = new List <SysRoles>();
                            var customMenus = new List <SysCustomMenus>();
                            ver.ProductRoleVerk__BackingField.ProductRolesk__BackingField.Each(o =>
                            {
                                var role       = new SysRoles();
                                role.CompanyId = CommonService.CompanyId;
                                role.RoleId    = o.RoleIdk__BackingField.GetValueOrDefault();
                                role.Title     = o.Titlek__BackingField;
                                role.LimitsIds = o.Limitidsk__BackingField ?? "";
                                //role.Type = 0;
                                role.Status = true;
                                var cm      = new SysCustomMenus()
                                {
                                    CompanyId = role.CompanyId,
                                    Type      = 2,
                                    ObjId     = role.RoleId,
                                    MenuIds   = string.Join(",", o.ProductRoleDatask__BackingField.Where(i => i.HasSelectedk__BackingField).OrderBy(i => i.SortOrderk__BackingField).Select(i => i.MenuIdk__BackingField))
                                };
                                roles.Add(role);
                                customMenus.Add(cm);
                            });
                            if (roles.Any())
                            {
                                var list = SysRoleBLL.FindList(o => o.CompanyId == CommonService.CompanyId);
                                roles.Each(o =>
                                {
                                    var r = list.FirstOrDefault(i => i.RoleId == o.RoleId);
                                    if (r != null)
                                    {
                                        //o.DeptId = r.DeptId;
                                        if (!r.Memo.IsNullOrEmpty())
                                        {
                                            o.Memo = r.Memo;
                                        }
                                        o.Status = r.Status;
                                    }
                                });
                                SysRoleBLL.RemoveCustomMenus(SysRoleBLL.GetCustomMenus());
                                SysRoleBLL.Delete(list);
                                SysRoleBLL.AddRange(roles);
                                SysRoleBLL.AddCustomMenus(customMenus);
                            }
                        }
                        #endregion
                        #region 字典
                        if (ver.ProductDictionaryVerk__BackingField != null)
                        {
                            var dicts = new List <SysDataDictionary>();
                            ver.ProductDictionaryVerk__BackingField.ProductDictionaryDatask__BackingField.Each(o =>
                            {
                                dicts.Add(new SysDataDictionary()
                                {
                                    Depth  = o.Depthk__BackingField,
                                    DicPSN = o.DicPSNk__BackingField,
                                    DicSN  = o.DicSNk__BackingField,
                                    //HasChild = o.HasChildk__BackingField,
                                    SortOrder = o.SortOrderk__BackingField,
                                    Status    = Convert.ToBoolean(o.Statusk__BackingField),
                                    Title     = o.Titlek__BackingField
                                });
                            });
                            if (dicts.Any())
                            {
                                var list = SysDataDictService.FindList(o => o.CompanyId == CommonService.CompanyId);
                                SysDataDictService.Delete(list);
                                SysDataDictService.AddRange(dicts);
                            }
                        }
                        #endregion
                        #region 初始化数据
                        var sqls = new Dictionary <int, string>();
                        var db   = new Pharos.DBFramework.DBHelper();
                        if (ver.ProductDataVerk__BackingField != null)
                        {
                            ver.ProductDataVerk__BackingField.ProductDataSqlsk__BackingField.OrderBy(o => o.RunSortk__BackingField).Each(o =>
                            {
                                sqls[o.MenuIdk__BackingField] = o.RunSqlk__BackingField;
                            });
                            foreach (var de in sqls)
                            {
                                try
                                {
                                    var sql = de.Value;
                                    if (sql.Contains("@"))
                                    {
                                        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"@\b[a-zA-Z0-9]*");
                                        sql = sql.Replace(regex.Match(sql).ToString(), CommonService.CompanyId.ToString());
                                    }
                                    db.ExecuteNonQueryText(sql, null);
                                }
                                catch (Exception ex)
                                {
                                    throw new Exception("更新初始化数据失败!MenuId:" + de.Key + ";" + Pharos.Sys.LogEngine.ToInnerException(ex).Message);
                                }
                            }
                            sqls.Clear();
                        }
                        #endregion
                        #region 历史数据处理
                        ver.ProductPublishSqlsk__BackingField.OrderBy(o => o.RunSortk__BackingField).Each(o =>
                        {
                            sqls[o.MenuIdk__BackingField] = o.RunSqlk__BackingField;
                        });
                        foreach (var de in sqls)
                        {
                            try
                            {
                                db.ExecuteNonQueryText(de.Value, null);
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("历史数据处理失败!MenuId:" + de.Key + ";" + Pharos.Sys.LogEngine.ToInnerException(ex).Message);
                            }
                        }
                        #endregion
                        tran.Complete();
                    }
                }
                catch (Exception e)
                {
                    new Pharos.Sys.LogEngine().WriteError(e);
                    if (ver != null)
                    {
                        client.AddUpdateLog(ver.PublishIdk__BackingField, CommonService.CompanyId, false, Pharos.Sys.LogEngine.ToInnerException(e).Message, Sys.CurrentUser.FullName);
                    }
                    return(Content(OpResult.Fail().ToJson()));
                }
                client.Close();
                return(Content(OpResult.Success().ToJson()));
            }
        }
Beispiel #4
0
        public ActionResult Save(ProductPublishVer obj)
        {
            var re = ProductPublishVerService.SaveVer(obj);

            return(new OpActionResult(re));
        }