Exemplo n.º 1
0
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="model">Data.Model.UsersRelation实体类</param>
        public int Update(Data.Model.UsersRelation model)
        {
            string sql = @"UPDATE UsersRelation SET 
				IsMain=@IsMain,Sort=@Sort
				WHERE UserID=@UserID and OrganizeID=@OrganizeID"                ;

            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@IsMain", SqlDbType.Int, -1)
                {
                    Value = model.IsMain
                },
                new SqlParameter("@Sort", SqlDbType.Int, -1)
                {
                    Value = model.Sort
                },
                new SqlParameter("@UserID", SqlDbType.UniqueIdentifier, -1)
                {
                    Value = model.UserID
                },
                new SqlParameter("@OrganizeID", SqlDbType.UniqueIdentifier, -1)
                {
                    Value = model.OrganizeID
                }
            };
            return(dbHelper.Execute(sql, parameters));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加记录
        /// </summary>
        /// <param name="model">Data.Model.UsersRelation实体类</param>
        /// <returns>操作所影响的行数</returns>
        public int Add(Data.Model.UsersRelation model)
        {
            string sql = @"INSERT INTO UsersRelation
				(UserID,OrganizeID,IsMain,Sort) 
				VALUES(@UserID,@OrganizeID,@IsMain,@Sort)"                ;

            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@UserID", SqlDbType.UniqueIdentifier, -1)
                {
                    Value = model.UserID
                },
                new SqlParameter("@OrganizeID", SqlDbType.UniqueIdentifier, -1)
                {
                    Value = model.OrganizeID
                },
                new SqlParameter("@IsMain", SqlDbType.Int, -1)
                {
                    Value = model.IsMain
                },
                new SqlParameter("@Sort", SqlDbType.Int, -1)
                {
                    Value = model.Sort
                }
            };
            return(dbHelper.Execute(sql, parameters));
        }
