public void ActualitzarRegistre() { using (Coders5GEntities CE = new Coders5GEntities()) { Users Usuari = new Users { CodeUser = SWCodeUser.Text, UserName = SWNomUsuari.Text, Login = SWLogin.Text, Password = SWPassword.Text, Photo = SWPhoto.Text, idUserCategory = int.Parse(SWCategoriaTB.Text), idPlanet = int.Parse(SWPlanetsTB.Text), idUserRank = int.Parse(SWUserRankTB.Text), idSpecie = int.Parse(SWEspeciesTB.Text) }; CE.Entry(Usuari).State = EntityState.Modified; try { CE.SaveChanges(); } catch (Exception) { } } }
public void InsertarRegistre() { if (SWPassword.Text.Trim() == "") { SWPassword.Text = E.EncriptarContrasenya(SWPassword.Text); } using (Coders5GEntities CE = new Coders5GEntities()) { Users nouUsuari = new Users { CodeUser = SWCodeUser.Text, UserName = SWNomUsuari.Text, Login = SWLogin.Text, Password = SWPassword.Text, Photo = SWPhoto.Text, idUserCategory = int.Parse(SWCategoriaTB.Text), idPlanet = int.Parse(SWPlanetsTB.Text), idUserRank = int.Parse(SWUserRankTB.Text), idSpecie = int.Parse(SWEspeciesTB.Text) }; CE.Users.Add(nouUsuari); try { CE.SaveChanges(); } catch (Exception) { } } }
private void DGV_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete) { try { Users u = CE.Users.First(x => x.CodeUser == SWCodeUser.Text); CE.Users.Remove(u); CE.SaveChanges(); } catch (Exception) { } CarregarDades(); BindejarDades(); } }