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_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_backup_Click(object sender, EventArgs e) { string database = Unity.con.Database.ToString(); try { if (txt_backupFileLoc.Text == string.Empty) { MessageBox.Show("Chưa chọn nơi lưu CSDL"); } else { //mở kế nối Unity.OpenConnection(); //string cmd = "BACKUP DATABASE [ " + database + "] TO DISK ='"+txt_backupFileLoc.Text+"\\"+"Database"+"-"+DateTime.Now.ToString("yyyy-mm-dd")+".bak'"; string cmd = "BACKUP DATABASE " + database + " TO DISK ='" + txt_backupFileLoc.Text + "\\" + "Database" + "-" + DateTime.Now.ToString("yyyy-mm-dd") + ".bak'"; //MessageBox.Show(cmd); Unity.Excute(cmd); //MessageBox.Show("chay toi day"); Unity.con.Close(); MessageBox.Show("Backup thành công."); btn_backup.Enabled = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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 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(); } } }
//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_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 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 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 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(); } }