Esempio n. 1
0
        protected void buttonSubmit_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request.Params[txtPickup.UniqueID]))
            {
                ShowWarning("Pick up address is required.");
            }

            //ScreenCaptureSave();
            BookingSetData();
            BookingViewBLL.BookingSaveOrUpdate(Booking);
            ShowSuccess("Booking updated. Please fix errors if exists and submit again");

            bool   needEmail = !Booking.Special && chkSpecial.Checked;
            string email     = string.Empty;

            if (needEmail)
            {
                email = "&confirm=1";
            }
            foreach (RepeaterItem extraService in rptExtraServices.Items)
            {
                var chkService = (HtmlInputCheckBox)extraService.FindControl("chkService");
                if (chkService.Checked)
                {
                    SaveExtraService();
                }
                else
                {
                    DeleteExtraService();
                }
            }
            foreach (RepeaterItem item in rptCustomers.Items)
            {
                CustomerInfoRowInput customerInfo1 = item.FindControl("customerData") as CustomerInfoRowInput;
                if (customerInfo1 != null)
                {
                    Customer customer1 = customerInfo1.NewCustomer(Module);
                    customer1.Booking = this.Booking;
                    Module.SaveOrUpdate(customer1);

                    Repeater rptService1 = item.FindControl("rptServices1") as Repeater;
                    if (rptService1 != null)
                    {
                        if (DetailService)
                        {
                            CustomerServiceRepeaterHandler.Save(rptService1, Module, customer1);
                        }
                    }
                }
            }
            Booking.EndDate     = Booking.StartDate.AddDays(Booking.Trip.NumberOfDay - 1);
            Session["Redirect"] = true;
            PageRedirect(string.Format("BookingView.aspx?NodeId={0}&SectionId={1}&bi={2}{3}", Node.Id, Section.Id, Booking.Id, email));
        }
        /// <summary>
        /// Dùng cho sự kiện data bound của một danh sách booking room
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <param name="module"></param>
        /// <param name="customPrice"></param>
        /// <param name="policies"></param>
        /// <param name="page"></param>
        /// <param name="roomTypes"></param>
        public static void rptRoomList_itemDataBound(object sender, RepeaterItemEventArgs e, SailsModule module, bool customPrice, IList policies, SailsAdminBasePage page, ListItemCollection roomTypes)
        {
            if (e.Item.ItemType != ListItemType.Header)
            {
                BookingRoom item = e.Item.DataItem as BookingRoom;
                if (item != null)
                {
                    #region -- Thông tin thường --

                    Label lblRoomName = (Label)e.Item.FindControl("lblRoomName");
                    if (item.Room != null)
                    {
                        Label label_RoomId = (Label)e.Item.FindControl("label_RoomId");
                        label_RoomId.Text = item.Room.Id.ToString();
                        if (item.Room != null)
                        {
                            lblRoomName.Text = string.Format("{2}: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0} {1}",
                                                             item.RoomClass.Name, item.RoomType.Name,
                                                             item.Room.Name);
                        }
                        else
                        {
                            lblRoomName.Text = string.Format("{0} {1}",
                                                             item.RoomClass.Name, item.RoomType.Name);
                        }
                    }
                    else
                    {
                        lblRoomName.Text = string.Format("Room {2}: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0} {1}",
                                                         item.RoomClass.Name, item.RoomType.Name,
                                                         e.Item.ItemIndex + 1);
                    }

                    HiddenField hiddenRoomClassId = (HiddenField)e.Item.FindControl("hiddenRoomClassId");
                    HiddenField hiddenRoomTypeId  = (HiddenField)e.Item.FindControl("hiddenRoomTypeId");

                    hiddenRoomClassId.Value = item.RoomClass.Id.ToString();
                    hiddenRoomTypeId.Value  = item.RoomType.Id.ToString();

                    if (item.Booked == 1 && item.RoomType.Id == SailsModule.TWIN)
                    {
                        e.Item.FindControl("trCustomer2").Visible = false;
                        e.Item.FindControl("trExtra").Visible     = false;
                    }

                    CheckBox    checkBoxAddChild = (CheckBox)e.Item.FindControl("checkBoxAddChild");
                    HtmlControl trChild          = (HtmlControl)e.Item.FindControl("trChild");
                    HtmlControl trChildServices  = (HtmlControl)e.Item.FindControl("trChildServices");

                    string scriptChild = string.Format(@"toggleVisible('{0}');toggleVisible('{1}');",
                                                       trChild.ClientID, trChildServices.ClientID);
                    checkBoxAddChild.Attributes.Add("onclick", scriptChild);

                    CheckBox    checkBoxAddBaby = (CheckBox)e.Item.FindControl("checkBoxAddBaby");
                    HtmlControl trBaby          = (HtmlControl)e.Item.FindControl("trBaby");
                    HtmlControl trBabyServices  = (HtmlControl)e.Item.FindControl("trBabyServices");
                    string      scriptBaby      = string.Format(@"toggleVisible('{0}');toggleVisible('{1}');", trBaby.ClientID,
                                                                trBabyServices.ClientID);
                    checkBoxAddBaby.Attributes.Add("onclick", scriptBaby);

                    CheckBox    checkBoxSingle      = (CheckBox)e.Item.FindControl("checkBoxSingle");
                    HtmlControl trCustomer2         = (HtmlControl)e.Item.FindControl("trCustomer2");
                    HtmlControl trCustomer2Services = (HtmlControl)e.Item.FindControl("trCustomer2Services");
                    string      scriptCustomer      = string.Format(@"toggleVisible('{0}');toggleVisible('{1}');",
                                                                    trCustomer2.ClientID, trCustomer2Services.ClientID);
                    checkBoxSingle.Attributes.Add("onclick", scriptCustomer);

                    #endregion

                    #region -- (back-end) --

                    bool isSecond = false;
                    // Load customer info đã có

                    #region -- customer info --

                    foreach (Customer customer in item.Customers)
                    {
                        if (customer.Type == CustomerType.Adult)
                        {
                            if (!isSecond)
                            {
                                CustomerInfoInput customer1   = e.Item.FindControl("customer1") as CustomerInfoInput;
                                Repeater          rptService1 = e.Item.FindControl("rptServices1") as Repeater;
                                if (customer1 != null && rptService1 != null)
                                {
                                    customer1.GetCustomer(customer, module);
                                    if (page.DetailService)
                                    {
                                        CustomerServiceRepeaterHandler handler =
                                            new CustomerServiceRepeaterHandler(customer, module);
                                        rptService1.DataSource     = module.CustomerServices;
                                        rptService1.ItemDataBound += handler.ItemDataBound;
                                        rptService1.DataBind();
                                    }
                                    else
                                    {
                                        rptService1.Visible = false;
                                    }
                                    isSecond = true;
                                }
                            }
                            else
                            {
                                CustomerInfoInput customer2   = e.Item.FindControl("customer2") as CustomerInfoInput;
                                Repeater          rptService2 = e.Item.FindControl("rptServices2") as Repeater;
                                if (customer2 != null && rptService2 != null)
                                {
                                    customer2.GetCustomer(customer, module);
                                    if (page.DetailService)
                                    {
                                        CustomerServiceRepeaterHandler handler =
                                            new CustomerServiceRepeaterHandler(customer, module);
                                        rptService2.DataSource     = module.CustomerServices;
                                        rptService2.ItemDataBound += handler.ItemDataBound;
                                        rptService2.DataBind();
                                    }
                                    else
                                    {
                                        rptService2.Visible = false;
                                    }
                                }
                            }
                        }


                        if (customer.Type == CustomerType.Children)
                        {
                            CustomerInfoInput customerChild =
                                e.Item.FindControl("customerChild") as CustomerInfoInput;
                            Repeater rptServicesChild = e.Item.FindControl("rptServicesChild") as Repeater;
                            if (customerChild != null && rptServicesChild != null)
                            {
                                customerChild.GetCustomer(customer, module);
                                if (page.DetailService)
                                {
                                    CustomerServiceRepeaterHandler handler = new CustomerServiceRepeaterHandler(
                                        customer, module);
                                    rptServicesChild.DataSource     = module.CustomerServices;
                                    rptServicesChild.ItemDataBound += handler.ItemDataBound;
                                    rptServicesChild.DataBind();
                                }
                                else
                                {
                                    rptServicesChild.Visible = false;
                                }
                            }
                        }

                        if (customer.Type == CustomerType.Baby)
                        {
                            CustomerInfoInput customerBaby    = e.Item.FindControl("customerBaby") as CustomerInfoInput;
                            Repeater          rptServicesBaby = e.Item.FindControl("rptServicesBaby") as Repeater;
                            if (customerBaby != null && rptServicesBaby != null)
                            {
                                customerBaby.GetCustomer(customer, module);
                                if (page.DetailService)
                                {
                                    CustomerServiceRepeaterHandler handler = new CustomerServiceRepeaterHandler(
                                        customer, module);
                                    rptServicesBaby.DataSource     = module.CustomerServices;
                                    rptServicesBaby.ItemDataBound += handler.ItemDataBound;
                                    rptServicesBaby.DataBind();
                                }
                                else
                                {
                                    rptServicesBaby.Visible = false;
                                }
                            }
                        }
                    }

                    #endregion

                    #region -- Check box và visible --

                    if (item.VirtualAdult == 1)
                    {
                        e.Item.FindControl("trCustomer2").Visible  = false;
                        e.Item.FindControl("rptServices2").Visible = false;
                    }

                    if (item.HasChild)
                    {
                        trChild.Attributes.CssStyle["display"]         = "";
                        trChildServices.Attributes.CssStyle["display"] = "";
                        checkBoxAddChild.Checked = true;
                    }
                    else
                    {
                        Repeater rptServicesChild = e.Item.FindControl("rptServicesChild") as Repeater;
                        if (rptServicesChild != null)
                        {
                            rptServicesChild.DataSource = module.CustomerServices;
                            rptServicesChild.DataBind();
                        }
                    }

                    if (item.HasBaby)
                    {
                        trBaby.Attributes.CssStyle["display"]         = "";
                        trBabyServices.Attributes.CssStyle["display"] = "";
                        checkBoxAddBaby.Checked = true;
                    }
                    else
                    {
                        Repeater rptServicesBaby = e.Item.FindControl("rptServicesBaby") as Repeater;
                        if (rptServicesBaby != null)
                        {
                            rptServicesBaby.DataSource = module.CustomerServices;
                            rptServicesBaby.DataBind();
                        }
                    }

                    if (item.IsSingle)
                    {
                        trCustomer2.Attributes.CssStyle["display"]         = "none";
                        trCustomer2Services.Attributes.CssStyle["display"] = "none";
                        checkBoxSingle.Checked = true;
                    }

                    #endregion

                    // Load room available

                    #region -- available --

                    DropDownList ddlRooms = e.Item.FindControl("ddlRooms") as DropDownList;
                    if (ddlRooms != null)
                    {
                        // Danh sách phòng được chọn bao gồm: toàn bộ các phòng chưa được chọn và phòng trong book hiện tại
                        IList datasouce = module.RoomGetAvailable(item.Book.Cruise, item, (item.Book.EndDate - item.Book.StartDate).Days,
                                                                  item.Book);
                        Room room = new Room("", false, null, null);
                        datasouce.Insert(0, room);
                        ddlRooms.DataSource     = datasouce;
                        ddlRooms.DataTextField  = Room.NAME;
                        ddlRooms.DataValueField = "Id";
                        ddlRooms.DataBind();

                        if (item.Room != null)
                        {
                            ListItem listItem = ddlRooms.Items.FindByValue(item.Room.Id.ToString());
                            if (listItem != null)
                            {
                                listItem.Selected = true;
                            }
                        }
                    }

                    #endregion

                    #region -- room price --

                    if (customPrice)
                    {
                        TextBox txtPrice = e.Item.FindControl("txtPrice") as TextBox;
                        if (txtPrice != null)
                        {
                            if (item.Total <= 0)
                            {
                                if (module.ModuleSettings(SailsModule.CUSTOMER_PRICE) == null || Convert.ToBoolean(module.ModuleSettings(SailsModule.CUSTOMER_PRICE)))
                                {
                                    txtPrice.Visible = false;
                                }
                                else
                                {
                                    txtPrice.Visible = true;
                                }
                                item.Total = item.Calculate(module, policies, page.ChildPrice, page.AgencySupplement, null);
                            }
                            txtPrice.Text = item.Total.ToString("0.#");
                        }
                    }
                    else
                    {
                        PlaceHolder plhRoomPrice = e.Item.FindControl("plhRoomPrice") as PlaceHolder;
                        if (plhRoomPrice != null)
                        {
                            plhRoomPrice.Visible = false;
                        }
                    }

                    #endregion

                    DropDownList ddlRoomTypes = e.Item.FindControl("ddlRoomTypes") as DropDownList;
                    if (ddlRoomTypes != null)
                    {
                        if (item.VirtualAdult == 2)
                        {
                            ddlRoomTypes.DataSource     = roomTypes; //module.RoomTypexGetAll();
                            ddlRoomTypes.DataValueField = "Value";
                            ddlRoomTypes.DataTextField  = "Text";
                            ddlRoomTypes.DataBind();

                            ListItem listitem =
                                ddlRoomTypes.Items.FindByValue(string.Format("{0}|{1}", item.RoomClass.Id,
                                                                             item.RoomType.Id));

                            if (listitem != null)
                            {
                                listitem.Selected = true;
                            }
                            else
                            {
                                ddlRoomTypes.Items.Add(new ListItem(item.RoomClass.Name + " " + item.RoomType.Name,
                                                                    string.Format("{0}|{1}", item.RoomClass.Id,
                                                                                  item.RoomType.Id)));
                                ddlRoomTypes.SelectedValue = string.Format("{0}|{1}", item.RoomClass.Id,
                                                                           item.RoomType.Id);
                            }
                        }
                        else
                        {
                            ddlRoomTypes.Visible = false;
                            e.Item.FindControl("labelRoomTypes").Visible = false;
                        }
                    }

                    #endregion
                }
            }
        }