Exemplo n.º 3
0
        public ActionResult UserAdd(FormCollection collection)
        {
            Business.Platform.Organize borganize = new Business.Platform.Organize();
            Business.Platform.Users    busers    = new Business.Platform.Users();

            string id = Request.QueryString["id"];

            string name    = string.Empty;
            string account = string.Empty;
            string status  = string.Empty;
            string note    = string.Empty;
            Guid   parentID;

            if (collection != null && id.IsGuid(out parentID))
            {
                name    = Request.Form["Name"];
                account = Request.Form["Account"];
                status  = Request.Form["Status"];
                note    = Request.Form["Note"];

                Guid   userID  = Guid.NewGuid();
                string userXML = string.Empty;
                using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
                {
                    //添加人员
                    Data.Model.Users user = new Data.Model.Users();
                    user.Account  = account.Trim();
                    user.Name     = name.Trim();
                    user.Note     = note.IsNullOrEmpty() ? null : note;
                    user.Password = busers.GetUserEncryptionPassword(userID.ToString(), busers.GetInitPassword());
                    user.Sort     = 1;
                    user.Status   = status.IsInt() ? status.ToInt() : 0;
                    user.ID       = userID;
                    busers.Add(user);

                    //添加关系
                    Data.Model.UsersRelation userRelation = new Data.Model.UsersRelation();
                    userRelation.IsMain     = 1;
                    userRelation.OrganizeID = parentID;
                    userRelation.Sort       = new Business.Platform.UsersRelation().GetMaxSort(parentID);
                    userRelation.UserID     = userID;
                    new Business.Platform.UsersRelation().Add(userRelation);

                    //更新父级[ChildsLength]字段
                    borganize.UpdateChildsLength(parentID);

                    //更新角色
                    new Business.Platform.UsersRole().UpdateByUserID(userID);

                    userXML = user.Serialize();
                    scope.Complete();
                }

                Business.Platform.Log.Add("添加了人员", userXML, Business.Platform.Log.Types.组织机构);
                ViewBag.Script = "alert('添加成功!');parent.frames[0].reLoad('" + id + "');window.location=window.location;";
            }
            ViewBag.StatusRadios = borganize.GetStatusRadio("Status", "0", "validate=\"radio\"");
            return(View());
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取用户主要岗位的ID。
        /// </summary>
        /// <param name="id">用户ID。</param>
        /// <returns>用户对应的主要岗位的ID。</returns>
        public Guid GetMainStation(Guid id)
        {
            IBase usersRelation = Factory.GetBase("UsersRelation", "Sort");

            Data.Model.UsersRelation model = usersRelation.Get <Data.Model.UsersRelation>(
                new KeyValuePair <string, object>("UserID", id),
                new KeyValuePair <string, object>("IsMain", 1));
            return(model != null ? model.OrganizeID : Guid.Empty);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 将DataRedar转换为List
        /// </summary>
        private List <Data.Model.UsersRelation> DataReaderToList(SqlDataReader dataReader)
        {
            List <Data.Model.UsersRelation> List = new List <Data.Model.UsersRelation>();

            Data.Model.UsersRelation model = null;
            while (dataReader.Read())
            {
                model            = new Data.Model.UsersRelation();
                model.UserID     = dataReader.GetGuid(0);
                model.OrganizeID = dataReader.GetGuid(1);
                model.IsMain     = dataReader.GetInt32(2);
                model.Sort       = dataReader.GetInt32(3);
                List.Add(model);
            }
            return(List);
        }
Exemplo n.º 6
0
        public ActionResult User(FormCollection collection)
        {
            Business.Platform.Organize      borganize     = new Business.Platform.Organize();
            Business.Platform.Users         busers        = new Business.Platform.Users();
            Business.Platform.UsersRelation buserRelation = new Business.Platform.UsersRelation();
            Data.Model.Users    user     = null;
            Data.Model.Organize organize = null;
            string id       = Request.QueryString["id"];
            string parentID = Request.QueryString["parentid"];

            string name    = string.Empty;
            string account = string.Empty;
            string status  = string.Empty;
            string note    = string.Empty;

            string parentString = string.Empty;

            Guid userID, organizeID;

            if (id.IsGuid(out userID))
            {
                user = busers.Get(userID);
                if (user != null)
                {
                    name    = user.Name;
                    account = user.Account;
                    status  = user.Status.ToString();
                    note    = user.Note;

                    //所在组织字符串
                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    var userRelations            = buserRelation.GetAllByUserID(user.ID).OrderByDescending(p => p.IsMain);
                    foreach (var userRelation in userRelations)
                    {
                        sb.Append("<div style='margin:3px 0;'>");
                        sb.Append(borganize.GetAllParentNames(userRelation.OrganizeID, true));
                        if (userRelation.IsMain == 0)
                        {
                            sb.Append("<span style='color:#999'> [兼职]</span>");
                        }
                        sb.Append("</div>");
                    }
                    ViewBag.ParentString = sb.ToString();
                }
            }
            if (parentID.IsGuid(out organizeID))
            {
                organize = borganize.Get(organizeID);
            }

            if (collection != null)
            {
                //保存
                if (!Request.Form["Save"].IsNullOrEmpty() && user != null)
                {
                    name    = Request.Form["Name"];
                    account = Request.Form["Account"];
                    status  = Request.Form["Status"];
                    note    = Request.Form["Status"];

                    string oldXML = user.Serialize();

                    user.Name    = name.Trim();
                    user.Account = account.Trim();
                    user.Status  = status.ToInt(1);
                    user.Note    = note.IsNullOrEmpty() ? null : note.Trim();

                    busers.Update(user);
                    Business.Platform.Log.Add("修改了用户", "", Business.Platform.Log.Types.组织机构, oldXML, user.Serialize());
                    ViewBag.Script = "alert('保存成功!');parent.frames[0].reLoad('" + parentID + "');";
                }

                //删除用户
                if (!Request.Form["DeleteBut"].IsNullOrEmpty() && user != null && organize != null)
                {
                    using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
                    {
                        var urs = buserRelation.GetAllByUserID(user.ID);
                        busers.Delete(user.ID);

                        buserRelation.DeleteByUserID(user.ID);

                        new Business.Platform.UsersInfo().Delete(user.ID);
                        new Business.Platform.UsersRole().DeleteByUserID(user.ID);

                        //更新父级[ChildsLength]字段
                        foreach (var ur in urs)
                        {
                            borganize.UpdateChildsLength(ur.OrganizeID);
                        }
                        scope.Complete();
                    }

                    string refreshID = parentID;
                    string url       = string.Empty;
                    var    users     = borganize.GetAllUsers(refreshID.ToGuid());
                    if (users.Count > 0)
                    {
                        url = "User?id=" + users.Last().ID + "&appid=" + Request.QueryString["appid"] + "&tabid=" + Request.QueryString["tabid"] + "&parentid=" + parentID;
                    }
                    else
                    {
                        refreshID = organize.ParentID == Guid.Empty ? organize.ID.ToString() : organize.ParentID.ToString();
                        url       = "Body?id=" + parentID + "&appid=" + Request.QueryString["appid"] + "&tabid=" + Request.QueryString["tabid"] + "&parentid=" + organize.ParentID;
                    }
                    Business.Platform.Log.Add("删除了用户", user.Serialize(), Business.Platform.Log.Types.组织机构);
                    ViewBag.Script = "alert('删除成功');parent.frames[0].reLoad('" + refreshID + "');window.location='" + url + "'";
                }

                //初始化密码
                if (!Request.Form["InitPass"].IsNullOrEmpty() && user != null)
                {
                    string initpass = busers.GetInitPassword();
                    busers.InitPassword(user.ID);
                    Business.Platform.Log.Add("初始化了用户密码", user.Serialize(), Business.Platform.Log.Types.组织机构);
                    ViewBag.Script = "alert('密码已初始化为:" + initpass + "');";
                }

                //调动
                if (!Request.Form["Move1"].IsNullOrEmpty() && user != null)
                {
                    string moveto          = Request.Form["movetostation"];
                    string movetostationjz = Request.Form["movetostationjz"];
                    Guid   moveToID;
                    if (moveto.IsGuid(out moveToID))
                    {
                        using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
                        {
                            var us = buserRelation.GetAllByUserID(user.ID);
                            if ("1" != movetostationjz)
                            {
                                buserRelation.DeleteByUserID(user.ID);
                            }

                            Data.Model.UsersRelation ur = new Data.Model.UsersRelation();
                            ur.UserID     = user.ID;
                            ur.OrganizeID = moveToID;
                            ur.IsMain     = "1" == movetostationjz ? 0 : 1;
                            ur.Sort       = buserRelation.GetMaxSort(moveToID);
                            buserRelation.Add(ur);

                            foreach (var u in us)
                            {
                                borganize.UpdateChildsLength(u.OrganizeID);
                            }

                            borganize.UpdateChildsLength(organizeID);
                            borganize.UpdateChildsLength(moveToID);

                            scope.Complete();
                            ViewBag.Script = "alert('调动成功!');parent.frames[0].reLoad('" + parentID + "');parent.frames[0].reLoad('" + moveto + "')";
                        }

                        Business.Platform.Log.Add(("1" == movetostationjz ? "兼职" : "全职") + "调动了人员的岗位", "将人员调往岗位(" + moveto + ")", Business.Platform.Log.Types.组织机构);
                    }
                }
            }
            ViewBag.StatusRadios = borganize.GetStatusRadio("Status", status, "validate=\"radio\"");
            return(View(user));
        }
Exemplo n.º 7
0
 /// <summary>
 /// 更新
 /// </summary>
 public int Update(Data.Model.UsersRelation model)
 {
     return(dataUsersRelation.Update(model));
 }
Exemplo n.º 8
0
 /// <summary>
 /// 新增
 /// </summary>
 public int Add(Data.Model.UsersRelation model)
 {
     return(dataUsersRelation.Add(model));
 }