public bool NhapHangTuNhaCungCap(int nhanVienId, int nccId, List <ChiTietHoaDonMua> chiTietHoaDonMuas) { if (chiTietHoaDonMuas.Any()) { string sql = @"INSERT INTO HoaDonMua VALUES (" + nhanVienId + ", " + nccId + DateTime.Now + ", " + null + ")"; try { var result = false; da.Connect(); result = da.ExecuteNonQuery(sql) > 0; if (result) { var sqlGetId = "SELECT TOP 1 Id FROM HoaDonMua ORDER BY DESC"; var val = da.ExecuteScalar(sqlGetId).ToString(); int chiTietHoaDonMuaId; if (int.TryParse(val, out chiTietHoaDonMuaId)) { double tongTien = 0; foreach (var chiTietHoaDonMua in chiTietHoaDonMuas) { sql = @"INSERT INTO ChiTietHoaDonMua VALUES (" + chiTietHoaDonMuaId + ", " + chiTietHoaDonMua.SanPhamId + ", " + chiTietHoaDonMua.SoLuong + ")"; result = da.ExecuteNonQuery(sql) > 0; sql = @"SELECT Gia FROM SanPham WHERE Id = " + chiTietHoaDonMua.SanPhamId; double gia = double.Parse(da.ExecuteScalar(sql).ToString()); tongTien += gia * chiTietHoaDonMua.SoLuong; } sql = @"UPDATE HoaDonMua SET TongTien = " + tongTien + " WHERE Id = " + chiTietHoaDonMuaId; result = da.ExecuteNonQuery(sql) > 0; } } da.Disconnet(); return(result); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } } else { return(false); } }
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); } }