Esempio n. 1
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string action = Request["action"];
        if (action == null) {
            if (string.IsNullOrEmpty(txtName.Text.Trim()) || string.IsNullOrEmpty(txtPrice.Text.Trim()) ||
                string.IsNullOrEmpty(txtDays.Text.Trim()) || string.IsNullOrEmpty(txtMaxPeople.Text.Trim()) ||
                string.IsNullOrEmpty(txtIntroduce.Text) || string.IsNullOrEmpty(txtAttention.Text)) {
                ClientScript.RegisterStartupScript(Page.GetType(), "ss", "<script>alert('请按要求输入完整信息')</script>");
                return;
            }

            string name = txtName.Text;
            string type = lstType.SelectedValue;
            int price = Convert.ToInt32(txtPrice.Text.Trim());
            int days = Convert.ToInt32(txtDays.Text.Trim());
            int maxPeople = Convert.ToInt32(txtMaxPeople.Text.Trim());
            string introduce = txtIntroduce.Text;
            string attention = txtAttention.Text;

            //插入数据库
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DataSource"].ConnectionString);
            string insert = string.Format("insert into TourLine(LineName, LineType, LinePrice, LineDays, LineMaxPeople, LineIntroduce, LineAttention) values('{0}', '{1}', {2}, {3}, {4}, '{5}', '{6}')", name, type, price, days, maxPeople, introduce, attention);
            SqlCommand cmd = new SqlCommand(insert, connection);

            try {
                connection.Open();
                cmd.ExecuteNonQuery();
                connection.Close();
                ClientScript.RegisterStartupScript(Page.GetType(), "Message", "<script>alert('添加成功');location.href('/Admin/Manage.aspx')</script>");
            } catch {
            }
        } else {  // 编辑信息

            int id = Convert.ToInt32(Request["id"]);
            var dataSet = new TourLineTableAdapter().GetDataByID(id).Single();

            if (string.IsNullOrEmpty(txtName.Text.Trim()) || string.IsNullOrEmpty(txtPrice.Text.Trim()) ||
                string.IsNullOrEmpty(txtDays.Text.Trim()) || string.IsNullOrEmpty(txtMaxPeople.Text.Trim()) ||
                string.IsNullOrEmpty(txtIntroduce.Text) || string.IsNullOrEmpty(txtAttention.Text)) {
                ClientScript.RegisterStartupScript(Page.GetType(), "ss", "<script>alert('请按要求输入完整信息')</script>");
                return;
            }

            dataSet.LineName = txtName.Text;
            dataSet.LineType = lstType.SelectedValue;
            dataSet.LinePrice = Convert.ToInt32(txtPrice.Text.Trim());
            dataSet.LineDays = Convert.ToInt32(txtDays.Text.Trim());
            dataSet.LineMaxPeople = Convert.ToInt32(txtMaxPeople.Text.Trim());
            dataSet.LineIntroduce = txtIntroduce.Text;
            dataSet.LineAttention = txtAttention.Text;

            new TourLineTableAdapter().Update(dataSet);
            //if (action == "edit") {
            ClientScript.RegisterStartupScript(Page.GetType(), "Message", "<script>alert('修改成功');location.href('/Admin/Manage.aspx')</script>");
            //} else {
            //ClientScript.RegisterStartupScript(Page.GetType(), "Message", "<script>alert('添加成功');location.href('/Admin/Manage.aspx')</script>");
            //}
        }
    }
