private void AddSPBD(int IDReceipt, int IDLoaiSP, int IDSanPham, string TenSP, int num) { //add a quantity of a product to current bill //check if the parameters are legal //DataSet prdPrice = new DataAccess().getGiaXuatSPByIDSanPham(ID); //if ((prdPrice != null) && (prdPrice.Tables[0].Rows.Count > 0)) //{ //txtPrice.Text = prdPrice.Tables[0].Rows[0][1].ToString(); if (IDReceipt >= 0) { DataSet dsGia = new DataAccess().getGiaXuatSPByIDSanPham(IDSanPham); //if (ds == null) // return; //if (ds.Tables[0].Rows.Count == 0) //{ ChitietHDXuat obj = new ChitietHDXuat(); obj.IDHoadonXuat = IDReceipt; obj.IDSanpham = IDSanPham; try { obj.Gia = Convert.ToInt32(dsGia.Tables[0].Rows[0]["Gia"]); } catch { MessageBox.Show("Chưa có giá cho " + TenSP, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } obj.Soluong = num; //get khuyen mai with this product ID DataSet ds = new DataAccess().getKhuyenmaiByIDLoaiSP(IDLoaiSP, DateTime.Now.Date); if (ds != null) { try { obj.Giam = Convert.ToInt32(ds.Tables[0].Rows[0]["Giam"]); } catch (Exception ex) { obj.Giam = 0; } } else { obj.Giam = 0; } obj.Trangthai = false; int res = new DataAccess().insertChitietHDXuat(obj); if (res < 0) { MessageBox.Show("Không thêm sản phẩm ban đầu vào hóa đơn hiện tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } }
public bool deleteChitietHDXuat(ChitietHDXuat objChitietHDXuat) { return(new ChitietHDXuatService().deleteChitietHDXuat(objChitietHDXuat)); }
public bool updateChitietHDXuat(ChitietHDXuat objChitietHDXuat) { return(new ChitietHDXuatService().updateChitietHDXuat(objChitietHDXuat)); }
public int insertChitietHDXuat(ChitietHDXuat objChitietHDXuat) { return(new ChitietHDXuatService().insertChitietHDXuat(objChitietHDXuat)); }
void updateBillProduct() { //check if whether transfer column diff zero if (newRoom < 0) { MessageBox.Show("Bạn hãy chọn phòng để chuyển sản phẩm!", "Thông báo", MessageBoxButtons.OK); return; } if (newIDHoadonXuat < 0) { if (MessageBox.Show("Bạn có chắc muốn mở phòng " + gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong").ToString() + " và chuyển sản phẩm?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } bool found = false; int i; for (i = 0; i < gridViewTransferedProductNew.RowCount; i++) { if (Convert.ToInt32(gridViewTransferedProductNew.GetRowCellValue(i, "Transfer")) != 0) { gridViewTransferedProductNew.FocusedRowHandle = i; found = true; break; } } for (i = 0; i < gridViewBillProduct.RowCount; i++) { if (Convert.ToInt32(gridViewBillProduct.GetRowCellValue(i, "Transfer")) != 0) { gridViewBillProduct.FocusedRowHandle = i; found = true; break; } } if (found) { if (MessageBox.Show("Sản phẩm chưa được chuyển hết (Cột 'Chuyển khác 0). Bạn có muốn tiếp tục cập nhật Hóa đơn?", "Thông báo", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } else { if (MessageBox.Show("Bạn có chắc muốn cập nhật Hóa đơn?", "Xác nhận", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } //update old chi tiet hoa don for (i = 0; i < oldProduct.Rows.Count; i++) { ChitietHDXuat objCTHDX = new ChitietHDXuat(); objCTHDX.IDChitietHDXuat = Convert.ToInt32(oldProduct.Rows[i]["IDChitietHDXuat"]); if (Convert.ToInt32(oldProduct.Rows[i]["Soluong"]) <= 0) { // chuyen het san pham cua 1 row qua phong moi // delete san pham nay khoi chi tiet hoa don xuat if (!(new DataAccess().deleteChitietHDXuat(objCTHDX))) { MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi"); return; } } else { // cap nhat lai chi tiet hoa don xuat objCTHDX.IDGiaxuat = Convert.ToInt32(oldProduct.Rows[i]["IDGiaxuatSP"]); objCTHDX.Giam = Convert.ToInt32(oldProduct.Rows[i]["Giam"]); objCTHDX.IDHoadonXuat = oldIDHoadonXuat; objCTHDX.IDSanpham = Convert.ToInt32(oldProduct.Rows[i]["IDSanpham"]); objCTHDX.Soluong = Convert.ToInt32(oldProduct.Rows[i]["Soluong"]); objCTHDX.Bep = false; if (!(new DataAccess().updateChitietHDXuat(objCTHDX))) { MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi"); return; } } } //update new HD if (newIDHoadonXuat >= 0) // hoa don da duoc mo { for (i = 0; i < newProduct.Rows.Count; i++) { ChitietHDXuat objCTHDX = new ChitietHDXuat(); objCTHDX.IDChitietHDXuat = Convert.ToInt32(newProduct.Rows[i]["IDChitietHDXuat"]); objCTHDX.IDGiaxuat = Convert.ToInt32(newProduct.Rows[i]["IDGiaxuatSP"]); objCTHDX.Giam = Convert.ToInt32(newProduct.Rows[i]["Giam"]); objCTHDX.IDHoadonXuat = newIDHoadonXuat; objCTHDX.IDSanpham = Convert.ToInt32(newProduct.Rows[i]["IDSanpham"]); objCTHDX.Soluong = Convert.ToInt32(newProduct.Rows[i]["Soluong"]); objCTHDX.Bep = false; if (objCTHDX.IDChitietHDXuat >= 0) { if (objCTHDX.Soluong <= 0) { if (!(new DataAccess().deleteChitietHDXuat(objCTHDX))) { MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi"); return; } } else { if (!(new DataAccess().updateChitietHDXuat(objCTHDX))) { MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi"); return; } } } else { int id = new DataAccess().insertChitietHDXuat(objCTHDX); if (id < 0) { MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi"); return; } else { oldProduct.Rows[i]["IDChitietHDXuat"] = id; } } } } else //open new bill { Hoadonxuat currentReceipt = new Hoadonxuat(); currentReceipt.Giam = 0; currentReceipt.GioBD = DateTime.Now; currentReceipt.GioKT = DateTime.Now; currentReceipt.Nhacnho = false; currentReceipt.Tratruoc = 0; currentReceipt.IDPhong = newRoom; currentReceipt.Ngayxuat = DateTime.Now.Date; currentReceipt.Phuthu = 0; currentReceipt.Thue = 0; currentReceipt.Trangthai = 0; currentReceipt.Thue = 0; currentReceipt.Phuthu = 0; currentReceipt.IDNhanvien = 0; currentReceipt.IDKhachhang = 0; currentReceipt.Ghichu = ""; //get current hour class TimeSpan ctime = DateTime.Now.TimeOfDay; DataSet hourclass = new DataAccess().getAllKhunggio(); int idkhunggio = 0; for (i = 0; i < hourclass.Tables[0].Rows.Count; i++) { string time = Convert.ToString(hourclass.Tables[0].Rows[i]["GioBD"]); int sh = Convert.ToInt32(time.Substring(0, time.IndexOf(":"))); int sm = Convert.ToInt32(time.Substring(time.IndexOf(":") + 1)); string time1 = Convert.ToString(hourclass.Tables[0].Rows[i]["GioKT"]); int eh = Convert.ToInt32(time1.Substring(0, time.IndexOf(":"))); int em = Convert.ToInt32(time1.Substring(time1.IndexOf(":") + 1)); if ((ctime.Hours < eh) || ((ctime.Hours == eh) && (ctime.Minutes <= em))) { if ((ctime.Hours > sh) || ((ctime.Hours == sh) && (ctime.Minutes > sm))) { idkhunggio = Convert.ToInt32(hourclass.Tables[0].Rows[i]["IDKhunggio"]); break; } } } //get Room price DataSet ds1 = new DataAccess().getGiaLoaiPhongByIDLoaiPhongAndIDKhunggio(Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "IDLoaiPhong")), idkhunggio); if (ds1.Tables[0].Rows.Count > 0) { currentReceipt.IDGiaLoaiphong = Convert.ToInt32(ds1.Tables[0].Rows[0]["IDGiaLoaiphong"]); } else { MessageBox.Show("Chưa có bảng giá cho phòng " + Convert.ToString(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) + " vào khung giờ này. Mở phòng không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } newIDHoadonXuat = new DataAccess().insertHoadonxuat(currentReceipt); if (newIDHoadonXuat > -1) { //wait for databa is update //ContactAction(0xbf, Convert.ToInt32(ds.Tables[0].Rows[0]["Congtac"])); //open electric cb //MessageBox.Show("Mở Phòng " + Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) + // " thành công", "Thông báo"); turnOnRoom.Enqueue(newRoom); //update status for this Room Phong updateRoom = new Phong(); updateRoom.IDPhong = newRoom; updateRoom.IDLoaiPhong = Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "IDLoaiPhong")); updateRoom.TenPhong = Convert.ToString(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")); updateRoom.Ghichu = Convert.ToString(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "Ghichu")); updateRoom.Trangthai = true; bool a = new DataAccess().updatePhong(updateRoom); if (!a) { MessageBox.Show("Không cập nhật được trạng thái cho phòng " + updateRoom.TenPhong, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } //update current status gridview gridViewRoom.SetFocusedRowCellValue(colRoomStatus, true); //add chitietHDxuat for (i = 0; i < newProduct.Rows.Count; i++) { ChitietHDXuat objCTHDX = new ChitietHDXuat(); objCTHDX.IDChitietHDXuat = -1; objCTHDX.IDGiaxuat = Convert.ToInt32(newProduct.Rows[i]["IDGiaxuatSP"]); objCTHDX.Giam = Convert.ToInt32(newProduct.Rows[i]["Giam"]); objCTHDX.IDHoadonXuat = newIDHoadonXuat; objCTHDX.IDSanpham = Convert.ToInt32(newProduct.Rows[i]["IDSanpham"]); objCTHDX.Soluong = Convert.ToInt32(newProduct.Rows[i]["Soluong"]); objCTHDX.Bep = false; if (objCTHDX.Soluong > 0) { int id = new DataAccess().insertChitietHDXuat(objCTHDX); if (id < 0) { MessageBox.Show("Lỗi Cơ sở dữ liệu!", "Lỗi"); return; } else { newProduct.Rows[i]["IDChitietHDXuat"] = id; } } } } else { MessageBox.Show("Mở Phòng " + Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) + " không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } MessageBox.Show("Chuyển sản phẩm thành công", "Thông báo", MessageBoxButtons.OK); }