Example #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (Equals(txtCNP.Text, "") || !OnlyNumbers() || txtCNP.Text.Length != 13)
     {
         MessageBox.Show("Introduceti un CNP valid");
     }
     else
     {
         using (UserEntities context = new UserEntities())
         {
             try {
                 tblUser2 obj = context.tblUser2.FirstOrDefault(r => r.CNP == txtCNP.Text);
                 if (obj != null)
                 {
                     context.tblUser2.Remove(obj);
                     context.SaveChanges();
                     MessageBox.Show("Stergere realizata cu succes");
                     Clear();
                 }
                 else
                 {
                     MessageBox.Show("Nu exista persoana cauta");
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
 }
Example #2
0
 private void Button1_Click(object sender, EventArgs e)
 {
     if (Equals(txtCNP.Text, "") || !OnlyNumbers() || txtCNP.Text.Length != 13)
     {
         MessageBox.Show("Introduceti un CNP valid");
     }
     else
     if (Equals(txtNume.Text.Trim(), "") && Equals(txtPrenume.Text.Trim(), "") && Equals(txtAdresa.Text.Trim(), ""))
     {
         MessageBox.Show("Trebuie modificat cel putin un camp");
     }
     else
     {
         using (UserEntities context = new UserEntities())
         {
             try
             {
                 tblUser2 obj = context.tblUser2.FirstOrDefault(r => r.CNP == txtCNP.Text);
                 if (obj != null)
                 {
                     if (!Equals(txtNume.Text.Trim(), ""))
                     {
                         obj.Nume = txtNume.Text.Trim();
                     }
                     if (!Equals(txtPrenume.Text.Trim(), ""))
                     {
                         obj.Prenume = txtPrenume.Text.Trim();
                     }
                     if (!Equals(txtAdresa.Text.Trim(), ""))
                     {
                         obj.Adresa = txtAdresa.Text.Trim();
                     }
                     context.SaveChanges();
                     MessageBox.Show("Editare realizata cu succes");
                     Clear();
                 }
                 else
                 {
                     MessageBox.Show("Persoana cautata nu exista");
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
 }
Example #3
0
 private void btnAdauga_Click(object sender, EventArgs e)
 {
     if (Equals(txtNume.Text.Trim(), "") || Equals(txtPrenume.Text.Trim(), "") || Equals(txtAdresa.Text.Trim(), "") || Equals(txtCNP.Text, ""))
     {
         MessageBox.Show("Te rog completeaza campurile obligatorii");
     }
     else
     if (txtCNP.Text.Length != 13)
     {
         MessageBox.Show("CNP-ul trebuie sa contina 13 cifre");
     }
     else
     if (!OnlyNumbers())
     {
         MessageBox.Show("CNP-ul contine doar cifre");
     }
     else
     if (Exists())
     {
         MessageBox.Show("CNP-ul introdus exista deja");
     }
     else
     {
         using (UserEntities context = new UserEntities())//UserEntities e clasa care reprezinta baza de data(kind of)
         {
             try
             {
                 tblUser2 obj = new tblUser2
                 {
                     Nume    = txtNume.Text.Trim(),
                     Prenume = txtPrenume.Text.Trim(),
                     CNP     = txtCNP.Text,
                     Adresa  = txtAdresa.Text.Trim()
                 };
                 context.tblUser2.Add(obj);
                 context.SaveChanges();
                 MessageBox.Show("Adaugare realizata cu succes");
                 Clear();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
 }