private void BtnSave_Click(object sender, EventArgs e) { int result; if (purchaseid > 0) { // we are in edit mode result = purchase.Update(purchaseid, CBOSupplier.SelectedValue.ToInt64(), CboBrand.SelectedValue.ToInt64(), DTPurchaseDate.Value, TxtRate.Text.ToInt64(), NBQty.Value, TxtAmount.Text.ToInt64(), TxtDiffAmount.Text.ToInt64()); } else { result = purchase.Add(CBOSupplier.SelectedValue.ToInt64(), CboBrand.SelectedValue.ToInt64(), DTPurchaseDate.Value, TxtRate.Text.ToInt64(), NBQty.Value, TxtAmount.Text.ToInt64(), TxtDiffAmount.Text.ToInt64()); } if (result > 0) { MessageBox.Show(@"Record Saved"); } BtnAdd.Enabled = true; BtnEdit.Enabled = true; BtnDelete.Enabled = true; BtnSave.Enabled = false; BtnCancel.Enabled = false; GBControls.Enabled = false; FillGrid(); }
private static List <Purchase> ReadExcel(string fileName) { var res = new List <Purchase>(); using var stream = File.Open(fileName, FileMode.Open, FileAccess.Read); using var reader = ExcelReaderFactory.CreateReader(stream); do { Purchase purchase = null; while (reader.Read()) //each Row { var obj = reader.GetValue(0); if (obj is DateTime dateTime && DataValidation.IsDateValid(dateTime)) { AddPurchase(res, purchase); purchase = new Purchase(dateTime); } else { var item = ReadRow(reader); if (item != null && purchase != null) { purchase.Add(item); } } }
/// <summary> /// If an order is being placed we want to add each orderline to the Purchase object to keep track /// </summary> /// <param name="ISBNAndQuantity"></param> /// <returns></returns> public bool AddNewOrderLine(string ISBNAndQuantity) { string[] lineFiltered = SplitString(ISBNAndQuantity); // Check if the book exists in the catalog if (!Book.CheckIfIsValidIsbn(lineFiltered[0])) { return(false); } var newOrderLine = new OrderLine(); newOrderLine.BookISBN = lineFiltered[0]; // make sure that the quantity is a number try { Int32.Parse(lineFiltered[1]); if (Int32.Parse(lineFiltered[1]) >= ordercap) { return(false); } } catch (Exception ex) { return(false); } // add the orderline to this order newOrderLine.Quantity = Int32.Parse(lineFiltered[1]); Purchase.Add(newOrderLine); return(true); }
public void ReceiptGroupsByArticle() { var article = new Article(1, Country.Ita, Category.ArtsAndCrafts, Guid.NewGuid().ToString(), 100); var tax = new NoBasicTax(); var purchase = new Purchase(article.SupplierCountry); purchase.Add(article, 2, tax); var receipt = purchase.BuildReceipt(); Assert.Single(receipt.Entries); }
public void PurchaseAppliesTax() { var article = new Article(1, Country.Ita, Category.ArtsAndCrafts, Guid.NewGuid().ToString(), 100); var tax = new BasicTax(); var purchase = new Purchase(article.SupplierCountry); purchase.Add(article, 1, tax); var receipt = purchase.BuildReceipt(); Assert.NotEqual(article.Price, receipt.Total); }
//Populate the script lists here. Follow the example on how to add to a list #region Populate Lists /// <summary> /// Use this method to populate the lists. They are already set to be selected from the /// CycleScripts method and no other work is required. /// </summary> public override void PopulateLists() { BrowserState.Clear(); Locale.Clear(); Purchase.Clear(); Register.Clear(); SingleSignOn.Clear(); SingleSignOnLocale.Clear(); base.PopulateLists(); //SignIn.Add(new Connect_SignIn(base.baseURL, base.webdriver, base.verificationErrors)); BrowserState.Add(new BrowserStateTest(base.baseURL, base.webdriver, base.verificationErrors)); Locale.Add(new LocaleTest(base.baseURL, base.webdriver, base.verificationErrors)); Purchase.Add(new PurchaseTest(base.baseURL, base.webdriver, base.verificationErrors)); Register.Add(new RegisterUserTest(base.baseURL, base.webdriver, base.verificationErrors)); SingleSignOnLocale.Add(new SingleSignOnLocaleTest(base.baseURL, base.webdriver, base.verificationErrors)); SingleSignOn.Add(new SingleSignOnTest(base.baseURL, base.webdriver, base.verificationErrors)); }
public void ReceiptForOneArticleMatchesItsData() { var articleName = Guid.NewGuid().ToString(); var article = new Article(1, Country.Ita, Category.ArtsAndCrafts, articleName, 100); var purchase = new Purchase(article.SupplierCountry); var tax = new BasicTax(); purchase.Add(article, 1, tax); var receipt = purchase.BuildReceipt(); var entry = receipt.Entries.Single(); const int quantity = 1; var priceWithTaxes = tax.ApplyTo(article.Price); Assert.Equal(articleName, entry.Description); Assert.Equal(quantity, entry.Quantity); Assert.Equal(priceWithTaxes, entry.TotalPriceWithTaxes); Assert.Equal(priceWithTaxes - article.Price, receipt.Taxes); Assert.Equal(priceWithTaxes, receipt.Total); }
public void EntryToStringFormatIsQuantityImportedIfApplicableNameColonPrice() { const string articleName = "Article ABC"; const decimal articlePrice = 32.54M; const int quantity = 2; const decimal totalPriceWithTaxes = quantity * articlePrice; var article = new Article(1, Country.Usa, Category.ArtsAndCrafts, articleName, articlePrice); var tax = new NoBasicTax(); var localPurchase = new Purchase(Country.Usa); localPurchase.Add(article, quantity, tax); var localReceipt = localPurchase.BuildReceipt(); var importedPurchase = new Purchase(Country.Ita); importedPurchase.Add(article, quantity, tax); var importedReceipt = importedPurchase.BuildReceipt(); Assert.Equal($"{quantity} {articleName}: {totalPriceWithTaxes}", localReceipt.Entries.Single().ToString()); Assert.Equal($"{quantity} imported {articleName}: {totalPriceWithTaxes}", importedReceipt.Entries.Single().ToString()); }
private void AddGoodPage_GoodCreated(PurchaseItem obj) { purchase.Add(obj); Refresh(); }