public List <SanPham> GetSanPhams(string key = "") { string sql = "SELECT Id, MaSP, TenSP, BaoHanh, Gia FROM SanPham"; if (string.IsNullOrEmpty(key)) { sql += " WHERE MaSp LIKE " + key + " OR TenSP LIKE " + key; } List <SanPham> sanPhams = new List <SanPham>(); try { da.Connect(); var dr = da.ExecuteReader(sql); while (dr.Read()) { DateTimeOffset?baoHanh; if (dr[3] == null) { baoHanh = null; } else { baoHanh = (DateTimeOffset)dr[3]; } sanPhams.Add(new SanPham { Id = (int)dr[0], MaSp = dr[1].ToString(), TenSp = dr[2].ToString(), BaoHanh = baoHanh, Gia = double.Parse(dr[4].ToString()) }); } da.Disconnet(); return(sanPhams); } catch (Exception e) { MessageBox.Show(e.Message); return(new List <SanPham>()); } }
public bool CheckLogIn(string username, string password) { string sql = "SELECT UserId FROM TaiKhoan WHERE Username = '******' AND Password = '******'"; try { var result = false; da.Connect(); var dr = da.ExecuteScalar(sql); result = dr != null; da.Disconnet(); return(result); } catch (Exception) { return(false); } }
public List <NhaCungCap> GetNhaCungCaps(string key = "") { string sql = "SELECT Id, MaNCC, TenNCC, DiaChi, Sdt, Email, Website FROM NhaCungCap"; if (!string.IsNullOrEmpty(key)) { sql += " WHERE MaNCC LIKE + N'%" + key + "%' OR " + "DiaChi LIKE + N'%" + key + "%' OR " + "Sdt LIKE + N'%" + key + "%' OR " + "Email LIKE + N'%" + key + "%' OR " + "Website LIKE + N'%" + key + "%'"; } List <NhaCungCap> nhaCungCaps = new List <NhaCungCap>(); try { da.Connect(); var dr = da.ExecuteReader(sql); while (dr.Read()) { nhaCungCaps.Add(new NhaCungCap { Id = (int)dr[0], MaNCC = dr[1].ToString(), TenNCC = dr[2].ToString(), DiaChi = dr[3].ToString(), Sdt = dr[4].ToString(), Email = dr[5].ToString(), Website = dr[6].ToString() }); } da.Disconnet(); return(nhaCungCaps); } catch (Exception e) { MessageBox.Show(e.Message); return(new List <NhaCungCap>()); } }