Guest User

MainForm

a guest
Aug 27th, 2013
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Text.RegularExpressions;
  11.  
  12. namespace WindowsFormsApplication4
  13. {
  14.     public partial class Furnish : Form
  15.     {
  16.         List<Item> items = new List<Item>();
  17.  
  18.         public void match(Regex Reg, TextBox box, Label lab)
  19.         {
  20.             if (Reg.IsMatch(box.Text))
  21.             {
  22.                 lab.ForeColor = Color.LimeGreen;
  23.                 lab.Text = "Complete";
  24.             }
  25.             else
  26.             {
  27.                 lab.ForeColor = Color.Red;
  28.                 lab.Text = "*Required";
  29.             }
  30.         }
  31.  
  32.         public void allClear()
  33.         {
  34.             nameText.Clear();
  35.             priceText.Clear();
  36.             urlText.Clear();
  37.             nameLabel.Text = "";
  38.             priceLabel.Text = "";
  39.             urlLabel.Text = "";
  40.         }
  41.  
  42.         public Furnish()
  43.         {
  44.             InitializeComponent();
  45.         }
  46.  
  47.         private void addButton_Click(object sender, EventArgs e)
  48.         {
  49.             Regex url = new Regex(@"^[a-zA-Z0-9\-\.]+\.(com|org|net|ca|mil|edu|COM|ORG|NET|CA|MIL|EDU)$");
  50.             Regex name = new Regex(@"^[0-9, a-z, A-Z, \-]+$");
  51.             Regex price = new Regex(@"^[0-9, \.]+$");
  52.  
  53.             if (url.IsMatch(urlText.Text) && name.IsMatch(nameText.Text) && price.IsMatch(priceText.Text))
  54.             {
  55.                 itemListBox.Items.Add(nameText.Text);
  56.                 double item_Price = Convert.ToDouble(priceText.Text);
  57.                 items.Add(new Item(@itemURL.Text, itemName.Text, item_Price));
  58.                 allClear();
  59.             }
  60.             else
  61.             {
  62.                 match(url, urlText, urlLabel);
  63.                 match(price, priceText, priceLabel);
  64.                 match(name, nameText, nameLabel);
  65.             }
  66.  
  67.  
  68.  
  69.         }
  70.  
  71.         private void menuQuit_Click(object sender, EventArgs e)
  72.         {
  73.             if (MessageBox.Show("Are You Sure You Want To Quit?", "Goodbye?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  74.             {
  75.                 Application.Exit();
  76.             }
  77.         }
  78.  
  79.         private void itemListBox_DoubleClick(object sender, EventArgs e)
  80.         {
  81.             if (itemListBox.SelectedItem != null)
  82.             {
  83.                 var editor = new Edit(items);
  84.                 editor.Show();
  85.             }
  86.         }
  87.  
  88.         private void menuEdit_Click(object sender, EventArgs e)
  89.         {
  90.             var editor = new Edit(items);
  91.             editor.Show();
  92.         }
  93.  
  94.         private void calculateTotalToolStripMenuItem_Click(object sender, EventArgs e)
  95.         {
  96.             var total = new Form3(items);
  97.             total.Show();
  98.         }
  99.  
  100.         private void resetAllToolStripMenuItem_Click(object sender, EventArgs e)
  101.         {
  102.             items.Clear();
  103.             itemListBox.ResetText();
  104.         }
  105.  
  106.         private void Furnish_Load(object sender, EventArgs e)
  107.         {
  108.             foreach (Item i in items)
  109.             {
  110.                 itemListBox.Items.Add(i.Name);
  111.             }
  112.         }
  113.  
  114.         private void menuOpen_Click(object sender, EventArgs e)
  115.         {
  116.             string filePath = "";
  117.             if (openFile.ShowDialog() != DialogResult.Cancel)
  118.             {
  119.                 filePath = openFile.FileName;
  120.             }
  121.         }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment