/// <summary> /// Valida si un MealticketType cumple con los filtros actuales /// </summary> /// <param name="mealTicketType">objeto para validar</param> /// <history> /// [emoguel] created 04/04/2016 /// </history> private bool ValidateFilter(MealTicketType mealTicketType) { if (_nWpax != -1)//Validacion wPax { if (mealTicketType.myWPax != Convert.ToBoolean(_nWpax)) { return(false); } } if (!string.IsNullOrWhiteSpace(_mealTkTypeFilter.myID))//Filtro por ID { if (_mealTkTypeFilter.myID != mealTicketType.myID) { return(false); } } if (!string.IsNullOrWhiteSpace(_mealTkTypeFilter.myN))//Filtro por descripcion { if (!mealTicketType.myN.Contains(_mealTkTypeFilter.myN, StringComparison.OrdinalIgnoreCase)) { return(false); } } return(true); }
/// <summary> /// Muestra la ventana detalle en modo ReadOnly|edicion /// </summary> /// <history> /// [emoguel] 04/04/2016 /// </history> private void Cell_DoubleClick(object sender, RoutedEventArgs e) { MealTicketType mealTicketType = (MealTicketType)dgrMealTkTypes.SelectedItem; frmMealTicketTypeDetail frmMealTkType = new frmMealTicketTypeDetail(); frmMealTkType.Owner = this; frmMealTkType.oldMealTicketType = mealTicketType; frmMealTkType.enumMode = EnumMode.Edit; if (frmMealTkType.ShowDialog() == true) { int nIndex = 0; List <MealTicketType> lstMealTkTypes = (List <MealTicketType>)dgrMealTkTypes.ItemsSource; if (!ValidateFilter(frmMealTkType.mealTicketType)) //verificamos si no cumple con los filtros { lstMealTkTypes.Remove(mealTicketType); //Quitamos el registro de la lista } else { ObjectHelper.CopyProperties(mealTicketType, frmMealTkType.mealTicketType); //Copiamos las nuevas propiedades lstMealTkTypes.Sort((x, y) => string.Compare(x.myN, y.myN)); //ordenamos la lista nIndex = lstMealTkTypes.IndexOf(mealTicketType); //obtenemos la posicion del registro } dgrMealTkTypes.Items.Refresh(); //Actualizamos la vista GridHelper.SelectRow(dgrMealTkTypes, nIndex); //Selecionamos el registro StatusBarReg.Content = lstMealTkTypes.Count + " Meal Ticket Types."; } }
/// <summary> /// Función para obtener los tipo de MealTicket /// </summary> /// <param name="mealTicketType">Objeto con filtros adicionales</param> /// <param name="nWPax">filtro de WPax</param> /// <returns> Lista de tipo MealTicketType </returns> /// <history> /// [vipacheco] 22/03/2016 Created /// [emoguel] 04/04/2016 Modified se agregaron filtros de busqueda /// [emoguel] modified28/06/2016 ---> Se volvió async /// </history> public async static Task<List<MealTicketType>> GetMealTicketType(MealTicketType mealTicketType=null,int nWPax=-1) { return await Task.Run(() => { using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString())) { var query = from my in dbContext.MealTicketTypes select my; if (nWPax != -1)//filtro por WPAX { bool blnWPax = Convert.ToBoolean(nWPax); query = query.Where(my => my.myWPax == blnWPax); } #region Filtros adicionales if (mealTicketType != null)//Validamos si tenemos objeto { if (!string.IsNullOrWhiteSpace(mealTicketType.myID))//Filtro por ID { query = query.Where(my => my.myID == mealTicketType.myID); } if (!string.IsNullOrWhiteSpace(mealTicketType.myN))//Filtro por descripcion { query = query.Where(my => my.myN.Contains(mealTicketType.myN)); } } #endregion return query.OrderBy(x => x.myN).ToList(); } }); }
/// <summary> /// Realiza los calculos de acuerdo a los parametros introducidos /// </summary> /// <history> /// [vipacheco] 31/Marzo/2016 Created /// </history> private void cboType_SelectionChanged(object sender, SelectionChangedEventArgs e) { RateType _rateType = cboRateType.SelectedItem as RateType; MealTicketType _mealTicketType = cboType.SelectedItem as MealTicketType; if (_mealTicketType != null) { if (!_mealTicketType.myWPax) { txtAdults.Text = $"{1}"; txtMinors.Text = $"{0}"; txtAdults.IsEnabled = txtMinors.IsEnabled = false; txtTAdults.Text = string.Format("{0:$0.00}", CalculateAdult(((_rateType == null) ? 1 : _rateType.raID), ((_meQty >= 0) ? _meQty : 0), ((txtAdults.Text != "") ? Convert.ToInt32(txtAdults.Text) : 0))); decimal _minors = (_meQty * ((txtMinors.Text != "") ? Convert.ToInt32(txtMinors.Text) : 0) * ((_mealTicketType != null) ? _mealTicketType.myPriceM : 0)); txtTMinors.Text = string.Format("{0:$0.00}", Convert.ToDouble(_minors)); } else { txtAdults.IsEnabled = txtMinors.IsEnabled = true; txtAdults.Text = ((txtAdults.Text != "") ? txtAdults.Text : "0"); txtMinors.Text = ((txtMinors.Text != "") ? txtMinors.Text : "0"); txtTAdults.Text = ((txtTAdults.Text != "") ? txtTAdults.Text : "$0.00"); txtTMinors.Text = ((txtTMinors.Text != "") ? txtTMinors.Text : "$0.00"); txtAdults_LostFocus(null, null); txtMinors_LostFocus(null, null); } } }
/// <summary> /// Valida los campos obligatorios segun sea requerido /// </summary> /// <returns> False - Algun Campo Vacio | True - Campos llenados correctamente </returns> /// <history> /// [vipacheco] 01/04/2016 Created /// [vipahceco] 15/Agosto/2016 Modified -> Se valida que el ticket tenga pax asociados. /// </history> private bool ValidateGeneral() { MealTicketType ticketCurrent = cboType.SelectedItem as MealTicketType; if (frmMealTickets._guestID == 0) { RateType rateType = cboRateType.SelectedItem as RateType; PersonnelShort personnel = cboCollaborator.SelectedItem as PersonnelShort; AgencyShort agency = cboAgency.SelectedItem as AgencyShort; if (rateType == null) { UIHelper.ShowMessage("Select an option of rate type, please", MessageBoxImage.Information); return(false); } else if (rateType.raID >= 2 && rateType.raID < 4 && personnel == null) { UIHelper.ShowMessage("Select a collaborator, please", MessageBoxImage.Information); return(false); } else if (rateType.raID == 4 && (agency == null || txtRepresentative.Text == "")) { UIHelper.ShowMessage("Select an agency and write the representative name in the field for External option.", MessageBoxImage.Information); return(false); } else if (ticketCurrent == null) { UIHelper.ShowMessage("Select an option of meal type, please", MessageBoxImage.Information); return(false); } // Verificamos el Pax int adults, minors = 0; if (string.IsNullOrEmpty(txtAdults.Text) && string.IsNullOrEmpty(txtMinors.Text)) { UIHelper.ShowMessage("Set the Pax information, adults or minors", MessageBoxImage.Information); return(false); } else if (int.TryParse(txtAdults.Text, out adults) && int.TryParse(txtMinors.Text, out minors)) { // Verificamos que no sean ambos 0 if (adults == 0 && minors == 0) { UIHelper.ShowMessage("Set the Pax information, adults or minors", MessageBoxImage.Information); return(false); } } } else { if (ticketCurrent == null) { UIHelper.ShowMessage("Select an option of meal type, please", MessageBoxImage.Information); return(false); } } return(true); }
/// <summary> /// Calcula el total de adulto /// </summary> /// <history> /// [vipacheco] 19/Agosto/2016 Created /// </history> private void CalculateTotalAdults() { RateType _rateType = cboRateType.SelectedItem as RateType; MealTicketType _mealTicketType = cboType.SelectedItem as MealTicketType; if (_mealTicketType != null) { if (!_mealTicketType.myWPax) { txtTAdults.Text = string.Format("{0:$0.00}", CalculateAdult(((_rateType == null) ? 1 : _rateType.raID), ((_meQty >= 0) ? _meQty : 0), ((txtAdults.Text != "") ? Convert.ToInt32(txtAdults.Text) : 0))); } else { txtTAdults.Text = string.Format("{0:$0.00}", CalculateAdult(((_rateType == null) ? 1 : _rateType.raID), ((_meQty >= 0) ? _meQty : 0), ((txtAdults.Text != "") ? Convert.ToInt32(txtAdults.Text) : 0))); } } }
/// <summary> /// Calcula los totales de los minors /// </summary> /// <history> /// [vipacheco] 19/Agosto/2016 Created /// </history> private void CalculateTotalMinors() { RateType _rateType = cboRateType.SelectedItem as RateType; MealTicketType _mealTicketType = cboType.SelectedItem as MealTicketType; if (_mealTicketType != null) { if (!_mealTicketType.myWPax) { decimal _minors = (_meQty * ((txtMinors.Text != "") ? Convert.ToInt32(txtMinors.Text) : 0) * ((_mealTicketType != null) ? _mealTicketType.myPriceM : 0)); txtTMinors.Text = string.Format("{0:$0.00}", Convert.ToDouble(_minors)); } else { decimal _minors = (_meQty * ((txtMinors.Text != "") ? Convert.ToInt32(txtMinors.Text) : 0) * ((_mealTicketType != null) ? _mealTicketType.myPriceM : 0)); txtTMinors.Text = string.Format("{0:$0.00}", Convert.ToDouble(_minors)); } } }
/// <summary> /// Abre la ventana de detalle en modo Add /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// [emoguel] created 04/04/2016 /// </history> private void btnAdd_Click(object sender, RoutedEventArgs e) { frmMealTicketTypeDetail frmMealTkTypeDetail = new frmMealTicketTypeDetail(); frmMealTkTypeDetail.Owner = this; frmMealTkTypeDetail.enumMode = EnumMode.Add; if (frmMealTkTypeDetail.ShowDialog() == true) { if (ValidateFilter(frmMealTkTypeDetail.mealTicketType))//validamos si cumple con los filtros { MealTicketType mealTicketType = frmMealTkTypeDetail.mealTicketType; List <MealTicketType> lstMealTkTypes = (List <MealTicketType>)dgrMealTkTypes.ItemsSource; lstMealTkTypes.Add(mealTicketType); //Agregamos el objeto lstMealTkTypes.Sort((x, y) => string.Compare(x.myN, y.myN)); //ordenamos la lista int nIndex = lstMealTkTypes.IndexOf(mealTicketType); //buscamos la posicion del nuevo registro dgrMealTkTypes.Items.Refresh(); //actualizamos la vista del grid GridHelper.SelectRow(dgrMealTkTypes, nIndex); //Seleccionamo el nuevo registro StatusBarReg.Content = lstMealTkTypes.Count + " Meal Ticket Types."; //Actualizamos el contador } } }
/// <summary> /// Función que devuelve el valor de adulto en base al RateType /// </summary> /// <param name="intRatetype"></param> /// <param name="intQt"></param> /// <param name="intAdults"></param> /// <history> /// [vipacheco] 23/03/2016 Created /// </history> private double CalculateAdult(int intRatetype, int intAdults, int intQt = 1) { MealTicketType mealTicket = cboType.SelectedItem as MealTicketType; double Amt = 0; if (mealTicket != null) { if (intRatetype == 1) { Amt = intQt * intAdults * Convert.ToDouble(mealTicket.myPriceA); } else if (intRatetype == 2) { Amt = intQt * intAdults * Convert.ToDouble(mealTicket.myCollaboratorWithCost); } else if (intRatetype >= 3) { Amt = intQt * intAdults * Convert.ToDouble(mealTicket.myCollaboratorWithoutCost); } } return(Amt); }
/// <summary> /// Llena el grid lstMealTkTypes /// </summary> /// <param name="mealTicketType">Objeto a selecionar</param> /// <history> /// [emoguel] created 04/04/2016 /// </history> private async void LoadMealTkTypes(MealTicketType mealTicketType = null) { try { status.Visibility = Visibility.Visible; int nIndex = 0; List <MealTicketType> lstMealTkTypes = await BRMealTicketTypes.GetMealTicketType(_mealTkTypeFilter, _nWpax); dgrMealTkTypes.ItemsSource = lstMealTkTypes; if (lstMealTkTypes.Count > 0 && mealTicketType != null) { mealTicketType = lstMealTkTypes.Where(my => my.myID == mealTicketType.myID).FirstOrDefault(); nIndex = lstMealTkTypes.IndexOf(mealTicketType); } GridHelper.SelectRow(dgrMealTkTypes, nIndex); StatusBarReg.Content = lstMealTkTypes.Count + " Meal Ticket Types."; status.Visibility = Visibility.Collapsed; } catch (Exception ex) { UIHelper.ShowMessage(ex); } }
/// <summary> /// Crea un nuevo mealticket /// </summary> /// <param name="_rateType"></param> /// <param name="_mealType"></param> /// <param name="_personnel"></param> /// <param name="_agency"></param> /// <param name="_meAdults"></param> /// <param name="_meMinors"></param> /// <param name="_meTAdultsString"></param> /// <param name="_meTMinorsString"></param> /// <param name="folioNew"></param> /// <returns></returns> /// <history> /// [vipacheco] 25/Abril/2016 Created /// </history> private MealTicket CreateMealTicket(RateType _rateType, MealTicketType _mealType, PersonnelShort _personnel, AgencyShort _agency, int _meAdults, int _meMinors, string _meTAdultsString, string _meTMinorsString, int folioNew) { return(new MealTicket { meD = dtpDate.Value.Value.Date, megu = frmMealTickets._guestID, meQty = frmMealTickets._Qty, meType = _mealType.myID, meAdults = _meAdults, meMinors = _meMinors, meFolios = folioNew + "", meTAdults = Convert.ToDecimal(_meTAdultsString), meTMinors = Convert.ToDecimal(_meTMinorsString), meComments = txtComments.Text, mesr = Context.User.SalesRoom.srID, meCanc = chkCancel.IsChecked.Value, mera = cboRateType.IsVisible ? _rateType.raID : 1, mepe = cboCollaborator.IsVisible ? _personnel.peID : null, mePrinted = chkPrinted.IsChecked.Value, meag = cboAgency.IsVisible ? _agency.agID : null, merep = txtRepresentative.IsVisible ? txtRepresentative.Text : null, meAuthorizedBy = Context.User.User.peID }); }
/// <summary> /// Recarga la lista de mealTicketTypes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// [emoguel] created 04/04/2016 /// </history> private void btnRef_Click(object sender, RoutedEventArgs e) { MealTicketType mealTktype = (MealTicketType)dgrMealTkTypes.SelectedItem; LoadMealTkTypes(mealTktype); }
/// <summary> /// Guarda la informacion proporcionada! /// </summary> /// <history> /// [vipacheco] 23/03/2016 Created /// </history> private void btnSave_Click(object sender, RoutedEventArgs e) { if (ValidateGeneral()) { RateType _rateType = cboRateType.SelectedItem as RateType; MealTicketType _mealType = cboType.SelectedItem as MealTicketType; PersonnelShort _personnel = cboCollaborator.SelectedItem as PersonnelShort; AgencyShort _agency = cboAgency.SelectedItem as AgencyShort; int _meAdults = Convert.ToInt32((txtAdults.Text == "") ? "0" : txtAdults.Text); int _meMinors = Convert.ToInt32((txtMinors.Text == "") ? "0" : txtMinors.Text); string _meTAdultsString = txtTAdults.Text.TrimStart('$'); string _meTMinorsString = txtTMinors.Text.TrimStart('$'); // Agrega un nuevo Meal Ticket if (_modeOpen == EnumMode.Add) { // Obtenemos el folio a asignar int folioNew = 1 + BRMealTicketFolios.GetMaxMealTicketFolio(Context.User.SalesRoom.srID, _mealType.myID, _rateType == null ? 1 : _rateType.raID); _mealTicketCurrency = CreateMealTicket(_rateType, _mealType, _personnel, _agency, _meAdults, _meMinors, _meTAdultsString, _meTMinorsString, folioNew); //Actualizamos el folio! BRMealTicketFolios.UpdateMealTicketFolio(Context.User.SalesRoom.srID, _mealType.myID, _rateType == null ? 1 : _rateType.raID, $"{folioNew}"); //Guardamos el Meal Ticket Creado BRMealTickets.InsertNewMealTicket(_mealTicketCurrency); } // Modo edicion else { int folio = Convert.ToInt32(_mealTicketCurrency.meFolios); // Creamos el Meal Ticket con el guestID _mealTicketCurrency.meD = dtpDate.Value.Value.Date; _mealTicketCurrency.megu = _mealTicketCurrency.megu != 0 ? _mealTicketCurrency.megu : frmMealTickets._guestID; _mealTicketCurrency.meQty = frmMealTickets._Qty; _mealTicketCurrency.meType = _mealType.myID; _mealTicketCurrency.meAdults = _meAdults; _mealTicketCurrency.meMinors = _meMinors; _mealTicketCurrency.meFolios = $"{folio}"; _mealTicketCurrency.meTAdults = Convert.ToDecimal(_meTAdultsString); _mealTicketCurrency.meTMinors = Convert.ToDecimal(_meTMinorsString); _mealTicketCurrency.meComments = txtComments.Text; _mealTicketCurrency.mesr = Context.User.SalesRoom.srID; _mealTicketCurrency.meCanc = chkCancel.IsChecked.Value; _mealTicketCurrency.mera = frmMealTickets._guestID > 0 ? 1 : _rateType.raID; _mealTicketCurrency.mepe = cboCollaborator.IsVisible ? _personnel.peID : null; _mealTicketCurrency.mePrinted = chkPrinted.IsChecked.Value; _mealTicketCurrency.meag = cboAgency.IsVisible ? _agency.agID : null; _mealTicketCurrency.merep = txtRepresentative.IsVisible ? txtRepresentative.Text : null; _mealTicketCurrency.meAuthorizedBy = Context.User.User.peID; //Actualizamos el folio! BRMealTicketFolios.UpdateMealTicketFolio(Context.User.SalesRoom.srID, _mealType.myID, _rateType.raID, _mealTicketCurrency.meFolios); // Insertamos el nuevo Meal Ticket con el folio asignado BRMealTickets.UpdateMealTicket(_mealTicketCurrency); } //Actualizamos el campo guMealTicket del Guest BRGuests.UpdateFieldguMealTicket(true, frmMealTickets._guestID); DialogResult = true; Close(); } }