public Hoadonxuat getHoadonxuatByID(int ID) { Database db = DatabaseFactory.CreateDatabase(); Hoadonxuat rs = new Hoadonxuat(); string sqlCommand = "SELECT * FROM Hoadonxuat WHERE IDHoadonXuat = @id "; try { DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand); db.AddInParameter(dbCommand, "id", DbType.Int32, ID); DataSet ds = db.ExecuteDataSet(dbCommand); dbCommand.Connection.Close(); if (ds.Tables[0].Rows.Count <= 0) { return(null); } //get current Bill rs.IDNhanvien = Convert.ToInt32(ds.Tables[0].Rows[0]["IDNhanvien"]); rs.IDPhong = Convert.ToInt32(ds.Tables[0].Rows[0]["IDPhong"]); rs.Giam = Convert.ToInt32(ds.Tables[0].Rows[0]["Giam"]); rs.Thue = Convert.ToInt32(ds.Tables[0].Rows[0]["Thue"]); rs.Phuthu = Convert.ToInt32(ds.Tables[0].Rows[0]["Phuthu"]); rs.IDGiaLoaiphong = Convert.ToInt32(ds.Tables[0].Rows[0]["IDGiaLoaiphong"]); rs.Ngayxuat = Convert.ToDateTime(ds.Tables[0].Rows[0]["Ngayxuat"]); rs.GioBD = Convert.ToDateTime(ds.Tables[0].Rows[0]["GioBD"]); rs.GioKT = Convert.ToDateTime(ds.Tables[0].Rows[0]["GioKT"]); rs.Tratruoc = Convert.ToInt32(ds.Tables[0].Rows[0]["Tratruoc"]); rs.Ghichu = Convert.ToString(ds.Tables[0].Rows[0]["Ghichu"]); rs.Trangthai = Convert.ToInt32(ds.Tables[0].Rows[0]["Trangthai"]); rs.IDHoadonXuat = ID; rs.IDNhanvienXuatHD = Convert.ToInt32(ds.Tables[0].Rows[0]["IDNhanvienXuatHD"]); rs.Nhacnho = Convert.ToBoolean(ds.Tables[0].Rows[0]["Nhacnho"]); rs.IDKhachhang = Convert.ToInt32(ds.Tables[0].Rows[0]["IDKhachhang"]); rs.Tanggio = Convert.ToInt32(ds.Tables[0].Rows[0]["Tanggio"]); rs.Suco = Convert.ToInt32(ds.Tables[0].Rows[0]["Suco"]); rs.TenHoadon = Convert.ToString(ds.Tables[0].Rows[0]["TenHoadon"]); return(rs); } catch { return(null); } }
public bool deleteHoadonxuat(Hoadonxuat objHoadonxuat) { return(new HoadonxuatService().deleteHoadonxuat(objHoadonxuat)); }
public bool updateHoadonxuat(Hoadonxuat objHoadonxuat) { return(new HoadonxuatService().updateHoadonxuat(objHoadonxuat)); }
//Global DataAccess #region Hoadonxuat public int insertHoadonxuat(Hoadonxuat objHoadonxuat) { return(new HoadonxuatService().insertHoadonxuat(objHoadonxuat)); }
private void Start() { //open or close selected room //first search if selected room is available DataSet ds = new DataAccess().getPhongByIDPhong(iCurrentFreeRoomID); if (ds.Tables[0].Rows.Count > 0) { iCurrentFreeRoomGroupID = Convert.ToInt32(ds.Tables[0].Rows[0]["IDLoaiphong"]); Hoadonxuat currentReceipt = new Hoadonxuat(); //in case of the room is available //ask to open room and create new receipt for this room if (MessageBox.Show("Bạn có muốn mở phòng " + Convert.ToString(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) + "?", "Thông báo mở phòng", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) { return; } //get khuyen mai tang gio cua phong DataSet dsKM = new DataAccess().getKhuyenmaiByIDLoaiPhong(iCurrentFreeRoomGroupID, DateTime.Now.Date); //Hoadonxuat currentReceipt = new Hoadonxuat(); try { currentReceipt.Giam = Convert.ToInt32(dsKM.Tables[0].Rows[0]["Giam"]); } catch (Exception ex) { currentReceipt.Giam = 0; } currentReceipt.TenHoadon = Convert.ToString(ds.Tables[0].Rows[0]["TenPhong"]) + " " + DateTime.Now.ToString("dd/MM/yy-hh:mm"); currentReceipt.GioBD = DateTime.Now; currentReceipt.GioKT = DateTime.Now; currentReceipt.Tratruoc = 0; currentReceipt.Nhacnho = false; currentReceipt.IDPhong = iCurrentFreeRoomID; currentReceipt.Ngayxuat = DateTime.Now.Date; currentReceipt.Phuthu = 0; currentReceipt.Thue = 0; currentReceipt.Trangthai = 0; currentReceipt.Thue = 0; currentReceipt.Phuthu = 0; currentReceipt.IDNhanvien = 0; currentReceipt.IDNhanvienXuatHD = Program.IDNhanvien; currentReceipt.IDKhachhang = 0; currentReceipt.Ghichu = ""; currentReceipt.Suco = 0; //get current hour class TimeSpan ctime = DateTime.Now.TimeOfDay; //TimeSpan stime = new TimeSpan(); //TimeSpan etime = new TimeSpan(); DataSet hourclass = new DataAccess().getAllKhunggio(); int idkhunggio = 0; int i; 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(iCurrentFreeRoomGroupID, 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; } int res = new DataAccess().insertHoadonxuat(currentReceipt); if (res > -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"); iCurrentReceiptID = res; iEffectedRoomID = iCurrentFreeRoomID; //add starting product for the room DataSet dsSPBD = new DataAccess().getAllSPBandauIDLoaiPhong(Convert.ToInt32(ds.Tables[0].Rows[0]["IDLoaiPhong"])); for (i = 0; i < dsSPBD.Tables[0].Rows.Count; i++) { int IDSanPham = Convert.ToInt32(dsSPBD.Tables[0].Rows[i]["IDSanPham"]); int IDLoaiSP = Convert.ToInt32(dsSPBD.Tables[0].Rows[i]["IDNhomSP"]); string TenSanPham = Convert.ToString(dsSPBD.Tables[0].Rows[i]["TenSanPham"]); int num = Convert.ToInt32(dsSPBD.Tables[0].Rows[i]["Soluong"]); AddSPBD(res, IDLoaiSP, IDSanPham, TenSanPham, num); } bNewReceipt = true; //update Hoadon group display //update status for this Room Phong updateRoom = new Phong(); updateRoom.IDPhong = Convert.ToInt32(ds.Tables[0].Rows[0]["IDPhong"]); updateRoom.IDLoaiPhong = Convert.ToInt32(ds.Tables[0].Rows[0]["IDLoaiPhong"]); updateRoom.TenPhong = Convert.ToString(ds.Tables[0].Rows[0]["TenPhong"]); updateRoom.Ghichu = Convert.ToString(ds.Tables[0].Rows[0]["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 initDataGrid(); //return ro main this.Hide(); //btnStart.Image = Karaoke.Properties.Resources.Status_user_busy_icon1; } else { MessageBox.Show("Mở Hóa đơn mới " + Convert.ToInt32(gridViewRoom.GetRowCellValue(gridViewRoom.FocusedRowHandle, "TenPhong")) + " không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } }
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); }