private void LoadDate() { CustomerEntities db = new CustomerEntities(); customers = db.Customers; foreach (var item in customers) { //Debug.WriteLine(item.Name + " " + item.Surname); dGv_dane_z_bazy.Rows.Add(item.Name, item.Surname); } }
private void btn_SaveChanges_Click(object sender, EventArgs e) { CustomerEntities db = new CustomerEntities(); if (log_add) { Customers cst = new Customers(); cst.Name = txB_Name.Text; cst.Surname = txB_Surname.Text; cst.Country = txB_Country.Text; cst.City = txB_City.Text; cst.Birthday = dTP_Birthday.Value; db.Customers.Add(cst); log_add = false; btn_SaveChanges.Text = "Zapisz zmiany"; cBx_deleteCustomer.Visible = true; } else { Customers cust = customers.ToList()[curRow]; var customer = db.Customers.Where(s => s.ID == cust.ID).First(); if (cBx_deleteCustomer.Checked == false) { customer.Name = txB_Name.Text; customer.Surname = txB_Surname.Text; customer.Country = txB_Country.Text; customer.City = txB_City.Text; customer.Birthday = dTP_Birthday.Value; } else { db.Customers.Remove(customer); } } db.SaveChanges(); RestartDate(); }