示例#1
0
 public Boolean Inserted(Bill bills)
 {
     try
     {
         contextDB.Bills.Add(bills);
         contextDB.SaveChanges();
         return true;
     }
     catch (Exception ex) { return false; }
 }
示例#2
0
 public void Updated(Bill bills)
 {
     try
     {
         Bill bill = contextDB.Bills.Where(bil => bil.BillId == bills.BillId).FirstOrDefault();
         bill.Total = bills.Total;
         DeletedBillsDetail(bill.BillDetails.ToList());
         bill.BillDetails = (List<BillDetail>)bills.BillDetails;
         contextDB.SaveChanges();
     }
     catch (Exception ex) { }
 }
示例#3
0
 public Boolean Deleted(Bill bills)
 {
     try
     {
         Bill bill = contextDB.Bills.Where(bil => bil.BillId == bills.BillId).FirstOrDefault();
         DeletedBillsDetail(bill.BillDetails.ToList());
         contextDB.Bills.Remove(bill);
         contextDB.SaveChanges();
         return true;
     }
     catch (Exception ex) { return false; }
 }
示例#4
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            List<BillDetail> lstBillDetail = new List<BillDetail>();
            for (int i = 0; i < gvProductsToBills.Rows.Count; i++)
            {
                BillDetail billDetail = new BillDetail()
                {
                    ProductId = int.Parse(gvProductsToBills.Rows[i].Cells["colID"].Value.ToString()),
                    Amounts = int.Parse(gvProductsToBills.Rows[i].Cells["colAmounts"].Value.ToString()),
                    RealPrice = float.Parse(gvProductsToBills.Rows[i].Cells["colRealPrice"].Value.ToString()),
                    Sum = float.Parse(gvProductsToBills.Rows[i].Cells["colTotal"].Value.ToString()),
                    BillDetailDescription = string.Empty
                };
                lstBillDetail.Add(billDetail);
            }

            Bill bills = new Bill()
            {
                BillId = int.Parse(gvBills.Rows[gvBills.CurrentCell.RowIndex].Cells["colBillsId"].Value.ToString()),
                CreatedDate = DateTime.Parse(gvBills.Rows[gvBills.CurrentCell.RowIndex].Cells["colBillsDate"].Value.ToString()),
                BillDescription = "",
                Total = SumTotal(),
                BillDetails = lstBillDetail
            };

            BLLBills bllBills = new BLLBills();
            bllBills.Updated(bills);
            MessageBox.Show("Update Successful", "Message");

            LoadGridBills();
            gvProductsToBills.Rows.Clear();
            lbTotal.Text = string.Empty;
            pictureBox1.Enabled = true;
            pictureBox2.Enabled = true;
            btnEdit.Enabled = false;
        }
示例#5
0
        private void gvBills_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex != -1)
            {
                pictureBox1.Enabled = false;
                pictureBox2.Enabled = false;
                btnEdit.Enabled = true;

                int billsID = int.Parse(gvBills.Rows[e.RowIndex].Cells["colBillsID"].Value.ToString());
                Bill bills = new Bill();
                BLLBills bllBills = new BLLBills();
                bills = bllBills.GetBillsById(billsID);

                if (gvBills.Columns[e.ColumnIndex].Name == "colBillsDeleted")
                {
                    if (MessageBox.Show("Are you sure to delete: " + gvBills.Rows[e.RowIndex].Cells["colBillsId"].Value.ToString(), "Message", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        bllBills.Deleted(bills);
                        LoadGridBills();
                        gvProductsToBills.Rows.Clear();
                        return;
                    }
                }

                gvProductsToBills.Rows.Clear();
                foreach (BillDetail billsDetail in bills.BillDetails)
                {
                    Product product = new Product();
                    BLLProduct productBLL = new BLLProduct();
                    product = productBLL.GetProductById(billsDetail.ProductId);

                    gvProductsToBills.Rows.Add(product.ProductId, product.ProductName, billsDetail.RealPrice, billsDetail.Amounts, billsDetail.Sum, Properties.Resources.DeleteRed);
                }

                lbTotal.Text = bills.Total.ToString();
            }
        }
示例#6
0
        private void pictureBox1_Click_1(object sender, EventArgs e)
        {
            if (gvProductsToBills.Rows.Count == 0)
            {
                MessageBox.Show("Choose product, Please!", "Message");
                return;
            }

            List<BillDetail> lstBillDetail = new List<BillDetail>();
            for (int i = 0; i < gvProductsToBills.Rows.Count; i++)
            {
                BillDetail billDetail = new BillDetail()
                {
                    ProductId = int.Parse(gvProductsToBills.Rows[i].Cells["colID"].Value.ToString()),
                    Amounts = int.Parse(gvProductsToBills.Rows[i].Cells["colAmounts"].Value.ToString()),
                    RealPrice = float.Parse(gvProductsToBills.Rows[i].Cells["colRealPrice"].Value.ToString()),
                    Sum = float.Parse(gvProductsToBills.Rows[i].Cells["colTotal"].Value.ToString()),
                    BillDetailDescription = string.Empty
                };
                lstBillDetail.Add(billDetail);
            }

            Bill bills = new Bill() {
                CreatedDate = DateTime.Parse(DateTime.Now.ToShortDateString()),
                BillDescription = "",
                Total = double.Parse(lbTotal.Text),
                BillDetails = lstBillDetail
            };

            BLLBills billsBLL = new BLLBills();
            if (billsBLL.Inserted(bills)) {
                MessageBox.Show("Add Successful", "Message");
                LoadGridBills();
            }
        }
示例#7
0
 public void Updated(Bill bills)
 {
     DALBills billsDAL = new DALBills();
     billsDAL.Updated(bills);
 }
示例#8
0
 public Boolean Inserted(Bill bills)
 {
     DALBills billsDAL = new DALBills();
     return billsDAL.Inserted(bills);
 }
示例#9
0
 public Boolean Deleted(Bill bills)
 {
     DALBills billsDAL = new DALBills();
     return billsDAL.Deleted(bills);
 }