예제 #1
0
        /// <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();
            }
        }