Exemplo n.º 1
0
        private void btnAddArticle_Click(object sender, EventArgs e)
        {
            //todo, see assignment 3
            int     id      = Convert.ToInt32(tbID.Text);
            double  bprice  = Convert.ToDouble(tbBasicPrice.Text);
            int     inStock = Convert.ToInt32(tbInStock.Text);
            Article a;

            if (this.rrbWine.Checked)
            {
                a = new Wine(id, tbName.Text, bprice, inStock, Convert.ToInt32(tbYear.Text));
            }
            else if (this.rbDepositArticle.Checked)
            {
                a = new DepositArticle(id, tbName.Text, bprice, inStock, Convert.ToDouble(tbDeposit.Text));
            }
            else
            {//then it will be a wc-art
                a = new WCArt(id, tbName.Text, bprice, inStock, cbDiscount.Checked);
            }

            if (this.myShop.AddArticle(a))
            {
                MessageBox.Show("succesfully added");
            }
            else
            {
                MessageBox.Show("not succesfully added");
            }
        }
Exemplo n.º 2
0
 private void btnLoadFromFile_Click(object sender, EventArgs e)
 {
     //todo, see assignment 3
     if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         FileStream   fs = null;
         StreamReader sr = null;
         this.myShop.clearArticleList();
         try
         {
             fs = new FileStream(this.openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
             sr = new StreamReader(fs);
             string s = sr.ReadLine();
             while (s != null)
             {
                 Article newArticle;
                 int     id         = Convert.ToInt32(sr.ReadLine());
                 string  name       = sr.ReadLine();
                 double  basicPrice = Convert.ToDouble(sr.ReadLine());
                 int     nrInStock  = Convert.ToInt32(sr.ReadLine());
                 if (s == "wine")
                 {
                     int year = Convert.ToInt32(sr.ReadLine());
                     newArticle = new Wine(id, name, basicPrice, nrInStock, year);
                 }
                 else if (s == "wcart")
                 {
                     String onDiscount = sr.ReadLine();
                     if (onDiscount == "discount yes")
                     {
                         newArticle = new WCArt(id, name, basicPrice, nrInStock, true);
                     }
                     else
                     {
                         newArticle = new WCArt(id, name, basicPrice, nrInStock, false);
                     }
                 }
                 else //now s == "dep"
                 {
                     double depositAmount = Convert.ToDouble(sr.ReadLine());
                     newArticle = new DepositArticle(id, name, basicPrice, nrInStock, depositAmount);
                 }
                 this.myShop.AddArticle(newArticle);
                 s = sr.ReadLine();//for skipping the delimiter-line with =-signs
                 s = sr.ReadLine();
             }
         }
         catch (IOException) { MessageBox.Show("something wrong about file"); }
         finally
         {
             if (sr != null)
             {
                 sr.Close();
             }
             if (fs != null)
             {
                 fs.Close();
             }
         }
     }
 }