/// <summary> /// The page_ initialize. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void Page_Init(object sender, EventArgs e) { this.pricingListController = new PricingListController(); this.roomTypeController = new RoomTypeController(); this.serviceController = new ServiceController(); var hotel = this.Session["Hotel"] as Hotel; this.RefreshPricingListEntityWithCodeInside(); this.typeOFRadioButtonList.DataSource = typeof(TypeOfBillableEntity).GetEnumValues(); this.typeOFRadioButtonList.DataBind(); var roomTypeList = this.roomTypeController.RefreshEntities(); this.roomTypeComboBox.DataSource = roomTypeList; this.roomTypeComboBox.DataBind(); this.roomTypeLabel.ClientVisible = false; this.roomTypeComboBox.ClientVisible = false; var serviceList = hotel == null ? this.serviceController.RefreshEntities().ToList() : this.serviceController.RefreshEntities().Where(x => x.HotelId == hotel.Id).ToList(); this.serviceComboBox.DataSource = serviceList; this.serviceComboBox.DataBind(); this.serviceLabel.ClientVisible = false; this.serviceComboBox.ClientVisible = false; }
/// <summary> /// The calculate room type price button_ on click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void CalculateAvailableRoomsButton(object sender, EventArgs e) { var hotel = this.Session["Hotel"] as Hotel; double roomPrice; var pricingListController = new PricingListController(); this.bookingController = new BookingController(); var errorlabel = this.Master?.FindControl("form1").FindControl("divErrorMessage") as Label; if (errorlabel != null) { errorlabel.Text = string.Empty; } var dateFrom = this.dateFromCalendar.Value; var dateTo = this.dateToCalendar.Value; var roomType = this.roomTypeComboBox.Text; var roomTypeId = this.roomTypeComboBox.Value; try { roomPrice = pricingListController.RoomPricing(dateFrom, dateTo, Convert.ToInt32(roomTypeId)); } catch (Exception ex) { if (errorlabel != null) { errorlabel.Text = ex.Message; } this.AvailableRooms = null; this.availableRoomsGridView.DataSource = this.AvailableRooms; this.availableRoomsGridView.DataBind(); this.roomTypePriceTextBox.Text = string.Empty; return; } this.roomTypePriceTextBox.Text = roomPrice.ToString(CultureInfo.InvariantCulture); if ((dateFrom != null) && (dateTo != null) && (roomType != string.Empty)) { this.AvailableRooms = this.bookingController.GetAvailableRooms(hotel, roomTypeId, dateFrom, dateTo); if (this.AvailableRooms.Count == 0) { errorlabel.Text = "No available rooms for the selected days"; } else { errorlabel.Text = string.Empty; } this.Session["AvailableRooms"] = this.AvailableRooms; } this.availableRoomsGridView.DataSource = this.AvailableRooms; this.availableRoomsGridView.DataBind(); }
protected void PricingListGridView_OnCustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e) { this.pricingListController = new PricingListController(); this.roomTypeController = new RoomTypeController(); this.serviceController = new ServiceController(); var gridviewIndex = e.VisibleIndex; var row = this.PricingListGridView.GetRow(gridviewIndex) as PricingList; var myPricingList = this.pricingListController.GetEntity(row.Id); if (myPricingList.TypeOfBillableEntity == TypeOfBillableEntity.RoomType) { var roomTypeTemp = this.roomTypeController.RefreshEntities() .SingleOrDefault(x => x.Id == myPricingList.BillableEntityId) as RoomType; myPricingList.BillableEntityCode = roomTypeTemp.Code; } else { var serviceTemp = this.serviceController.RefreshEntities() .SingleOrDefault(x => x.Id == myPricingList.BillableEntityId) as Service; myPricingList.BillableEntityCode = serviceTemp.Code; } this.PricingListGridView.JSProperties["cp_text1"] = myPricingList.Id; this.PricingListGridView.JSProperties["cp_text2"] = (int)myPricingList.TypeOfBillableEntity; this.PricingListGridView.JSProperties["cp_text3"] = myPricingList.BillableEntityCode; this.PricingListGridView.JSProperties["cp_text4"] = myPricingList.BillableEntityCode; this.PricingListGridView.JSProperties["cp_text5"] = myPricingList.ValidFrom.ToString(CultureInfo.CurrentCulture); this.PricingListGridView.JSProperties["cp_text6"] = myPricingList.ValidTo.ToString(CultureInfo.CurrentCulture); this.PricingListGridView.JSProperties["cp_text7"] = myPricingList.Price; this.PricingListGridView.JSProperties["cp_text8"] = myPricingList.VatPrc; if (e.ButtonID == "editButton") { this.DisplayBillableServiceControl(myPricingList.TypeOfBillableEntity.ToString()); } }
/// <summary> /// The delete pricing list button_ on click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void DeletePricingListButton_OnClick(object sender, EventArgs e) { this.pricingListController = new PricingListController(); this.roomTypeController = new RoomTypeController(); this.serviceController = new ServiceController(); var errorlabel = this.Master?.FindControl("form1").FindControl("divErrorMessage") as Label; if (errorlabel != null) { errorlabel.Text = string.Empty; if (this.PricingListGridView.VisibleRowCount == 0) { errorlabel.Text = $"There are no Pricing Lists to delete"; } var firstRun = true; this.Session["errorMessage"] = string.Empty; var selectedRowKeys = this.PricingListGridView.GetSelectedFieldValues(this.PricingListGridView.KeyFieldName, "Id"); if ((selectedRowKeys == null) || (selectedRowKeys.Count == 0)) { errorlabel.Text = @"Please select a Pricing List first to delete"; return; } foreach (object[] row in selectedRowKeys) { var id = Convert.ToInt32(row[0]); var pricingListTemp = new PricingList() { Id = id }; try { this.pricingListController.DeleteEntity(pricingListTemp); } catch (ArgumentNullException) { if (firstRun) { errorlabel.Text = $"You can't delete "; firstRun = false; } errorlabel.Text += $"'{pricingListTemp.Id}',"; this.PricingListGridView.Selection.UnselectRowByKey(id); } catch (SqlException exp) { errorlabel.Text = $"Sql error: " + exp.Message; } errorlabel.Text = errorlabel.Text.TrimEnd(' ', ','); this.Session["errorMessage"] = errorlabel.Text; this.RefreshPricingListEntityWithCodeInside(); } } }
/// <summary> /// The save button_ on click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void SaveButton_OnClick(object sender, EventArgs e) { this.pricingList = new PricingList(); this.pricingListController = new PricingListController(); var errorlabel = this.Master?.FindControl("form1").FindControl("divErrorMessage") as Label; if (errorlabel != null) { this.pricingList.Id = Convert.ToInt32(this.idTextBox.Text); if (this.pricingList.Id == 0) { this.pricingList.TypeOfBillableEntity = (TypeOfBillableEntity) Enum.Parse(typeof(TypeOfBillableEntity), this.typeOFRadioButtonList.SelectedItem.Text); if (this.typeOFRadioButtonList.SelectedItem.Value.ToString() == "RoomType") { var roomTypeList = this.roomTypeComboBox.DataSource as List <RoomType>; if (roomTypeList != null) { var roomTypeTemp = roomTypeList.SingleOrDefault( x => x.Id == Convert.ToInt32(this.roomTypeComboBox.SelectedItem.Value)); this.pricingList.BillableEntityId = roomTypeTemp.Id; } } else if (this.typeOFRadioButtonList.SelectedItem.Value.ToString() == "Service") { var serviceList = this.serviceComboBox.DataSource as List <Service>; if (serviceList != null) { var serviceTemp = serviceList.SingleOrDefault( x => x.Id == Convert.ToInt32(this.serviceComboBox.SelectedItem.Value)); this.pricingList.BillableEntityId = serviceTemp.Id; } } } this.pricingList.Price = Convert.ToDouble(this.priceSpinEdit.Number); this.pricingList.VatPrc = Convert.ToDouble(this.VatPrcSpinEdit.Number); this.pricingList.ValidFrom = this.validFromDateEdit.Date; this.pricingList.ValidTo = this.validToDateEdit.Date; if (this.pricingListController.ValidationDateForPricingList( this.pricingList.ValidFrom, this.pricingList.ValidTo, this.pricingList.TypeOfBillableEntity, this.pricingList.BillableEntityId)) { this.pricingListController.CreateOrUpdateEntity(this.pricingList); this.Page.Response.Redirect(this.Page.Request.Url.ToString(), true); } else { this.validFromDateEdit.IsValid = false; this.validToDateEdit.IsValid = false; this.validFromDateEdit.ErrorText = "There is allready Pricing List for the period you declared!"; this.validToDateEdit.ErrorText = "There is allready Pricing List for the period you declared!"; } } }
/// <summary> /// The bt ok click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void BtOkClick(object sender, EventArgs e) { var errorlabel = this.Master?.FindControl("form1").FindControl("divErrorMessage") as Label; var selectedRowKeys = this.BookingListGridview.GetSelectedFieldValues( this.BookingListGridview.KeyFieldName, "Id"); if ((selectedRowKeys == null) || (selectedRowKeys.Count == 0)) { return; } else { try { foreach (object[] row in selectedRowKeys) { var id = Convert.ToInt32(row[0]); this.pricingListEntityController = new PricingListController(); this.customerEntityController = new CustomerController(); var booking = this.bookingEntityController.GetEntity(id); this.bookingIdTextBox.Text = id.ToString(); this.customerSurnameTextBox.Text = this.customerEntityController.GetEntity(booking.CustomerId).Surname; this.priceValueTextBox.Text = booking.AgreedPrice.ToString(CultureInfo.InvariantCulture); this.customerNameTextBox.Text = this.customerEntityController.GetEntity(booking.CustomerId).Name; this.fromTextBox.Text = booking.From.ToShortDateString().ToString(CultureInfo.InvariantCulture); this.toTextBox.Text = booking.To.ToShortDateString().ToString(CultureInfo.InvariantCulture); this.roomTextBox.Text = booking.Room.Code; this.billing = new Billing { PriceForRoom = booking.AgreedPrice }; var servicesList = this.serviceController.RefreshEntities(); var billingServices = new List <BillingService>(); foreach (var item in servicesList) { if (item.HotelId == booking.Room.HotelId) { try { this.price = this.pricingListEntityController.ServicePricing(booking.From, item.Id); } catch (ArgumentNullException ex) { this.price = 0; } catch (NullReferenceException ex) { this.price = 0; } { var myBillingService = new BillingService { Service = item, Price = this.price, Quantity = 0 }; billingServices.Add(myBillingService); } } } this.myBillingServices = billingServices.Select( item => new BillingServiceWithServiceDescription { Id = item.Service.Id, Description = item.Service.Description, Quantity = item.Quantity, PricePerUnit = item.Price, TotalPrice = 0 }).ToList(); this.Session["billingServiceWithServiceDescription"] = this.myBillingServices; this.BillingListGridView.DataSource = this.myBillingServices; this.BillingListGridView.DataBind(); this.BillingListGridView.Visible = true; this.saveButton.Enabled = true; this.totalSumTextBox.Visible = true; this.totalSumTextBox.ReadOnly = true; this.totalSumTextBox.Text = this.priceValueTextBox.Text; this.paidCheckBox.Visible = true; this.sumOfServicesTextBox.Visible = true; this.sumOfServicesTextBox.ReadOnly = true; this.paidLabel.Visible = true; this.totalSumLabel.Visible = true; this.sumOfServicesLabel.Visible = true; } } catch (SqlException ex) { if (errorlabel != null) { errorlabel.Text = "Something went wrong with the database.Please check the connection string."; } } catch (ArgumentNullException ex) { if (errorlabel != null) { errorlabel.Text = "Couldn't create the current Billing"; } } catch (Exception ex) { errorlabel.Text = ex.Message; } } }