/// <summary> /// Obtiene los Wholesalers a traves del SP "USP_OR_GetWholesalers" /// </summary> /// <returns>Lista de tipo WholesalersData</returns> /// <hitory> /// [emoguel] created 07/06/2016 /// </hitory> public async static Task <List <WholesalerData> > GetWholesalers(WholesalerData wholesalerData = null) { List <WholesalerData> lstWholesalers = await Task.Run(() => { using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString())) { var query = from ws in dbContext.USP_OR_GetWholesalers() select ws; if (wholesalerData != null) { if (wholesalerData.wscl > 0)//Filtro por Club { query = query.Where(ws => ws.wscl == wholesalerData.wscl); } if (!string.IsNullOrWhiteSpace(wholesalerData.wsApplication))//Filtro por Application { query = query.Where(ws => ws.wsApplication == wholesalerData.wsApplication); } if (!string.IsNullOrWhiteSpace(wholesalerData.Name))//Filtro por Name { query = query.Where(ws => ws.Name.Contains(wholesalerData.Name)); } } return(query.OrderByDescending(ws => ws.Name).ToList()); } }); return(lstWholesalers); }
/// <summary> /// Valida que cumpla con los filtros actuales /// </summary> /// <param name="wholesalerData">OBjeto a validar</param> /// <returns>True. Si cumple | False. No cumple</returns> /// <history> /// [Emoguel] created 07/06/2016 /// </history> private bool ValidateFilter(WholesalerData wholesalerData) { if (_WholeSalerFilter.wscl > 0) { if (_WholeSalerFilter.wscl != wholesalerData.wscl) { return(false); } } if (!string.IsNullOrWhiteSpace(_WholeSalerFilter.Name)) { if (!wholesalerData.Name.Contains(_WholeSalerFilter.Name)) { return(false); } } if (!string.IsNullOrWhiteSpace(_WholeSalerFilter.wsApplication)) { if (_WholeSalerFilter.wsApplication != wholesalerData.wsApplication) { return(false); } } return(true); }
/// <summary> /// Llena el grid de Wholesalers /// </summary> /// <history> /// [emoguel] created 07/06/2016 /// </history> private async void LoadWholesalers(WholesalerData wholesalersData = null) { try { status.Visibility = Visibility.Visible; int nIndex = 0; List <WholesalerData> lstWholesalers = await BRWholesalers.GetWholesalers(_WholeSalerFilter); dgrWholesalers.ItemsSource = lstWholesalers; if (lstWholesalers.Count > 0) { if (wholesalersData != null) { wholesalersData = lstWholesalers.Where(wh => wh.wscl == wholesalersData.wscl && wh.wsApplication == wholesalersData.wsApplication && wh.wsCompany == wholesalersData.wsCompany).FirstOrDefault(); nIndex = lstWholesalers.IndexOf(wholesalersData); } btnDel.IsEnabled = _blnDel; GridHelper.SelectRow(dgrWholesalers, nIndex); } else { btnDel.IsEnabled = false; } StatusBarReg.Content = lstWholesalers.Count + " Wholesalers."; status.Visibility = Visibility.Collapsed; } catch (Exception ex) { UIHelper.ShowMessage(ex); } }
/// <summary> /// Abre la ventana detalle en modo "detalle" o "edición" dependiendo de sus permisos /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// [emoguel] created 07/06/2016 /// </history> private void Cell_DoubleClick(object sender, RoutedEventArgs e) { WholesalerData wholesalerData = (WholesalerData)dgrWholesalers.SelectedItem; frmWholesalerDetail frmwholesalerDetail = new frmWholesalerDetail(); frmwholesalerDetail.Owner = this; frmwholesalerDetail.enumMode = EnumMode.ReadOnly; frmwholesalerDetail.oldWholesaler = new Wholesaler { wsApplication = wholesalerData.wsApplication, wscl = wholesalerData.wscl, wsCompany = wholesalerData.wsCompany }; frmwholesalerDetail.ShowDialog(); }
/// <summary> /// Guarda los datos /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// [emoguel] created 07/06/2016 /// </history> private async void btnAccept_Click(object sender, RoutedEventArgs e) { if (enumMode != EnumMode.Search) { if (ObjectHelper.IsEquals(wholesaler, oldWholesaler)) { _isClosing = true; Close(); } else { txtStatus.Text = "Saving Data..."; skpStatus.Visibility = Visibility.Visible; string strMsj = ""; strMsj = ValidateHelper.ValidateForm(this, "Wholesaler"); if (strMsj == "") { int nRes = await BRWholesalers.SaveWholesaler(wholesaler); UIHelper.ShowMessageResult("Whosaler", nRes); if (nRes > 0) { var wholesalersData = await BRWholesalers.GetWholesalers(new WholesalerData { wscl = wholesaler.wscl, wsApplication = wholesaler.wsApplication, wsCompany = wholesaler.wsCompany }); wholesalerData = wholesalersData.FirstOrDefault(); _isClosing = true; DialogResult = true; Close(); } } else { UIHelper.ShowMessage(strMsj); } skpStatus.Visibility = Visibility.Collapsed; } } else { _isClosing = true; DialogResult = true; Close(); } }
/// <summary> /// Recarga los registros de la lista /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <history> /// [emoguel] created 07/06/2016 /// </history> private void btnRef_Click(object sender, RoutedEventArgs e) { WholesalerData wholeSalerData = (WholesalerData)dgrWholesalers.SelectedItem; LoadWholesalers(wholeSalerData); }