/// <summary> /// 新增子部门 /// </summary> /// <param name="NewDepartmentName">新增子部門的名字</param> /// <param name="errMsg">返回錯誤信息</param> /// <returns>返回操作結果</returns> public bool AddChildDepartment(string NewDepartmentName, string UserID, ref string errMsg) { try { QYConfig.RegistWX(); var accessToken = AccessTokenContainer.GetToken(QYConfig.CorpId); var result = MailListApi.CreateDepartment(accessToken, NewDepartmentName, int.Parse(DepartmentID)); if (result.errcode.ToString() == "请求成功") { if (DepartmentDA.AddDepartment(result.id.ToString(), DepartmentID, NewDepartmentName, "1", UserID)) { QYDepartmentBL newdep = GetByWXID(result.id.ToString()); Departments.Add(newdep); return(true); } else { errMsg = "数据库新增部门失败"; return(false); } } else { Logger.Log4Net.Error(result.errcode + ":" + result.errmsg); errMsg = result.errcode + ":" + result.errmsg; } } catch (Exception e) { Logger.Log4Net.Error("add department error:" + e); errMsg = "操作失敗:" + e.Message; return(false); } return(false); }
/// <summary> /// 更新部门信息到微信与数据库 /// </summary> /// <param name="UserID">操作者ID</param> /// <param name="errMsg">返回信息</param> /// <returns>操作是否成功</returns> public bool UpdateDepartment(string UserID, ref string errMsg) { try { QYConfig.RegistWX(); var accessToken = AccessTokenContainer.GetToken(QYConfig.CorpId); var result = MailListApi.UpdateDepartment(accessToken, DepartmentID, Name, int.Parse(ParentDepartmentID)); if (result.errcode.ToString() == "请求成功") { if (DepartmentDA.UpdateDepartmentByPkID(ID.ToString(), ParentDepartmentID, Name, wcOrder, UserID)) { return(true); } else { errMsg = "数据库修改部门失败"; return(false); } } else { Logger.Log4Net.Error(result.errcode + ":" + result.errmsg); errMsg = result.errcode + ":" + result.errmsg; } } catch (Exception e) { Logger.Log4Net.Error("Delete department error:" + e); errMsg = "操作失敗:" + e.Message; return(false); } return(false); }
/// <summary> /// 添加用户 /// </summary> /// <param name="CreateUserid">操作者ID</param> /// <param name="errMsg">返回错误信息</param> /// <param name="wxDepartmentID"></param> /// <returns></returns> public bool AddMember(string CreateUserid, ref string errMsg, string wxDepartmentID = null) { try { QYConfig.RegistWX(); var accessToken = AccessTokenContainer.GetToken(QYConfig.CorpId); var result = MailListApi.CreateMember(accessToken, UserId, Name, new int[] { int.Parse(wxDepartmentID ?? DepartMent.DepartmentID) }, Position, Mobile, null, Email, Weixinid, 0); if (result.errcode.ToString() == "请求成功") { var gresult = MailListApi.GetMember(accessToken, UserId); Avatar = gresult.avatar; if (MembertDA.AddMember(UserId, Name, Position, Mobile, Email, Weixinid, Avatar, Status, CreateBy, DepartmentPKId.ToString())) { return(true); } else { errMsg = result.errcode + ":" + result.errmsg; return(false); } } else { return(false); } } catch (Exception e) { Logger.Log4Net.Error("add Member error:" + e); errMsg = "操作失敗:" + e.Message; return(false); } }
/// <summary> /// 根据部门获取该部门下所有的Member /// </summary> /// <param name="DepPKID">部门在数据库的主键ID</param> /// <returns></returns> public static List <QYMemberBL> GetMemberAllByDep(QYDepartmentBL department) { List <string> l = GetAllDepID(department); QYMemberDA MembertDA = new QYMemberDA(); List <QYMemberBL> members = MembertDA.TableToEntity <QYMemberBL>(MembertDA.GetMemberByDepPKIDs(l)); if (members.Count > 0) { QYConfig.RegistWX(); var accessToken = AccessTokenContainer.GetToken(QYConfig.CorpId); var mlist = MailListApi.GetDepartmentMemberInfo(accessToken, int.Parse(members.First().DepartMent.DepartmentID), 1, 0).userlist; GetMemberResult item; for (int i = 0; i < members.Count; i++) { item = mlist.Find(p => p.userid == members[i].UserId); if (item != null) { if (item.status.ToString() != members[i].Status || item.avatar != members[i].Avatar) { members[i].Status = item.status.ToString(); members[i].Avatar = item.avatar; string errMsg = ""; members[i].UpdateMember("1", ref errMsg); } } } } return(members); }
/// <summary> /// 删除Member /// </summary> /// <param name="DeleteUserid">操作者ID</param> /// <param name="errMsg">返回错误信息</param> /// <returns></returns> public bool DeleteMember(string DeleteUserid, ref string errMsg) { try { QYConfig.RegistWX(); var accessToken = AccessTokenContainer.GetToken(QYConfig.CorpId); var result = MailListApi.DeleteMember(accessToken, UserId); if (result.errcode.ToString() == "请求成功") { if (MembertDA.DeleteMember(ID.ToString(), DeleteUserid)) { return(true); } else { errMsg = result.errcode + ":" + result.errmsg; return(false); } } else { return(false); } } catch (Exception e) { Logger.Log4Net.Error("add Member error:" + e); errMsg = "操作失敗:" + e.Message; return(false); } }
public static void DownloadDatafromWX() { QYConfig.RegistWX(); var accessToken = AccessTokenContainer.GetToken(QYConfig.CorpId); var result = MailListApi.GetDepartmentList(accessToken); for (int i = 0; i < result.department.Count; i++) { DepartmentDA.AddDepartment(result.department[i].id.ToString(), result.department[i].parentid.ToString(), result.department[i].name, "1", "1"); } QYDepartmentBL d = GetAllDepartments(); var l = MailListApi.GetDepartmentMemberInfo(accessToken, 1, 1, 0); for (int i = 0; i < l.userlist.Count; i++) { QYMemberDA mda = new QYMemberDA(); QYDepartmentBL p = QYDepartmentBL.GetByWXID(l.userlist[i].department[0].ToString()); mda.AddMember(l.userlist[i].userid, l.userlist[i].name, l.userlist[i].position, l.userlist[i].mobile, l.userlist[i].email, l.userlist[i].weixinid, l.userlist[i].avatar, l.userlist[i].status.ToString(), "1", p.ID.ToString()); } }
/// <summary> /// 删除本部门 /// </summary> /// <param name="errMsg">返回錯誤信息</param> /// <returns>返回操作結果</returns> public bool DeleteDepartment(string UserID, ref string errMsg, List <QYDepartmentBL> list = null) { try { QYConfig.RegistWX(); var accessToken = AccessTokenContainer.GetToken(QYConfig.CorpId); var result = MailListApi.DeleteDepartment(accessToken, DepartmentID); if (result.errcode.ToString() == "请求成功") { if (DepartmentDA.DeleteDepartmentByPkID(ID.ToString(), UserID)) { DeleteBy = UserID; DeleteDate = DateTime.Now; if (list != null) { list.Remove(this); } return(true); } else { errMsg = "数据库刪除部门失败"; return(false); } } else { Logger.Log4Net.Error(result.errcode + ":" + result.errmsg); errMsg = result.errcode + ":" + result.errmsg; } } catch (Exception e) { Logger.Log4Net.Error("Delete department error:" + e); errMsg = "操作失敗:" + e.Message; return(false); } return(false); }
public bool Invite(ref string errMsg) { try { QYConfig.RegistWX(); var accessToken = AccessTokenContainer.GetToken(QYConfig.CorpId); var result = MailListApi.InviteMember(accessToken, UserId, QYConfig.InvateMsg); if (result.errcode.ToString() == "请求成功") { return(true); } else { errMsg = result.errcode + ":" + result.errmsg; return(false); } } catch (Exception e) { Logger.Log4Net.Error("Invite error:" + e); errMsg = "操作失敗:" + e.Message; return(false); } }