sharepoint 获得上级和部门的封装函数

sharepoint 获得上级和部门的封装函数

分类: MOSS sharepoint
[csharp] view plaincopy
 
  1. /// <summary>  
  2.      /// 根据用户登录名得到部门名称,只保留三级  
  3.      /// </summary>  
  4.      /// <param name="loginName">用户登录名</param>  
  5.      /// <returns></returns>  
  6.      private string DepartmentByLoginName(string loginName)  
  7.      {  
  8.          string rst = string.Empty;  
  9.          using (SPSite site = new SPSite(SPContext.Current.Site.ID))  
  10.          {  
  11.              using (SPWeb web = site.OpenWeb())  
  12.              {  
  13.                  SPList list = web.Lists["员工信息列表"];  
  14.                  SPQuery spQuery = new SPQuery();  
  15.                  spQuery.Query = "<Where> <Eq><FieldRef Name='LoginName'/> <Value Type ='Text'>" + loginName + "</Value></Eq></Where>";  
  16.                  spQuery.ViewFields = "<FieldRef Name='Department'/>";  
  17.                  SPListItemCollection items = list.GetItems(spQuery);  
  18.                  if (items.Count == 1)  
  19.                  {  
  20.                      rst = items[0]["Department"].ToString();  
  21.                      if (rst.Contains("#"))  
  22.                          rst = rst.Split('#')[1];  
  23.                  }  
  24.              }  
  25.          }  
  26.          string[] departs = rst.Split('-');  
  27.          if (departs.Length > 2)  
  28.          {  
  29.              rst = departs[0] + "-" + departs[1] + "-" + departs[2];  
  30.          }  
  31.          return rst;  
  32.      }  
  33.      /// <summary>  
  34.      /// 得到上级经理  
  35.      /// </summary>  
  36.      void Manager(string loginName)  
  37.      {  
  38.   
  39.          HiddenFieldPosition.Value = "";  
  40.  
  41.          #region 给部门和岗位赋值  
  42.          using (SPSite site = new SPSite(SPContext.Current.Site.ID))  
  43.          {  
  44.              using (SPWeb web = site.OpenWeb())  
  45.              {  
  46.                  #region 从员工列表读取当前用户的信息,给部门和岗位赋值  
  47.                  SPList list = web.Lists["员工信息列表"];  
  48.                  SPQuery query = new SPQuery();  
  49.                  query.Query = "<Where><Eq><FieldRef Name='LoginName' /><Value Type='Text'>" + loginName + "</Value></Eq></Where>";  
  50.                  SPListItemCollection itemCollection = list.GetItems(query);  
  51.                  if (itemCollection.Count > 0)  
  52.                  {  
  53.                      SPListItem item = itemCollection[0];  
  54.                      string[] strDeparts = item["Department"].ToString().Split('#');  
  55.                      //上级经理  
  56.                      FormFieldManager.Value = item["Manager"];  
  57.                      SPFieldUserValue userValue = new SPFieldUserValue(web, item["Manager"].ToString());  
  58.                      SPUser user = userValue.User;  
  59.                      LabelManager.Text = user.Name;  
  60.                      //岗位标签  
  61.                      FormFieldPostlabel.Value = null;  
  62.                      FormFieldAttache.Value = "";  
  63.                      LabelAttache.Text = "";  
  64.                      if (item["Postlabel"] != null)  
  65.                      {  
  66.                          FormFieldPostlabel.Value = item["Postlabel"].ToString();  
  67.                          //if (item["Postlabel"].ToString() == "销售")  
  68.                          //{  
  69.                          if (item["costcommissioner"] != null)  
  70.                          {  
  71.                              FormFieldAttache.Value = item["costcommissioner"];  
  72.   
  73.                              SPFieldUserValue costManagerValue = new SPFieldUserValue(web, item["costcommissioner"].ToString());  
  74.                              SPUser costManager = costManagerValue.User;  
  75.                              LabelAttache.Text = costManager.Name;  
  76.                              //HiddenFieldAttachDisplayMode.Value = "true";  
  77.                              //LabelAttache.Visible = true;  
  78.                          }  
  79.                          //}  
  80.                          //else  
  81.                          //{  
  82.                          //    HiddenFieldAttachDisplayMode.Value = "false";  
  83.                          //    LabelAttache.Visible = false;  
  84.                          //}  
  85.                      }  
  86.                      if (item["Managementlevel"] != null)  
  87.                      {  
  88.                          HiddenFieldPosition.Value = item["Managementlevel"].ToString();  
  89.                      }  
  90.   
  91.                  }  
  92.  
  93.                  #endregion  
  94.              }  
  95.          }  
  96.          #endregion  

posted on 2015-03-08 18:05  创造快乐  阅读(198)  评论(0编辑  收藏  举报

导航