//删除分配项 //private bool DeletePerform() //{ // string siteUrl = SPContext.Current.Site.Url; // bool ret = false; // SPSecurity.RunWithElevatedPrivileges(delegate () // { // using (SPSite spSite = new SPSite(siteUrl)) //找到网站集 // { // using (SPWeb spWeb = spSite.OpenWeb(SPContext.Current.Web.ID)) // { // SPList spList = spWeb.Lists.TryGetList(webObj.ResultList); // if (spList != null) // { // spWeb.AllowUnsafeUpdates = true; // SPListItem listItem; // int id = int.Parse(ViewState["id"].ToString()); // listItem = spList.Items.GetItemById(id); // listItem.Delete(); // spWeb.AllowUnsafeUpdates = false; // ret= true; // } // } // } // }); // return ret; //} private void UpdateAllPerforms(List <string> performs) { SPUser appraiseUser = SPContext.Current.Web.CurrentUser; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite spSite = new SPSite(SPContext.Current.Site.ID)) //找到网站集 { using (SPWeb spWeb = spSite.OpenWeb(SPContext.Current.Web.ID)) { SPList spList = spWeb.Lists.TryGetList(webObj.ResultList); if (spList != null) { SPQuery query; SPListItemCollection items; string ID = Page.Request.QueryString["ID"]; spWeb.AllowUnsafeUpdates = true; SPListItem listItem; string lookupInternalName = GetSubTitleInterlname.Trim(); foreach (string strPerform in performs) { string[] itmes = strPerform.Split(';'); int id = int.Parse(itmes[0]); if (id < 0) { query = new SPQuery(); query.Query = @"<Where><And><And><Eq><FieldRef Name='AuthorName' LookupId='True' /><Value Type='Integer'>" + itmes[1] + "</Value></Eq><Eq><FieldRef Name='Action' /><Value Type='Choice'>" + webObj.CurrentAction + "</Value></Eq></And><Eq><FieldRef Name='" + lookupInternalName + "' LookupId='True' /><Value Type='Lookup'>" + ID + "</Value></Eq></And></Where>"; items = spList.GetItems(query); if (items.Count == 0) { listItem = spList.AddItem(); listItem[GetTitleDispName] = ID;// + ";#" + strPerformance; } else { continue; } } else { listItem = spList.Items.GetItemById(id); } listItem[GetAuthorDispName] = int.Parse(itmes[1]); //GetUserValue(spWeb, picker);//用户填写的 listItem[GetRadioDispName] = double.Parse(itmes[2]); //系数 listItem["动作"] = webObj.CurrentAction; listItem["创建者"] = appraiseUser.ID; // + ";#" + appraiseUser.Name;//当前用户 listItem.Update(); } spWeb.AllowUnsafeUpdates = false; } } } }); }
//是否已经评审 /// <summary> /// 当前登录者是否已经审批过,只能审批一次 /// </summary> /// <param name="strAction">操作名称</param> /// <param name="strCreativity">创意名称</param> /// <returns></returns> public SPListItem GetAppraiseRecord(string strAction, string strPerformanceID, string strState, ref int flag) { string siteUrl = SPContext.Current.Site.Url; int f = flag; SPListItem retItem = null; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite spSite = new SPSite(siteUrl)) //找到网站集 { using (SPWeb spWeb = spSite.OpenWeb(SPContext.Current.Web.ID)) { SPList spList = spWeb.Lists.TryGetList(webObj.ResultList); SPList spTList = spWeb.Lists.TryGetList(webObj.ListName); string lookupInternalName = GetSubTitleInterlname.Trim(); if (spList != null) { SPQuery qry = new SPQuery(); //<And><Eq><FieldRef Name='Author' /> <Value Type='Integer'> <UserID /> </Value></Eq></And> qry.Query = @"<Where><And><Eq><FieldRef Name='Action' /><Value Type='Choice'>" + strAction + "</Value></Eq><And><Eq><FieldRef Name='State' /><Value Type='Choice'>" + strState + "</Value></Eq><Eq><FieldRef Name='" + lookupInternalName + "' LookupId='True' /><Value Type='Lookup'>" + strPerformanceID + "</Value></Eq></And></And></Where>"; SPListItemCollection listItems = spList.GetItems(qry); if (listItems.Count > 0) { //ViewState["id"] = listItems[0]["ID"]; SPListItem parentItem = spTList.GetItemById(int.Parse(strPerformanceID)); if (strState == webObj.ReturnResult) { if (spTList != null && spTList.Fields.ContainsFieldWithStaticName("Flag"))//审核通过,主表加标记 { if (parentItem["Flag"] == null || parentItem["Flag"].ToString() != "1") { spWeb.AllowUnsafeUpdates = true; parentItem["Flag"] = 1; parentItem.Update(); spWeb.AllowUnsafeUpdates = false; } } } f = int.Parse(parentItem["Flag"].ToString()); retItem = listItems[0]; } } } } }); flag = f; return(retItem); }
//获取与论文相关的业绩, public DataTable GetPerformRecord(string strAction, string strPerformanceID) { string siteUrl = SPContext.Current.Site.Url; //List<string> authors = new List<string>(); IDictionary <int, string> authors = new Dictionary <int, string>(); using (SPSite spSite = new SPSite(siteUrl)) //找到网站集 { using (SPWeb spWeb = spSite.OpenWeb(SPContext.Current.Web.ID)) { SPList spList = spWeb.Lists.TryGetList(webObj.ResultList); string lookupInternalName = GetSubTitleInterlname.Trim(); if (spList != null) { SPQuery qry = new SPQuery(); string strQuery = @"<Where><And><Eq><FieldRef Name='Action' /><Value Type='Choice'>" + strAction + "</Value></Eq><Eq><FieldRef Name='" + lookupInternalName + "' LookupId='True' /><Value Type='Lookup'>" + strPerformanceID + "</Value></Eq></And></Where>"; qry.Query = strQuery; SPListItemCollection listItems = spList.GetItems(qry); rblAuthors.Items.Clear(); double tRatio = 0; string authorNameTitle = spList.Fields.GetFieldByInternalName("AuthorName").Title; foreach (SPListItem listItem in listItems) { SPFieldUserValue author = new SPFieldUserValue(spWeb, listItem[authorNameTitle].ToString()); //double ratio = listItem[GetRadioDispName]==null?0: (double )listItem[GetRadioDispName] ; //tRatio = tRatio + ratio; //rblAuthors.Items.Add(new ListItem(author.User.Name +" "+ratio , author.User.ID + ";" + listItem.ID+";"+ratio )); authors.Add(listItem.ID, author.User.LoginName); } ViewState["TotalRatio"] = tRatio; ViewState["Authors"] = authors; DataTable dt = listItems.GetDataTable(); if (dt == null) { dt = spList.GetItems().GetDataTable().Clone(); } DataTable dt1 = dt.Copy(); if (dt1.Columns.Contains("Radio")) { dt1.Columns["Radio"].ColumnName = "Ratio"; } int id = -1; for (int i = dt1.Rows.Count; i < webObj.TotolRows; i++) { DataRow dr = dt1.NewRow(); dr["ID"] = id; dt1.Rows.Add(dr); id = id - 1; } if (dt.Rows.Count == 0) { SPUser use = SPContext.Current.Web.CurrentUser; dt1.Rows[0]["AuthorName"] = use.ID; dt1.Rows[0]["Ratio"] = TotalRatio; authors.Add((int)dt1.Rows[0]["ID"], use.LoginName); } ViewState["gvSource"] = dt1; return(dt1); } } } return(null); }