示例#1
0
        private void btnTambah_Click(object sender, EventArgs e)
        {
            tbDetailRetur TDetailRetur = new tbDetailRetur();


            if (Status == "Baru")
            {
                TDetailRetur.ID_Barang = dgvDetailPembelianRetur.SelectedRows[0].Cells["ID_Barang"].Value.ToString();
                TDetailRetur.ID_Retur  = IDRetur;

                int jumlah_beli = (int)dgvDetailPembelianRetur.SelectedRows[0].Cells["Jumlah_Beli"].Value;
                if (nudJumlahRetur.Value > jumlah_beli)
                {
                    MessageBox.Show("Jumlah yang akan diretur melebihi jumlah yang dibeli.", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    TDetailRetur.Jumlah_Retur = (int)nudJumlahRetur.Value;

                    tbRetur TRetur = new tbRetur();
                    TRetur.ID_Retur      = IDRetur;
                    TRetur.No_Faktur     = NoFaktur;
                    TRetur.Tanggal_Retur = dtpTanggalRetur.Value;

                    db.tbReturs.InsertOnSubmit(TRetur);
                    db.SubmitChanges();

                    db.tbDetailReturs.InsertOnSubmit(TDetailRetur);
                    db.SubmitChanges();
                }
            }
            else
            {
                TDetailRetur.ID_Barang = dgvDetailPembelianRetur.SelectedRows[0].Cells["ID_Barang"].Value.ToString();
                TDetailRetur.ID_Retur  = IDRetur;

                int jumlah_beli = (int)dgvDetailPembelianRetur.SelectedRows[0].Cells["Jumlah_Beli"].Value;
                if (nudJumlahRetur.Value > jumlah_beli)
                {
                    MessageBox.Show("Jumlah yang akan diretur melebihi jumlah yang dibeli.", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    TDetailRetur.Jumlah_Retur = (int)nudJumlahRetur.Value;

                    tbRetur TRetur = new tbRetur();
                    TRetur.ID_Retur      = IDRetur;
                    TRetur.No_Faktur     = NoFaktur;
                    TRetur.Tanggal_Retur = dtpTanggalRetur.Value;
                    db.SubmitChanges();

                    db.tbDetailReturs.InsertOnSubmit(TDetailRetur);
                    db.SubmitChanges();
                }
            }

            dgvDetailRetur.DataSource = "";
            dgvDetailRetur.DataSource = db.tbDetailReturs.Where(x => x.ID_Retur == IDRetur).Select(x => new { ID_Barang = x.ID_Barang, Jumlah_Retur = x.Jumlah_Retur, ID_Retur = x.ID_Retur }).ToList();
        }
示例#2
0
        private void btnHapus_Click(object sender, EventArgs e)
        {
            if (dgvDetailRetur.SelectedRows.Count > 0)
            {
                string IDRetur = dgvDetailRetur.SelectedRows[0].Cells["ID_Retur"].Value.ToString();

                tbDetailRetur dataDetailRetur = db.tbDetailReturs.Where(x => x.ID_Retur == IDRetur).FirstOrDefault();
                if (dataDetailRetur != null)
                {
                    db.tbDetailReturs.DeleteOnSubmit(dataDetailRetur);
                    db.SubmitChanges();
                    MessageBox.Show("Data Detail Retur berhasil dihapus.", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    dgvDetailRetur.DataSource = db.tbDetailReturs.Where(x => x.ID_Retur == IDRetur).Select(x => new { ID_Barang = x.ID_Barang, Jumlah_Retur = x.Jumlah_Retur, ID_Retur = x.ID_Retur }).ToList();
                }
            }
        }