private void btnSimpan_Click(object sender, EventArgs e) { if (WithErrors()) { val.validateTextBox(txtNamaPengguna, errorProvider1, "Nama pengguna harus diisi."); val.validateTextBox(txtSandi, errorProvider1, "Sandi harus diisi."); val.validateTextBox(txtNamaLengkap, errorProvider1, "Nama lengkap harus diisi."); val.validateTextBox(txtAlamat, errorProvider1, "Alamat harus diisi."); val.validateTextBox(txtTelp, errorProvider1, "Telepon harus diisi."); val.validateComboBox(cbPeran,errorProvider1,"Peran harus dipilih."); return; } try { if (Convert.ToInt32(txtId.Text) == 0) { var user = new REF_PENGGUNA(); user.NAMA_PENGGUNA = txtNamaPengguna.Text; user.SANDI = Encryption.Encrypt(txtSandi.Text, true); user.NAMA_LENGKAP = txtNamaLengkap.Text; user.ALAMAT = txtAlamat.Text; user.TELP = txtTelp.Text; user.ID_PERAN = Convert.ToInt32(cbPeran.SelectedValue); context.REF_PENGGUNAs.InsertOnSubmit(user); } else { var query = from a in context.REF_PENGGUNAs where a.ID_PENGGUNA == Convert.ToInt32(txtId.Text) select a; foreach (var a in query) { a.NAMA_PENGGUNA = txtNamaPengguna.Text; a.SANDI = Encryption.Encrypt(txtSandi.Text, true); a.NAMA_LENGKAP = txtNamaLengkap.Text; a.ALAMAT = txtAlamat.Text; a.TELP = txtTelp.Text; a.ID_PERAN = Convert.ToInt32(cbPeran.SelectedValue); } } context.SubmitChanges(); Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
partial void DeleteREF_PENGGUNA(REF_PENGGUNA instance);
partial void InsertREF_PENGGUNA(REF_PENGGUNA instance);
partial void UpdateREF_PENGGUNA(REF_PENGGUNA instance);
private void detach_REF_PENGGUNAs(REF_PENGGUNA entity) { this.SendPropertyChanging(); entity.REF_PERAN = null; }