Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace VPEx2
- {
- public partial class InformationSystemSales : Form
- {
- public InformationSystemSales()
- {
- InitializeComponent();
- listviewSales.View = View.Details;
- listviewSales.Columns.Add("Date", 100, HorizontalAlignment.Left);
- listviewSales.Columns.Add("Article", 80, HorizontalAlignment.Left);
- listviewSales.Columns.Add("Unit Price", 60, HorizontalAlignment.Left);
- listviewSales.Columns.Add("Qty", 50, HorizontalAlignment.Left);
- listviewSales.Columns.Add("Discount", 66, HorizontalAlignment.Left);
- listviewSales.Columns.Add("Total Amount", 100, HorizontalAlignment.Left);
- }
- int numOfSales = 0;
- decimal grandDiscountValue = 0.0m;
- decimal grandTotalValue = 0.0m;
- ToolTip toolTip = new ToolTip();
- MessageBoxButtons button = MessageBoxButtons.OK;
- DialogResult result;
- private void newSaleBtn_Click(object sender, EventArgs e)
- {
- MessageBoxButtons button = MessageBoxButtons.OK;
- DialogResult result;
- string newSaleMessage = "Inputting data for a sale.";
- string newSaleCaption = "New Sale";
- result = MessageBox.Show(newSaleMessage, newSaleCaption, button);
- article.Text = "";
- unitPrice.Clear();
- quantity.Clear();
- discount.Clear();
- totalAmount.Clear();
- totalBtn.Enabled = true;
- newSaleBtn.Enabled = false;
- discountLabel.ForeColor = Color.Black;
- }
- private void totalBtn_Click(object sender, EventArgs e)
- {
- decimal discountValue = 0.0m;
- decimal totalAmountValue = 0.0m;
- string fieldIsIncorrect = "Some of the input data is incorrect. Please make sure you enter a valid data.";
- double n;
- bool isNumeric = double.TryParse(unitPrice.Text, out n) &&
- double.TryParse(quantity.Text, out n);
- if (article.SelectedIndex == -1 || !isNumeric ||
- unitPrice.Text.Trim().Length == 0 || quantity.Text.Trim().Length == 0 ||
- selectedCurrency.SelectedIndex == -1 ||
- int.Parse(unitPrice.Text) <= 0 || int.Parse(quantity.Text) <= 0)
- {
- MessageBox.Show(fieldIsIncorrect, "Error", button);
- }
- else
- {
- string totalMessage = "Calculating discount and total amount of a current entered sale.";
- string totalCaption = "Total";
- result = MessageBox.Show(totalMessage, totalCaption, button);
- decimal unitPriceValue = decimal.Parse(unitPrice.Text);
- int quantityValue = int.Parse(quantity.Text);
- totalAmountValue = unitPriceValue * quantityValue;
- double discountPercent = 0.1;
- if (totalAmountValue >= 100)
- {
- discountValue = (decimal)discountPercent * totalAmountValue;
- totalAmountValue = totalAmountValue - discountValue;
- }
- else
- {
- discountValue = 0;
- }
- if (discountValue > 0)
- {
- grandDiscountValue += discountValue;
- discountLabel.ForeColor = Color.Red;
- }
- else
- {
- discountLabel.ForeColor = Color.Black;
- }
- numOfSales++;
- grandTotalValue += totalAmountValue;
- totalAmount.Text = string.Format("{0:0.00}", totalAmountValue);
- discount.Text = string.Format("{0:0.00}", discountValue);
- newSaleBtn.Enabled = true;
- totalBtn.Enabled = false;
- selectDate.Enabled = false;
- }
- string[] currentRow = { article.Text, unitPrice.Text, quantity.Text,
- discount.Text, totalAmount.Text };
- listviewSales.Items.Add(Convert.ToString(selectDate.Text)).SubItems.AddRange(currentRow);
- }
- public Boolean IsNumber(String value)
- {
- Boolean isNum = true;
- foreach (Char c in value.ToCharArray())
- {
- isNum = isNum && Char.IsDigit(c);
- }
- return isNum;
- }
- private void finishAllSalesBtn_Click(object sender, EventArgs e)
- {
- if (finishAllSalesBtn.Text == "New Operation")
- {
- numberOfSales.Clear();
- grandDiscount.Clear();
- grandTotal.Clear();
- grandDiscountBGN.Clear();
- grandTotalBGN.Clear();
- selectedCurrency.SelectedIndex = -1;
- listviewSales.Items.Clear();
- article.Text = "";
- unitPrice.Clear();
- quantity.Clear();
- discount.Clear();
- totalAmount.Clear();
- numOfSales = 0;
- grandDiscountValue = 0;
- grandTotalValue = 0;
- grandDiscLabel.ForeColor = Color.Black;
- finishAllSalesBtn.Text = "Finish All Sales";
- totalBtn.Enabled = true;
- article.Enabled = true;
- unitPrice.ReadOnly = false;
- quantity.ReadOnly = false;
- selectDate.Enabled = true;
- }
- else
- {
- string finishSalesMessage = "Conclusion of input sales and calculating the total discount and total amount of all entries.";
- string finishSalesCaption = "Finish Sales";
- result = MessageBox.Show(finishSalesMessage, finishSalesCaption, button);
- numberOfSales.Text = numOfSales.ToString();
- grandDiscount.Text = string.Format("{0:0.00}", grandDiscountValue);
- grandTotal.Text = string.Format("{0:0.00}", grandTotalValue);
- finishAllSalesBtn.Text = "New Operation";
- newSaleBtn.Enabled = false;
- totalBtn.Enabled = true;
- article.Enabled = true;
- unitPrice.ReadOnly = true;
- quantity.ReadOnly = true;
- if (grandDiscountValue > 0)
- {
- grandDiscLabel.ForeColor = Color.Red;
- }
- else
- {
- grandDiscLabel.ForeColor = Color.Black;
- }
- discountLabel.ForeColor = Color.Black;
- finishAllSalesBtn.Text = "New Operation";
- }
- numberOfSalesBGN.Text = numberOfSales.Text;
- decimal exchangeRateEUR = 0.51m;
- decimal exchangeRateUSD = 0.64m;
- switch (selectedCurrency.Text)
- {
- case "BGN":
- currencyLabel.Text = "BGN";
- grandDiscountBGN.Text = grandDiscount.Text;
- grandTotalBGN.Text = grandTotal.Text;
- break;
- case "EUR":
- decimal grandDiscountEUR = grandDiscountValue * exchangeRateEUR;
- decimal grandTotalEUR = grandTotalValue * exchangeRateEUR;
- grandDiscountBGN.Text = string.Format("{0:0.00}", grandDiscountEUR);
- grandTotalBGN.Text = string.Format("{0:0.00}", grandTotalEUR);
- currencyLabel.Text = "EUR";
- break;
- case "USD":
- decimal grandDiscountUSD = grandDiscountValue * exchangeRateUSD;
- decimal grandTotalUSD = grandTotalValue * exchangeRateUSD;
- grandDiscountBGN.Text = string.Format("{0:0.00}", grandDiscountUSD);
- grandTotalBGN.Text = string.Format("{0:0.00}", grandTotalUSD);
- currencyLabel.Text = "USD";
- break;
- }
- }
- private void exitBtn_Click(object sender, EventArgs e)
- {
- string exitMessage = "Exit the application";
- string exitCaption = "Exit";
- result = MessageBox.Show(exitMessage, exitCaption, button);
- this.Close();
- }
- private void unitPrice_MouseHover(object sender, EventArgs e)
- {
- toolTip.Show("Positive value. Required field.", unitPrice);
- }
- private void quantity_MouseHover(object sender, EventArgs e)
- {
- toolTip.Show("Positive whole value. Required field.", quantity);
- }
- private void newSaleBtn_MouseHover(object sender, EventArgs e)
- {
- toolTip.Show("Adds a new sale to the current operation.", newSaleBtn);
- }
- private void totalBtn_MouseHover(object sender, EventArgs e)
- {
- toolTip.Show("Calculates the total sum of the current sale.", totalBtn);
- }
- private void finishAllSalesBtn_MouseHover(object sender, EventArgs e)
- {
- if (finishAllSalesBtn.Text == "New Operation")
- {
- toolTip.Show("Begins a new operation.", finishAllSalesBtn);
- }
- toolTip.Show("Finishes the current operation and calculates grand sums.", finishAllSalesBtn);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement