Thi CSDL
Thi CSDL
Thi CSDL
Form.cs
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 PhamThiMinhPhuong_94685
{
public partial class FrmQuanLyNhanVien : Form
{
public FrmQuanLyNhanVien()
{
InitializeComponent();
}
private void loadDgvNhanVien()
{
dgvNhanVien.DataSource = Database.Query("SELECT * FROM NhanVien");
//cbbLoaiPhim.DataSource = Database.Query("SELECT * FROM LoaiPhim");
- trong trường hợp dùng cbb
}
private void FrmQuanLyNhanVien_Load(object sender, EventArgs e)
{
loadDgvNhanVien();
}
private bool check()
{
bool kt = true;
if (tboHoTen.Text.Trim() == "")
{
loi.SetError(tboHoTen, "Chưa nhập họ tên");
kt = false;
}
if (tboHoTen.Text.Trim().Length > 30)
{
loi.SetError(tboHoTen, "Họ tên vượt quá 30 ký tự");
kt = false;
}
if (tboDienThoai.Text.Trim() == "")
{
loi.SetError(tboDienThoai, "Chưa nhập số điện thoại");
kt = false;
}
return kt;
}
Database.cs
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PhamThiMinhPhuong_94685
{
class Database
{
private static SqlConnection conn = new SqlConnection(@"Data Source=LAPTOP-
4A3VP30J;Initial Catalog=BaiKiemTra3;Integrated Security=True;Encrypt=False");
public static void Execute(string sql, Dictionary<string, object> parameters = null)
{
conn.Open();
SqlCommand command = new SqlCommand(sql, conn);
if (parameters != null)
foreach (string key in parameters.Keys)
command.Parameters.Add(new SqlParameter(key, parameters[key]));
try
{
command.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
}