private void fillTextBox(Ukuran_Pakaian ukp) { txtNIK.Text = ukp.NIK; txtUkuranBaju.Text = ukp.Ukuran_Baju; txtUkuranCelana.Text = ukp.Ukuran_Celana; txtUkuranSepatu.Text = ukp.Ukuran_Sepatu; txtUkuranBaju.Focus(); }
private Ukuran_Pakaian MappingRowToObject(NpgsqlDataReader dtr) { Ukuran_Pakaian upk = new Ukuran_Pakaian(); upk.NIK = dtr["nik"] is DBNull ? string.Empty : dtr["nik"].ToString(); upk.Ukuran_Baju = dtr["ukuran_baju"] is DBNull ? string.Empty : dtr["ukuran_baju"].ToString(); upk.Ukuran_Celana = dtr["ukuran_celana"] is DBNull ? string.Empty : dtr["ukuran_celana"].ToString(); upk.Ukuran_Sepatu = dtr["ukuran_sepatu"] is DBNull ? string.Empty : dtr["ukuran_sepatu"].ToString(); return(upk); }
public bool cekRecord(string nik) { Ukuran_Pakaian upk = GetByNIK(nik); if (upk != null) { return(true); } else { return(false); } }
//Method CRUD. Insert, Update, Delete, Select public int Save(Ukuran_Pakaian upk) { strSql = "INSERT INTO ukuran_pakaian (nik, ukuran_baju, ukuran_celana, ukuran_sepatu) VALUES (@1, @2, @3, @4)"; using (NpgsqlCommand cmd = new NpgsqlCommand(strSql, conn)) { cmd.Parameters.AddWithValue("@1", upk.NIK); cmd.Parameters.AddWithValue("@2", upk.Ukuran_Baju); cmd.Parameters.AddWithValue("@3", upk.Ukuran_Celana); cmd.Parameters.AddWithValue("@4", upk.Ukuran_Sepatu); return(cmd.ExecuteNonQuery()); } }
public int Update(Ukuran_Pakaian upk) { strSql = "UPDATE ukuran_pakaian SET ukuran_baju = @1, ukuran_celana = @2, ukuran_sepatu = @3 WHERE nik = @4"; using (NpgsqlCommand cmd = new NpgsqlCommand(strSql, conn)) { cmd.Parameters.AddWithValue("@1", upk.Ukuran_Baju); cmd.Parameters.AddWithValue("@2", upk.Ukuran_Celana); cmd.Parameters.AddWithValue("@3", upk.Ukuran_Sepatu); cmd.Parameters.AddWithValue("@4", upk.NIK); return(cmd.ExecuteNonQuery()); } }
private void loadTxtBox() { Ukuran_Pakaian ukp = ukpDAO.GetByNIK(txtNIK.Text); if (ukp != null) { txtUkuranBaju.Text = ukp.Ukuran_Baju; txtUkuranCelana.Text = ukp.Ukuran_Celana; txtUkuranSepatu.Text = ukp.Ukuran_Sepatu; } else { txtUkuranBaju.Clear(); txtUkuranCelana.Clear(); txtUkuranSepatu.Clear(); } }
public Ukuran_Pakaian GetByNIK(string nik) { Ukuran_Pakaian upk = null; strSql = "SELECT * FROM ukuran_pakaian WHERE nik = @1"; using (NpgsqlCommand cmd = new NpgsqlCommand(strSql, conn)) { cmd.Parameters.AddWithValue("@1", nik); using (NpgsqlDataReader dtr = cmd.ExecuteReader()) { if (dtr.Read()) { upk = MappingRowToObject(dtr); } } } return(upk); }
private void btnSimpan_Click(object sender, EventArgs e) { try { if (txtUkuranBaju.Text == "" || txtUkuranCelana.Text == "" || txtUkuranSepatu.Text == "") { lblMsgString("Seluruh Field harus diisi !", Color.Yellow); } else { Ukuran_Pakaian ukp = new Ukuran_Pakaian(); ukp.NIK = txtNIK.Text; ukp.Ukuran_Baju = txtUkuranBaju.Text; ukp.Ukuran_Celana = txtUkuranCelana.Text; ukp.Ukuran_Sepatu = txtUkuranSepatu.Text; object[] data = new object[] { ukp.Ukuran_Baju, ukp.Ukuran_Celana, ukp.Ukuran_Sepatu }; //Cek Record Ukuran Pakaian apakah sudah ada atau belum, guna menentukan operasi //Update atau Save resultBool = ukpDAO.cekRecord(txtNIK.Text); if (resultBool == false) //Data Level masih kosong jadi bisa disimpan { result = ukpDAO.Save(ukp); if (result > 0) { lblMsgString("Data berhasil disimpan.", Color.Green); fillTextBox(ukp); fillTextBoxMainForm(data, 0, init); } else { lblMsgString("Data gagal disimpan.", Color.Red); } } else //Meng-update data level { if (msgBoxWarning("Anda yakin akan mengubah data Ukuran Karyawan yang memiliki NIK = " + txtNIK.Text + " ?") == true) { result = ukpDAO.Update(ukp); if (result > 0) { lblMsgString("Data berhasil diubah.", Color.Green); fillTextBox(ukp); fillTextBoxMainForm(data, 0, init); } else { lblMsgString("Data gagal diubah.", Color.Red); } } else { //clearTextBox(); } } } } catch (Exception ex) { errorDBox(ex.Message.ToString(), "btnSimpan_Click"); } }