private async void OnSave(object sender, EventArgs e) { List <Party> p = await dbTransaction.GetParties(); if (isPartyValid()) { if (_party.PartyID != 0) { dbTransaction.UpdateAsync(_party); await DisplayAlert("Success", $"{_party.PartyName} updated", "OK"); await Navigation.PopAsync(); } else { dbTransaction.InsertAsync(_party); await DisplayAlert("Success", $"{_party.PartyName} saved", "OK"); } ClearControls(); } }
private async void OnSave(object sender, EventArgs e) { if (isItemValid()) { //List<Item> a = await dbTransaction.GetItems(); CleanData(); if (_item.ItemID != 0) { dbTransaction.UpdateAsync(_item); await DisplayAlert("Success", $"{_item.ItemName} updated", "OK"); await Navigation.PopAsync(); } else { dbTransaction.InsertAsync(_item); await DisplayAlert("Success", $"{_item.ItemName} saved", "OK"); } ClearControls(); } }
private async void OnSave(object sender, EventArgs e) { string billNo = await Utils.GetBillNo(_party.PartyType); List <Transaction> transactions = new List <Transaction>(); int gridRowCount = itemList.Children.Select(c => Grid.GetRow(c)).Max(); for (int i = 1; i <= gridRowCount; i++) { var itemNameLabel = itemList.Children.Where(c => Grid.GetRow(c) == i && Grid.GetColumn(c) == 0).FirstOrDefault() as Label; if (string.IsNullOrWhiteSpace(itemNameLabel.Text)) { continue; } var qtyEntry = itemList.Children.Where(c => Grid.GetRow(c) == i && Grid.GetColumn(c) == 1).FirstOrDefault() as Entry; if (string.IsNullOrWhiteSpace(qtyEntry.Text)) { await DisplayAlert("Error", "Qty is required", "OK"); return; } var mrpEntry = itemList.Children.Where(c => Grid.GetRow(c) == i && Grid.GetColumn(c) == 2).FirstOrDefault() as Entry; if (string.IsNullOrWhiteSpace(mrpEntry.Text)) { mrpEntry.Text = "0"; } var amountEntry = itemList.Children.Where(c => Grid.GetRow(c) == i && Grid.GetColumn(c) == 3).FirstOrDefault() as Entry; if (string.IsNullOrWhiteSpace(amountEntry.Text)) { amountEntry.Text = "0"; } transactions.Add(new Transaction { BillNo = billNo, TransactionType = Utils.GetTransactionType(_party.PartyType), PartyName = _party.PartyName, PartyType = _party.PartyType, City = _party.City, ItemName = itemNameLabel.Text, Qty = qtyEntry.Text, MRP = mrpEntry.Text, Amount = amountEntry.Text, CreatedDate = DateTime.Now }); } DbTransaction dbTransaction = DbTransaction.GetInstance(); dbTransaction.InsertAllAsync(transactions); Register register = new Register { BillNo = billNo, TransactionDate = DateTime.Now, PartyName = _party.PartyName, City = _party.City, TransactionType = Utils.GetTransactionType(_party.PartyType), Amount = transactions.Sum(t => Utils.ToDecimal(t.Amount)).ToString() }; dbTransaction.InsertAsync(register); await DisplayAlert("Success", $"Bill No: {billNo} generated", "OK"); OnClear(null, null); }