Exemple #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                switch (wybor1)
                {
                case 1:     //dodawanie

                    Gracz gracz = new Gracz
                    {
                        Nazwa = textBox2.Text,
                        Haslo = textBox3.Text,
                        Email = textBox4.Text
                    };

                    dc.Graczs.InsertOnSubmit(gracz);
                    dc.SubmitChanges();
                    break;

                case 2:     //zmiana
                    int id     = Int32.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                    var gracz2 = from n in dc.GetTable <Gracz>()
                                 where n.GraczID == id
                                 select n;
                    gracz2.First().Haslo   = textBox3.Text;
                    gracz2.First().Nazwa   = textBox2.Text;
                    gracz2.First().Email   = textBox4.Text;
                    gracz2.First().GraczID = Int32.Parse(textBox1.Text.ToString());
                    dc.SubmitChanges();

                    break;

                case 3:     //usuwanie
                    int GraczID = Int32.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                    var gamer   = from n in dc.GetTable <Gracz>()
                                  where n.GraczID == GraczID
                                  select n;
                    dc.Graczs.DeleteOnSubmit(gamer.First());
                    dc.SubmitChanges();

                    break;

                default:
                    MessageBox.Show("Nie wybrano operacji");
                    break;
                }
                odswiez();
            }
            catch (Exception f)
            {
                if (wybor1 == 1)
                {
                    foreach (var n in dc.GetChangeSet().Inserts)
                    {
                        dc.GetTable(n.GetType()).DeleteOnSubmit(n);
                    }
                }
                if (wybor1 == 3)
                {
                    foreach (var n in dc.GetChangeSet().Deletes)
                    {
                        dc.GetTable(n.GetType()).InsertOnSubmit(n);
                    }
                }
                MessageBox.Show(f.Message);
            }
        }
 partial void UpdateGracz(Gracz instance);
 partial void DeleteGracz(Gracz instance);
 partial void InsertGracz(Gracz instance);