public static void Ekle(YemekListesi a)
        {
            DataRow ra = null;

            ra = _dt_yemeklistesi.Rows.Find(a.Tarih);
            if (ra != null)
            {
                MessageBox.Show("O Tarihe Yemek eklenmiş");
                return;
            }
            DataTable dt = GetAll();
            DataRow   r  = dt.NewRow();

            r["Tarih"]        = a.Tarih;
            r["Ogun"]         = a.Ogun;
            r["a1"]           = a.a1;
            r["a2"]           = a.a2;
            r["a3"]           = a.a3;
            r["a4"]           = a.a4;
            r["a5"]           = a.a5;
            r["a6"]           = a.a6;
            r["a7"]           = a.a7;
            r["ToplamKalori"] = a.ToplamKalori;
            _dt_yemeklistesi.Rows.Add(r);
            _dt_yemeklistesi.AcceptChanges();
            string path = Application.StartupPath + "\\veriler\\yemeklistesi.xml";

            _dt_yemeklistesi.WriteXml(path);
        }
        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count < 1)
            {
                return;
            }
            string  rid = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            DataRow r   = null;

            foreach (DataRow item in dt.Rows)
            {
                if (item["Tarih"].ToString() == rid)
                {
                    r = item;
                    break;
                }
            }

            yliste = new YemekListesi
            {
                Tarih        = r["Tarih"].ToString(),
                Ogun         = r["Ogun"].ToString(),
                a1           = r["a1"].ToString(),
                a2           = r["a2"].ToString(),
                a3           = r["a3"].ToString(),
                a4           = r["a4"].ToString(),
                a5           = r["a5"].ToString(),
                a6           = r["a6"].ToString(),
                a7           = r["a7"].ToString(),
                ToplamKalori = Convert.ToInt32(r["ToplamKalori"].ToString())
            };
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            YemekListesi y = new YemekListesi()
            {
                Tarih        = dateTimePicker1.Value.ToLongDateString(),
                Ogun         = comboBox_ogun.SelectedItem.ToString(),
                a1           = comboBox1.SelectedItem.ToString(),
                a2           = comboBox2.SelectedItem.ToString(),
                a3           = comboBox3.SelectedItem.ToString(),
                a4           = comboBox4.SelectedItem.ToString(),
                a5           = comboBox5.SelectedItem.ToString(),
                a6           = comboBox6.SelectedItem.ToString(),
                a7           = comboBox7.SelectedItem.ToString(),
                ToplamKalori = Convert.ToInt32(lbl_kalori.Text)
            };

            if (yemek == null)
            {
                YemekListesi.Ekle(y);
                MessageBox.Show("Eklendi");
            }
            else if (yemek != null)
            {
                YemekListesi.Guncelle(y, yemek.Tarih);
                MessageBox.Show("Güncelle");
            }

            this.Close();
        }
        public static void Sil(YemekListesi a)
        {
            DataTable dt = GetAll();
            DataRow   r  = dt.Rows.Find(a.Tarih);

            dt.Rows.Remove(r);
            _dt_yemeklistesi.AcceptChanges();
            string path = Application.StartupPath + "\\veriler\\yemeklistesi.xml";

            _dt_yemeklistesi.WriteXml(path);
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count < 1)
            {
                return;
            }
            DialogResult ra = MessageBox.Show("Yemek Silinsin mi", "Yemek Silme", MessageBoxButtons.YesNoCancel);

            if (ra == DialogResult.Yes)
            {
                DataRow r = dt.Rows[dataGridView1.SelectedRows[0].Index];
                YemekListesi.Sil(new YemekListesi()
                {
                    Tarih = r["Tarih"].ToString()
                });
                MessageBox.Show("Silindi");
            }
        }
        public static void Guncelle(YemekListesi a, string eskiplaka)
        {
            DataTable dt = GetAll();
            DataRow   r  = dt.Rows.Find(eskiplaka);

            r["Tarih"]        = a.Tarih;
            r["Ogun"]         = a.Ogun;
            r["a1"]           = a.a1;
            r["a2"]           = a.a2;
            r["a3"]           = a.a3;
            r["a4"]           = a.a4;
            r["a5"]           = a.a5;
            r["a6"]           = a.a6;
            r["a7"]           = a.a7;
            r["ToplamKalori"] = a.ToplamKalori;
            _dt_yemeklistesi.AcceptChanges();
            string path = Application.StartupPath + "\\veriler\\yemeklistesi.xml";

            _dt_yemeklistesi.WriteXml(path);
        }
 void VerileriYukle()
 {
     dt = YemekListesi.GetAll();
     dataGridView1.DataSource = dt;
 }