private void themChuyenBay_Click(object sender, EventArgs e) { CBDTO cbDTO = new CBDTO(); //2. Kiểm tra data hợp lệ or not if (checkNullData()) { //1. Map data from GUI cbDTO.MaChuyenBay = txbMaChuyenBay.Text; cbDTO.SanBayDi = cbbSanBayDi.SelectedValue.ToString(); cbDTO.SanBayDen = cbbSanBayDen.SelectedValue.ToString(); cbDTO.TGKhoiHanh = ngayKhoiHanh.Value.ToShortDateString(); cbDTO.TGBay = int.Parse(txbThoiGianBay.Text); cbDTO.SLGheHang1 = int.Parse(txbSLGheHang1.Text); cbDTO.SLGheHang2 = int.Parse(txbSLGheHang2.Text); cbDTO.GiaVe = int.Parse(txbDonGiaVe.Text); //3. Thêm vào DB bool kq = cbBUS.ThemChuyenBay(cbDTO); if (kq == false) { MessageBox.Show("Thêm Chuyến bay thất bại. Vui lòng kiểm tra lại dũ liệu! \n" + cbDTO.Error, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Thêm Chuyến bay thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.loadData_Vao_dtgvDsChuyenBay(); this.ClearInput(); } } }
//Xoá chuyến bay public bool XoaChuyenBay(CBDTO cb) { string query = string.Empty; query += "DELETE FROM LichChuyenBay WHERE [MaChuyenBay] = @MaChuyenBay"; 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", cb.MaChuyenBay); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { cb.Error = ex.Message.Remove(0, 65).Trim(); con.Close(); return(false); } } } return(true); }
//Xoá Chuyến bay private void btnXoaChuyenBay_Click(object sender, EventArgs e) { CBDTO cbDTO = new CBDTO(); //2. Kiểm tra data hợp lệ or not if (checkNullData()) { //1. Map data from GUI cbDTO.MaChuyenBay = txbMaChuyenBay.Text; //3. Thêm vào DB bool kq = cbBUS.XoaChuyenBay(cbDTO); if (kq == false) { MessageBox.Show("Xoá Chuyến bay thất bại. Vui lòng kiểm tra lại dũ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Xoá Chuyến bay thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.loadData_Vao_dtgvDsChuyenBay(); } } else { MessageBox.Show("Vui lòng chọn thông tin cần chỉnh sửa", "Thông tin", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public List <CBDTO> search(string valueDen, string valueDi) { string query = string.Empty; query += "SELECT *"; query += "FROM [LichChuyenBay]"; query += "WHERE ([SanBayDi]=@di)"; query += "AND ([SanBayDen]=@den)"; List <CBDTO> lsChuyenBay = new List <CBDTO>(); 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("@di", valueDi); cmd.Parameters.AddWithValue("@den", valueDen); try { con.Open(); SqlDataReader reader = null; reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { CBDTO cb = new CBDTO(); cb.MaChuyenBay = reader["MaChuyenBay"].ToString(); cb.SanBayDi = reader["SanBayDi"].ToString(); cb.SanBayDen = reader["SanBayDen"].ToString(); cb.TGKhoiHanh = reader["NgayGio"].ToString(); cb.TGBay = int.Parse(reader["ThoiGianBay"].ToString()); cb.SLGheHang1 = int.Parse(reader["SoLuongGheHang1"].ToString()); cb.SLGheHang2 = int.Parse(reader["SoLuongGheHang2"].ToString()); cb.GiaVe = int.Parse(reader["GiaVe"].ToString()); lsChuyenBay.Add(cb); } } con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); return(null); } } } return(lsChuyenBay); }
//Binding dữ liệu vào texbox thuộc Chuyến bay private void MaChuyenBay_comboBox_SelectedIndexChanged(object sender, EventArgs e) { CBDTO cbDTO = MaChuyenBay_comboBox.SelectedItem as CBDTO; HVDTO hvDTO = HangVe_comboBox.SelectedItem as HVDTO; txbSanBayDi.Text = cbDTO.SanBayDi; txbSanBayDen.Text = cbDTO.SanBayDen; txbNgayGio.Text = cbDTO.TGKhoiHanh; txbThoiGianBay.Text = cbDTO.TGBay.ToString(); txbDonGia.Text = cbDTO.GiaVe.ToString(); txbGiaTien.Text = (cbDTO.GiaVe * hvDTO.TiLeDonGia).ToString(); }
//Sửa chuyến bay public bool SuaChuyenBay(CBDTO cb) { string query = string.Empty; query += "UPDATE [LichChuyenBay] SET [SanBayDi] = @SanBayDi, [SanBayDen] = @SanBayDen, [NgayGio] = @NgayGio, [ThoiGianBay] = @ThoiGianBay, [SoLuongGheHang1] = @SoLuongGheHang1, [SoLuongGheHang2] = @SoLuongGheHang2, [GiaVe] = @GiaVe "; query += "WHERE [MaChuyenBay] = @MaChuyenBay"; 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", cb.MaChuyenBay); cmd.Parameters.AddWithValue("@SanBayDi", cb.SanBayDi); cmd.Parameters.AddWithValue("@SanBayDen", cb.SanBayDen); cmd.Parameters.AddWithValue("@NgayGio", cb.TGKhoiHanh); cmd.Parameters.AddWithValue("@ThoiGianBay", cb.TGBay); cmd.Parameters.AddWithValue("@SoLuongGheHang1", cb.SLGheHang1); cmd.Parameters.AddWithValue("@SoLuongGheHang2", cb.SLGheHang2); cmd.Parameters.AddWithValue("@GiaVe", cb.GiaVe); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { cb.Error = ex.Message.Remove(0, 65).Trim(); con.Close(); return(false); } } } return(true); }
public bool SuaChuyenBay(CBDTO cb) { bool re = vbmDAL.SuaChuyenBay(cb); return(re); }
public bool ThemChuyenBay(CBDTO cb) { bool re = vbmDAL.ThemChuyenBay(cb); return(re); }