Ejemplo n.º 1
0
        /// <summary>
        /// 得到一个人员的分管领导。
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public string GetChargeLeader(Guid userId)
        {
            Guid organizeId = this.GetMainStation(userId);

            if (organizeId == null)
            {
                return(string.Empty);
            }
            Organize organizeBll = new Organize();

            Data.Model.Organize organize = organizeBll.Get(organizeId);
            if (organize == null)
            {
                return(string.Empty);
            }
            if (!string.IsNullOrEmpty(organize.ChargeLeader))
            {
                return(organize.ChargeLeader);
            }
            var parents = organizeBll.GetAllParent(organize.Number);

            foreach (var current in parents)
            {
                if (!string.IsNullOrEmpty(current.ChargeLeader))
                {
                    return(current.ChargeLeader);
                }
            }
            return(string.Empty);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 得到一个人员的主管。
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public string GetLeader(Guid userId)
        {
            Guid organizeId = this.GetMainStation(userId);

            if (Guid.Empty.Equals(organizeId))
            {
                return(string.Empty);
            }
            Organize organizeBll = new Organize();

            Data.Model.Organize organize = organizeBll.Get(organizeId);
            if (organize == null)
            {
                return(string.Empty);
            }
            if (!string.IsNullOrEmpty(organize.Leader))
            {
                return(organize.Leader);
            }
            List <Data.Model.Organize> list = organizeBll.GetAllParent(organize.Number);

            foreach (Data.Model.Organize current in list)
            {
                if (!string.IsNullOrEmpty(current.Leader))
                {
                    return(current.Leader);
                }
            }
            return(string.Empty);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 将DataRedar转换为List
        /// </summary>
        private List <Data.Model.Organize> DataReaderToList(SqlDataReader dataReader)
        {
            List <Data.Model.Organize> List = new List <Data.Model.Organize>();

            Data.Model.Organize model = null;
            while (dataReader.Read())
            {
                model              = new Data.Model.Organize();
                model.ID           = dataReader.GetGuid(0);
                model.Name         = dataReader.GetString(1);
                model.Number       = dataReader.GetString(2);
                model.Type         = dataReader.GetInt32(3);
                model.Status       = dataReader.GetInt32(4);
                model.ParentID     = dataReader.GetGuid(5);
                model.Sort         = dataReader.GetInt32(6);
                model.Depth        = dataReader.GetInt32(7);
                model.ChildsLength = dataReader.GetInt32(8);
                if (!dataReader.IsDBNull(9))
                {
                    model.Note = dataReader.GetString(9);
                }
                List.Add(model);
            }
            return(List);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="model">Data.Model.Organize实体类</param>
        public int Update(Data.Model.Organize model)
        {
            string sql = @"UPDATE Organize SET 
				Name=@Name,Number=@Number,Type=@Type,Status=@Status,ParentID=@ParentID,Sort=@Sort,Depth=@Depth,ChildsLength=@ChildsLength,Note=@Note
				WHERE ID=@ID"                ;

            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@Name", SqlDbType.VarChar, 2000)
                {
                    Value = model.Name
                },
                new SqlParameter("@Number", SqlDbType.VarChar, 900)
                {
                    Value = model.Number
                },
                new SqlParameter("@Type", SqlDbType.Int, -1)
                {
                    Value = model.Type
                },
                new SqlParameter("@Status", SqlDbType.Int, -1)
                {
                    Value = model.Status
                },
                new SqlParameter("@ParentID", SqlDbType.UniqueIdentifier, -1)
                {
                    Value = model.ParentID
                },
                new SqlParameter("@Sort", SqlDbType.Int, -1)
                {
                    Value = model.Sort
                },
                new SqlParameter("@Depth", SqlDbType.Int, -1)
                {
                    Value = model.Depth
                },
                new SqlParameter("@ChildsLength", SqlDbType.Int, -1)
                {
                    Value = model.ChildsLength
                },
                model.Note == null ? new SqlParameter("@Note", SqlDbType.NVarChar, -1)
                {
                    Value = DBNull.Value
                } : new SqlParameter("@Note", SqlDbType.NVarChar, -1)
                {
                    Value = model.Note
                },
                new SqlParameter("@ID", SqlDbType.UniqueIdentifier, -1)
                {
                    Value = model.ID
                }
            };
            return(dbHelper.Execute(sql, parameters));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 添加记录
        /// </summary>
        /// <param name="model">Data.Model.Organize实体类</param>
        /// <returns>操作所影响的行数</returns>
        public int Add(Data.Model.Organize model)
        {
            string sql = @"INSERT INTO Organize
				(ID,Name,Number,Type,Status,ParentID,Sort,Depth,ChildsLength,Note) 
				VALUES(@ID,@Name,@Number,@Type,@Status,@ParentID,@Sort,@Depth,@ChildsLength,@Note)"                ;

            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@ID", SqlDbType.UniqueIdentifier, -1)
                {
                    Value = model.ID
                },
                new SqlParameter("@Name", SqlDbType.VarChar, 2000)
                {
                    Value = model.Name
                },
                new SqlParameter("@Number", SqlDbType.VarChar, 900)
                {
                    Value = model.Number
                },
                new SqlParameter("@Type", SqlDbType.Int, -1)
                {
                    Value = model.Type
                },
                new SqlParameter("@Status", SqlDbType.Int, -1)
                {
                    Value = model.Status
                },
                new SqlParameter("@ParentID", SqlDbType.UniqueIdentifier, -1)
                {
                    Value = model.ParentID
                },
                new SqlParameter("@Sort", SqlDbType.Int, -1)
                {
                    Value = model.Sort
                },
                new SqlParameter("@Depth", SqlDbType.Int, -1)
                {
                    Value = model.Depth
                },
                new SqlParameter("@ChildsLength", SqlDbType.Int, -1)
                {
                    Value = model.ChildsLength
                },
                model.Note == null ? new SqlParameter("@Note", SqlDbType.NVarChar, -1)
                {
                    Value = DBNull.Value
                } : new SqlParameter("@Note", SqlDbType.NVarChar, -1)
                {
                    Value = model.Note
                }
            };
            return(dbHelper.Execute(sql, parameters));
        }
Ejemplo n.º 6
0
        public ActionResult BodyAdd(FormCollection collection)
        {
            Business.Platform.Organize borganize = new Business.Platform.Organize();
            Data.Model.Organize        org       = null;
            string id     = Request.QueryString["id"];
            string name   = string.Empty;
            string type   = string.Empty;
            string status = string.Empty;
            string note   = string.Empty;

            Guid orgID;

            if (id.IsGuid(out orgID))
            {
                org = borganize.Get(orgID);
            }

            if (collection != null && org != null)
            {
                name   = Request.Form["Name"];
                type   = Request.Form["Type"];
                status = Request.Form["Status"];
                note   = Request.Form["note"];

                Data.Model.Organize org1 = new Data.Model.Organize();
                Guid org1ID = Guid.NewGuid();
                org1.ID       = org1ID;
                org1.Name     = name.Trim();
                org1.Note     = note.IsNullOrEmpty() ? null : note.Trim();
                org1.Number   = org.Number + "," + org1ID.ToString().ToLower();
                org1.ParentID = org.ID;
                org1.Sort     = borganize.GetMaxSort(org.ID);
                org1.Status   = status.IsInt() ? status.ToInt() : 0;
                org1.Type     = type.ToInt();
                org1.Depth    = org.Depth + 1;

                using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
                {
                    borganize.Add(org1);
                    //更新父级[ChildsLength]字段
                    borganize.UpdateChildsLength(org.ID);
                    scope.Complete();
                }

                Business.Platform.Log.Add("添加了组织机构", org1.Serialize(), Business.Platform.Log.Types.组织机构);
                ViewBag.Script = "alert('添加成功!');parent.frames[0].reLoad('" + id + "');window.location=window.location;";
            }
            ViewBag.TypeRadios   = borganize.GetTypeRadio("Type", type, "validate=\"radio\"");
            ViewBag.StatusRadios = borganize.GetStatusRadio("Status", "0", "validate=\"radio\"");
            return(View());
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 更新
 /// </summary>
 public int Update(Data.Model.Organize model)
 {
     return(dataOrganize.Update(model));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 新增
 /// </summary>
 public int Add(Data.Model.Organize model)
 {
     return(dataOrganize.Add(model));
 }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
0
        public ActionResult Body(FormCollection collection)
        {
            Data.Model.Organize        org       = null;
            Business.Platform.Organize borganize = new Business.Platform.Organize();
            string id = Request.QueryString["id"];

            if (id.IsGuid())
            {
                org = borganize.Get(id.ToGuid());
            }

            //保存
            if (!Request.Form["Save"].IsNullOrEmpty() && org != null)
            {
                string name         = Request.Form["Name"];
                string type         = Request.Form["Type"];
                string status       = Request.Form["Status"];
                string chargeLeader = Request.Form["ChargeLeader"];
                string leader       = Request.Form["Leader"];
                string note         = Request.Form["note"];
                string oldXML       = org.Serialize();
                org.Name         = name.Trim();
                org.Type         = type.ToInt(1);
                org.Status       = status.ToInt(0);
                org.ChargeLeader = chargeLeader;
                org.Leader       = leader;
                org.Note         = note.IsNullOrEmpty() ? null : note.Trim();

                borganize.Update(org);
                Business.Platform.Log.Add("修改了组织机构", "", Business.Platform.Log.Types.组织机构, oldXML, org.Serialize());
                string rid = org.ParentID == Guid.Empty ? org.ID.ToString() : org.ParentID.ToString();
                ViewBag.Script = "alert('保存成功!');parent.frames[0].reLoad('" + rid + "');";
            }

            //移动
            if (!Request.Form["Move1"].IsNullOrEmpty() && org != null)
            {
                string toOrgID = Request.Form["deptmove"];
                Guid   toID;
                if (toOrgID.IsGuid(out toID) && borganize.Move(org.ID, toID))
                {
                    Business.Platform.Log.Add("移动了组织机构", "将机构:" + org.ID + "移动到了:" + toID, Business.Platform.Log.Types.组织机构);
                    string refreshID = org.ParentID == Guid.Empty ? org.ID.ToString() : org.ParentID.ToString();
                    ViewBag.Script = "alert('移动成功!');parent.frames[0].reLoad('" + refreshID + "');parent.frames[0].reLoad('" + toOrgID + "')";
                }
                else
                {
                    ViewBag.Script = "alert('移动失败!');";
                }
            }

            //删除
            if (!Request.Form["Delete"].IsNullOrEmpty())
            {
                int i = borganize.DeleteAndAllChilds(org.ID);
                Business.Platform.Log.Add("删除了组织机构及其所有下级共" + i.ToString() + "项", org.Serialize(), Business.Platform.Log.Types.组织机构);
                string refreshID = org.ParentID == Guid.Empty ? org.ID.ToString() : org.ParentID.ToString();
                ViewBag.Script = "alert('共删除了" + i.ToString() + "项!');parent.frames[0].reLoad('" + refreshID + "');";
            }

            if (org == null)
            {
                org = new Data.Model.Organize();
            }
            ViewBag.TypeRadios   = borganize.GetTypeRadio("Type", org.Type.ToString(), "validate=\"radio\"");
            ViewBag.StatusRadios = borganize.GetStatusRadio("Status", org.Status.ToString(), "validate=\"radio\"");

            return(View(org));
        }