分类: MOSS sharepoint2013-03-19 12:04 314人阅读 评论(0) 收藏 举报
- /// <summary>
- /// 根据用户登录名得到部门名称,只保留三级
- /// </summary>
- /// <param name="loginName">用户登录名</param>
- /// <returns></returns>
- private string DepartmentByLoginName(string loginName)
- {
- string rst = string.Empty;
- using (SPSite site = new SPSite(SPContext.Current.Site.ID))
- {
- using (SPWeb web = site.OpenWeb())
- {
- SPList list = web.Lists["员工信息列表"];
- SPQuery spQuery = new SPQuery();
- spQuery.Query = "<Where> <Eq><FieldRef Name='LoginName'/> <Value Type ='Text'>" + loginName + "</Value></Eq></Where>";
- spQuery.ViewFields = "<FieldRef Name='Department'/>";
- SPListItemCollection items = list.GetItems(spQuery);
- if (items.Count == 1)
- {
- rst = items[0]["Department"].ToString();
- if (rst.Contains("#"))
- rst = rst.Split('#')[1];
- }
- }
- }
- string[] departs = rst.Split('-');
- if (departs.Length > 2)
- {
- rst = departs[0] + "-" + departs[1] + "-" + departs[2];
- }
- return rst;
- }
- /// <summary>
- /// 得到上级经理
- /// </summary>
- void Manager(string loginName)
- {
- HiddenFieldPosition.Value = "";
- #region 给部门和岗位赋值
- using (SPSite site = new SPSite(SPContext.Current.Site.ID))
- {
- using (SPWeb web = site.OpenWeb())
- {
- #region 从员工列表读取当前用户的信息,给部门和岗位赋值
- SPList list = web.Lists["员工信息列表"];
- SPQuery query = new SPQuery();
- query.Query = "<Where><Eq><FieldRef Name='LoginName' /><Value Type='Text'>" + loginName + "</Value></Eq></Where>";
- SPListItemCollection itemCollection = list.GetItems(query);
- if (itemCollection.Count > 0)
- {
- SPListItem item = itemCollection[0];
- string[] strDeparts = item["Department"].ToString().Split('#');
- //上级经理
- FormFieldManager.Value = item["Manager"];
- SPFieldUserValue userValue = new SPFieldUserValue(web, item["Manager"].ToString());
- SPUser user = userValue.User;
- LabelManager.Text = user.Name;
- //岗位标签
- FormFieldPostlabel.Value = null;
- FormFieldAttache.Value = "";
- LabelAttache.Text = "";
- if (item["Postlabel"] != null)
- {
- FormFieldPostlabel.Value = item["Postlabel"].ToString();
- //if (item["Postlabel"].ToString() == "销售")
- //{
- if (item["costcommissioner"] != null)
- {
- FormFieldAttache.Value = item["costcommissioner"];
- SPFieldUserValue costManagerValue = new SPFieldUserValue(web, item["costcommissioner"].ToString());
- SPUser costManager = costManagerValue.User;
- LabelAttache.Text = costManager.Name;
- //HiddenFieldAttachDisplayMode.Value = "true";
- //LabelAttache.Visible = true;
- }
- //}
- //else
- //{
- // HiddenFieldAttachDisplayMode.Value = "false";
- // LabelAttache.Visible = false;
- //}
- }
- if (item["Managementlevel"] != null)
- {
- HiddenFieldPosition.Value = item["Managementlevel"].ToString();
- }
- }
- #endregion
- }
- }
- #endregion