private void btnSimpan_Click(object sender, EventArgs e) { try { if (Helpers.GetValidate(panel1) == true) { if (statusDisplay == 1) { if (Rekanan.InsertData(SetData(1)) == true) { Helpers.MsgBoxSave(); } } else if (statusDisplay == 2) { if (Rekanan.UpdateDate(SetData(2)) == true) { Helpers.MsgBoxSave(); } } PreCreateDisplay(); } } catch (Exception ex) { Helpers.MsgBoxError(ex.Message); } }
public static Boolean InsertData(Rekanan rekanan) { string sql = "Insert into Rekanan values('" + rekanan.IdRekanan + "','" + rekanan.TipeRekanan + "','" + rekanan.NamaRekanan + "'" + ",'" + rekanan.Alamat + "','" + rekanan.NoTlp + "','" + rekanan.IsActive + "')"; try { DataAccess.ExecuteNonQuery(sql); return(true); } catch (Exception ex) { return(false); throw ex; } }
int statusDisplay; //1 for create,2 for edit Rekanan SetData(byte status) { //1 for create,2 for edit Rekanan myData = new Rekanan(); switch (status) { case (1): { myData.IdRekanan = Rekanan.GenerateId(); myData.TipeRekanan = cmbTipe.Text == "Supplier" ? Convert.ToChar("S") : Convert.ToChar("P"); myData.NamaRekanan = txtNama.Text; myData.Alamat = txtAlamat.Text; myData.NoTlp = txtTlp.Text; if (rdAktif.Checked == true) { myData.IsActive = true; } if (rdTdkAktif.Checked == true) { myData.IsActive = false; } } break; case (2): { myData.IdRekanan = myID; myData.TipeRekanan = cmbTipe.Text == "Supplier" ? Convert.ToChar("S") : Convert.ToChar("P"); myData.NamaRekanan = txtNama.Text; myData.Alamat = txtAlamat.Text; myData.NoTlp = txtTlp.Text; if (rdAktif.Checked == true) { myData.IsActive = true; } if (rdTdkAktif.Checked == true) { myData.IsActive = false; } } break; } return(myData); }
public static Boolean UpdateDate(Rekanan rekanan) { string sql = "Update Rekanan set TipeRekanan = '" + rekanan.TipeRekanan + "',NamaRekanan = '" + rekanan.NamaRekanan + "'" + ",Alamat = '" + rekanan.Alamat + "',NoTlp = '" + rekanan.NoTlp + "',IsActive = " + rekanan.IsActive + " Where IdRekanan= " + rekanan.IdRekanan + ""; try { DataAccess.ExecuteNonQuery(sql); return(true); } catch (Exception ex) { return(false); throw ex; } }
void ListDataBySearch() { dgv.DataSource = Rekanan.GetListRekananByNama(txtCari.Text, cmbCari.Text); dgv.ReadOnly = true; HeaderGrid(); }
void ListData() { dgv.DataSource = Rekanan.GetListRekanan(1); dgv.ReadOnly = true; HeaderGrid(); }