protected void rptCustomers_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.DataItem is Customer) { Customer customer = (Customer)e.Item.DataItem; CustomerInfoRowInput customerData = e.Item.FindControl("customerData") as CustomerInfoRowInput; if (customerData != null) { customerData.GetCustomer(customer, Module); } } }
/// <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}: {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}: {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; } HtmlInputCheckBox checkBoxAddChild = (HtmlInputCheckBox)e.Item.FindControl("checkBoxAddChild"); HtmlControl trChild = (HtmlControl)e.Item.FindControl("trChild"); string scriptChild = string.Format(@"toggleVisible('{0}');", trChild.ClientID); checkBoxAddChild.Attributes.Add("onclick", scriptChild); HtmlInputCheckBox checkBoxAddBaby = (HtmlInputCheckBox)e.Item.FindControl("checkBoxAddBaby"); HtmlControl trBaby = (HtmlControl)e.Item.FindControl("trBaby"); string scriptBaby = string.Format(@"toggleVisible('{0}');", trBaby.ClientID); checkBoxAddBaby.Attributes.Add("onclick", scriptBaby); HtmlInputCheckBox checkBoxSingle = (HtmlInputCheckBox)e.Item.FindControl("checkBoxSingle"); HtmlControl trCustomer2 = (HtmlControl)e.Item.FindControl("trCustomer2"); string scriptCustomer = string.Format(@"toggleVisible('{0}');", trCustomer2.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 != null && customer.Type == CustomerType.Adult) { if (!isSecond) { CustomerInfoRowInput customer1 = e.Item.FindControl("customer1") as CustomerInfoRowInput; 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 { CustomerInfoRowInput customer2 = e.Item.FindControl("customer2") as CustomerInfoRowInput; 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) { CustomerInfoRowInput customerChild = e.Item.FindControl("customerChild") as CustomerInfoRowInput; 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) { CustomerInfoRowInput customerBaby = e.Item.FindControl("customerBaby") as CustomerInfoRowInput; 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 -- checkBoxSingle.Checked = false; checkBoxAddChild.Checked = false; checkBoxAddBaby.Checked = false; if (item.Adult == 1) { trCustomer2.Attributes.CssStyle["display"] = "none"; checkBoxSingle.Checked = true; } trChild.Attributes.CssStyle["display"] = "none"; if (item.HasChild) { trChild.Attributes.CssStyle["display"] = ""; checkBoxAddChild.Checked = true; } else { Repeater rptServicesChild = e.Item.FindControl("rptServicesChild") as Repeater; if (rptServicesChild != null) { rptServicesChild.DataSource = module.CustomerServices; rptServicesChild.DataBind(); } } trBaby.Attributes.CssStyle["display"] = "none"; if (item.HasBaby) { trBaby.Attributes.CssStyle["display"] = ""; checkBoxAddBaby.Checked = true; } else { Repeater rptServicesBaby = e.Item.FindControl("rptServicesBaby") as Repeater; if (rptServicesBaby != null) { rptServicesBaby.DataSource = module.CustomerServices; rptServicesBaby.DataBind(); } } #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 = "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; // } // } //} var txtRoomNumber = e.Item.FindControl("txtRoomNumber") as TextBox; txtRoomNumber.Text = item.RoomNumber; #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 } } }