예제 #1
0
 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();
     }
 }
예제 #2
0
        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;
        }
예제 #3
0
        private void btnTSubmit_Click(object sender, EventArgs e)
        {
            //=============================== if insert ====================================
            if (_tInsert)
            {
                input_transaction();

                if (isNotaNum && isStatus && isDiscount)
                {
                    if (detail_grid.RowCount == 0)
                    {
                        MessageBox.Show("Detail tidak bisa kosong");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Success input transaksi baru");
                    }
                }
                else
                {
                    return;
                }
            }
            //=============================== if update ====================================
            else if (_tUpdate)
            {
                int            myId = int.Parse(lblTransId.Text.ToString());
                tblTransaction updateTransaction = (from x in de.tblTransactions
                                                    where x.TransactionId == myId
                                                    select x).FirstOrDefault();

                input_transaction();
                if (isNotaNum && isStatus && isDiscount)
                {
                    if (detail_grid.RowCount == 0)
                    {
                        MessageBox.Show("Detail tidak bisa kosong");
                        return;
                    }
                    else
                    {
                        //change data transaction in database
                        updateTransaction.NotaNumber = txtNotaNum.Text.ToUpper();
                        updateTransaction.Discount   = discount;
                        updateTransaction.Date       = date;
                        if (radLunas.Checked == true)
                        {
                            updateTransaction.Status   = "LUNAS";
                            updateTransaction.PaidDate = paidDate;
                        }
                        else
                        {
                            updateTransaction.Status   = "BELUM LUNAS";
                            updateTransaction.PaidDate = null;
                        }
                        updateTransaction.Information = rtxtKeterangan.Text.ToUpper();

                        MessageBox.Show("Success update data");
                    }
                }
                else
                {
                    return;
                }
            }

            de.SaveChanges();
            clear_detail();
            update_transaction();
            update_sum();
            _tInsert = _tUpdate = false;
            modeDetail(true);
            modeTransaction(true);
            btnDInsert.Enabled = false;
            btnDUpdate.Enabled = false;
            btnDDelete.Enabled = false;
        }