/// <summary>
        /// Valida que un registro tipo notBookingMotive cumpla con los filtros actuales
        /// </summary>
        /// <param name="notBookingMotive">Filtro a validar</param>
        /// <returns>Truw. Si cumple | False. No cumple</returns>
        /// <history>
        /// [emoguel] created 05/04/2016
        /// </history>
        private bool ValidateFilter(NotBookingMotive notBookingMotive)
        {
            if (_nStatus != -1)//Filtro por estatus
            {
                if (notBookingMotive.nbA != Convert.ToBoolean(_nStatus))
                {
                    return(false);
                }
            }

            if (_notBookingMotFilter.nbID > 0)//Filtro por ID
            {
                if (_notBookingMotFilter.nbID != notBookingMotive.nbID)
                {
                    return(false);
                }
            }

            if (!string.IsNullOrWhiteSpace(_notBookingMotFilter.nbN))//Filtro por descripcion
            {
                if (!notBookingMotive.nbN.Contains(_notBookingMotFilter.nbN, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Muestra la ventada detalle
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        /// [emoguel] created 05/04/2016
        /// </history>
        private void Cell_DoubleClick(object sender, RoutedEventArgs e)
        {
            NotBookingMotive          notBookingMotive   = (NotBookingMotive)dgrNotBokMotives.SelectedItem;
            frmNotBookingMotiveDetail frmNotBokMotDetail = new frmNotBookingMotiveDetail();

            frmNotBokMotDetail.Owner               = this;
            frmNotBokMotDetail.enumMode            = (_blnEdit == true) ? EnumMode.Edit : EnumMode.ReadOnly;
            frmNotBokMotDetail.oldNotBookingMotive = notBookingMotive;

            if (frmNotBokMotDetail.ShowDialog() == true)
            {
                int nIndex = 0;
                List <NotBookingMotive> lstNotBokMotives = (List <NotBookingMotive>)dgrNotBokMotives.ItemsSource;
                if (!ValidateFilter(frmNotBokMotDetail.notBookingMotive))
                {
                    lstNotBokMotives.Remove(notBookingMotive);//Quitamos el registro de la lista
                }
                else
                {
                    ObjectHelper.CopyProperties(notBookingMotive, frmNotBokMotDetail.notBookingMotive); //Actualizamos los datos del registro
                    lstNotBokMotives.Sort((x, y) => string.Compare(x.nbN, y.nbN));                      //Ordenamos la lista
                    nIndex = lstNotBokMotives.IndexOf(notBookingMotive);                                //Buscamos la posicion del registro
                }
                dgrNotBokMotives.Items.Refresh();                                                       //Actualizamos la vista
                GridHelper.SelectRow(dgrNotBokMotives, nIndex);                                         //Seleccionamos el registro
                StatusBarReg.Content = lstNotBokMotives.Count + " Not Booking Motives.";
            }
        }
        /// <summary>
        /// Abre la ventana detalle en modo Add
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        /// [emoguel] created 05/04/2016
        /// </history>
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            frmNotBookingMotiveDetail frmNotBokMotDetail = new frmNotBookingMotiveDetail();

            frmNotBokMotDetail.Owner    = this;
            frmNotBokMotDetail.enumMode = EnumMode.Add;
            if (frmNotBokMotDetail.ShowDialog() == true)
            {
                NotBookingMotive notBookingMotive = frmNotBokMotDetail.notBookingMotive;
                if (ValidateFilter(notBookingMotive))//verificamos que cumpla con los filtros actuales
                {
                    List <NotBookingMotive> lstNotBokMotives = (List <NotBookingMotive>)dgrNotBokMotives.ItemsSource;
                    lstNotBokMotives.Add(notBookingMotive);                                  //Agregamos el registro
                    lstNotBokMotives.Sort((x, y) => string.Compare(x.nbN, y.nbN));           //Ordenamos la lista
                    int nIndex = lstNotBokMotives.IndexOf(notBookingMotive);                 //Obtenemos el index del nuevo registro
                    dgrNotBokMotives.Items.Refresh();                                        //Actualizamos la vista
                    GridHelper.SelectRow(dgrNotBokMotives, nIndex);                          //Seleccionamos el nuevo registro
                    StatusBarReg.Content = lstNotBokMotives.Count + " Not Booking Motives."; //Actualizamos el contador
                }
            }
        }
        /// <summary>
        /// llena el grid de Not Booking Motives
        /// </summary>
        /// <param name="notBookingMotive">Objeto a seleccionar</param>
        /// <history>
        /// [emoguel] created 05/04/2016
        /// </history>
        private async void LoadNotBookingMotives(NotBookingMotive notBookingMotive = null)
        {
            try
            {
                status.Visibility = Visibility.Visible;
                int nIndex = 0;
                List <NotBookingMotive> lstNotBokMotives = await BRNotBookingMotives.GetNotBookingMotives(_nStatus, _notBookingMotFilter);

                dgrNotBokMotives.ItemsSource = lstNotBokMotives;
                if (lstNotBokMotives.Count > 0 && notBookingMotive != null)
                {
                    notBookingMotive = lstNotBokMotives.Where(nb => nb.nbID == notBookingMotive.nbID).FirstOrDefault();
                    nIndex           = lstNotBokMotives.IndexOf(notBookingMotive);
                }
                GridHelper.SelectRow(dgrNotBokMotives, nIndex);
                StatusBarReg.Content = lstNotBokMotives.Count + " Not Booking Motives.";
                status.Visibility    = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                UIHelper.ShowMessage(ex);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Obtiene registros del catalogo NotBoikingMotives
        /// </summary>
        /// <param name="nStatus">-1. Todos | 0. Inactivos | 1.Activos</param>
        /// <param name="notBookingMotive">Objeto con filtros adicionales</param>
        /// <returns>lista de tipo NotBookingMotive</returns>
        /// <history>
        /// [emoguel] created 05/04/2016
        /// </history>
        public async static Task <List <NotBookingMotive> > GetNotBookingMotives(int nStatus = -1, NotBookingMotive notBookingMotive = null)
        {
            return(await Task.Run(() =>
            {
                using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString()))
                {
                    var query = from nb in dbContext.NotBookingMotives
                                select nb;

                    if (nStatus != -1)//Filtro por estatus
                    {
                        bool blnStatus = Convert.ToBoolean(nStatus);
                        query = query.Where(nb => nb.nbA == blnStatus);
                    }

                    #region Filtros adicionales
                    if (notBookingMotive != null)
                    {
                        if (notBookingMotive.nbID > 0)//Filtro por ID
                        {
                            query = query.Where(nb => nb.nbID == notBookingMotive.nbID);
                        }

                        if (!string.IsNullOrEmpty(notBookingMotive.nbN))//Filtro por Descripción
                        {
                            query = query.Where(nb => nb.nbN.Contains(notBookingMotive.nbN));
                        }
                    }
                    #endregion

                    return query.OrderBy(nb => nb.nbN).ToList();
                }
            }));
        }
        /// <summary>
        /// Actualiza los registros del Grid de Not Booking Motive
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        /// [emoguel] created 05/04/2016
        /// </history>
        private void btnRef_Click(object sender, RoutedEventArgs e)
        {
            NotBookingMotive notBookingMotive = (NotBookingMotive)dgrNotBokMotives.SelectedItem;

            LoadNotBookingMotives(notBookingMotive);
        }