public bool themBaoCaoNam(BaoCaoNam bCN) { 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_NAM (MaBaoCaoNam) VALUES ('" + bCN.MaBCNam + "')"; SqlCommand cmd = new SqlCommand(SQL, sqlConnection); string SQL1 = "UPDATE BAO_CAO_DOANH_THU_NAM SET Nam = (SELECT SUBSTRING('" + bCN.MaBCNam + "',4,4)), TongDoanhThuNam = (SELECT SUM(V.GiaTien) FROM VE_CHUYEN_BAY V, LICH_CHUYEN_BAY L WHERE V.MaCB = L.MaCB AND YEAR(L.NgayGio) = (SELECT SUBSTRING('" + bCN.MaBCNam + "',4,4))) WHERE MaBaoCaoNam = '" + bCN.MaBCNam + "'"; 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); }
public bool suaBCNam(BaoCaoNam bCN) { SqlConnection sqlConnection = createConnection(); try { sqlConnection.Open(); string SQL = "UPDATE BAO_CAO_DOANH_THU_NAM SET Nam = '" + bCN.Nam + "', TongDoanhThuNam = '" + bCN.TongDoanhThuNam + "' WHERE MaBaoCaoNam = '" + bCN.MaBCNam + "'";; 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); }