1
1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace De_1
{
public partial class Form1 : Form
{
string ketnoi = @"Data Source=LAPTOP-H0KQF1IJ\SQLEXPRESS;Initial Catalog=QLNS;Integrated
Security=True";
SqlConnection con = null;
public Form1()
{
InitializeComponent();
}
}
private void dgvthongke_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void ClearInputFields()
{
txbhovaten.Text = "";
txbquequan.Text = "";
txbdonvi.Text = "";
txbhamhoc.Text = "";
rbnam.Checked = false;
rbnu.Checked = false;
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace de_3
{
public partial class Form1 : Form
{
string ketnoi = @"Data Source=LAPTOP-H0KQF1IJ\SQLEXPRESS;Initial
Catalog=QLSV;Integrated Security=True";
SqlConnection con = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
con = new SqlConnection(ketnoi);
con.Open();
string sql = "select * from thongke ";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
da.Fill(dt);
dgvthongke.DataSource = dt;
}
}
private void btnthem_Click(object sender, EventArgs e)
{
string masinhvien = txbmasv.Text;
string hovaten = txbhovaten.Text;
string ngaysinh = dtpngaysinh.Text;
string noisinh = txbnoisinh.Text;
string gioitinh = "";
if (rbnam.Checked)
{
gioitinh = "Nam";
}
else if (rbnu.Checked)
{
gioitinh = "Nữ";
}
using (SqlConnection connection = new SqlConnection(ketnoi))
{
string query = "insert into thongke (masv,tensv,ngaysinh,noisinh,gioitinh) values
(@masv,@tensv,@ngaysinh,@noisinh,@gioitinh)";
using (SqlCommand command = new SqlCommand(query, connection))
{
command.Parameters.AddWithValue("@masv", masinhvien);
command.Parameters.AddWithValue("@tensv", hovaten);
command.Parameters.AddWithValue("@ngaysinh", ngaysinh);
command.Parameters.AddWithValue("@noisinh", noisinh);
command.Parameters.AddWithValue("@gioitinh", gioitinh);
connection.Open();
int sodong = command.ExecuteNonQuery();
if (sodong > 0)
{
MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
string sql = "select * from thongke ";
SqlDataAdapter da = new SqlDataAdapter(sql, connection);
DataTable dt = new DataTable();
da.Fill(dt);
dgvthongke.DataSource = dt;
}
else
{
MessageBox.Show("Thêm dữ liệu không thành công!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
else
{
MessageBox.Show("Vui lòng chọn một dòng để sửa!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
if (rbnam.Checked)
{
gioitinh = "Nam";
}
else if (rbnu.Checked)
{
gioitinh = "Nữ";
}
// Tạo câu truy vấn SQL tương ứng với thông tin tìm kiếm
string query = "SELECT * FROM thongke WHERE masv LIKE @masv AND tensv
LIKE @tensv AND noisinh LIKE @noisinh";
// Thêm điều kiện tìm kiếm theo giới tính nếu giới tính được chọn
if (!string.IsNullOrEmpty(gioitinh))
{
query += " AND gioitinh = @gioitinh";
}
// Thêm điều kiện tìm kiếm theo ngày sinh nếu có
if (!string.IsNullOrEmpty(ngaysinh))
{
query += " AND ngaysinh = @ngaysinh";
}
connection.Open();
SqlDataAdapter da = new SqlDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count == 0)
{
MessageBox.Show("Không tìm thấy thông tin.", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
dgvthongke.DataSource = dt;
}
}
}
De 4
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace de_4_quan_ly_diem_thi
{
public partial class Form1 : Form
{
string ketnoi = @"Data Source=LAPTOP-H0KQF1IJ\SQLEXPRESS;Initial
Catalog=QLDT;Integrated Security=True";
SqlConnection con = null;
public Form1()
{
InitializeComponent();
}
connection.Open();
int count = (int)commandCheckDuplicate.ExecuteScalar();
if (count > 0)
{
MessageBox.Show("Mã sinh viên đã tồn tại!", "Lỗi",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
connection.Open();
int sodong = command.ExecuteNonQuery();
if (sodong > 0)
{
MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
// Load lại dữ liệu trên DataGridView
string sql = "SELECT * FROM thongke";
SqlDataAdapter da = new SqlDataAdapter(sql, connection);
DataTable dt = new DataTable();
da.Fill(dt);
dgvthongke.DataSource = dt;
}
else
{
MessageBox.Show("Cập nhật dữ liệu không thành công!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
else
{
MessageBox.Show("Vui lòng chọn một dòng để sửa!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
connection.Open();
int sodong = command.ExecuteNonQuery();
if (sodong > 0)
{
MessageBox.Show("Xóa dữ liệu thành công!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
// Load lại dữ liệu trên DataGridView
string sql = "SELECT * FROM thongke";
SqlDataAdapter da = new SqlDataAdapter(sql, connection);
DataTable dt = new DataTable();
da.Fill(dt);
dgvthongke.DataSource = dt;
}
else
{
MessageBox.Show("Xóa dữ liệu không thành công!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
}
else
{
MessageBox.Show("Vui lòng chọn một dòng để xóa!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
// Áp dụng bộ lọc vào DataView của DataTable hiện tại của DataGridView
((DataTable)dgvthongke.DataSource).DefaultView.RowFilter = filterExpression;
}
}
}
De chon ve xem phim
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace quan_ly_ban_ve_xem_phim
{
public partial class Form1 : Form
{
Dictionary<Button, int> seatPrices = new Dictionary<Button, int>();
int totalPayment = 0;
public Form1()
{
InitializeComponent();
InitializeSeatPrices();
InitializeSeatButtons();
cbChonPhim.SelectedIndexChanged += cbChonPhim_SelectedIndexChanged;
}
private void InitializeSeatPrices()
{
// Thiết lập giá vé cho từng ghế
seatPrices.Add(button1, 25000);
seatPrices.Add(button2, 25000);
seatPrices.Add(button3, 25000);
seatPrices.Add(button4, 25000);
seatPrices.Add(button5, 30000);
seatPrices.Add(button6, 30000);
seatPrices.Add(button7, 30000);
seatPrices.Add(button8, 30000);
seatPrices.Add(button9, 35000);
seatPrices.Add(button10, 35000);
seatPrices.Add(button11, 35000);
seatPrices.Add(button12, 35000);
seatPrices.Add(button13, 40000);
seatPrices.Add(button14, 40000);
seatPrices.Add(button15, 40000);
seatPrices.Add(button16, 40000);
}
private void InitializeSeatButtons()
{
// Gắn sự kiện click cho từng ghế
foreach (Button button in seatPrices.Keys)
{
button.Click += SeatButton_Click;
}
}
private void SeatButton_Click(object sender, EventArgs e)
{
Button seatButton = (Button)sender;
}
private void cbChonPhim_SelectedIndexChanged(object sender, EventArgs e)
{
// Lấy tên phim từ combobox cbChonPhim
string selectedMovie = cbChonPhim.SelectedItem.ToString();
}
}
QlMayTinh
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ban_may_tinh
{
public partial class Form1 : Form
{
string ketnoi = @"Data Source=LAPTOP-H0KQF1IJ\SQLEXPRESS;Initial
Catalog=QLMAYTINH;Integrated Security=True";
SqlConnection con = null;
public Form1()
{
InitializeComponent();
}
txbdongia.TextChanged += txbdongia_TextChanged;
nudsoluong.ValueChanged += nudsoluong_ValueChanged;
}
// Kiểm tra xem người dùng đã chọn hàng nào trong DataGridView chưa
if (dgvthongke.SelectedRows.Count > 0)
{
// Lấy chỉ số của hàng được chọn
int rowIndex = dgvthongke.SelectedRows[0].Index;
// Kiểm tra xem mã hóa đơn đã được chọn có trùng với mã hóa đơn nhập vào
không
if (mahd != selectedMaHD)
{
MessageBox.Show("Không thể thay đổi mã hóa đơn!", "Thông báo",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
Muontruyen
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace cho_thue_truyen
{
public partial class Form1 : Form
{
string ketnoi = @"Data Source=LAPTOP-H0KQF1IJ\SQLEXPRESS;Initial Catalog=thuetruyen1;Integrated
Security=True";
SqlConnection con = null;
Dictionary<string, decimal> giaTriTruyen = new Dictionary<string, decimal>()
{
{ "manga", 50000 },
{ "truyen hai", 100000 },
{ "truyen ma", 150000 }
};
public Form1()
{
InitializeComponent();
}
dgvthongke.DataSource = dt;
}
private void cbtentruyen_SelectedIndexChanged(object sender, EventArgs e)
{
if (cbtentruyen.SelectedItem != null)
{
KeyValuePair<string, decimal> selectedItem = (KeyValuePair<string, decimal>)cbtentruyen.SelectedItem;
txbdongia.Text = selectedItem.Value.ToString();
}
}
dgvthongke.DataSource = dataTable;
Form1_Load(sender, e);
}
}
connection.Open();
int sodong = command.ExecuteNonQuery();
if (sodong > 0)
{
MessageBox.Show("Xóa dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK,
MessageBoxIcon.Information);
// Load lại dữ liệu trên DataGridView
string sql = "SELECT * FROM thongke";
SqlDataAdapter da = new SqlDataAdapter(sql, connection);
DataTable dt = new DataTable();
da.Fill(dt);
dgvthongke.DataSource = dt;
}
else
{
MessageBox.Show("Xóa dữ liệu không thành công!", "Thông báo", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
}
}
else
{
MessageBox.Show("Vui lòng chọn một dòng để xóa!", "Thông báo", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
QL hoa qua
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Quan_ly_ban_hoa_qua
{
public partial class Form1 : Form
{
string ketnoi = @"Data Source=LAPTOP-H0KQF1IJ\SQLEXPRESS;Initial Catalog=QLHOAQUA;Integrated
Security=True";
SqlConnection con = null;
public Form1()
{
InitializeComponent();
cbloaihoaqua.SelectedIndexChanged += cbloaihoaqua_SelectedIndexChanged;
nudsoluong.ValueChanged += nudsoluong_ValueChanged;
txbsotienkhachdua.TextChanged += txbsotienkhachdua_TextChanged;
btnthem.Click += btnthem_Click;
}
// Nếu loại hoa quả tồn tại trong danh sách giá, hiển thị giá tương ứng
if (giaHoaQua.ContainsKey(loaiHoaQua))
{
txbdongia.Text = giaHoaQua[loaiHoaQua].ToString();
}
else
{
txbdongia.Text = "0"; // Hoặc một giá trị mặc định khác bạn chọn
}
}
private void nudsoluong_ValueChanged(object sender, EventArgs e)
{
// Kiểm tra xem đã chọn loại hoa quả chưa
if (cbloaihoaqua.SelectedItem != null)
{
// Lấy đơn giá từ txbdongia và chuyển đổi thành kiểu số
if (int.TryParse(txbdongia.Text, out int donGia))
{
// Lấy số lượng từ NumericUpDown
int soLuong = (int)nudsoluong.Value;