public bool XoaPhieuDatVe(PDVDTO pd) { string query = string.Empty; query += "DELETE FROM [PhieuDatVe] WHERE [MaPhieuDat] = @MaPhieuDat"; 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("@MaPhieuDat", pd.MaPhieuDat); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { pd.Error = ex.Message.Remove(0, 65).Trim(); con.Close(); return(false); } } } return(true); }
public bool ThemPhieuDatVe(PDVDTO pd) { string query = string.Empty; query += "INSERT INTO [PhieuDatVe] ([MaPhieuDat], [MaHanhKhach], [MaChuyenBay], [MaHangVe]) "; query += "VALUES (@MaPhieuDat,@MaHanhKhach,@MaChuyenBay,@MaHangVe)"; 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("@MaHanhKhach", pd.MaHanhKhach); cmd.Parameters.AddWithValue("@MaChuyenBay", pd.MaChuyenBay); cmd.Parameters.AddWithValue("@MaPhieuDat", pd.MaPhieuDat); cmd.Parameters.AddWithValue("@MaHangVe", pd.MaHangVe); try { con.Open(); cmd.ExecuteNonQuery(); con.Close(); con.Dispose(); } catch (Exception ex) { pd.Error = ex.Message.Remove(0, 65).Trim(); con.Close(); return(false); } } } return(true); }
public List <PDVDTO> select() { string query = string.Empty; query += "SELECT * "; query += "FROM [PhieuDatVe]"; List <PDVDTO> listPhieuDatVe = new List <PDVDTO>(); 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()) { PDVDTO pd = new PDVDTO(); pd.MaChuyenBay = reader["MaChuyenBay"].ToString(); pd.MaHanhKhach = reader["MaHanhKhach"].ToString(); pd.MaHangVe = reader["MaHangVe"].ToString(); listPhieuDatVe.Add(pd); } } con.Close(); con.Dispose(); } catch (Exception ex) { con.Close(); return(null); } } } return(listPhieuDatVe); }
private void DatVe_button_Click(object sender, EventArgs e) { PDVDTO pdvDTO = new PDVDTO(); //2. Kiểm tra data hợp lệ or not //1. Map data from GUI pdvDTO.MaChuyenBay = MaChuyenBay_comboBox.SelectedValue.ToString(); pdvDTO.MaHangVe = HangVe_comboBox.SelectedValue.ToString(); pdvDTO.MaHanhKhach = MaHanhKhach_comboBox.SelectedValue.ToString(); pdvDTO.MaPhieuDat = RandomString(5, true); //3. Thêm vào DB bool kq = pdvBUS.ThemPhieuDatVe(pdvDTO); if (kq == false) { MessageBox.Show("Thêm vé đặt thất bại \n" + pdvDTO.Error, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Thêm vé đặt thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public bool XoaPhieuDatVe(PDVDTO pd) { bool re = pdvDAL.XoaPhieuDatVe(pd); return(re); }
public bool ThemPhieuDatVe(PDVDTO pd) { bool re = pdvDAL.ThemPhieuDatVe(pd); return(re); }