Beispiel #1
0
        //int satilanTop;
        //int satilanMaliyet;

        private void btn_YeniEkle_Click(object sender, EventArgs e)
        {
            if (txt_Dosya.Text != "")
            {
                //Dictionary<string, List<Urun>> dt = new Dictionary<string, List<Urun>>();

                UrunTXTReader reader = new UrunTXTReader();
                try
                {
                    reader.fromTxtToTree(txt_Dosya.Text, bst, dt);
                    MessageBox.Show("Ürünler başarıyla eklendi.");
                }
                catch (FileNotFoundException ex)
                {
                    Console.WriteLine("[Data File Missing] {0}", ex);
                    throw new FileNotFoundException(@"[urunler.txt not in c:\temp directory]", ex);
                }
            }
            else
            {
                Dictionary <string, List <Urun> > dt = new Dictionary <string, List <Urun> >();
                char[] delimiterChars = { '\'', ',' };

                if (!bst.contains(txt_UrunAdi.Text))
                {
                    Urun urun = new Urun();

                    urun.setUrunAdi(txt_UrunAdi.Text);
                    urun.setUrunKategori(txt_UrunKategori.Text);
                    urun.setMarka(txt_UrunMarka.Text);
                    urun.setModel(txt_UrunModel.Text);
                    urun.setMiktar(Convert.ToInt32(txt_UrunMiktar.Text));
                    urun.setMaliyet(Convert.ToInt32(txt_UrunMaliyet.Text));
                    urun.setSatisFiyatı(Convert.ToInt32(txt_UrunSatisFiyati.Text));

                    string[]      words = txt_UrunAciklama.Text.Split(delimiterChars);
                    List <string> lst   = new List <string>();
                    foreach (string str in words)
                    {
                        if (str == null)
                        {
                            break;
                        }

                        lst.Add(str);

                        if (!dt.ContainsKey(str))
                        {
                            List <Urun> hList = new List <Urun>();
                            hList.Add(urun);
                            dt.Add(str, hList);
                        }
                        else
                        {
                            dt[str].Add(urun);
                        }
                    }
                    urun.setAciklama(lst);
                    bst.put(urun);
                    MessageBox.Show(txt_UrunAdi.Text + " ürünü başarıyla eklendi.");
                    temizle();
                }
                else
                {
                    Urun urun = new Urun();
                    urun = bst.get(txt_UrunAdi.Text);

                    List <TheOthers> digerleri = new List <TheOthers>();
                    TheOthers        to        = new TheOthers();
                    to.setMarka(txt_UrunMarka.Text);
                    to.setModel(txt_UrunModel.Text);
                    to.setMiktar(Convert.ToInt32(txt_UrunMiktar.Text));
                    to.setMaliyet(Convert.ToInt32(txt_UrunMaliyet.Text));
                    to.setSatisFiyatı(Convert.ToInt32(txt_UrunSatisFiyati.Text));

                    string[]      words = txt_UrunAciklama.Text.Split(delimiterChars);
                    List <string> lst   = new List <string>();
                    foreach (string str in words)
                    {
                        if (str == null)
                        {
                            break;
                        }

                        lst.Add(str);

                        if (!dt.ContainsKey(str))
                        {
                            List <Urun> hList = new List <Urun>();
                            hList.Add(urun);
                            dt.Add(str, hList);
                        }
                        else
                        {
                            dt[str].Add(urun);
                        }
                    }
                    to.setAciklama(lst);

                    digerleri.Add(to);
                    urun.setDigerleri(digerleri);
                    MessageBox.Show(txt_UrunAdi.Text + " ürünü başarıyla eklendi.");
                    temizle();
                }
            }
        }
        public void fromTxtToTree(string txtFile, BSTUrun BSTree, Dictionary <string, List <Urun> > dt)
        {
            string[][] strDizi = reader(txtFile);
            //Hasher hs = new Hasher();
            char[] delimiterChars = { '\'', ',' };


            foreach (string[] str in strDizi)
            {
                if (str == null)
                {
                    break;
                }

                if (!bst.contains(str[0]))
                {
                    Urun urun = new Urun();
                    urun.setUrunAdi(str[0]);
                    urun.setUrunKategori(str[1]);
                    urun.setMarka(str[2]);
                    urun.setModel(str[3]);
                    urun.setMiktar(Convert.ToInt32(str[4]));
                    urun.setMaliyet(Convert.ToInt32(str[5]));
                    urun.setSatisFiyatı(Convert.ToInt32(str[6]));
                    List <string> lst = new List <string>();
                    int           i   = 7;
                    string        gecici;
                    try
                    {
                        while ((gecici = str[i]) != null)
                        {
                            lst.Add(gecici);
                            i++;
                        }
                    }
                    catch (IndexOutOfRangeException) { }
                    hs.hasher(str, dt, urun);
                    urun.setAciklama(lst);
                    BSTree.put(urun);
                }
                else
                {
                    Urun urun = new Urun();
                    urun = bst.get(str[0]);

                    List <TheOthers> digerleri = new List <TheOthers>();
                    TheOthers        to        = new TheOthers();
                    to.setMarka(str[2]);
                    to.setModel(str[3]);
                    to.setMiktar(Convert.ToInt32(str[4]));
                    to.setMaliyet(Convert.ToInt32(str[5]));
                    to.setSatisFiyatı(Convert.ToInt32(str[6]));

                    List <string> lst = new List <string>();
                    int           i   = 7;
                    string        gecici;
                    try
                    {
                        while ((gecici = str[i]) != null)
                        {
                            lst.Add(gecici);
                            i++;
                        }
                    }
                    catch (IndexOutOfRangeException) { }
                    hs.hasher(str, dt, urun);
                    to.setAciklama(lst);
                    digerleri.Add(to);
                    urun.setDigerleri(digerleri);
                    BSTree.put(urun);
                }
            }
        }