Esempio n. 1
0
        public Product getProductByName(string keyWord)
        {
            string query = "SELECT * FROM ProductTable WHERE Name = '" + keyWord + "';";

            try
            {
                SqlDataReader reader = DBConnection.getReader(query);

                while (reader.Read())
                {
                    Product product = new Product()
                    {
                        ID         = reader.GetInt32(reader.GetOrdinal("ProductId")),
                        Name       = reader.GetString(reader.GetOrdinal("Name")),
                        vender     = db.Venders.getVender(reader.GetInt32(reader.GetOrdinal("VenderId"))),
                        AmountLeft = reader.GetDouble(reader.GetOrdinal("AmountLeft")),
                        UnitPrice  = reader.GetDouble(reader.GetOrdinal("UnitPrice"))
                    };
                    if (product != null)
                    {
                        return(product);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Esempio n. 2
0
        public Login getUser(Login user)
        {
            Login  loginUser = new Login();
            string query     = "SELECT * FROM LoginTable WHERE UserId = '" + user.UserId + "'; ";

            try
            {
                SqlDataReader reader = DBConnection.getReader(query);

                while (reader.Read())
                {
                    loginUser = new Login()
                    {
                        UserId       = reader.GetInt32(reader.GetOrdinal("UserId")),
                        UserPassword = reader.GetString(reader.GetOrdinal("Password")),
                        UserStatus   = reader.GetInt32(reader.GetOrdinal("Status"))
                    };
                }
            }
            catch (Exception)
            {
                throw;
            }
            if (loginUser.UserId == user.UserId)
            {
                return(loginUser);
            }
            return(null);
        }
Esempio n. 3
0
        public ArrayList searchFor(string keyWord)
        {
            keyWord = "%" + keyWord + "%";
            ArrayList result = new ArrayList();
            string    query  = "SELECT * FROM ProductTable WHERE Name LIKE '" + keyWord + "';";

            try
            {
                SqlDataReader reader = DBConnection.getReader(query);

                while (reader.Read())
                {
                    Product product = new Product()
                    {
                        ID         = reader.GetInt32(reader.GetOrdinal("ProductId")),
                        Name       = reader.GetString(reader.GetOrdinal("Name")),
                        UnitPrice  = reader.GetDouble(reader.GetOrdinal("UnitPrice")),
                        vender     = db.Venders.getVender(reader.GetInt32(reader.GetOrdinal("VenderId"))),
                        AmountLeft = reader.GetDouble(reader.GetOrdinal("AmountLeft"))
                    };
                    result.Add(product);
                }
            }
            catch (Exception)
            {
                throw;
            }
            if (result != null)
            {
                return(result);
            }
            return(null);
        }
Esempio n. 4
0
        public User getUser(int userId)
        {
            string query = "SELECT * FROM Users WHERE UserId = '" + userId + "'; ";

            try
            {
                SqlDataReader reader = DBConnection.getReader(query);

                while (reader.Read())
                {
                    User user = new User()
                    {
                        Id       = reader.GetInt32(reader.GetOrdinal("UserId")),
                        Name     = reader.GetString(reader.GetOrdinal("Name")),
                        Contact  = reader.GetInt32(reader.GetOrdinal("Contact")),
                        Salary   = (float)reader.GetDouble(reader.GetOrdinal("Salary")),
                        JoidDate = reader.GetDateTime(reader.GetOrdinal("JoinDate"))
                    };
                    if (user != null)
                    {
                        return(user);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Esempio n. 5
0
        public ArrayList getAllVender()
        {
            ArrayList result = new ArrayList();
            string    query  = "SELECT * FROM VenderTable ;";

            try
            {
                SqlDataReader reader = DBConnection.getReader(query);
                while (reader.Read())
                {
                    Vender vender = new Vender()
                    {
                        ID      = reader.GetInt32(reader.GetOrdinal("VenderId")),
                        Name    = reader.GetString(reader.GetOrdinal("Name")),
                        Contact = reader.GetString(reader.GetOrdinal("Contact")),
                        Company = reader.GetString(reader.GetOrdinal("Company"))
                    };
                    result.Add(vender);
                }
            }
            catch (Exception)
            {
                throw;
            }
            if (result != null)
            {
                return(result);
            }
            return(null);
        }
Esempio n. 6
0
        public Vender getVenderbyName(string name)
        {
            string query = "SELECT * FROM VenderTable WHERE Name = '" + name + "'; ";

            try
            {
                SqlDataReader reader = DBConnection.getReader(query);

                while (reader.Read())
                {
                    Vender vender = new Vender()
                    {
                        ID      = reader.GetInt32(reader.GetOrdinal("VenderId")),
                        Name    = reader.GetString(reader.GetOrdinal("Name")),
                        Contact = reader.GetString(reader.GetOrdinal("Contact")),
                        Company = reader.GetString(reader.GetOrdinal("Company"))
                    };
                    if (vender != null)
                    {
                        return(vender);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
Esempio n. 7
0
        public ArrayList getAllVenderName()
        {
            ArrayList result = new ArrayList();
            string    query  = "SELECT Name FROM VenderTable ;";

            try
            {
                SqlDataReader reader = DBConnection.getReader(query);

                while (reader.Read())
                {
                    result.Add(reader.GetString(reader.GetOrdinal("Name")));
                }
            }
            catch (Exception)
            {
                throw;
            }
            if (result != null)
            {
                return(result);
            }
            return(null);
        }