public void ProcessRequest(HttpContext context) { try { HttpRequest request = context.Request; string strJSON = System.Web.HttpContext.Current.Server.UrlDecode(request.Form.ToString()); CY.CSTS.Core.Business.Vote voteJson = (CY.CSTS.Core.Business.Vote)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(strJSON, typeof(CY.CSTS.Core.Business.Vote)); #region Insert CY.CSTS.Core.Business.Vote vote = new CY.CSTS.Core.Business.Vote(); vote.VoteTitle = voteJson.VoteTitle; vote.VoteStartTime = System.DateTime.Now; vote.VoteLimit = voteJson.VoteLimit; vote.VoteSate = 1; vote.UserID = 1; vote.VoteItemList = voteJson.VoteItemList; vote.Save(); for(int i=0; i < vote.VoteItemList.Count; i++) { CY.CSTS.Core.Business.VoteItem voteItem = new CY.CSTS.Core.Business.VoteItem(); voteItem.VoteItemContent = vote.VoteItemList[i].VoteItemContent; voteItem.VoteID = vote.Id; voteItem.IsMutiChoose = vote.VoteItemList[i].IsMutiChoose; voteItem.IsUserDefine = vote.VoteItemList[i].IsUserDefine; voteItem.VoteAnswerList = vote.VoteItemList[i].VoteAnswerList; voteItem.Save(); foreach (CY.CSTS.Core.Business.VoteAnswer va in voteItem.VoteAnswerList) { CY.CSTS.Core.Business.VoteAnswer voteAnswer = new CY.CSTS.Core.Business.VoteAnswer(); voteAnswer.VoteItemID = voteItem.Id; voteAnswer.VoteAnswerContent = va.VoteAnswerContent; voteAnswer.Save(); } } #endregion context.Response.ContentType = "application/json"; context.Response.Write("{success: true}"); } catch (Exception ex) { context.Response.ContentType = "application/json"; context.Response.Write("{success: false, msg: '" + ex.Message + "'}"); } }
/// <summary> /// VoteGridView的删除事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void VoteGridView_OnRowDeleting(object sender, GridViewDeleteEventArgs e) { CY.CSTS.Core.Business.Vote vote = new CY.CSTS.Core.Business.Vote(); int ID = 0; if (int.TryParse(this.VoteGridView.DataKeys[e.RowIndex].Value.ToString(), out ID)) { try { vote = CY.CSTS.Core.Business.Vote.Load(ID); vote.DeleteOnSave(); vote.Save(); CY.CSTS.Core.Business.VoteRole.DeleteVoteRoleByVoteId(ID); IList<CY.CSTS.Core.Business.VoteItem> vIList = DeleteVoteItem(ID);//删除所有投票项 DeleteVoteAnswer(vIList);//删除所有答案项 List<CY.CSTS.Core.Business.VoteRecord> voteRecordList = CY.CSTS.Core.Business.VoteRecord.GetVoteAdviceByVoteID(ID) as List<CY.CSTS.Core.Business.VoteRecord>; if (voteRecordList != null) { for (int m = 0; m < voteRecordList.Count; ++m) { CY.CSTS.Core.Business.VoteRecord voteReco = CY.CSTS.Core.Business.VoteRecord.Load(voteRecordList[m].Id); if (voteReco != null) { voteReco.DeleteOnSave(); voteReco.Save(); CY.CSTS.Core.Business.UserAnswer.DeleteByVoteRecordID(voteRecordList[m].Id); CY.CSTS.Core.Business.VoteRecordDetail.DeleteByVoteRecordID(voteRecordList[m].Id); } } } ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('删除成功!');</script>"); VoteGridView_DataBind(); } catch { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('删除成功!');</script>"); } } }
/// <summary> /// VoteGridView的删除事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void VoteGridView_OnRowDeleting(object sender, GridViewDeleteEventArgs e) { CY.CSTS.Core.Business.Vote vote = new CY.CSTS.Core.Business.Vote(); int ID = 0; if (int.TryParse(this.VoteGridView.DataKeys[e.RowIndex].Value.ToString(), out ID)) { try { vote = CY.CSTS.Core.Business.Vote.Load(ID); vote.DeleteOnSave(); vote.Save(); CY.CSTS.Core.Business.VoteRole.DeleteVoteRoleByVoteId(ID); IList<CY.CSTS.Core.Business.VoteItem> vIList = DeleteVoteItem(ID);//删除所有投票项 DeleteVoteAnswer(vIList);//删除所有答案项 ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('删除成功!');</script>"); VoteGridView_DataBind(); } catch { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('删除失败!');</script>"); } } }
public void ProcessRequest(HttpContext context) { try { HttpRequest request = context.Request; string strJSON = System.Web.HttpContext.Current.Server.UrlDecode(request.Params["vote"].ToString()); CY.CSTS.Core.Business.Vote voteJson = (CY.CSTS.Core.Business.Vote)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(strJSON, typeof(CY.CSTS.Core.Business.Vote)); #region Insert CY.CSTS.Core.Business.Vote vote = new CY.CSTS.Core.Business.Vote(); vote.VoteTitle = voteJson.VoteTitle; vote.VoteStartTime = System.DateTime.Now; vote.VoteLimit = voteJson.VoteLimit; vote.VoteSate = 1; CY.CSTS.Core.Business.User userSession = context.Session["User"] as CY.CSTS.Core.Business.User; vote.UserID = userSession.Id; //1; vote.VoteItemList = voteJson.VoteItemList; vote.Save(); for (int i = 0; i < vote.VoteItemList.Count; i++) { CY.CSTS.Core.Business.VoteItem voteItem = new CY.CSTS.Core.Business.VoteItem(); voteItem.VoteItemContent = vote.VoteItemList[i].VoteItemContent; voteItem.VoteID = vote.Id; voteItem.IsMutiChoose = vote.VoteItemList[i].IsMutiChoose; voteItem.IsUserDefine = vote.VoteItemList[i].IsUserDefine; voteItem.VoteAnswerList = vote.VoteItemList[i].VoteAnswerList; voteItem.Save(); foreach (CY.CSTS.Core.Business.VoteAnswer va in voteItem.VoteAnswerList) { CY.CSTS.Core.Business.VoteAnswer voteAnswer = new CY.CSTS.Core.Business.VoteAnswer(); voteAnswer.VoteItemID = voteItem.Id; voteAnswer.VoteAnswerContent = va.VoteAnswerContent; voteAnswer.Save(); } } if (context.Request.Params["userType"] != null) { string userTypeTemp = context.Request.Params["userType"].ToString(); string[] userType = userTypeTemp.Split(','); for (int i = 0; i < userType.Count(); i++) { CY.CSTS.Core.Business.VoteRole voteRole = new CY.CSTS.Core.Business.VoteRole(); int role = 0; switch (userType[i]) { case "普通用户": role = 1; break; //case "分中心普通用户": role = 2; break; //case "协作单位普通用户": role = 3; break; case "专家用户": role = 4; break; case "管理员": role = 5; break; case "分中心管理员用户": role = 6; break; case "协作单位管理员用户": role = 7; break; } voteRole.RoleID = role; voteRole.DepartmentID = role; voteRole.VoteID = vote.Id; voteRole.Save(); } } #endregion context.Response.ContentType = "application/json"; context.Response.Write("{success: true}"); } catch (Exception ex) { context.Response.ContentType = "application/json"; context.Response.Write("{success: false, msg: '" + ex.Message + "'}"); } }