/*Lấy ra dòng dữ liệu và gán vào các hộp text*/ public void SelectCoDK(DChuyenBay DCB, TextEdit txtMaCB, ComboBoxEdit cbMaDB, ComboBoxEdit cbMaMB , TimeEdit dtGioBay, TextEdit txtDiemDi, ComboBoxEdit cbDiemDen , DateTimePicker dtNgayDi, DateTimePicker dtNgayDen, TextEdit txtVeL1, TextEdit txtVeL2, TextEdit txtGhiChu) { try { string path = string.Format("Select * From ChuyenBay Where MaChuyenBay='{0}'", DCB.MCB); DataTable dtt = DA.TbView(path); txtMaCB.EditValue = dtt.Rows[0]["MaChuyenBay"].ToString().Trim(); cbMaDB.EditValue = dtt.Rows[0]["MaDuongBay"].ToString().Trim(); cbMaMB.EditValue = dtt.Rows[0]["MaMayBay"].ToString().Trim(); dtGioBay.Text = dtt.Rows[0]["GioBay"].ToString().Trim(); txtDiemDi.EditValue = dtt.Rows[0]["DiemDi"].ToString().Trim(); cbDiemDen.EditValue = dtt.Rows[0]["DiemDen"].ToString().Trim(); dtNgayDi.Text = dtt.Rows[0]["NgayDi"].ToString().Trim(); dtNgayDen.Text = dtt.Rows[0]["NgayDen"].ToString().Trim(); txtVeL1.EditValue = dtt.Rows[0]["SLV_Loai1"].ToString().Trim(); txtVeL2.EditValue = dtt.Rows[0]["SLV_Loai2"].ToString().Trim(); txtGhiChu.EditValue = dtt.Rows[0]["GhiChu"].ToString().Trim(); //return dt.TbView(path); } catch { XtraMessageBox.Show("Vui lòng kích vào lưới thông tin chọn thông tin cần sửa !", "Chú ý !", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void LoadTTChuyenBay1(DChuyenBay DCB, DevExpress.XtraEditors.ComboBoxEdit cbMaCB, ComboBox cbVeMua) { int a, b; if (cbMaCB.Text != "") { myTB = DA.TbView("Select * From ChuyenBay Where MaChuyenBay='" + cbMaCB.Text + "'"); DCB.MDB = myTB.Rows[0]["MaDuongBay"].ToString().Trim(); DCB.MMB = myTB.Rows[0]["MaMayBay"].ToString().Trim(); DCB.GioBay = myTB.Rows[0]["GioBay"].ToString().Trim(); DCB.NgayDi = ((DateTime)myTB.Rows[0]["NgayDi"]).ToShortDateString().Trim(); DCB.NgayDen = ((DateTime)myTB.Rows[0]["NgayDen"]).ToShortDateString().Trim(); DCB.DiemDi = myTB.Rows[0]["DiemDi"].ToString().Trim(); DCB.DiemDen = myTB.Rows[0]["DiemDen"].ToString().Trim(); DCB.GhiChu = myTB.Rows[0]["GhiChu"].ToString().Trim(); DCB.VeLoai1 = (int)myTB.Rows[0]["SLV_Loai1"]; DCB.VeLoai2 = (int)myTB.Rows[0]["SLV_Loai2"]; cbVeMua.Enabled = true; /*Xử lý sự kiện textchanged của combobox .... nếu số lượng vé * ở 2 ô textbox=0 thì lập tức đổ vào là hết vé và các trường hợp còn lại*/ a = Convert.ToInt32(DCB.VeLoai1); b = Convert.ToInt32(DCB.VeLoai2); cbVeMua.Items.Clear(); if (a == 0 & b == 0) { cbVeMua.Items.Add("Hết Vé"); cbVeMua.Enabled = false; } if (a > 0) { cbVeMua.Items.Add("Vé Loại 1"); } if (b > 0) { cbVeMua.Items.Add("Vé Loại 2"); } myTB = null; } }
/*Thao tác đẩy các dữ liệu lên hộp combobox*/ public void LoadCombo(DChuyenBay DCB, ComboBoxEdit cbMaDB, ComboBoxEdit cbMaMB, ComboBoxEdit cbDiemDen) { cbMaDB.Properties.Items.Clear(); cbMaMB.Properties.Items.Clear(); cbDiemDen.Properties.Items.Clear(); DataTable dt = DA.TbView("select MaDuongBay,ViTri from DuongBay"); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { cbMaDB.Properties.Items.AddRange(new object[] { dt.Rows[i]["MaDuongBay"] }); cbDiemDen.Properties.Items.AddRange(new object[] { dt.Rows[i]["ViTri"] }); } } DataTable dt1 = DA.TbView("select MaMayBay from MayBay"); if (dt1.Rows.Count > 0) { for (int i = 0; i < dt1.Rows.Count; i++) { cbMaMB.Properties.Items.AddRange(new object[] { dt1.Rows[i]["MaMayBay"] }); } } }
/*Phương thức sửa dữ liệu áp dụng cho lập vé bán vs số lượng vé bị thay đổi*/ public void Sua2(DChuyenBay DCB) { /*Bắt sự kiện xóa bảng dữ liệu không tồn tại dữ liệu*/ DataTable myTB = DA.TbView("select * from ChuyenBay"); if (myTB.Rows.Count == 0) { MessageBox.Show("Dữ Liệu Chuyến Bay Không Tồn Tại !", "Thông báo !", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { string sql = string.Format(@"Update ChuyenBay Set MaChuyenBay='{0}',Site='HN',MaDuongBay='{1}',MaMayBay='{2}' ,GioBay='{3}',DiemDi=N'{4}',DiemDen=N'{5}',NgayDi='{6}',NgayDen='{7}' ,SLV_Loai1={8},SLV_Loai2={9},GhiChu=N'{10}' Where MaChuyenBay='{11}'", DCB.MCB, DCB.MDB, DCB.MMB, DCB.GioBay, DCB.DiemDi, DCB.DiemDen, DCB.NgayDi, DCB.NgayDen, DCB.VeLoai1, DCB.VeLoai2, DCB.GhiChu, DCB.MCB); DA.ThucThi(sql); return; } }
/*Phương thức xóa dữ liệu*/ public void Xoa(DChuyenBay DCB, DLichSuHD DLS) { try { DataTable myTB = DA.TbView("select * from ChuyenBay");/*Bắt sự kiện xóa bảng dữ liệu không tồn tại dữ liệu*/ if (myTB.Rows.Count == 0) { MessageBox.Show("Dữ Liệu Chuyến Bay Không Tồn Tại !", "Thông báo !", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { string sql = "Delete From ChuyenBay Where MaChuyenBay='" + DCB.MCB + "'"; DialogResult tl = XtraMessageBox.Show("Có phải bạn muốn Xóa thông tin của Chuyến Bay với ..: " + "\n Điểm Đi: " + DCB.DiemDi + "\n Điểm Đến: " + DCB.DiemDen , "Chú ý", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (tl == DialogResult.Yes) { /*Chèn vào bảng lịch sử hoạt động*/ string time = DateTime.Now.ToLocalTime().ToString(); string str = @"Insert Into LichSuHD(MaNhanVien,Site,TenNhanVien,HanhDong,TGTH)" + " Values('" + frmDangNhap.MaNhanVien + "','" + "HN" + "',N'" + frmDangNhap.TenNhanVien + "',N'Xóa Thông Tin Chuyến Bay Mã: " + DCB.MCB + "','" + time + "')"; DA.ThucThi(str); /*Trèn vào CSDL*/ DA.ThucThi(sql); /*Thực thi câu lệnh Xóa*/ XtraMessageBox.Show("Xóa thành công !", "Thông báo !", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); myTB = null; } } myTB = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/*Phương thức sửa dữ liệu*/ public void Sua(DChuyenBay DCB, DLichSuHD DLS) { /*Bắt sự kiện xóa bảng dữ liệu không tồn tại dữ liệu*/ DataTable myTB = DA.TbView("select * from ChuyenBay"); if (myTB.Rows.Count == 0) { MessageBox.Show("Dữ Liệu Chuyến Bay Không Tồn Tại !", "Thông báo !", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { string sql = string.Format(@"Update ChuyenBay Set MaChuyenBay='{0}',Site='HN',MaDuongBay='{1}',MaMayBay='{2}' ,GioBay='{3}',DiemDi=N'{4}',DiemDen=N'{5}',NgayDi='{6}',NgayDen='{7}' ,SLV_Loai1={8},SLV_Loai2={9},GhiChu=N'{10}' Where MaChuyenBay='{11}'", DCB.MCB, DCB.MDB, DCB.MMB, DCB.GioBay, DCB.DiemDi, DCB.DiemDen, DCB.NgayDi, DCB.NgayDen, DCB.VeLoai1, DCB.VeLoai2, DCB.GhiChu, DCB.MCB); /*Chèn vào bảng lịch sử hoạt động*/ string time = DateTime.Now.ToLocalTime().ToString(); string str = "Insert Into LichSuHD(MaNhanVien,Site,TenNhanVien,HanhDong,TGTH)" + " Values('" + frmDangNhap.MaNhanVien + "','" + "HN" + "',N'" + frmDangNhap.TenNhanVien + "',N'Sửa Thông Tin Chuyến Bay Mã: " + DCB.MCB + "','" + time + "')"; DA.ThucThi(str); DA.ThucThi(sql); return; } }
/*Phương thức chèn vào CSDL*/ public void Them(DChuyenBay DCB, DLichSuHD DLS) { string sql = @"Insert Into ChuyenBay(MaChuyenBay,Site,MaDuongBay,MaMayBay,GioBay, DiemDi,DiemDen,NgayDi,NgayDen,SLV_Loai1,SLV_Loai2,GhiChu)" + "Values('" + DCB.MCB + "','" + "HN" + "','" + DCB.MDB + "','" + DCB.MMB + "','" + DCB.GioBay + "',N'" + DCB.DiemDi + "',N'" + DCB.DiemDen + "','" + DCB.NgayDi + "','" + DCB.NgayDen + "','" + DCB.VeLoai1 + "','" + DCB.VeLoai2 + "',N'" + DCB.GhiChu + "')"; /*Chèn vào bảng lịch sử hoạt động*/ string time = DateTime.Now.ToLocalTime().ToString(); string str = "Insert Into LichSuHD(MaNhanVien,Site,TenNhanVien,HanhDong,TGTH)" + " Values('" + frmDangNhap.MaNhanVien + "','" + "HN" + "',N'" + frmDangNhap.TenNhanVien + "',N'Thêm Thông Tin Chuyến Bay Mã: " + DCB.MCB + "','" + time + "')"; DA.ThucThi(str); DA.ThucThi(sql); XtraMessageBox.Show("Thêm Chuyến Bay Thành Công", "Chú ý !", MessageBoxButtons.OK, MessageBoxIcon.Information); return; }