Exemplo n.º 1
0
        /// <summary>
        /// VoteGridView的删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void VoteGridView_OnRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            CY.GFive.Core.Business.Vote vote = new CY.GFive.Core.Business.Vote();
            int ID = 0;

            if (int.TryParse(this.VoteGridView.DataKeys[e.RowIndex].Value.ToString(), out ID))
            {
                try
                {
                    vote = CY.GFive.Core.Business.Vote.Load(ID);
                    vote.DeleteOnSave();
                    vote.Save();
                    CY.GFive.Core.Business.VoteRole.DeleteVoteRoleByVoteId(ID);
                    IList<CY.GFive.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>");
                }
            }
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                HttpRequest request = context.Request;

                string strJSON = System.Web.HttpContext.Current.Server.UrlDecode(request.Form.Get("Vote").ToString());
                string teacher = request.Form.Get("Depart").ToString();
                string[] depart = teacher.Split(',');
                CY.GFive.Core.Business.Vote voteJson = (CY.GFive.Core.Business.Vote)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(strJSON, typeof(CY.GFive.Core.Business.Vote));

                #region Insert

                CY.GFive.Core.Business.Vote vote = new CY.GFive.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.GFive.Core.Business.VoteItem voteItem = new CY.GFive.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.GFive.Core.Business.VoteAnswer va in voteItem.VoteAnswerList)
                    {
                        CY.GFive.Core.Business.VoteAnswer voteAnswer = new CY.GFive.Core.Business.VoteAnswer();
                        voteAnswer.VoteItemID = voteItem.Id;
                        voteAnswer.VoteAnswerContent = va.VoteAnswerContent;
                        voteAnswer.Save();
                    }
                }

                foreach (string dep in depart)
                {
                    CY.GFive.Core.Business.VoteRole voterole = new CY.GFive.Core.Business.VoteRole();
                    if (dep != "教师")
                    {
                        CY.GFive.Core.Business.Department depitem = CY.GFive.Core.Business.Department.GetDepartByName(dep);
                        voterole.DepartmentID = depitem.Id;
                    }
                    else
                        voterole.DepartmentID = 0;
                    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 + "'}");
            }
        }