private void button1_Click(object sender, EventArgs e) { if (validate()) //kiểm tra dữ liệu k rỗng thì : { //khai báo chuỗi lệnh sql Unity.OpenConnection(); string sql = "select * from NguoiDung where taikhoan = '" + txt_taikhoan.Text + "' and matkhau = '" + txt_matkhau.Text + "'"; //MessageBox.Show("cau lenh: "+sql); DataTable data = Unity.getDatatable(sql); if (data.Rows.Count <= 0) //gọi hàm getTable từ lớp có giá trị truyền vào là chuỗi lênh select để lấy thông tin từ bảng nếu có số dòng <= 0 thì: { MessageBox.Show("Sai tài khoản hoặc mật khẩu!"); Unity.Close(); } else //nếu số dòng lấy được > 0 thì : { //lay dữ liệu quyền cho form 1 (main) Form1.quyen = data.Rows[0][2].ToString().Trim(); MessageBox.Show("quyen: " + Form1.quyen); MessageBox.Show("Đăng nhập thành công!", "Thông báo!", MessageBoxButtons.OK); Form1 f2 = new Form1(); this.Visible = false; f2.ShowDialog(); Unity.Close(); } //else //{ // MessageBox.Show("Sai thông tin đăng nhập!", "Cảnh báo!", MessageBoxButtons.OK); } }
private void btn_luu_Click(object sender, EventArgs e) { //mở kế nối Unity.OpenConnection(); // MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK); if (them) { try { string sql = "Insert into nguoidung values(" + "N'" + this.txt_taikhoan.Text.ToString() + "',N'" + this.txt_matkhau.Text.ToString() + "',N'" + this.cbx_VT.Text.ToString() + "')"; //MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); String sqlload = "select * from nguoidung"; LoadDB(sqlload); MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } catch (SqlException) { MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK); } } else { //lấy thứ tự record hiện hành int r = dataGridViewTK.CurrentCell.RowIndex; string sql = "Update nguoidung set taikhoan = N'" + this.txt_taikhoan.Text.ToString() + "'," + "matkhau = N'" + this.txt_matkhau.Text.ToString() + "'," + "Vaitro = N'" + this.cbx_VT.Text.ToString() + "'where taikhoan=N'" + dataGridViewTK.Rows[r].Cells[0].Value.ToString() + "' AND matkhau =N'" + dataGridViewTK.Rows[r].Cells[1].Value.ToString() + "' AND Vaitro =N'" + dataGridViewTK.Rows[r].Cells[2].Value.ToString() + "'"; //MessageBox.Show("sql sửa: " + sql, "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); String sqlload = "select * from nguoidung"; LoadDB(sqlload); MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } }
private void btn_luu_Click(object sender, EventArgs e) { //mở kế nối Unity.OpenConnection(); MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK); if (them) { try { string sql = "Insert into ThanhPho values(" + "N'" + this.txt_thanhpho.Text.ToString() + "',N'" + this.txt_tenthanhpho.Text.ToString() + "')"; //MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); this.showData("Select ThanhPho , TenThanhPho from ThanhPho"); MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } catch (SqlException) { MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK); } } else { //lấy thứ tự record hiện hành int r = dataGridViewQLDMTP.CurrentCell.RowIndex; //lấy thanhpho của record hiện hành string strThanhPho = dataGridViewQLDMTP.Rows[r].Cells[0].Value.ToString(); string sql = "Update ThanhPho set TenThanhPho = N'" + this.txt_tenthanhpho.Text.ToString() + "' where ThanhPho='" + strThanhPho + "'"; Unity.Excute(sql); this.showData("Select ThanhPho , TenThanhPho from ThanhPho"); MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } }
private void btn_xoa_Click(object sender, EventArgs e) { try { //mở kế nối Unity.OpenConnection(); //lấy thứ tự record hiện hành int r = dataGridViewTK.CurrentCell.RowIndex; //lấy thanhpho của record hiện hành string strtaikhoan = dataGridViewTK.Rows[r].Cells[0].Value.ToString(); //câu lệnh SQL //string sql = "Delete From Chitiethoadon Where MaHD = '" + strmaHD + "'"; string sql = "Delete From NguoiDung where taikhoan=N'" + strtaikhoan + "'"; //MessageBox.Show("sql xóa: " + sql, "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); //MessageBox.Show("chại đến đây", "Cảnh báo", MessageBoxButtons.OK); String sqlload = "select * from NguoiDung"; LoadDB(sqlload); MessageBox.Show("Xóa thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } catch (SqlException) { MessageBox.Show("Lỗi dữ liệu đã được dùng!", "Cảnh báo", MessageBoxButtons.OK); } }
private void btn_them_Click(object sender, EventArgs e) { them = true; //khoi tao lai cac text this.txt_taikhoan.ResetText(); this.cbx_VT.ResetText(); this.txt_matkhau.ResetText(); //khong Cho thao tác trên nút Thêm/Sửa/Xóa/Trở về. this.btn_them.Enabled = false; this.btn_sua.Enabled = false; this.btn_xoa.Enabled = false; this.btn_trove.Enabled = false; //cho thao tác trên nút lưu, hũy this.btn_luu.Enabled = true; this.btn_huybo.Enabled = true; this.panel.Enabled = true; this.txt_taikhoan.Enabled = true; //đưa dữ liệu lên combo box //lấy thứ tự record hiện hành int r = dataGridViewTK.CurrentCell.RowIndex; //tải dữ liệu vào bảng VT DataTable dt = new DataTable(); Unity.OpenConnection(); dt = Unity.getDatatable("select * from Nguoidung"); this.cbx_VT.DataSource = dt; this.cbx_VT.DisplayMember = "Vaitro"; this.cbx_VT.ValueMember = "Vaitro"; this.cbx_VT.Text = dataGridViewTK.Rows[r].Cells[2].Value.ToString(); Unity.Close(); //đua trỏ this.txt_taikhoan.Focus(); }
public void LoadDB(string sql) { Unity.OpenConnection(); //truy xuất đến bản Khachang this.dataGridViewTK.DataSource = Unity.getDatatable(sql); this.dataGridViewTK.AutoResizeColumns(); Unity.Close(); }
private void button1_Click(object sender, EventArgs e) { if (txt_taikhoan.Text.Trim() == "") { MessageBox.Show("Chưa nhập tên tài khoản!", "Cảnh báo", MessageBoxButtons.OK); txt_taikhoan.Focus(); } else if (txt_matkhau.Text.Trim() == "") { MessageBox.Show("Chưa nhập mật khẩu!", "Cảnh báo", MessageBoxButtons.OK); txt_matkhau.Focus(); } else if (txt_matkhaumoi.Text.Trim() == "") { MessageBox.Show("Chưa nhập mật khẩu mới!", "Cảnh báo", MessageBoxButtons.OK); txt_matkhaumoi.Focus(); } else if (txt_matkhaumoilaplai.Text.Trim() == "") { MessageBox.Show("Chưa nhập mật khẩu mới nhập lại!", "Cảnh báo", MessageBoxButtons.OK); txt_matkhaumoilaplai.Focus(); } else { //String userName ="******"; //String passWord = "******"; //changePassword(userName, passWord); //Doc du lieu if (Check(txt_taikhoan.Text, txt_matkhau.Text) == true) { if (txt_matkhaumoi.Text.Trim() == txt_matkhaumoilaplai.Text.Trim()) { MessageBox.Show("Đổi mật khẩu thành công!", "Thông báo", MessageBoxButtons.OK); //xu ly cap nhat mat khau string sql = "Update nguoidung set matkhau = N'" + this.txt_matkhaumoi.Text.ToString() + "'where taikhoan=N'" + this.txt_taikhoan.Text.ToString() + "'"; Unity.OpenConnection(); MessageBox.Show("sql capnhat: " + sql, "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); Unity.Close(); //String userName ="******"; //String passWord = "******"; } else { MessageBox.Show("Mật khẩu mới không trùng nhau!", "Cảnh báo", MessageBoxButtons.OK); } } else { MessageBox.Show("Không tồn tại tài khoản này!", "Cảnh báo", MessageBoxButtons.OK); txt_taikhoan.Focus(); } } }
private Boolean Check(String taikhoan, String matkhau) { Unity.OpenConnection(); string sql = "select * from NguoiDung where taikhoan = '" + taikhoan + "' and matkhau = '" + matkhau + "'"; //MessageBox.Show("cau lenh: "+sql); DataTable data = Unity.getDatatable(sql); if (data.Rows.Count <= 0) //gọi hàm getTable từ lớp có giá trị truyền vào là chuỗi lênh select để lấy thông tin từ bảng nếu có số dòng <= 0 thì: { Unity.Close(); return(false); } else //nếu số dòng lấy được > 0 thì : { Unity.Close(); return(true); } }
//hàm đưa dữ liệu từ datagrid vào SQL public void them() { //mở kế nối Unity.OpenConnection(); //====================== for (int i = 1; i < dataGridView1.RowCount - 1; i++) //bỏ qua i= 0 là title của dadagridview { //câu lệnh SQl String sql = "Insert into ThanhPho values(N'" + dataGridView1.Rows[i].Cells["A"].Value + "',N'" + dataGridView1.Rows[i].Cells["B"].Value + "')"; MessageBox.Show(sql); Unity.Excute(sql); MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); } //====================== //đóng kết nối Unity.Close(); }
private void btn_them_Click(object sender, EventArgs e) { them = true; //khoi tao lai cac text this.cbx_MaHD.ResetText(); this.cbx_maSP.ResetText(); this.txt_soluong.ResetText(); //khong Cho thao tác trên nút Thêm/Sửa/Xóa/Trở về. this.btn_them.Enabled = false; this.btn_sua.Enabled = false; this.btn_xoa.Enabled = false; this.btn_trove.Enabled = false; //cho thao tác trên nút lưu, hũy this.btn_luu.Enabled = true; this.btn_huybo.Enabled = true; this.panel.Enabled = true; this.cbx_MaHD.Enabled = true; //đưa dữ liệu lên combo box //lấy thứ tự record hiện hành int r = dataGridViewQLDMCTHD.CurrentCell.RowIndex; //tải dữ liệu vào bảng HD DataTable dt = new DataTable(); Unity.OpenConnection(); dt = Unity.getDatatable("select * from HoaDon"); this.cbx_MaHD.DataSource = dt; this.cbx_MaHD.DisplayMember = "MaHD"; this.cbx_MaHD.ValueMember = "MaHD"; this.cbx_MaHD.Text = dataGridViewQLDMCTHD.Rows[r].Cells[0].Value.ToString(); Unity.Close(); //tải dữ liệu vào bảng SP DataTable dt1 = new DataTable(); Unity.OpenConnection(); dt1 = Unity.getDatatable("select * from SanPham"); this.cbx_maSP.DataSource = dt1; this.cbx_maSP.DisplayMember = "MaSP"; this.cbx_maSP.ValueMember = "MaSP"; this.cbx_maSP.Text = dataGridViewQLDMCTHD.Rows[r].Cells[1].Value.ToString(); Unity.Close(); //đua trỏ this.cbx_MaHD.Focus(); }
private void btn_xoa_Click(object sender, EventArgs e) { try { //mở kế nối Unity.OpenConnection(); //lấy thứ tự record hiện hành int r = dataGridViewQLDMTP.CurrentCell.RowIndex; //lấy thanhpho của record hiện hành string strThanhPho = dataGridViewQLDMTP.Rows[r].Cells[0].Value.ToString(); //câu lệnh SQL string sql = "Delete From ThanhPho Where ThanhPho = '" + strThanhPho + "'"; Unity.Excute(sql); this.showData("Select ThanhPho , TenThanhPho from ThanhPho"); MessageBox.Show("Xóa thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } catch (SqlException) { MessageBox.Show("Lỗi dữ liệu đã được dùng!", "Cảnh báo", MessageBoxButtons.OK); } }
private void btn_luu_Click(object sender, EventArgs e) { //mở kế nối Unity.OpenConnection(); // MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK); if (them) { try { string sql = "Insert into Chitiethoadon values(" + "N'" + this.cbx_MaHD.Text.ToString() + "',N'" + this.cbx_maSP.Text.ToString() + "',N'" + this.txt_soluong.Text.ToString() + "')"; //MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); String sqlload = "select * from Chitiethoadon"; LoadDB(sqlload); MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } catch (SqlException) { MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK); } } else { //lấy thứ tự record hiện hành int r = dataGridViewQLDMCTHD.CurrentCell.RowIndex; //lấy thanhpho của record hiện hành string strMaHD = dataGridViewQLDMCTHD.Rows[r].Cells[0].Value.ToString(); string sql = "Update Chitiethoadon set MaHD = N'" + this.cbx_MaHD.Text.ToString() + "'," + "MaSP = N'" + this.cbx_maSP.Text.ToString() + "'," + "Soluong = N'" + this.txt_soluong.Text.ToString() + "'where MaHD=N'" + dataGridViewQLDMCTHD.Rows[r].Cells[0].Value.ToString() + "' AND MaSP =N'" + dataGridViewQLDMCTHD.Rows[r].Cells[1].Value.ToString() + "' AND Soluong =N'" + dataGridViewQLDMCTHD.Rows[r].Cells[2].Value.ToString() + "'"; MessageBox.Show("sql sửa: " + sql, "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); String sqlload = "select * from Chitiethoadon"; LoadDB(sqlload); MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } }
private void btn_luu_Click(object sender, EventArgs e) { //mở kế nối Unity.OpenConnection(); // MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK); if (them) { try { string sql = "Insert into NhanVien values(" + "N'" + this.txt_maNV.Text.ToString() + "',N'" + this.txt_holot.Text.ToString() + "',N'" + this.txt_ten.Text.ToString() + "',N'" + this.txt_ngaysinh.Text.ToString() + "',N'" + this.txt_diachi.Text.ToString() + "',N'" + this.txt_dienthoai.Text.ToString() + "')"; MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); String sqlload = "select * from NhanVien"; LoadDB(sqlload); MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } catch (SqlException) { MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK); } } else { //lấy thứ tự record hiện hành int r = dataGridViewQLDMNV.CurrentCell.RowIndex; //lấy thanhpho của record hiện hành string strMaNV = dataGridViewQLDMNV.Rows[r].Cells[0].Value.ToString(); string sql = "Update NhanVien set MaNV = N'" + this.txt_maNV.Text.ToString() + "'," + "Holot = N'" + this.txt_holot.Text.ToString() + "'," + "Ten = N'" + this.txt_ten.Text.ToString() + "'," + "Ngaysinh = N'" + this.txt_ngaysinh.Text.ToString() + "'," + "Diachi = N'" + this.txt_diachi.Text.ToString() + "'," + "Dienthoai = N'" + this.txt_dienthoai.Text.ToString() + "'where MaNV='" + strMaNV + "'"; MessageBox.Show("chuoi: " + sql.ToString(), "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); String sqlload = "select * from NhanVien"; LoadDB(sqlload); MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } }
private void btn_luu_Click(object sender, EventArgs e) { //mở kế nối Unity.OpenConnection(); // MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK); if (them) { try { string sql = "Insert into SanPham values(" + "N'" + this.txt_maSP.Text.ToString() + "',N'" + this.txt_tensp.Text.ToString() + "',N'" + this.txt_dvt.Text.ToString() + "',N'" + this.txt_dongia.Text.ToString() + "','null'" + ")"; MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); String sqlload = "select * from SanPham"; LoadDB(sqlload); MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } catch (SqlException) { MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK); } } else { //lấy thứ tự record hiện hành int r = dataGridViewQLDMSP.CurrentCell.RowIndex; //lấy thanhpho của record hiện hành string strMaSP = dataGridViewQLDMSP.Rows[r].Cells[0].Value.ToString(); string sql = "Update SanPham set MaSP = N'" + this.txt_maSP.Text.ToString() + "'," + "TenSP = N'" + this.txt_tensp.Text.ToString() + "'," + "Donvitinh = N'" + this.txt_dvt.Text.ToString() + "'," + "Dongia = N'" + this.txt_dongia.Text.ToString() + "',Hinh = 'null' where MaSP='" + strMaSP + "'"; MessageBox.Show("chuoi: " + sql.ToString(), "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); String sqlload = "select * from SanPham"; LoadDB(sqlload); MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } }
private void btn_luu_Click(object sender, EventArgs e) { //mở kế nối Unity.OpenConnection(); // MessageBox.Show("Biến thêm: " + them.ToString(), "Cảnh báo", MessageBoxButtons.OK); if (them) { try { string sql = "Insert into KhachHang values(" + "N'" + this.txt_maKH.Text.ToString() + "',N'" + this.txt_tencongty.Text.ToString() + "',N'" + this.txt_diachi.Text.ToString() + "',N'" + this.cbx_thanhpho.Text.ToString() + "',N'" + this.txt_dienthoai.Text.ToString() + "')"; //MessageBox.Show("sql thêm: " + sql, "Cảnh báo", MessageBoxButtons.OK); Unity.Excute(sql); String sqlload = "select * from Khachhang"; LoadDB(sqlload); MessageBox.Show("Thêm dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } catch (SqlException) { MessageBox.Show("Lỗi!", "Cảnh báo", MessageBoxButtons.OK); } } else { //lấy thứ tự record hiện hành int r = dataGridViewQLDMKH.CurrentCell.RowIndex; //lấy thanhpho của record hiện hành string strMaKH = dataGridViewQLDMKH.Rows[r].Cells[0].Value.ToString(); string sql = "Update KhachHang set MaKH = N'" + this.txt_maKH.Text.ToString() + "'," + "TenCty = N'" + this.txt_tencongty.Text.ToString() + "'," + "Diachi = N'" + this.txt_diachi.Text.ToString() + "'," + "ThanhPho = N'" + this.cbx_thanhpho.Text.ToString() + "'," + "Dienthoai = N'" + this.txt_dienthoai.Text.ToString() + "'where MaKH='" + strMaKH + "'"; Unity.Excute(sql); String sqlload = "select * from Khachhang"; LoadDB(sqlload); MessageBox.Show("Cập nhật dữ liệu thành công!", "Thông báo", MessageBoxButtons.OK); Unity.Close(); } }
private void FormQLDMTP_FormClosing(object sender, FormClosingEventArgs e) { Unity.Close(); }
private void Formdanhmucsanpham_FormClosing(object sender, FormClosingEventArgs e) { Unity.Close(); }
private void Formdanhmuckhachhang_FormClosing(object sender, FormClosingEventArgs e) { Unity.Close(); }
private void Formdanhmucthanhpho_FormClosing(object sender, FormClosingEventArgs e) { Unity.Close(); }
private void Formdanhmucchitiethoadon_FormClosing(object sender, FormClosingEventArgs e) { Unity.Close(); }