コード例 #1
0
ファイル: Route.aspx.cs プロジェクト: johnsonhaovip/Travel
    protected void btn_sure_Click(object sender, EventArgs e)
    {
        string title       = tx_title.Text.Trim();       //旅行名字
        string depart      = tx_depart.Text.Trim();      //获取出发地
        string destination = tx_destination.Text.Trim(); //从地图上获取目的地
        string sumtime     = tx_sumTime.Text.Trim();     //获取旅行的天数
        string starttime   = tx_startTime.Text.Trim();   //获取开始旅行的时间

        Travel.Model.Tab_user   tab_user   = new Travel.Model.Tab_user();
        Travel.Model.Tab_travel tab_travel = new Travel.Model.Tab_travel();

        //通过Session将emaile和ID交给tab_travel对象
        tab_travel.U_emaile = Travel.BLL.UserBusiness.GetUserByEmaile(Session["u_emaile"].ToString()).U_emaile;//获取用户emaile

        if (string.IsNullOrEmpty(tab_travel.U_emaile))
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('请先登录!')</script>");
            //跳转到指定界面
            Response.Redirect("Login.aspx");
        }

        else
        {
            if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(depart) || string.IsNullOrEmpty(destination) || string.IsNullOrEmpty(sumtime) || string.IsNullOrEmpty(starttime))
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('请先填写完整数据!')</script>");
            }
            else
            {
                int      sumTime   = Convert.ToInt32(sumtime);
                DateTime startTime = Convert.ToDateTime(starttime);
                tab_travel.T_title       = title;
                tab_travel.T_depart      = depart;//将其交给它
                tab_travel.T_destination = destination;
                tab_travel.T_sumTime     = sumTime;
                tab_travel.T_startTime   = startTime;
                tab_travel.UploadTime    = Convert.ToDateTime(DateTime.Now.ToString());


                if (Travel.BLL.TravelBusiness.TravelIsExist(destination))
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('您已经有该行程!')</script>");
                }

                else
                {
                    if (Travel.BLL.TravelBusiness.AddTravel(tab_travel))
                    {
                        Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('添加行程成功!')</script>");
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(GetType(), "info", "<script>alert('添加行程失败!')</script>");
                    }
                }
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// 我的行程修改和删除
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "delete")
        {
            string u_id = e.CommandArgument.ToString();
            Session["u_id"] = u_id;

            Travel.Model.Tab_user   tab_user   = new Travel.Model.Tab_user();
            Travel.Model.Tab_travel tab_travel = new Travel.Model.Tab_travel();
            //通过Session获取用户行程标题
            tab_travel.T_title = Travel.BLL.TravelBusiness.GetTravelByID(Convert.ToInt32(Session["u_id"])).T_title;
            //通过Session获取用户emaile
            tab_user.U_emaile = Travel.BLL.UserBusiness.GetUserByEmaile(Session["u_emaile"].ToString()).U_emaile;



            //调用数据库里的删除行程的存储过程
            if (Travel.BLL.TravelBusiness.DeleteTravel(tab_user.U_emaile, tab_travel.T_title))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('删除行程成功!')</script>");
                Response.AddHeader("Refresh", "0");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "info", "<script>alert('删除行程失败!')</script>");
            }
        }
        if (e.CommandName == "change")
        {
            //通过commandArgument传参数过来
            string u_id = Convert.ToString(e.CommandArgument);

            Session["u_id"] = u_id;
            Response.Redirect("ChangeTravel.aspx?u_id=" + Session["u_id"]);
        }
    }