//Sửa chuyến bay public bool XoaChiTietSanBay(CTDTO ct) { string query = string.Empty; query += "DELETE FROM [ChiTietSanBayTrungGian] WHERE [MaChuyenBay] = @MaChuyenBay AND [MaSanBay] = @MaSanBay"; using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@MaChuyenBay", ct.MaChuyenBay); cmd.Parameters.AddWithValue("@MaSanBay", ct.MaSanBay); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { ct.Error = ex.Message; con.Close(); return(false); } } } return(true); }
//Thêm chuyến bay public bool ThemChiTietSanBay(CTDTO ct) { string query = string.Empty; query += "INSERT INTO [ChiTietSanBayTrungGian] ([MaChuyenBay], [MaSanBay], [ThoiGianDung], [GhiChu]) "; query += "VALUES (@MaChuyenBay,@MaSanBay,@ThoiGianDung,@GhiChu)"; using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@MaChuyenBay", ct.MaChuyenBay); cmd.Parameters.AddWithValue("@MaSanBay", ct.MaSanBay); cmd.Parameters.AddWithValue("@ThoiGianDung", ct.TGDung); cmd.Parameters.AddWithValue("@GhiChu", ct.GhiChu); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { ct.Error = ex.Message.Remove(0, 65).Trim(); con.Close(); return(false); } } } return(true); }
//Xoá chuyến bay public bool SuaChiTietSanBay(CTDTO ct) { string query = string.Empty; query += "UPDATE [ChiTietSanBayTrungGian] SET [ThoiGianDung] = @ThoiGianDung, [GhiChu] = @GhiChu WHERE [MaChuyenBay] = @MaChuyenBay and [MaSanBay] = @MaSanBay"; using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@MaChuyenBay", ct.MaChuyenBay); cmd.Parameters.AddWithValue("@MaSanBay", ct.MaSanBay); cmd.Parameters.AddWithValue("@ThoiGianDung", ct.TGDung); cmd.Parameters.AddWithValue("@GhiChu", ct.GhiChu); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { ct.Error = ex.Message; con.Close(); return(false); } } } return(true); }
private void btnXoa_Click(object sender, EventArgs e) { CTDTO ctDTO = new CTDTO(); //2. Kiểm tra data hợp lệ or not if (checkNullData()) { //1. Map data from GUI ctDTO.MaChuyenBay = txbMaChuyenBay.Text.ToString(); ctDTO.MaSanBay = txbMaSanBay.Text.ToString(); //3. Thêm vào DB bool kq = ctBUS.XoaChiTietSanBay(ctDTO); if (kq == false) { MessageBox.Show("Cập nhật Sân bay trung gian thất bại. Vui lòng kiểm tra lại dũ liệu! \n" + ctDTO.Error, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Cập nhật Sân bay trung gian thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.ClearInput(); this.loadData_Vao_dtgvDsSanBayTrungGian(); } } }
private void buttonThem_Click(object sender, EventArgs e) { CTDTO ctDTO = new CTDTO(); //2. Kiểm tra data hợp lệ or not if (checkNullData()) { //1. Map data from GUI ctDTO.MaChuyenBay = cbbMaChuyenBay.SelectedValue.ToString(); ctDTO.MaSanBay = cbbMaSanBay.SelectedValue.ToString(); ctDTO.TGDung = int.Parse(txbThoiGianDung.Text); ctDTO.GhiChu = txbGhiChu.Text; //3. Thêm vào DB bool kq = ctBUS.ThemChiTietSanBay(ctDTO); if (kq == false) { MessageBox.Show("Thêm Sân bay trung gian thất bại. Vui lòng kiểm tra lại dữ liệu! \n" + ctDTO.Error, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Thêm Sân bay trung gian thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.ClearInput(); this.loadData_Vao_dtgvDsSanBayTrungGian(); } } }
public List <CTDTO> select() { string query = string.Empty; //query += "SELECT MaChuyenBay, sb.TenSanBay, ThoiGianDung, GhiChu "; //query += "From ChiTietSanBayTrungGian ct, SanBay sb "; //query += "Where ct.MaSanBay = sb.MaSanBay "; query += "SELECT * From [ChiTietSanBayTrungGian]"; List <CTDTO> lsChiTiet = new List <CTDTO>(); using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; try { con.Open(); SqlDataReader reader = null; reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { CTDTO cttg = new CTDTO(); cttg.MaChuyenBay = reader["MaChuyenBay"].ToString(); cttg.MaSanBay = reader["MaSanBay"].ToString(); cttg.TGDung = int.Parse(reader["ThoiGianDung"].ToString()); cttg.GhiChu = reader["GhiChu"].ToString(); lsChiTiet.Add(cttg); } } con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); return(null); } } } return(lsChiTiet); }
public bool SuaChiTietSanBay(CTDTO ct) { bool re = ctDAL.SuaChiTietSanBay(ct); return(re); }
public bool ThemChiTietSanBay(CTDTO ct) { bool re = ctDAL.ThemChiTietSanBay(ct); return(re); }