Beispiel #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 article;

            if (rrbWine.Checked)
            {
                article = new WineArt(id, tbName.Text, bPrice, inStock, Convert.ToInt32(tbYear.Text));
            }
            else if (rbWCArticle.Checked)
            {
                article = new WCArt(id, tbName.Text, bPrice, inStock, cbDiscount.Checked);
            }
            else
            {
                article = new DepositArt(id, tbName.Text, bPrice, inStock, Convert.ToDouble(tbDeposit.Text));
            }
            if (myShop.AddArticle(article))
            {
                MessageBox.Show("Successfully added article.");
            }
            else
            {
                MessageBox.Show("Already exists an article with that ID number.");
            }
        }
Beispiel #2
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");
            }
        }
Beispiel #3
0
 private void btnLoadFromFile_Click(object sender, EventArgs e)
 {
     //todo, see assignment 3
     using (OpenFileDialog ofd = new OpenFileDialog())
     {
         if (ofd.ShowDialog() == DialogResult.OK)
         {
             FileStream   fs;
             StreamReader sr = null;
             try
             {
                 fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
                 sr = new StreamReader(fs);
                 bool    temp;
                 string  line = sr.ReadLine();
                 int     id;
                 string  name;
                 double  basicPrice;
                 int     nrInStock;
                 Article article;
                 while (!sr.EndOfStream)
                 {
                     id         = Convert.ToInt32(sr.ReadLine());
                     name       = sr.ReadLine();
                     basicPrice = Convert.ToDouble(sr.ReadLine());
                     nrInStock  = Convert.ToInt32(sr.ReadLine());
                     if (line.Contains("wine"))
                     {
                         int year = Convert.ToInt32(sr.ReadLine());
                         article = new WineArt(id, name, basicPrice, nrInStock, year);
                     }
                     else if (line.Contains("wcart"))
                     {
                         if (sr.ReadLine() == "discount yes")
                         {
                             temp = true;
                         }
                         else
                         {
                             temp = false;
                         }
                         article = new WCArt(id, name, basicPrice, nrInStock, temp);
                     }
                     else
                     {
                         double deposit = Convert.ToDouble(sr.ReadLine());
                         article = new DepositArt(id, name, basicPrice, nrInStock, deposit);
                     }
                     myShop.AddArticle(article);
                     sr.ReadLine();
                     line = sr.ReadLine();
                 }
             }
             catch (IOException ex)
             {
                 MessageBox.Show(ex.Message);
             }
             finally
             {
                 if (sr != null)
                 {
                     sr.Close();
                 }
             }
         }
     }
 }
Beispiel #4
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();
             }
         }
     }
 }