/// <summary> /// Valida que un objeto underPaymentMotive cumpla con los filtros actuales /// </summary> /// <param name="underPaymentMotive">Objeto a validar</param> /// <returns>True. Si cumple | False. No cumple</returns> /// <history> /// [emoguel] created 28/04/2016 /// </history> private bool ValidateFilter(UnderPaymentMotive underPaymentMotive) { if (_nStatus != -1)//Filtro por estatus { if (underPaymentMotive.upA != Convert.ToBoolean(_nStatus)) { return(false); } } if (_underPaymentMotiveFilter.upID > 0)//Filtro por ID { if (underPaymentMotive.upID != _underPaymentMotiveFilter.upID) { return(false); } } if (!string.IsNullOrWhiteSpace(_underPaymentMotiveFilter.upN)) { if (!underPaymentMotive.upN.Contains(_underPaymentMotiveFilter.upN, StringComparison.OrdinalIgnoreCase)) { return(false); } } return(true); }
/// <summary> /// Muestra la ventana detalle en modo edit /// </summary> /// <history> /// [emoguel] 28/04/2016 Created /// </history> private void Cell_DoubleClick(object sender, RoutedEventArgs e) { UnderPaymentMotive underPaymentMotive = (UnderPaymentMotive)dgrUnderPayMentMotive.SelectedItem; frmUnderPaymentMotiveDetail frmUndPayMotDetail = new frmUnderPaymentMotiveDetail(); frmUndPayMotDetail.Owner = this; frmUndPayMotDetail.enumMode = (_blnEdit) ? EnumMode.Edit : EnumMode.ReadOnly; frmUndPayMotDetail.oldUnderPaymentMOtive = underPaymentMotive; if (frmUndPayMotDetail.ShowDialog() == true) { int nIndex = 0; List <UnderPaymentMotive> lstUnderPaymentMotive = (List <UnderPaymentMotive>)dgrUnderPayMentMotive.ItemsSource; if (ValidateFilter(frmUndPayMotDetail.underPaymentMotive)) //Verificamos que cumpla con los filtros { ObjectHelper.CopyProperties(underPaymentMotive, frmUndPayMotDetail.underPaymentMotive); //Actualizamos los datos lstUnderPaymentMotive.Sort((x, y) => string.Compare(x.upN, y.upN)); //Reordenamos la lista nIndex = lstUnderPaymentMotive.IndexOf(underPaymentMotive); //Buscamos la posición del registro } else { lstUnderPaymentMotive.Remove(underPaymentMotive); //Quitamos el registro de la lista } dgrUnderPayMentMotive.Items.Refresh(); //Actualizamos la vista GridHelper.SelectRow(dgrUnderPayMentMotive, nIndex); //Seleccionamos el registro StatusBarReg.Content = lstUnderPaymentMotive.Count + " Under Payment Motives."; //Actualizamos el contador } }
/// <summary> /// Abre la ventana detalle en modo add /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// [emoguel] created 28/04/2016 /// </history> private void btnAdd_Click(object sender, RoutedEventArgs e) { frmUnderPaymentMotiveDetail frmUndPayMotDetail = new frmUnderPaymentMotiveDetail(); frmUndPayMotDetail.Owner = this; frmUndPayMotDetail.enumMode = EnumMode.Add; if (frmUndPayMotDetail.ShowDialog() == true) { UnderPaymentMotive underPaymentMotive = frmUndPayMotDetail.underPaymentMotive; if (ValidateFilter(underPaymentMotive))//verificamos que cumpla con los filtros actuales { List <UnderPaymentMotive> lstUnderPaymentMotives = (List <UnderPaymentMotive>)dgrUnderPayMentMotive.ItemsSource; lstUnderPaymentMotives.Add(underPaymentMotive); //Agregamos el registro lstUnderPaymentMotives.Sort((x, y) => string.Compare(x.upN, y.upN)); //Reordenamos la lista int nIndex = lstUnderPaymentMotives.IndexOf(underPaymentMotive); //Obtenemos la posición del registro dgrUnderPayMentMotive.Items.Refresh(); //Actualizamos la vista GridHelper.SelectRow(dgrUnderPayMentMotive, nIndex); //Seleccionamos el registro StatusBarReg.Content = lstUnderPaymentMotives.Count + " Under Payment Motives."; //Actualizamos el contador } } }
/// <summary> /// Llena el grid de paymentMotives /// </summary> /// <param name="underPaymentMotive">objeto a seleccionar</param> /// <history> /// [emoguel] created 28/06/2016 /// </history> private async void LoadUnderPaymentMotives(UnderPaymentMotive underPaymentMotive = null) { try { status.Visibility = Visibility.Visible; int nIndex = 0; List <UnderPaymentMotive> lstUnderPaymentMotive = await BRUnderPaymentMotives.getUnderPaymentMotives(_nStatus, _underPaymentMotiveFilter); dgrUnderPayMentMotive.ItemsSource = lstUnderPaymentMotive; if (lstUnderPaymentMotive.Count > 0 && underPaymentMotive != null) { underPaymentMotive = lstUnderPaymentMotive.Where(up => up.upID == underPaymentMotive.upID).FirstOrDefault(); nIndex = lstUnderPaymentMotive.IndexOf(underPaymentMotive); } GridHelper.SelectRow(dgrUnderPayMentMotive, nIndex); StatusBarReg.Content = lstUnderPaymentMotive.Count + " Under Payment Motives."; status.Visibility = Visibility.Collapsed; } catch (Exception ex) { UIHelper.ShowMessage(ex); } }
/// <summary> /// Obtiene registros del catalogo UnderPaymentMotives -1-Todos | 0-Inactivos | 1-Activos /// </summary> /// <param name="nStatus">-1. Todos | 0. Inactivos | 1. Activos</param> /// <param name="underPaymentMotive">Objeto con filtros actuales</param> /// <returns>Lista de tipo UnderPaymentMotive</returns> /// <history> /// [emoguel] created 28/04/2016 /// [emoguel] modified 28/06/2016 ---> Se volvió async /// </history> public async static Task <List <UnderPaymentMotive> > getUnderPaymentMotives(int nStatus = -1, UnderPaymentMotive underPaymentMotive = null) { return(await Task.Run(() => { using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString())) { var query = from up in dbContext.UnderPaymentMotives select up; if (nStatus != -1)//Filtro por estatus { bool blnStatus = Convert.ToBoolean(nStatus); query = query.Where(up => up.upA == blnStatus); } if (underPaymentMotive != null) { if (underPaymentMotive.upID > 0)//Filtro por ID { query = query.Where(up => up.upID == underPaymentMotive.upID); } if (!string.IsNullOrWhiteSpace(underPaymentMotive.upN))//Filtro por descripción { query = query.Where(up => up.upN.Contains(underPaymentMotive.upN)); } } return query.OrderBy(up => up.upN).ToList(); } })); }
/// <summary> /// Actualiza los datos del grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// [emoguel] created 28/04/2016 /// </history> private void btnRef_Click(object sender, RoutedEventArgs e) { UnderPaymentMotive underPaymentMotive = (UnderPaymentMotive)dgrUnderPayMentMotive.SelectedItem; LoadUnderPaymentMotives(underPaymentMotive); }