private void button2_Click(object sender, EventArgs e) { try { HoaDonObject hd = new HoaDonObject(); hd.IDHoaDon = int.Parse(cbb_phong2.SelectedValue.ToString()); //lbl_dongia.Text = cbb_phong2.Text; //tinh thoi gian giữa 2 dtp TimeSpan time = dtp_thoigiantra2.Value - dtp_thoigiandat2.Value; hd.ThanhTien = time.Hours * int.Parse(lbl_dongia.Text); hd.GhiChu = txt_ghichu2.Text; int a = hd_model.TraPhong(hd, cbb_phong2.Text); if (a > 0) { MessageBox.Show("Trả phòng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); lbl_thanhtien.Text = hd.ThanhTien.ToString() + " vnd"; lbl_thoigian.Text = time.Hours.ToString() + " giờ"; } else { MessageBox.Show("Trả phòng thất bại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { MessageBox.Show("Trả phòng thất bại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public int TraPhong(HoaDonObject hd, string tenphong) { cmd = new SqlCommand(); cmd.Connection = con.Connection; try { cmd.CommandText = "sp_TraPhong"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@idhoadon", hd.IDHoaDon); cmd.Parameters.AddWithValue("@tenphong", tenphong); cmd.Parameters.AddWithValue("@thanhtien", hd.ThanhTien); cmd.Parameters.AddWithValue("@ghichu", hd.GhiChu); con.OpenConn(); a = cmd.ExecuteNonQuery(); } catch (Exception) { a = -1; } finally { con.CloseConn(); } return(a); }
public int DatPhong(HoaDonObject hd) { cmd = new SqlCommand(); cmd.Connection = con.Connection; try { cmd.CommandText = "sp_DatPhong"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@idphong", hd.IDPhong); cmd.Parameters.AddWithValue("@idnhanvien", hd.IDNhanVien); cmd.Parameters.AddWithValue("@tenkhachhang", hd.TenKhachHang); cmd.Parameters.AddWithValue("@cmt", hd.CMT); cmd.Parameters.AddWithValue("@dienthoai", hd.DienThoai); cmd.Parameters.AddWithValue("@ghichu", hd.GhiChu); con.OpenConn(); a = cmd.ExecuteNonQuery(); } catch (Exception) { a = -1; } finally { con.CloseConn(); } return(a); }
HoaDonObject get_data_hoadon1() { HoaDonObject hd = new HoaDonObject(); hd.CMT = txt_socmt1.Text; hd.DienThoai = txt_dienthoai1.Text; hd.GhiChu = txt_ghichu1.Text; hd.IDNhanVien = int.Parse(cbb_nhanvien.SelectedValue.ToString()); hd.IDPhong = int.Parse(cbb_phong1.SelectedValue.ToString()); hd.TenKhachHang = txt_tenkhachhang1.Text; return(hd); }
private void button1_Click(object sender, EventArgs e) { try { HoaDonObject hd = new HoaDonObject(); hd = get_data_hoadon1(); int a = hd_model.DatPhong(hd); if (a > 0) { MessageBox.Show("Đặt phòng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Đặt phòng thất bại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } DatPhong_Load(sender, e); } catch (Exception) { MessageBox.Show("Đặt phòng thất bại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }