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.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using BookShop.Forms;
- using BookShop.Data;
- using System.Drawing.Drawing2D;
- namespace BookShop.UserControls
- {
- public partial class UC_Sales : UserControl
- {
- private Business bs = new Business();
- book book = new book();
- public static float amount = 0;
- public UC_Sales()
- {
- InitializeComponent();
- }
- private void panel5_Paint(object sender, PaintEventArgs e)
- {
- }
- private void listView1_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void button7_Click(object sender, EventArgs e)
- {
- if (listView1.Items.Count == 0)
- {
- MessageBox.Show("Add books to cart please!");
- }
- else
- {
- using (Form_FinishOrder uf = new Form_FinishOrder())
- {
- uf.ShowDialog();
- }
- }
- }
- private void button8_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrWhiteSpace(textBox1.Text))
- {
- MessageBox.Show("Barcode can't be null or whitespace");
- return;
- }
- int parsedValue;
- if (!int.TryParse(textBox1.Text, out parsedValue))
- {
- MessageBox.Show("This is a number only field");
- return;
- }
- int barcodeText = int.Parse(textBox1.Text);
- button1.Enabled = false;
- if (barcodeText > 0 && barcodeText <= bs.GetAllBarcodesCount())
- {
- book = bs.GetBookByBarcode(int.Parse(textBox1.Text));
- textBox2.Text = book.Book1;
- textBox3.Text = book.Author;
- textBox4.Text = book.Price.ToString("N2");
- textBox5.Text = book.Publisher;
- button1.Enabled = true;
- }
- else
- {
- MessageBox.Show("Barcode is invalid, try another one.");
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrWhiteSpace(textBox1.Text))
- {
- MessageBox.Show("Firstly type barcode.");
- button1.Enabled = false;
- }
- else
- {
- string[] row = { textBox2.Text, "1", textBox4.Text };
- var listViewItem = new ListViewItem(row);
- if (listView1.FindItemWithText(textBox2.Text) != null)
- {
- amount = 0;
- listView1.FindItemWithText(textBox2.Text).SubItems[1].Text = int.Parse(listView1.FindItemWithText(textBox2.Text).SubItems[1].Text) + 1 + "";
- CalculateAmount();
- }
- else
- {
- listView1.Items.Add(listViewItem);
- CalculateAmount();
- }
- }
- }
- private void UC_Sales_Load(object sender, EventArgs e)
- {
- listView1.FullRowSelect = true;
- amount = 0;
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- textBox2.Clear();
- textBox3.Clear();
- textBox4.Clear();
- textBox5.Clear();
- button1.Enabled = false;
- }
- private void button3_Click(object sender, EventArgs e)
- {
- if (listView1.SelectedItems.Count > 0)
- {
- ListViewItem item = listView1.SelectedItems[0];
- amount = 0;
- item.SubItems[1].Text = int.Parse(item.SubItems[1].Text) + 1 + "";
- CalculateAmount();
- }
- else
- {
- MessageBox.Show("Select row...");
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- if (listView1.SelectedItems.Count > 0)
- {
- ListViewItem item = listView1.SelectedItems[0];
- amount = 0;
- if(int.Parse(item.SubItems[1].Text) > 1) { item.SubItems[1].Text = int.Parse(item.SubItems[1].Text) - 1 + ""; CalculateAmount(); }//PETUK
- else
- {
- MessageBox.Show("Amount can't be less than 1");
- item.SubItems[1].Text = 1 + "";
- }
- }
- else
- {
- MessageBox.Show("Select row...");
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- if (listView1.SelectedItems.Count > 0)
- {
- ListViewItem item = listView1.SelectedItems[0];
- item.Remove();
- label3.Text = "0.00 $";
- }
- else
- {
- MessageBox.Show("Select row...");
- }
- }
- private void button6_Click(object sender, EventArgs e)
- {
- DialogResult result = MessageBox.Show("Your cart will be lost", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
- if (result == DialogResult.Yes)
- {
- listView1.Items.Clear();
- }
- else if(result == DialogResult.No)
- {
- return;
- }
- else
- {
- return;
- }
- }
- public void CalculateAmount()
- {
- for (int i = 0; i < listView1.Items.Count; i++)
- {
- amount += float.Parse(listView1.Items[i].SubItems[2].Text) * float.Parse(listView1.Items[i].SubItems[1].Text);
- }
- label3.Text = amount.ToString("N2") + " $";
- }
- public float amountValue
- {
- get
- {
- return amount;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement