Ejemplo n.º 1
0
        protected void bunSumbit_Click(object sender, EventArgs e)
        {
            #region Valid
            if (string.IsNullOrEmpty(tbName.Text.Trim()))
            {
                //Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '错误', content: '活动名称不能为空'});</script>");
                base.ExecuteClientScript("$('#add_msg').html('活动名称不能为空。').fadeOut(10000, function () { $(this).html('').show(); });");
                tbName.Focus();
                return;
            }
            if (tbName.Text.Trim().Length > 20)
            {
                //Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '错误', content: '活动名称不能超过20字符'});</script>");
                base.ExecuteClientScript("$('#add_msg').html('活动名称不能为空。').fadeOut(10000, function () { $(this).html('').show(); });");
                tbName.Focus();
                return;
            }
            if (string.IsNullOrEmpty(tbStartTime.Text.Trim()))
            {
                //Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '错误', content: '活动起始时间不能为空'});</script>");
                base.ExecuteClientScript("$('#add_msg').html('活动起始时间不能为空。').fadeOut(10000, function () { $(this).html('').show(); });");
                tbStartTime.Focus();
                return;
            }
            if (string.IsNullOrEmpty(tbEndTime.Text.Trim()))
            {
                //Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '错误', content: '活动结束时间不能为空'});</script>");
                base.ExecuteClientScript("$('#add_msg').html('活动结束时间不能为空。').fadeOut(10000, function () { $(this).html('').show(); });");
                tbEndTime.Focus();
                return;
            }
            HttpPostedFile files = Request.Files["file"];
            if (files.ContentLength > 0 && !string.IsNullOrEmpty(files.FileName))
            {
                string fileExtension = CY.Utility.Common.FileUtility.GetFileExtension(files.FileName).ToLower();
                if (fileExtension != ".jpg" && fileExtension != ".jpeg" && fileExtension != ".gif" && fileExtension != ".png" && fileExtension != ".bmp")
                {
                    //Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '错误', content: '图片格式不正确,请上传图片格式'});</script>");
                    base.ExecuteClientScript("$('#add_msg').html('图片格式不正确,请重新选择图片上传。').fadeOut(10000, function () { $(this).html('').show(); });");
                    return;
                }
            }

            #endregion
            try
            {
                if (Request.QueryString["ActiveID"] == null)
                {
                    CY.UME.Core.Business.Activities activ = new CY.UME.Core.Business.Activities();
                    activ.Name = tbName.Text.Trim();//活动名称
                    if (!string.IsNullOrEmpty(tbStartTime.Text.Trim()))
                    {
                        string startH = tbStartTime.Text.Trim();
                        string startM = ddlHour.SelectedValue;
                        string startS = ddlM.SelectedValue;
                        string Time = startH + " " + startM + ":" + startS;
                        activ.StartTime = DateTime.Parse(Time);//起始时间
                    }
                    if (!string.IsNullOrEmpty(tbEndTime.Text.Trim()))
                    {
                        string endH = tbEndTime.Text.Trim();
                        string endM = ddlH2.SelectedValue;
                        string endS = ddlM2.SelectedValue;
                        string endTime = endH + " " + endM + ":" + endS;
                        activ.EndTime = DateTime.Parse(endTime);//结束时间
                    }
                    activ.Sponsor = CurrentAccount.Id;//发起人
                    activ.Overview = tbOverView.Text.Trim();//活动简介
                    //activ.Slogans = tbSlogans.Text.Trim();//活动广告语
                    activ.Type = int.Parse(ddlType.SelectedValue);//活动类型
                    activ.Address = tbAddress.Text.Trim();//活动地址
                    if (Request.QueryString["groupId"] != null)
                    {
                        activ.Organizer = CY.Utility.Common.ConvertUtility.ConvertToLong(Request.QueryString["groupId"], 0);
                    }
                    activ.Save();

                    if (files != null && files.ContentLength > 0 && !string.IsNullOrEmpty(files.FileName))
                    {
                        SaveFiles(activ.Id, activ.Name, files);
                    }
                    else
                    {
                        activ.CreateActiveAlbum();
                    }
                    /*****************************************************************************/
                    //存入参加人表
                    CY.UME.Core.Business.ActivitieParticipants ap = new CY.UME.Core.Business.ActivitieParticipants();
                    ap.ActivitieId = activ.Id;
                    ap.AccountId = CurrentAccount.Id;
                    ap.JionTime = DateTime.Now;
                    ap.Type = 1;//参加
                    ap.Save();
                    //存入感兴趣表
                    CY.UME.Core.Business.ActivitieParticipants apInterest = new CY.UME.Core.Business.ActivitieParticipants();
                    apInterest.ActivitieId = activ.Id;
                    apInterest.AccountId = CurrentAccount.Id;
                    apInterest.JionTime = DateTime.Now;
                    apInterest.Type = 2;//感兴趣
                    apInterest.Save();
                    /******************************************************************************************************/
                    //添加通知
                    //CurrentAccount.SendNoticeToAllFriend("activites", CurrentAccount.Name + "创建了新活动:" + activ.Name, activ.Id.ToString());后台加
                    //Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '提示', content: '发起活动成功,等待管理员审核,跳转到活动首页'});window.location.href='ActiveDefault.aspx'</script>");
                    base.ShowAlert("提示", "发起活动成功,等待管理员审核。<span>3</span>秒后自动跳转。", true, pageName, true);
                }
                else
                {
                    int aID = CY.Utility.Common.ConvertUtility.ConvertToInt(Request.QueryString["ActiveID"], 0);
                    CY.UME.Core.Business.Activities at = CY.UME.Core.Business.Activities.Load(aID);
                    if (at != null)
                    {
                        at.Name = tbName.Text.Trim();//活动名称
                        if (!string.IsNullOrEmpty(tbStartTime.Text.Trim()))
                        {
                            string startH = tbStartTime.Text.Trim();
                            string startM = ddlHour.SelectedValue;
                            string startS = ddlM.SelectedValue;
                            string Time = startH + " " + startM + ":" + startS;
                            at.StartTime = DateTime.Parse(Time);//起始时间
                        }
                        if (!string.IsNullOrEmpty(tbEndTime.Text.Trim()))
                        {
                            string endH = tbEndTime.Text.Trim();
                            string endM = ddlH2.SelectedValue;
                            string endS = ddlM2.SelectedValue;
                            string endTime = endH + " " + endM + ":" + endS;
                            at.EndTime = DateTime.Parse(endTime);//结束时间
                        }

                        //at.Sponsor = CurrentAccount.Id;//发起人
                        at.Overview = tbOverView.Text.Trim();//活动简介
                        //at.Slogans = tbSlogans.Text.Trim();//活动广告语
                        at.Type = int.Parse(ddlType.SelectedValue);//活动类型
                        at.Address = tbAddress.Text.Trim();//活动地址
                        at.Save();
                        if (files != null && files.ContentLength > 0 && !string.IsNullOrEmpty(files.FileName))
                        {
                            if (File.Exists(Server.MapPath(at.Pic)))
                            {
                                File.Delete(Server.MapPath(at.Pic));
                            }
                            SaveFiles(at.Id, at.Name, files);
                        }
                        if (at.IsCheck)
                        {
                            //添加通知
                            //CurrentAccount.SendNoticeToAllFriend("activites", CurrentAccount.Name + "创建了新活动:" + at.Name, aID.ToString());后台加
                            //Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '提示', content: '编辑活动成功,跳转到活动首页'});window.location.href='ActiveDetail2.aspx?aid=" + aID + "'</script>");
                            base.ShowAlert("提示", "编辑活动成功。<span>3</span>秒后自动跳转。请稍后。。。", true, pageName, true);
                        }
                        else
                        {
                            //Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '提示', content: '修改活动成功,等待管理员审核,跳转到活动首页'});window.location.href='ActiveDefault.aspx'</script>");
                            base.ShowAlert("提示", "修改活动成功,等待管理员审核。<span>3</span>秒后自动跳转。<br/>请稍后。。。", true, pageName, true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>cy.ume.ui.window({title: '错误', content: '" + ex.Message + "'});</script>");
                base.ShowAlert("提示", ex.Message, false, "", true);
                return;
            }
        }