private async void UserControl_Loaded(object sender, RoutedEventArgs e) { window = Window.GetWindow(this) as MahApps.Metro.Controls.MetroWindow; var x = await window.ShowProgressAsync("LOADING", "Please wait...", false) as ProgressDialogController; string dtee = "1" + "/" + dteNow.Month + "/" + dteNow.Year; dteFirstDay = DateTime.Parse(dtee); chkPaid.Visibility = Visibility.Hidden; if (!UserModel.isDSAdmin) { btnSave.Visibility = Visibility.Hidden; btnUpdate.Visibility = Visibility.Hidden; btnSearch.Visibility = Visibility.Hidden; btnCancel.Visibility = Visibility.Hidden; btnReset.Visibility = Visibility.Hidden; dgvDirectSales.IsEnabled = false; } if (UserModel.isDSConsoAdmin) { chkPaid.Visibility = Visibility.Visible; chkCancelled.Visibility = Visibility.Visible; } btnUpdate.Visibility = Visibility.Hidden; cmbClients.IsTextSearchEnabled = true; loadProducts(); loadPaymentModeOnCombo(); loadCourierOnCombo(); loadClientOnCombo(); loadExpense(dteNow, dteFirstDay); dgvDirectSales.ItemsSource = await loadDataGridDetails(); await x.CloseAsync(); }
private async Task <List <DirectSalesDaily> > search() { var x = await window.ShowProgressAsync("LOADING", "Please wait...", false) as ProgressDialogController; Clients cc = cmbSearchClient.SelectedItem as Clients; Banks bb = searchBank.SelectedItem as Banks; lstDS = new List <DirectSalesDaily>(); lstProds = new List <Products>(); try { conDB = new ConnectionDB(); loadProducts(); MongoClient client = conDB.initializeMongoDB(); var db = client.GetDatabase("DBFH"); var collection = db.GetCollection <DirectSalesDaily>("DirectSalesDaily"); var filter = Builders <DirectSalesDaily> .Filter.And( Builders <DirectSalesDaily> .Filter.Where(p => p.isDeleted == false)); iTotalAmount = 0; iTotalExpenses = 0; iTotalBoxes = 0; iTotalPads = 0; iTotaljuice = 0; iTotalGuavaBox = 0; iTotalGuyabanoBox = 0; if (checkDate.IsChecked.Value) { DateTime dteNow = (!string.IsNullOrEmpty(searchDateFrom.Text)) ? DateTime.Parse(searchDateFrom.Text) : DateTime.Now; DateTime dteFirstDay = (!string.IsNullOrEmpty(searchDateTo.Text)) ? DateTime.Parse(searchDateTo.Text) : DateTime.Now; filter = filter & Builders <DirectSalesDaily> .Filter.And( Builders <DirectSalesDaily> .Filter.Gte("DateOrdered", dteNow), Builders <DirectSalesDaily> .Filter.Lte("DateOrdered", dteFirstDay)); } if (checkClient.IsChecked.Value) { filter = filter & Builders <DirectSalesDaily> .Filter.And( Builders <DirectSalesDaily> .Filter.Where(d => d.Client.Id == cc.Id)); } if (checkBank.IsChecked.Value) { filter = filter & Builders <DirectSalesDaily> .Filter.And( Builders <DirectSalesDaily> .Filter.Where(d => d.Bank.Id == bb.Id)); } lstDS = collection.Find(filter).ToList(); foreach (DirectSalesDaily ds in lstDS) { ds.strDateOrdered = ds.DateOrdered.ToShortDateString(); ds.Client.strFullName = ds.Client.LastName + ", " + ds.Client.FirstName; } lstDS = lstDS.OrderByDescending(a => a.DateOrdered).ToList(); foreach (DirectSalesDaily ds in lstDS) { ds.strClientFullName = ds.Client.LastName + ", " + ds.Client.FirstName; ds.strBankName = ds.Bank.Description; foreach (ProductsOrderedDS pp in ds.ProductsOrdered) { foreach (Products p in lstProds) { if (pp.Products != null && pp.Products.Id.Equals(p.Id)) { p.Qty = p.Qty + Convert.ToInt32(pp.Qty); } if (ds.isCancelled && (p.Qty > 0)) { p.Qty -= Convert.ToInt32(pp.Qty); } } } iTotalAmount += Convert.ToInt32(ds.Total); iTotalExpenses += Convert.ToInt32(ds.Expenses); iTotalPads += Convert.ToInt32(ds.FreePads); iTotaljuice += Convert.ToInt32(ds.FreeJuice); ds.strCancelled = ds.isCancelled ? "YES" : "NO"; ds.strDateOrdered = ds.DateOrdered.ToShortDateString(); ds.Client.strFullName = ds.Client.LastName + ", " + ds.Client.FirstName; } await x.CloseAsync(); } catch (Exception ex) { await window.ShowMessageAsync("ERROR", "Caused by: " + ex.StackTrace); } return(lstDS); }