public List <DoanhThu> getListRP() { string query = "select Ngay,DanhMuc,Thu,Chi,Note from DoanhThu where MaBC='" + getCurrentReport() + "'"; List <DoanhThu> list = new List <DoanhThu>(); using (SqlConnection conn = new SqlConnection(ConnectionString.connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(query, conn); //SqlDataAdapter adapter = new SqlDataAdapter(query, conn); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { DoanhThu dt = new DoanhThu(reader.GetDateTime(0), reader.GetString(1), 0, 0, ""); if (!reader.IsDBNull(2)) { dt.Thu = reader.GetInt32(2); } if (!reader.IsDBNull(3)) { dt.Chi = reader.GetInt32(3); } if (!reader.IsDBNull(4)) { dt.Note = reader.GetString(4); } list.Add(dt); } } } conn.Close(); } return(list); }
//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 }
public List <DoanhThu> getListDT(string date) { List <DoanhThu> listDT = new List <DoanhThu>(); DateTime sDate; string query = "select * from DoanhThu "; string filt = " where Ngay ='" + date + "'"; string sort = " order by Ngay DESC"; if (date == "") { listDT = new List <DoanhThu>(); using (SqlConnection conn = new SqlConnection(ConnectionString.connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(query + sort, conn); using (SqlDataReader rd = cmd.ExecuteReader()) { while (rd.Read()) { DoanhThu dt = new DoanhThu(rd.GetDateTime(0), "", rd.GetString(2), rd.GetString(3), 0, 0, ""); if (!rd.IsDBNull(1)) { dt.IdBill = rd.GetString(1); } if (!rd.IsDBNull(4)) { dt.Thu = rd.GetInt32(4); } if (!rd.IsDBNull(5)) { dt.Chi = rd.GetInt32(5); } if (!rd.IsDBNull(6)) { dt.Note = rd.GetString(6); } listDT.Add(dt); } } conn.Close(); } } else { try { sDate = Convert.ToDateTime(date); using (SqlConnection conn = new SqlConnection(ConnectionString.connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(query + filt + sort, conn); using (SqlDataReader rd = cmd.ExecuteReader()) { while (rd.Read()) { DoanhThu dt = new DoanhThu(rd.GetDateTime(0), "", rd.GetString(2), rd.GetString(3), 0, 0, ""); if (!rd.IsDBNull(1)) { dt.IdBill = rd.GetString(1); } if (!rd.IsDBNull(4)) { dt.Thu = rd.GetInt32(4); } if (!rd.IsDBNull(5)) { dt.Chi = rd.GetInt32(5); } if (!rd.IsDBNull(6)) { dt.Note = rd.GetString(6); } listDT.Add(dt); } } conn.Close(); } } catch (Exception) { throw; } } return(listDT); }
public CashInfoForm(Object dt) { a = dt as DoanhThu; InitializeComponent(); load(); }