public bool suaBCThang(BaoCaoThang bCT) { SqlConnection sqlConnection = createConnection(); try { sqlConnection.Open(); string SQL = "UPDATE BAO_CAO_DOANH_THU_THANG SET Thang = '" + bCT.Thang + "', TongDoanhThu = '" + bCT.TongDoanhThu + "' WHERE MaBaoCaoThang = '" + bCT.MaBCThang + "'";; SqlCommand cmd = new SqlCommand(SQL, sqlConnection); // Query và kiểm tra if (cmd.ExecuteNonQuery() > 0) { return(true); } } catch (Exception e) { throw e; } finally { // Dong ket noi sqlConnection.Close(); } return(false); }
public bool themBaoCaoThang(BaoCaoThang bCT) { SqlConnection sqlConnection = createConnection(); try { sqlConnection.Open(); //SqlCommand cmd = new SqlCommand("INSERT INTO SAN_BAY(MaSB,TenSB) VALUES ('" + txtMaSB.Text + "',N'" + txtTenSB.Text + "')", con); string SQL = "INSERT INTO BAO_CAO_DOANH_THU_THANG(MaBaoCaoThang, Thang) VALUES ('" + bCT.MaBCThang + "', '" + bCT.Thang + "')"; SqlCommand cmd = new SqlCommand(SQL, sqlConnection); string SQL1 = "UPDATE BAO_CAO_DOANH_THU_THANG SET TongDoanhThu = (SELECT SUM(V.GiaTien) FROM VE_CHUYEN_BAY V, LICH_CHUYEN_BAY L WHERE V.MaCB = L.MaCB AND MONTH(L.NgayGio) = " + bCT.Thang + " AND YEAR(L.NgayGio) = (SELECT SUBSTRING('" + bCT.MaBCThang + "',6,4))) WHERE MaBaoCaoThang = '" + bCT.MaBCThang + "'"; SqlCommand cmd1 = new SqlCommand(SQL1, sqlConnection); // Query và kiểm tra if ((cmd.ExecuteNonQuery() > 0) && (cmd1.ExecuteNonQuery() > 0)) { return(true); } } catch (Exception e) { throw e; } finally { // Dong ket noi sqlConnection.Close(); } return(false); }