private void simpan_button1_Click(object sender, EventArgs e) { modelItem.stok = Convert.ToInt32(tambah_numericUpDown1.Value); db.Entry(modelItem).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Stok berhasil ditambahkan sejumlah " + tambah_numericUpDown1.Value + " menjadi " + modelItem.stok); Clear(); PopulateDataGridView(); }
private void delete_button1_Click(object sender, EventArgs e) { if (MessageBox.Show("Anda yakin ingin menghapus data ini?", "EF CRUD Operation", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (dibumilaptopEntities db = new dibumilaptopEntities()) { var entry = db.Entry(model); if (entry.State == System.Data.Entity.EntityState.Detached) { db.items.Attach(model); } db.items.Remove(model); db.SaveChanges(); PopulateDataGridView(); Clear(); MessageBox.Show("Berhasil Menghapus."); } } }
private void button1_Click(object sender, EventArgs e) { modelTransaksi.item_id = modelItem.id; modelTransaksi.tanggal_transaksi = tanggal_transaksi_dateTimePicker1.Value; modelTransaksi.qty = Convert.ToInt32(qty_numericUpDown1.Value); modelTransaksi.harga_satuan_temp = Convert.ToInt32(harga_satuan_textBox1.Text); modelTransaksi.total_harga = Convert.ToInt32(harga_total_textbox.Text); modelTransaksi.deskripsi = keterangan_richTextBox1.Text; using (dibumilaptopEntities db = new dibumilaptopEntities()) { db.transaksis.Add(modelTransaksi); modelItem.stok = modelItem.stok - modelTransaksi.qty; db.Entry(modelItem).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Transaksi Berhasil Ditambahkan"); Clear(); } }
private void simpan_button1_Click(object sender, EventArgs e) { model.merek_id = Convert.ToInt64(merek_comboBox1.SelectedValue); model.tipe = tipe_textBox1.Text; model.deskripsi = deskripsi_richTextBox1.Text; model.processor = processor_textBox2.Text; model.ram = ram_textBox3.Text; model.penyimpanan = penyimpanan_textBox4.Text; model.ukuran_layar = ukuran_layar_textBox5.Text; model.stok = Convert.ToInt32(stok_numericUpDown1.Value); model.gudang_id = Convert.ToInt64(lokasi_gudang_comboBox2.SelectedValue); model.kondisi_id = Convert.ToInt64(kondisi_comboBox3.SelectedValue); model.tanggal_ditambahkan = tanggal_ditambahkan_dateTimePicker1.Value; model.garansi_id = Convert.ToInt64(jenis_garansi_comboBox4.SelectedValue); model.garansi_expired = garansi_expired_dateTimePicker2.Value; model.harga = Convert.ToInt64(harga_numericUpDown1.Value); using (dibumilaptopEntities db = new dibumilaptopEntities()) { if (model.id == 0) { db.items.Add(model); MessageBox.Show("Data berhasil ditambahkan"); } else { db.Entry(model).State = System.Data.Entity.EntityState.Modified; MessageBox.Show("Data berhasil diupdate"); } db.SaveChanges(); } Clear(); PopulateDataGridView(); }