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;
- using System.Text.RegularExpressions;
- namespace WindowsFormsApplication4
- {
- public partial class Furnish : Form
- {
- List<Item> items = new List<Item>();
- public void match(Regex Reg, TextBox box, Label lab)
- {
- if (Reg.IsMatch(box.Text))
- {
- lab.ForeColor = Color.LimeGreen;
- lab.Text = "Complete";
- }
- else
- {
- lab.ForeColor = Color.Red;
- lab.Text = "*Required";
- }
- }
- public void allClear()
- {
- nameText.Clear();
- priceText.Clear();
- urlText.Clear();
- nameLabel.Text = "";
- priceLabel.Text = "";
- urlLabel.Text = "";
- }
- public Furnish()
- {
- InitializeComponent();
- }
- private void addButton_Click(object sender, EventArgs e)
- {
- Regex url = new Regex(@"^[a-zA-Z0-9\-\.]+\.(com|org|net|ca|mil|edu|COM|ORG|NET|CA|MIL|EDU)$");
- Regex name = new Regex(@"^[0-9, a-z, A-Z, \-]+$");
- Regex price = new Regex(@"^[0-9, \.]+$");
- if (url.IsMatch(urlText.Text) && name.IsMatch(nameText.Text) && price.IsMatch(priceText.Text))
- {
- itemListBox.Items.Add(nameText.Text);
- double item_Price = Convert.ToDouble(priceText.Text);
- items.Add(new Item(@itemURL.Text, itemName.Text, item_Price));
- allClear();
- }
- else
- {
- match(url, urlText, urlLabel);
- match(price, priceText, priceLabel);
- match(name, nameText, nameLabel);
- }
- }
- private void menuQuit_Click(object sender, EventArgs e)
- {
- if (MessageBox.Show("Are You Sure You Want To Quit?", "Goodbye?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- Application.Exit();
- }
- }
- private void itemListBox_DoubleClick(object sender, EventArgs e)
- {
- if (itemListBox.SelectedItem != null)
- {
- var editor = new Edit(items);
- editor.Show();
- }
- }
- private void menuEdit_Click(object sender, EventArgs e)
- {
- var editor = new Edit(items);
- editor.Show();
- }
- private void calculateTotalToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var total = new Form3(items);
- total.Show();
- }
- private void resetAllToolStripMenuItem_Click(object sender, EventArgs e)
- {
- items.Clear();
- itemListBox.ResetText();
- }
- private void Furnish_Load(object sender, EventArgs e)
- {
- foreach (Item i in items)
- {
- itemListBox.Items.Add(i.Name);
- }
- }
- private void menuOpen_Click(object sender, EventArgs e)
- {
- string filePath = "";
- if (openFile.ShowDialog() != DialogResult.Cancel)
- {
- filePath = openFile.FileName;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment