/// <summary> /// Muestra la ventada detalle /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// [emoguel] created 06/04/2016 /// </history> private void Cell_DoubleClick(object sender, RoutedEventArgs e) { PaymentSchema paymentSchema = (PaymentSchema)dgrPaymentSchemas.SelectedItem; frmPaymentSchemaDetail frmPaymentScheDetail = new frmPaymentSchemaDetail(); frmPaymentScheDetail.Owner = this; frmPaymentScheDetail.enumMode = EnumMode.Edit; frmPaymentScheDetail.oldPaymentSchema = paymentSchema; if (frmPaymentScheDetail.ShowDialog() == true) { int nIndex = 0; List <PaymentSchema> lstPaymentSchemas = (List <PaymentSchema>)dgrPaymentSchemas.ItemsSource; if (!ValidateFilter(frmPaymentScheDetail.paymentSchema)) { lstPaymentSchemas.Remove(paymentSchema);//Removemos el registro } else { ObjectHelper.CopyProperties(paymentSchema, frmPaymentScheDetail.paymentSchema); //Actualizamos los datos del registro lstPaymentSchemas.Sort((x, y) => string.Compare(x.pasN, y.pasN)); //Ordenamos la lista nIndex = lstPaymentSchemas.IndexOf(paymentSchema); //Obtenemos la posicion del registro } dgrPaymentSchemas.Items.Refresh(); //Actualizamos la lista GridHelper.SelectRow(dgrPaymentSchemas, nIndex); //Seleccionamos el registro StatusBarReg.Content = lstPaymentSchemas.Count + " Payment Schemas."; //Actualizamos el contador } }
/// <summary> /// Valida que un objeto paymentSchema cumpla con los filtros actuales /// </summary> /// <param name="paymentSchema">Objeto a validar</param> /// <returns>True. Si cumple | False. No cumple</returns> /// <history> /// [emoguel] created 06/04/2016 /// </history> private bool ValidateFilter(PaymentSchema paymentSchema) { if (_nStatus != -1)//Filtro por estatus { if (paymentSchema.pasA != Convert.ToBoolean(_nStatus)) { return(false); } } if (_paymentSchemaFilter.pasID > 0)//Filtro por ID { if (paymentSchema.pasID != _paymentSchemaFilter.pasID) { return(false); } } if (!string.IsNullOrWhiteSpace(_paymentSchemaFilter.pasN))//Filtro por estatus { if (!paymentSchema.pasN.Contains(_paymentSchemaFilter.pasN, StringComparison.OrdinalIgnoreCase)) { return(false); } } return(true); }
/// <summary> /// Abre la ventana detalle en modo Add /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// [emoguel] created 06/04/2016 /// </history> private void btnAdd_Click(object sender, RoutedEventArgs e) { frmPaymentSchemaDetail frmPaymentScheDetail = new frmPaymentSchemaDetail(); frmPaymentScheDetail.Owner = this; frmPaymentScheDetail.enumMode = EnumMode.Add; if (frmPaymentScheDetail.ShowDialog() == true) { PaymentSchema paymentSchema = frmPaymentScheDetail.paymentSchema; if (ValidateFilter(paymentSchema))//Verificamos que cumpla con los filtros { List <PaymentSchema> lstPaymentSchemas = (List <PaymentSchema>)dgrPaymentSchemas.ItemsSource; lstPaymentSchemas.Add(paymentSchema); //Agregamos el registro a la lista lstPaymentSchemas.Sort((x, y) => string.Compare(x.pasN, y.pasN)); //ordenamos la lista int nIndex = lstPaymentSchemas.IndexOf(paymentSchema); //obtenemos la posición del registro dgrPaymentSchemas.Items.Refresh(); //Actualizamos la vista GridHelper.SelectRow(dgrPaymentSchemas, nIndex); //Seleccionamos el registro StatusBarReg.Content = lstPaymentSchemas.Count + " Payment Schemas."; } } }
/// <summary> /// Llena el grid de PaymentSchemas /// </summary> /// <param name="paymentSchemas">Objeto para seleccionar</param> /// <history> /// [emoguel] created 06/04/2016 /// </history> private async void LoadPaymentSchemas(PaymentSchema paymentSchemas = null) { try { status.Visibility = Visibility.Visible; int nIndex = 0; List <PaymentSchema> lstPaymentSchemas = await BRPaymentSchemas.GetPaymentSchemas(_nStatus, _paymentSchemaFilter); dgrPaymentSchemas.ItemsSource = lstPaymentSchemas; if (lstPaymentSchemas.Count > 0 && paymentSchemas != null) { paymentSchemas = lstPaymentSchemas.Where(pas => pas.pasID == paymentSchemas.pasID).FirstOrDefault(); nIndex = lstPaymentSchemas.IndexOf(paymentSchemas); } GridHelper.SelectRow(dgrPaymentSchemas, nIndex); StatusBarReg.Content = lstPaymentSchemas.Count + " Payment Schemas."; status.Visibility = Visibility.Collapsed; } catch (Exception ex) { UIHelper.ShowMessage(ex); } }
/// <summary> /// Actualiza los registros del grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// [emoguel] created 06/04/2016 /// </history> private void btnRef_Click(object sender, RoutedEventArgs e) { PaymentSchema paymentSchema = (PaymentSchema)dgrPaymentSchemas.SelectedItem; LoadPaymentSchemas(paymentSchema); }
/// <summary> /// Obtiene registros del catalogo paymentSchemas /// </summary> /// <param name="nStatus">-1. Todos | 0. Inactivos | 1. Activos</param> /// <param name="paymentSchemas">Objeto con filtros adicionales</param> /// <returns>Lista de tipo PaymentSchemas</returns> /// <history> /// [emoguel] created 06/04/2016 /// [emoguel] modified 28/06/2016 ---> Se volvió async /// </history> public async static Task <List <PaymentSchema> > GetPaymentSchemas(int nStatus = -1, PaymentSchema paymentSchemas = null) { return(await Task.Run(() => { using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString())) { var query = from pas in dbContext.PaymentSchemas select pas; if (nStatus != -1)//Filtro por estatus { bool blnStatus = Convert.ToBoolean(nStatus); query = query.Where(pas => pas.pasA == blnStatus); } #region Filtros adicionales if (paymentSchemas != null) //Verificamos si tenemos el objeto { if (paymentSchemas.pasID > 0) //Filtro por ID { query = query.Where(pas => pas.pasID == paymentSchemas.pasID); } if (!string.IsNullOrWhiteSpace(paymentSchemas.pasN))//Filtro por descripcion { query = query.Where(pas => pas.pasN.Contains(paymentSchemas.pasN)); } } #endregion return query.OrderBy(pas => pas.pasN).ToList(); } })); }