Esempio n. 2
0
    protected void btnReserve_Click(object sender, EventArgs e)
    {
        if (Session["UserName"] == null) {
            Response.Redirect("~/UserLogin.aspx");
        } else {
            int lineId = Convert.ToInt32(Request["id"]);
            var lineTable = new TourLineTableAdapter().GetDataByID(lineId);
            var lineRow = lineTable.Single();

            // 判断当天余量是否充足
            long lineID = lineRow.LineID;               // 订单编号
            int maxPeople = lineRow.LineMaxPeople;      // 最大人数
            DateTime travelTime = CaleOrderTime.SelectedDate.Date;  // 旅行日期

            if (travelTime == DateTime.Parse("0001-01-01")) {   // 判断是否选择合法日期
                ClientScript.RegisterStartupScript(Page.GetType(), "ss", "<script>alert('请选择日期')</script>");
                return;
            }

            // 获取已选人数
            string count = string.Format("select count(*) as ordered from OrderInfo where LineID={0} and TravelDate='{1}';", lineID, travelTime);
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DataSource"].ConnectionString);
            SqlCommand cmd = new SqlCommand(count, conn);

            try {
                conn.Open();    // 打开数据库连接
                int ordered = (int)(cmd.ExecuteScalar());   // 获取已选人数
                if (ordered >= maxPeople) {
                    ClientScript.RegisterStartupScript(Page.GetType(), "ss", "<script>alert('Sorry,当前已选人数已满,请更换日期')</script>");
                }
            } catch {

            } finally {
                conn.Close();   // 关闭数据库连接
            }

            string orderID =
                DateTime.Now.ToString("yyyyMMddHHmmss") + Session["UserName"].ToString();   // 订单编号

            // 将此订单加入数据库
            string insert = string.Format(@"insert into OrderInfo(OrderID, UserName, LineID, TravelDate, IsComplete, IsComment)
                Values('{0}', '{1}', {2}, '{3}', {4}, {5})", orderID, Session["UserName"].ToString(), lineID, travelTime, 0, 0);
            SqlCommand insertCmd = new SqlCommand(insert, conn);

            try {
                conn.Open();
                insertCmd.ExecuteNonQuery();
                ClientScript.RegisterStartupScript(Page.GetType(), "ss", "<script>alert('订购成功');{location.href='UserViewOrders.aspx'}</script>");
            } catch {
            } finally {
                conn.Close();
            }

        }
    }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) {
            string action = Request["action"];
            if (action == "edit") {
                this.Title = "修改线路";
                int id = Convert.ToInt32(Request["id"]);
                var dataSet = new TourLineTableAdapter().GetDataByID(id).Single();

                txtName.Text = dataSet.LineName;
                lstType.Text = dataSet.LineType;
                txtPrice.Text = dataSet.LinePrice.ToString();
                txtDays.Text = dataSet.LineDays.ToString();
                txtMaxPeople.Text = dataSet.LineMaxPeople.ToString();
                txtIntroduce.Text = dataSet.LineIntroduce;
                txtAttention.Text = dataSet.LineAttention;
            } else {
                this.Title = "添加线路";
            }
        }
    }
Esempio n. 4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) {
            int lineId = Convert.ToInt32(Request["id"]);
            var lineTable = new TourLineTableAdapter().GetDataByID(lineId);

            if (lineTable.Count <= 0) {
                litLineName.Text = "线路不存在";
            }

            var lineRow = lineTable.Single();

            litLineName.Text = lineRow.LineName;
            litLineType.Text = lineRow.LineType;
            litLinePrice.Text = lineRow.LinePrice.ToString() + "¥";
            litLineDays.Text = lineRow.LineDays.ToString() + "天";
            litLineMaxPeople.Text = lineRow.LineMaxPeople.ToString() + "人";
            litLineIntroduce.Text = lineRow.LineIntroduce;
            litLineAttention.Text = lineRow.LineAttention;

            this.Title = litLineName.Text;
            // 显示评论
            SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["DataSource"].ConnectionString);
            string select = string.Format("select UserName, Grade, Content from CommentTable where LineID={0}", Convert.ToInt32(Request["id"]));
            DataSet dataset = new DataSet();

            try {
                conn.Open();
                SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(select, conn);
                adapter.Fill(dataset);
                GridView1.DataSource = dataset;
                GridView1.DataBind();
            } finally {
                conn.Close();
            }

            // 综合评分
            var table = new GradeTableAdapters.CommentTableTableAdapter();
            int? count = table.ScalarQueryCount(Convert.ToInt32(Request["id"]));
            double? sum = table.ScalarQuerySum(Convert.ToInt32(Request["id"]));

            if ((count == null) || (sum == null)) {
                litGrade.Text = "尚无评分";
            } else {
                litGrade.Text = (sum / count).ToString() + "/5";
            }
        }
    }