public int getData(petModel pet) { str = "select pet_nama as 'Nama Pet', pet_jenis as 'Jenis Pet', pet_info as 'Pet Info' from pet where id_pet = @a"; using (MySqlCommand cmd = new MySqlCommand(str, conn)) { cmd.Parameters.AddWithValue("@a", pet.IdPet); var reader = cmd.ExecuteReader(); reader.Read(); if (reader.HasRows) { pet.Petnama = reader["Nama Pet"].ToString(); pet.PetInfo = reader["Pet Info"].ToString(); pet.PetJenis = reader["Jenis Pet"].ToString(); reader.Close(); return(1); } else { reader.Close(); return(0); } } }
public int getInfo(petModel pet) { count(pet); int hit = Int32.Parse(hitung); str = "select * from pet where id_user = @1"; using (MySqlCommand cmd = new MySqlCommand(str, conn)) { cmd.Parameters.AddWithValue("@1", pet.IdUser); var read = cmd.ExecuteReader(); read.Read(); if (read.HasRows) { pet.IdPet = read["id_pet"].ToString(); pet.Petnama = read["pet_nama"].ToString(); pet.PetJenis = read["pet_jenis"].ToString(); pet.PetInfo = read["pet_info"].ToString(); getPet(pet); read.Close(); return(1); } else { read.Close(); return(0); } } }
private petModel Mapping(MySqlDataReader read, petModel pet) { pet.Petnama = read["pet_nama"] is DBNull ? string.Empty : read["pet_nama"].ToString(); return(pet); }
private void saveData() { petModel pet = new petModel(); TextRange text = new TextRange( rtb_info.Document.ContentStart, rtb_info.Document.ContentEnd ); pet.IdPet = ConfigurationManager.AppSettings["petid"]; pet.Petnama = tb_nama.Text; pet.PetJenis = cb_jenis.Text; pet.PetInfo = text.Text; result = petDAO.update(pet); if (result > 0) { MessageBox.Show("Berhasil menyimpan data baru!"); clear(); Uri uri = new Uri("View/petListView.xaml", UriKind.Relative); this.NavigationService.Navigate(uri); } else { MessageBox.Show("Gagal menyimpan data!"); clear(); Uri uri = new Uri("View/petListView.xaml", UriKind.Relative); this.NavigationService.Navigate(uri); } }
private void bt_tambah_Copy_Click(object sender, RoutedEventArgs e) { petModel pet = new petModel(); TextRange text = new TextRange( rtb_info.Document.ContentStart, rtb_info.Document.ContentEnd ); pet.Petnama = tb_nama.Text; pet.PetJenis = cb_jenis.Text; pet.PetInfo = text.Text; pet.IdUser = ConfigurationManager.AppSettings["userid"]; result = petDAO.save(pet); if (result > 0) { MessageBox.Show("Berhasil menambahkan pet baru!"); clear(); } else { MessageBox.Show("Gagal menambahkan pet baru!"); clear(); } }
private void filldg() { petModel pet = new petModel(); pet.IdUser = ConfigurationManager.AppSettings["userid"]; DataSet ds = new DataSet(); ds = petDAO.datamap(pet); dataGrid.DataContext = ds; }
public int delete(petModel pet) { str = "delete from pet where id_pet = @1"; using (MySqlCommand cmd = new MySqlCommand(str, conn)) { cmd.Parameters.AddWithValue("@1", pet.IdPet); return(cmd.ExecuteNonQuery()); } }
public ObservableCollection <petModel> getPet(petModel petModel) { var pet = new ObservableCollection <petModel>(); pet.Add(new petModel() { Petnama = petModel.Petnama, PetJenis = petModel.PetJenis, PetInfo = petModel.PetInfo, IdPet = petModel.IdPet, IdUser = petModel.IdUser }); return(pet); }
private void b1_Click(object sender, RoutedEventArgs e) { petModel pet = dataGrid.SelectedItem as petModel; MessageBoxResult msresult = System.Windows.MessageBox.Show("Akan mengedit " + pet.Petnama, "Hapus data", System.Windows.MessageBoxButton.YesNo); if (msresult == MessageBoxResult.Yes) { ConfigurationManager.AppSettings["petid"] = pet.IdPet; Uri uri = new Uri("View/petEditView.xaml", UriKind.Relative); this.NavigationService.Navigate(uri); } }
public int update(petModel pet) { str = "update pet set pet_nama = @1, pet_info = @2, pet_jenis = @3 where id_pet = @4"; using (MySqlCommand cmd = new MySqlCommand(str, conn)) { cmd.Parameters.AddWithValue("@1", pet.Petnama); cmd.Parameters.AddWithValue("@2", pet.PetInfo); cmd.Parameters.AddWithValue("@3", pet.PetJenis); cmd.Parameters.AddWithValue("@4", pet.IdPet); return(cmd.ExecuteNonQuery()); } }
public int save(petModel pet) { str = "insert into pet(pet_nama, pet_info, pet_jenis, id_user) values (@1, @2, @3, @4)"; using (MySqlCommand cmd = new MySqlCommand(str, conn)) { cmd.Parameters.AddWithValue("@1", pet.Petnama); cmd.Parameters.AddWithValue("@2", pet.PetInfo); cmd.Parameters.AddWithValue("@3", pet.PetJenis); cmd.Parameters.AddWithValue("@4", pet.IdUser); return(cmd.ExecuteNonQuery()); } }
private void loadData() { petModel pet = new petModel(); pet.IdPet = ConfigurationManager.AppSettings["petid"]; result = petDAO.getData(pet); if (result == 1) { tb_nama.Text = pet.Petnama; cb_jenis.SelectedItem = pet.PetJenis; rtb_info.Document.Blocks.Add(new Paragraph(new Run(pet.PetInfo))); } }
public DataSet datamap(petModel petModel) { str = "select pet_nama as 'Nama Pet' from pet where id_user = @a"; using (MySqlCommand cmd = new MySqlCommand(str, conn)) { cmd.Parameters.AddWithValue("@a", petModel.IdUser); DataTable table = new DataTable(); MySqlDataAdapter da = new MySqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds, "loadData"); return(ds); } }
private void b_del_Click(object sender, RoutedEventArgs e) { petModel pet = dataGrid.SelectedItem as petModel; MessageBoxResult msresult = System.Windows.MessageBox.Show("Akan menghapus " + pet.Petnama, "Hapus data", System.Windows.MessageBoxButton.YesNo); if (msresult == MessageBoxResult.Yes) { result = petDAO.delete(pet); if (result > 0) { MessageBox.Show("Berhasil menghapus data!"); filltolst(); } } }
public List <petModel> GetAll(petModel petmodel) { List <petModel> petlist = new List <petModel>(); str = "select pet_nama from pet where id_user = @1"; using (MySqlCommand cmd = new MySqlCommand(str, conn)) { cmd.Parameters.AddWithValue("@1", petmodel.IdUser); using (MySqlDataReader read = cmd.ExecuteReader()) { while (read.Read()) { petlist.Add(Mapping(read, petmodel)); } } } return(petlist); }
public void filltolst() { petModel pet = new petModel(); /*DataSet ds = new DataSet(); * ds = petDAO.datamap(pet); * dataGrid.DataContext = ds;*/ pet.IdUser = ConfigurationManager.AppSettings["userid"]; result = petDAO.getInfo(pet); if (result == 1) { dataGrid.ItemsSource = petDAO.getPet(pet); } else { MessageBox.Show("Gagal menampilkan data!"); } }
public int count(petModel pet) { str = "select count(*) as jumlah from pet where id_user = @1"; using (MySqlCommand cmd = new MySqlCommand(str, conn)) { cmd.Parameters.AddWithValue("@1", pet.IdUser); var read = cmd.ExecuteReader(); read.Read(); if (read.HasRows) { hitung = read["jumlah"].ToString(); read.Close(); return(1); } else { read.Close(); return(0); } } }