예제 #1
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            int      userId        = Convert.ToInt32(Session["UserId"]);
            int      serviceId     = Convert.ToInt32(Request.QueryString["Id"]);
            Label    lblPrice      = fvService.FindControl("lblPrice") as Label;
            Label    lblSurcharge  = fvService.FindControl("lblSurcharge") as Label;
            Label    lblUrgentDays = fvService.FindControl("lblUrgentDays") as Label;
            decimal  surcharge     = Convert.ToDecimal(lblSurcharge.Text);
            int      urgentDays    = Convert.ToInt32(lblUrgentDays.Text);
            DateTime serviceDate   = calTimeslot.SelectedDate;
            decimal  unitPrice     = Convert.ToDecimal(lblPrice.Text);

            if ((serviceDate - DateTime.Now).Days < urgentDays)
            {
                unitPrice = unitPrice + surcharge;
            }

            List <DateTime> selectedTimeslots = new List <DateTime>();
            foreach (ListViewDataItem item in lvTimeslot.Items)
            {
                CheckBox chkTimeslot = item.FindControl("chkTimeslot") as CheckBox;
                if (chkTimeslot.Checked)
                {
                    string   strTime  = chkTimeslot.Text;
                    DateTime timeslot = serviceDate.Date + TimeSpan.FromHours(Convert.ToInt32(strTime.Split(':')[0]));
                    selectedTimeslots.Add(timeslot);
                }
            }

            ServiceOrderEntities soe = new ServiceOrderEntities();

            Order order = new Order();

            order.UserId      = userId;
            order.ServiceId   = serviceId;
            order.Price       = unitPrice * selectedTimeslots.Count;
            order.Address     = "Please Enter Address.";
            order.ServiceDate = serviceDate;
            foreach (DateTime timeslot in selectedTimeslots)
            {
                OrderTimeslot ots = new OrderTimeslot();
                ots.Order     = order;
                ots.ServiceId = serviceId;
                ots.Timeslot  = timeslot;
                order.OrderTimeslot.Add(ots);
            }
            order.Status          = "PENDING";
            order.Enabled         = true;
            order.CreatedDateTime = DateTime.Now;
            soe.Order.Add(order);
            soe.SaveChanges();

            Response.Redirect(String.Format("~/UserPages/OrderForm.aspx?Id={0}", order.Id));
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            int      orderId     = Convert.ToInt32(Request.QueryString["Id"]);
            DateTime serviceDate = calTimeslot.SelectedDate;

            List <DateTime> selectedTimeslots = new List <DateTime>();
            foreach (ListViewDataItem item in lvTimeslot.Items)
            {
                CheckBox chkTimeslot = item.FindControl("chkTimeslot") as CheckBox;
                if (chkTimeslot.Checked)
                {
                    string   strTime  = chkTimeslot.Text;
                    DateTime timeslot = serviceDate.Date + TimeSpan.FromHours(Convert.ToInt32(strTime.Split(':')[0]));
                    selectedTimeslots.Add(timeslot);
                }
            }


            ServiceOrderEntities soe = new ServiceOrderEntities();

            Order order = soe.Order.Find(orderId);

            order.ServiceDate = serviceDate;
            order.OrderTimeslot.Clear();
            foreach (DateTime timeslot in selectedTimeslots)
            {
                OrderTimeslot ots = new OrderTimeslot();
                ots.Order     = order;
                ots.ServiceId = order.ServiceId.Value;
                ots.Timeslot  = timeslot;
                order.OrderTimeslot.Add(ots);
            }

            order.CreatedDateTime = DateTime.Now;
            soe.SaveChanges();

            Response.Redirect(String.Format("~/UserPages/OrderPayment.aspx?Id={0}", order.Id));
        }
    }