Example #1
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (checkedListBox1.CheckedItems.Count == 1)
            {
                int br = 0;
                if (textBox3.Text == "")
                {
                    textBox3.Text = "1";
                    br            = 1;
                }
                else
                {
                    br = int.Parse(textBox3.Text);
                }

                Pijalok cekiran = (Pijalok)checkedListBox1.SelectedItem;

                for (int i = 0; i < pijaloci.Count; i++)
                {
                    if (cekiran != null)
                    {
                        if (pijaloci[i].ime == cekiran.ime)
                        {
                            if (pijaloci[i].kolicina < br)
                            {
                                MessageBox.Show(String.Format("Од тој производ има преостанато уште {0}", pijaloci[i].kolicina));
                            }
                            else
                            {
                                pijaloci[i].kolicina -= br;
                                pijalociL1.Add(new Pijalok(pijaloci[i].ime, br, pijaloci[i].cena));
                                if (pijaloci[i].kolicina == 0)
                                {
                                    pijaloci.RemoveAt(i);
                                }
                                updateCH1();
                                updateL1();
                            }
                        }
                        textBox3.Text = "";
                    }

                    using (System.IO.StreamWriter file =
                               new System.IO.StreamWriter(FileName))
                    {
                        foreach (Pijalok a in pijaloci)
                        {
                            file.WriteLine(a.ToString());
                        }
                    }


                    textBox3.Text = "";
                }
            }
        }
Example #2
0
        private void button6_Click(object sender, EventArgs e)
        {
            if (checkedListBox1.CheckedItems.Count == 1 && textBox5.Text != "")
            {
                int k = int.Parse(textBox5.Text);
                if (checkedListBox1.SelectedItems.Count == 0)
                {
                    return;
                }
                String  p1    = checkedListBox1.SelectedItem.ToString();
                Pijalok nov   = null;
                int     index = 0;
                foreach (Pijalok pi in pijaloci)


                {
                    if (pi.ToString() == p1)
                    {
                        pi.kolicina += k;
                        nov          = new Pijalok(pi.ime, pi.kolicina, pi.cena);
                        index++;
                        break;
                    }
                    index++;
                }
                pijaloci.RemoveAt(index - 1);
                pijaloci.Add(nov);


                updateCH1();
                textBox5.Text = "";
            }
            else
            {
                MessageBox.Show("Изберете само 1 пијалок");
            }
            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(FileName))
            {
                foreach (Pijalok p in pijaloci)
                {
                    file.WriteLine(p.ToString());
                }
            }
        }
Example #3
0
        private void Form2_Load(object sender, EventArgs e)
        {
            String path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\baza.txt";

            if (!File.Exists(path))
            {
                File.Create(path).Close();
            }

            FileName = path;


            string[] lines = File.ReadAllLines(FileName);
            foreach (String l in lines)
            {
                string[] red = l.Split('-');
                Pijalok  p   = new Pijalok(red[0], int.Parse(red[1]), int.Parse(red[2]));
                pijaloci.Add(p);
            }
            updateCH1();
        }