private void btnDDelete_Click(object sender, EventArgs e) { if (detailId.Text == "") { MessageBox.Show("Anda harus memilih data dulu"); } else { int myId = int.Parse(detailId.Text.ToString()); tblDetail deleteDetail = (from x in de.tblDetails where x.DetailId == myId select x).FirstOrDefault(); DialogResult result = MessageBox.Show("Apa Anda yakin ingin delete data?", "Confirmation", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { if (detail_grid.RowCount == 1) { MessageBox.Show("Detail tidak bisa kosong"); return; } else { de.tblDetails.Remove(deleteDetail); clear_detail(); } } else { return; } de.SaveChanges(); update_detail(); } }
private void btnTDelete_Click(object sender, EventArgs e) { if (lblTransId.Text == "") { MessageBox.Show("Anda harus memilih data dulu"); } else { int myId = int.Parse(lblTransId.Text.ToString()); tblTransaction deleteTransaction = (from x in de.tblTransactions where x.TransactionId == myId select x).FirstOrDefault(); DialogResult result = MessageBox.Show("Apa Anda yakin ingin delete data?", "Confirmation", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { var query = (from x in de.tblDetails join y in de.tblTransactions on x.TransactionId equals y.TransactionId where x.TransactionId == myId select x).Count(); label1.Text = query.ToString(); for (int i = 0; i < query; i++) { tblDetail deleteRelatedDetail = (from x in de.tblDetails join y in de.tblTransactions on x.TransactionId equals y.TransactionId where x.TransactionId == myId select x).FirstOrDefault(); de.tblDetails.Remove(deleteRelatedDetail); de.SaveChanges(); } de.tblTransactions.Remove(deleteTransaction); clear_detail(); clear_transaction(); } else { return; } de.SaveChanges(); update_transaction(); update_sum(); } }
private void btnDSubmit_Click(object sender, EventArgs e) { //====================================== if insert detail ============================================ if (_dInsert) { input_detail(); if (isNamaBrg && isQty && isSprice) { //check klo transaction ud dbuat prtma kali if (detail_grid.RowCount == 0) { if (radLunas.Checked == true) { tblTransaction newTransaction = new tblTransaction { ShopId = currentId, NotaNumber = txtNotaNum.Text.ToUpper(), Discount = discount, Date = date, Information = rtxtKeterangan.Text.ToUpper(), Status = "LUNAS", PaidDate = paidDate }; de.tblTransactions.Add(newTransaction); } else { tblTransaction newTransaction = new tblTransaction { ShopId = currentId, NotaNumber = txtNotaNum.Text.ToUpper(), Discount = discount, Date = date, Information = rtxtKeterangan.Text.ToUpper(), Status = "BELUM LUNAS" }; de.tblTransactions.Add(newTransaction); } de.SaveChanges(); } //get latest id var query = (from x in de.tblTransactions orderby x.TransactionId descending select x).FirstOrDefault(); lblTransId.Text = query.TransactionId.ToString(); tblDetail newDetail = new tblDetail { TransactionId = int.Parse(query.TransactionId.ToString()), ProductName = txtNamaBarang.Text.ToUpper(), Quantity = int.Parse(txtQuantity.Text), SellPrice = int.Parse(txtHrgaJual.Text) }; de.tblDetails.Add(newDetail); MessageBox.Show("Success input detail baru"); } else { return; } } //====================================== if update detail ============================================ else if (_dUpdate) { int myId = int.Parse(detailId.Text.ToString()); tblDetail updateDetail = (from x in de.tblDetails where x.DetailId == myId select x).FirstOrDefault(); input_detail(); if (isNamaBrg && isQty && isSprice) { updateDetail.ProductName = txtNamaBarang.Text.ToUpper(); updateDetail.Quantity = int.Parse(txtQuantity.Text); updateDetail.SellPrice = int.Parse(txtHrgaJual.Text); //updateDetail.BuyPrice = int.Parse(txtHrgaBeli.Text); MessageBox.Show("Success update data"); } else { return; } } de.SaveChanges(); clear_detail(); update_detail(); update_transaction(); _dInsert = _dUpdate = false; //mode modeTransaction(false); modeDetail(true); transaction_grid.Enabled = false; detail_grid.Enabled = true; }