protected void btnOrder_Click(object sender, EventArgs e) { Order order = new Order(); order.OrderHotelRoomTypes = new List<OrderHotelRoomType>(); int sId = int.Parse(Request["sId"]); _input = _db.SearchInputs.Find(sId); order.StartDate = _input.DateCheckIn; order.EndDate = _input.DateCheckOut; order.Price = 0; order.OrderHotelRoomTypes = new List<OrderHotelRoomType>(); if (lvRoomDetail.Items.Count > 0) { foreach (ListViewDataItem it in lvRoomDetail.Items) { HiddenField hidRoomTypeId = it.FindControl("hidRoomTypeId") as HiddenField; HotelRoomType htrt = _db.HotelRoomTypes.Find(int.Parse(hidRoomTypeId.Value)); DropDownList ddlRoomCount = it.FindControl("ddlRoomCount") as DropDownList; if (int.Parse(ddlRoomCount.SelectedValue) > 0) { Literal litPrice = it.FindControl("litPrice") as Literal; order.Price += int.Parse(ddlRoomCount.SelectedValue) * int.Parse(litPrice.Text.Replace(".","")); OrderHotelRoomType type = new OrderHotelRoomType(); type.HotelRoomType = htrt; type.NumOfRoom = int.Parse(ddlRoomCount.SelectedValue); TextBox txtPeople = it.FindControl("txtPeople") as TextBox; int num; if (int.TryParse(txtPeople.Text,out num)&&num>0) { type.NumOfPeople = num; } else { litError.Text = "cần phải nhập số người cho các phòng được chọn !"; return; } order.OrderHotelRoomTypes.Add(type); } } } if(order.Price==0) { litError.Text = "cần chọn ít nhất một phòng !"; return; } OrderContact contact = new OrderContact(); contact.Name = txtName.Text; contact.Phone = txtPhone.Text; contact.Adress = txtAdress.Text; contact.Email = txtEmail.Text; contact.BirthDay = order.StartDate; order.OrderContact = contact; order.OrderDate = DateTime.Now; order.State = OrderStateEnum.NEW; _db.Orders.Add(order); _db.SaveChanges(); //Response.Redirect("http://google.com.vn"); }
protected void mnOrderBy_MenuItemClick(object sender, MenuEventArgs e) { int sId = int.Parse(Request["sId"]); input = _db.SearchInputs.Find(sId); if (e.Item.Value == "thap-nhat") { Hotel[] li = _db.Hotels.Where(x => (input.KeyWord.Length == 0 || x.Name.Contains(input.KeyWord)) && (input.CityId == 0 || x.City.Id == input.CityId) && (input.Star == 0 || input.Star == x.Star)).ToArray(); for (int i = 0; i < li.Length - 1; i++) { for (int j = i; j < li.Length; j++) { if (li[i].getMinPrice(input.DateCheckIn, input.DateCheckOut) > li[j].getMinPrice(input.DateCheckIn, input.DateCheckOut)) { Hotel a = li[i]; li[i] = li[j]; li[j] = a; } } } lvHotel.DataSource = li; lvHotel.DataBind(); } else if (e.Item.Value == "cao-nhat") { Hotel[] li = _db.Hotels.Where(x => (input.KeyWord.Length == 0 || x.Name.Contains(input.KeyWord)) && (input.CityId == 0 || x.City.Id == input.CityId) && (input.Star == 0 || input.Star == x.Star)).ToArray(); for (int i = 0; i < li.Length - 1; i++) { for (int j = i; j < li.Length; j++) { if (li[i].getMinPrice(input.DateCheckIn, input.DateCheckOut) < li[j].getMinPrice(input.DateCheckIn, input.DateCheckOut)) { Hotel a = li[i]; li[i] = li[j]; li[j] = a; } } } lvHotel.DataSource = li; lvHotel.DataBind(); } else if (e.Item.Value == "sao") { lvHotel.DataSource = _db.Hotels.Where(x => (input.KeyWord.Length == 0 || x.Name.Contains(input.KeyWord)) && (input.CityId == 0 || x.City.Id == input.CityId) && (input.Star == 0 || input.Star == x.Star)).OrderByDescending(x => x.Star).ToList(); lvHotel.DataBind(); } }
protected void lvHotel_ItemDataBound(object sender, ListViewItemEventArgs e) { Literal litFeature = e.Item.FindControl("litFeature") as Literal; if (litFeature != null) { int sId = int.Parse(Request["sId"]); input = _db.SearchInputs.Find(sId); int hotelId = int.Parse(DataBinder.Eval(e.Item.DataItem, "Id").ToString()); List<HotelFeature> htfs = _db.HotelFeatures.Where(x => x.HotelRoomTypes.Where(y => y.Hotel.Id == hotelId).Count() > 0).ToList(); foreach (HotelFeature hf in htfs) litFeature.Text += "<div class='divFeatured'><b>" + hf.Name + "</b> miễn phí</div>"; Hotel hotel = _db.Hotels.Find(hotelId); Literal litPrice = e.Item.FindControl("litPrice") as Literal; litPrice.Text = FormatHelper.FormatPrice(hotel.getMinPrice(input.DateCheckIn, input.DateCheckOut).ToString()); } }
protected void ButtonSearch_Click(object sender, EventArgs e) { try { string hotelName = TextBoxHotelName.Text; string CheckInTime = TextBoxCheckIn.Text; if (CheckInTime == "") { LiteralSearchError.Text = "<div class='error'>Bạn phải chọn ngày đến !</div>"; LiteralSearchError.Visible = true; return; } string CheckOutTime = TextBoxCheckOut.Text; if (CheckOutTime == "") { LiteralSearchError.Text = "<div class='error'>Bạn phải chọn ngày đi !</div>"; LiteralSearchError.Visible = true; return; } SearchInput input = new SearchInput { KeyWord = hotelName, DateCheckIn = DateTime.Parse(CheckInTime, CultureInfo.GetCultureInfo("en-Gb")), DateCheckOut = DateTime.Parse(CheckOutTime, CultureInfo.GetCultureInfo("en-Gb")), CityId = int.Parse(ddlCity.SelectedValue), Star = int.Parse(ddlStar.SelectedValue) }; _db.SearchInputs.Add(input); _db.SaveChanges(); Response.Redirect("/tim-kiem?sId=" + input.Id); } catch { LiteralSearchError.Text = "<div class='error'>đã xảy ra lỗi !</div>"; LiteralSearchError.Visible = true; } }
protected void ButtonSearch_Click(object sender, EventArgs e) { try { string hotelName = TextBoxHotelName.Text; string CheckInTime = TextBoxNgayDen.Text; string CheckOutTime = TextBoxNgayDi.Text; SearchInput input = new SearchInput { KeyWord = hotelName, DateCheckIn = DateTime.Parse(CheckInTime, CultureInfo.GetCultureInfo("en-Gb")), DateCheckOut = DateTime.Parse(CheckOutTime, CultureInfo.GetCultureInfo("en-Gb")), CityId = int.Parse(ddlCity.SelectedValue), Star = int.Parse(ddlStar.SelectedValue) }; DatPhongKhachSanDbContext db = new DatPhongKhachSanDbContext(); db.SearchInputs.Add(input); db.SaveChanges(); Response.Redirect("/tim-kiem?sId=" + input.Id); } catch { } }
private void LoadData() { try { int sId = int.Parse(Request["sId"]); input = _db.SearchInputs.Find(sId); TextBoxHotelName.Text = input.KeyWord; TextBoxNgayDen.Text = input.DateCheckIn.ToString("dd/MM/yyyy"); TextBoxNgayDi.Text = input.DateCheckOut.ToString("dd/MM/yyyy"); ddlCity.DataSource = _db.Cities.OrderBy(x => x.Name).ToList(); ddlCity.DataValueField = "Id"; ddlCity.DataTextField = "Name"; ddlCity.DataBind(); ddlCity.Items.Insert(0, new ListItem("Tất cả", "0")); ddlCity.SelectedValue = input.CityId.ToString(); ddlStar.SelectedValue = input.Star.ToString(); hidHotelTag.Value = string.Join(",", _db.Hotels.Select(x => x.Name).ToList()); Hotel[] li = _db.Hotels.Where(x => (input.KeyWord.Length == 0 || x.Name.Contains(input.KeyWord)) && (input.CityId == 0 || x.City.Id == input.CityId) && (input.Star == 0 || input.Star == x.Star)).ToArray(); for (int i = 0; i < li.Length - 1; i++) { for (int j = i; j < li.Length; j++) { if (li[i].getMinPrice(input.DateCheckIn, input.DateCheckOut) > li[j].getMinPrice(input.DateCheckIn, input.DateCheckOut)) { Hotel a = li[i]; li[i] = li[j]; li[j] = a; } } } lvHotel.DataSource = li; lvHotel.DataBind(); } catch { }; }
protected void kiemtragia_Click(object sender, EventArgs e) { try { string CheckInTime = ngay_den.Text; if (CheckInTime == "") { return; } string CheckOutTime = ngay_di.Text; if (CheckOutTime == "") { litError.Text = "Chon ngay tra phong"; return; } SearchInput input; int id; if (int.TryParse(Request["sId"], out id)) { input = _db.SearchInputs.Find(id); input.DateCheckIn = DateTime.Parse(CheckInTime, CultureInfo.GetCultureInfo("en-Gb")); input.DateCheckOut = DateTime.Parse(CheckOutTime, CultureInfo.GetCultureInfo("en-Gb")); } else { input = new SearchInput { KeyWord = "", DateCheckIn = DateTime.Parse(CheckInTime, CultureInfo.GetCultureInfo("en-Gb")), DateCheckOut = DateTime.Parse(CheckOutTime, CultureInfo.GetCultureInfo("en-Gb")) }; _db.SearchInputs.Add(input); _db.SaveChanges(); Response.Redirect("/chi-tiet-khach-san-" + Page.RouteData.Values["hotelId"] + "?sId=" + input.Id); } } catch { } }
private void LoadData() { int id = int.Parse(Page.RouteData.Values["hotelId"].ToString()); _hotel = _db.Hotels.Find(id); int sId = 0; if (int.TryParse(Request["sId"], out sId)) { _input = _db.SearchInputs.Find(sId); ngay_den.Text = _input.DateCheckIn.ToString("dd/MM/yyyy"); ngay_di.Text = _input.DateCheckOut.ToString("dd/MM/yyyy"); lvRoomDetail.DataSource = _hotel.getListHotelRoomType(_input.DateCheckIn, _input.DateCheckOut); lvRoomDetail.DataBind(); } else { btnOrder.Visible = false; } }
protected void lvRoomDetail_ItemDataBound(object sender, ListViewItemEventArgs e) { DropDownList ddlRoomCount = e.Item.FindControl("ddlRoomCount") as DropDownList; if (ddlRoomCount != null) { int sId = int.Parse(Request["sId"]); _input = _db.SearchInputs.Find(sId); int id = int.Parse(DataBinder.Eval(e.Item.DataItem, "Id").ToString()); HotelRoomType htrt = _db.HotelRoomTypes.Find(id); int max = htrt.MaxPeople - _db.GetNumOfRoomTypeOrder(_input.DateCheckIn,_input.DateCheckOut,htrt.Id); for (int i = 0; i < max; i++) { ddlRoomCount.Items.Add(new ListItem(i + " Phòng", i.ToString())); } Literal litPrice = e.Item.FindControl("litPrice") as Literal; litPrice.Text =FormatHelper.FormatPrice( htrt.getTotalPrice(_input.DateCheckIn, _input.DateCheckOut).ToString()); } }