private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { hoadDonXuat hdx = db.hoadDonXuats.Where(s => s.maHDX == dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()).FirstOrDefault(); tranferId.id = hdx.maHDX; if (dataGridView1.Columns[e.ColumnIndex].Name == "detail") { Frm_Detail_Bill frm_Detail_Bill = new Frm_Detail_Bill(); frm_Detail_Bill.ShowDialog(); } else if (dataGridView1.Columns[e.ColumnIndex].Name == "delete") { //chiTietHDX ct = db.chiTietHDXes.Where(s => s.maHDX == hd).FirstOrDefault(); DialogResult result = MessageBox.Show("Are you sure ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { db.update_status_hoadon(hdx.maHDX, "Cancel"); db.update_tongtienHD(hdx.maHDX, 0); foreach (var a in db.chiTietHDXes.Where(s => s.maHDX == hdx.maHDX)) { sanPham sp = db.sanPhams.Where(s => s.maSP == a.maSP).FirstOrDefault(); db.update_soluong(a.maSP, sp.soLuong + a.soLuong); db.update_chitiet(a.maHDX, 0, 0); } UcBill_Sell_Load(sender, e); } } } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { btnPrintBill.Visible = true; btnMail.Visible = true; //int i = dataGridView1.CurrentRow.Index; hoadDonXuat hdx = db.hoadDonXuats.Where(s => s.maHDX == dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()).FirstOrDefault(); //tranferId.id = hdx.maHDX; //hd = hdx.maHDX; khachHang kh = db.khachHangs.Where(s => s.maKH == hdx.maKH).FirstOrDefault(); txtCusName.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); txtCusPhone.Text = kh.sdt.ToString(); txtCusAddress.Text = kh.diaChi.ToString(); txtCusEmail.Text = kh.email.ToString(); txtBillid.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); txtBillDate.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); txtBillStatus.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); txtStaffName.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); txtBillPrice.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); } }
private void Frm_Detail_Bill_Load(object sender, EventArgs e) { dataGridView1.AutoGenerateColumns = false; dataGridView1.DataSource = db.bill_info(UcBill_Sell.tranferId.id); lbMaHDX.Text = UcBill_Sell.tranferId.id; hoadDonXuat hdx = db.hoadDonXuats.Where(s => s.maHDX == UcBill_Sell.tranferId.id).FirstOrDefault(); lbStatus.Text = hdx.trangThai.ToString(); if (lbStatus.Text == "Cancel") { lbStatus.ForeColor = Color.Red; } else { lbStatus.ForeColor = Color.Green; } }
private void gunaButton1_Click(object sender, EventArgs e) { var hd = from u in db.hoadDonXuats select u; if (hd.Count() == 0) { db.hdx_insert("hdx000001", frmLogin.GetID.id, UCShowProduct.tranferIDBill.CusId, Convert.ToDouble(lbTotalPrice.Text), "Paid", DateTime.Now, Convert.ToInt32(numericUpDown1.Value)); foreach (var a in db.CTGios) { db.cthdx_insert("hdx000001", a.masp, Convert.ToDouble(a.donGia), Convert.ToInt32(a.soluong), Convert.ToDouble(a.thanhTien)); sanPham sp = db.sanPhams.Where(s => s.maSP == a.masp).FirstOrDefault(); db.update_soluong(a.masp, sp.soLuong - a.soluong); } signal.sign = 1; } else { hoadDonXuat ssp = db.hoadDonXuats.OrderByDescending(s => s.maHDX).FirstOrDefault(); stt = Convert.ToInt32(ssp.maHDX.ToString().Trim().Substring(3)) + 1; if (stt / 10 >= 100000) { id = "HDX" + stt; } else if (stt / 10 >= 1000 && stt / 10 < 10000) { id = "HDX0" + stt; } else if (stt / 10 >= 100 && stt / 10 < 1000) { id = "HDX00" + stt; } else if (stt / 10 >= 10 && stt / 10 < 100) { id = "HDX000" + stt; } else if (stt / 10 >= 1 && stt / 10 < 10) { id = "HDX0000" + stt; } else if (stt / 10 < 1) { id = "HDX00000" + stt; } db.hdx_insert(id, frmLogin.GetID.id, UCShowProduct.tranferIDBill.CusId, Convert.ToDouble(lbTotalPrice.Text), "Paid", DateTime.Now, Convert.ToInt32(numericUpDown1.Value)); foreach (var a in db.CTGios) { db.cthdx_insert(id, a.masp, Convert.ToDouble(a.donGia), Convert.ToInt32(a.soluong), Convert.ToDouble(a.thanhTien)); sanPham sp = db.sanPhams.Where(s => s.maSP == a.masp).FirstOrDefault(); db.update_soluong(a.masp, sp.soLuong - a.soluong); } signal.sign = 1; } db.delete_cart(UCShowProduct.tranferIDBill.cartID); this.Close(); }