private void btnEdit_Click(object sender, EventArgs e)//ok?? { #region Excel //if (selectedZoom != "NULL") //{ // var package = new ExcelPackage(new FileInfo("CurrentCustomer.xlsx")); // ExcelWorksheet a = package.Workbook.Worksheets[0]; // for (int i = 1; i <= a.Dimension.End.Row; i++) // { // if (Convert.ToString(a.Cells[i + 1, 2].Value) == selectedZoom && Convert.ToString(a.Cells[i,3].Value)!="") // { // DateTime od = Convert.ToDateTime(a.Cells[i, 3].Value); // TimeSpan ts = od - DateTime.Now; // int t = ts.Days; // if (t > 1) MessageBox.Show("Phòng này đã được đặt trước vào ngày " + od + "\n Chỉ bán " + (t-1) + " đêm!"); // else if (t == 0|| t==1) MessageBox.Show("Phòng này đã được đặt trong ngày.\nVui lòng không bán!"); // else a.Cells[i, 3].Value = ""; // } // } // Byte[] bin = package.GetAsByteArray(); // File.WriteAllBytes("CurrentCustomer.xlsx", bin); // updateForm uF = new updateForm(selectedZoom); // uF.ShowDialog(); // getThongTinPhong(); //} #endregion bool isUsing = false; if (selectedZoom != 0) { foreach (Zoom item in ListZoom) { if (item.getIdPhong() == selectedZoom) { isUsing = (item.getIdBill() != ""); } } if (isUsing) { updateForm uF = new updateForm(selectedZoom, updateForm.EDIT); uF.ShowDialog(); getThongTinPhong(selectedZoom); } else { updateForm uF = new updateForm(selectedZoom, updateForm.ADD); uF.ShowDialog(); getThongTinPhong(selectedZoom); } } }
//Tra Phong private void button19_Click(object sender, EventArgs e)//Chưa sửa { bool dv = true, tt = true; if (selectedZoom != 0) { if (tbCI.Text == "") { tt = false; } List <ThongTinDichVu> ListDV = new DatabaseConnection().getDV(conn.getIDBill(selectedZoom), DatabaseConnection.EDIT); foreach (ThongTinDichVu item in ListDV) { if (item.Dg * item.Sl == 0) { dv = false; } } if (!tt) { MessageBox.Show("Điền đầy đủ thông tin khách hàng trước khi thanh toán"); updateForm uF = new updateForm(selectedZoom, updateForm.EDIT); uF.ShowDialog(); getThongTinPhong(selectedZoom); } if (!dv) { MessageBox.Show("Hoàn thanh thông tin dịch vụ trước"); } if (tt && dv) { string idBill = ""; bool b = true; //DateTime CI = Convert.ToDateTime(tbCI.Text); //string sCI = String.Format("{0:dd/MM/yyyy HH:mm}", CI); if (tbCO.Text == "") { tbCO.Text = String.Format("{0:dd/MM/yyyy HH:mm}", DateTime.Now); } DateTime CO = Convert.ToDateTime(tbCO.Text); string sCO = String.Format("{0:MM/dd/yyyy HH:mm}", CO); string query1 = "update Bill set CO='" + sCO + "' where idphong=" + selectedZoom; string query2 = "select IdBill from Phong where IdPhong = " + selectedZoom; using (SqlConnection conn = new SqlConnection(ConnectionString.connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(query1, conn); b = cmd.ExecuteNonQuery() > 0; cmd = new SqlCommand(query2, conn); using (SqlDataReader rd = cmd.ExecuteReader()) { if (rd.Read()) { idBill = rd.GetString(0); } } conn.Close(); } if (b) { DoanhThu dt = new DoanhThu(DateTime.Now, idBill, radioButton1.Text, "", sum, 0, "", new DatabaseConnection().getCurrentReport()); CashInfoForm cash = new CashInfoForm(dt); cash.ShowDialog(); getThongTinPhong(selectedZoom); Update(); } } } #region //{ // var package = new ExcelPackage(new FileInfo("CurrentCustomer.xlsx")); // ExcelWorksheet a = package.Workbook.Worksheets[0]; // for (int i = 1; i <= a.Dimension.End.Row; i++) // { // if (Convert.ToString(a.Cells[i + 1, 2].Value) == selectedZoom) // { // DateTime co = new DateTime(); // if (Convert.ToString(a.Cells[i + 1, 4].Value) == "") // { // co = DateTime.Now; // } // else co = Convert.ToDateTime(a.Cells[i + 1, 4].Value); // if (Convert.ToString(a.Cells[i + 1, 3].Value) == "") // { // MessageBox.Show("Cập nhập đầy đủ thông tin khách hàng trước"); // btnEdit.PerformClick(); // } // else // { // info = new KhachHang(Convert.ToString(a.Cells[i + 1, 1].Value), Convert.ToString(a.Cells[i + 1, 2].Value), Convert.ToDateTime(a.Cells[i + 1, 3].Value), co, Convert.ToInt32(a.Cells[i + 2, 4].Value), Convert.ToString(a.Cells[i,4].Value)); // if (info.Ten == "") info.Ten = "NoName"; // a.Cells[i, 2].Value = ""; // a.Cells[i + 1, 1].Value = ""; // a.Cells[i + 1, 3].Value = ""; // a.Cells[i + 1, 4].Value = ""; // a.Cells[i + 2, 2].Value = 3; // a.Cells[i + 3, 2].Value = 0; // a.Cells[i + 3, 3].Value = 0; // for (int n = 1; n < 9; n++) // { // a.Cells[i + 3 + n, 3].Value = 0; // a.Cells[i + 3 + n, 2].Value = 0; // a.Cells[i + 3 + n, 1].Value = ""; // } // Byte[] bin = package.GetAsByteArray(); // File.WriteAllBytes("CurrentCustomer.xlsx", bin); // } // Hoanthientt subform = new Hoanthientt(selectedZoom); // subform.Show(); // LuuTru(); // } // } // getThongTinPhong(); // Update(); //} #endregion }