public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            supplier other = obj as supplier;

            if (other == null)
            {
                return(false);
            }

            return(this.supplier_number == other.supplier_number);
        }
        public void AddNewProduct(supplier s)
        {
            products   e   = new products();
            productDAO dao = new productDAO();

            Console.WriteLine("enter the name of the product you want to Add");
            string product = Console.ReadLine();

            SqlCommand cmd = new SqlCommand();

            cmd.Connection = new SqlConnection(@"Data Source=.;Initial Catalog=DBschool;Integrated Security=True");
            cmd.Connection.Open();
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add(new SqlParameter("@product", product));
            cmd.CommandText = $"SELECT * FROM products where product_name = '{product}'";

            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);

            if (reader.Read() == true)
            {
                {
                    e.product_number  = (int)reader["product_number"];
                    e.product_name    = (string)reader["product_name"];
                    e.supplier_number = (int)reader["supplier_number"];
                    e.price           = (int)reader["price"];
                    e.amount          = (int)reader["amount"];
                };

                if (e.supplier_number == s.supplier_number)
                {
                    Console.WriteLine("How many product do you want to Add to stock?");
                    int amount = Convert.ToInt32(Console.ReadLine());
                    dao.addExistingPoduct(product, amount);
                }
                else
                {
                    Console.WriteLine("product exist at another supplier stock");
                }
            }
            else
            {
                dao.AddNewProduct(product, s);
            }

            cmd.Connection.Close();
        }
Ejemplo n.º 3
0
        static public supplier exsitingSupplier(string userName, int password)
        {
            supplier supplierLogIn = null;

            suppliersDAO dao2 = new suppliersDAO();
            SqlCommand   cmd  = new SqlCommand();

            cmd.Connection = new SqlConnection(@"Data Source=.;Initial Catalog=DBschool;Integrated Security=True");
            cmd.Connection.Open();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = ($"select * from suppliers where password = {password} and user_Name = '{userName}'");

            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default);

            while (reader.Read() == true)
            {
                supplierLogIn = new supplier
                {
                    supplier_number = (int)reader["supplier_number"],
                    user_name       = (string)reader["user_name"],
                    password        = (int)reader["password"],
                    company_name    = (string)reader["company_name"],
                };

                Console.WriteLine("===================menu:============== " +
                                  "\n 1.To Add new product to stock press 1" +
                                  "\n 2.To watch all products press number 2");
                cmd.CommandText = ("");

                int answer = Convert.ToInt32(Console.ReadLine());

                if (answer == 1)
                {
                    dao2.AddNewProduct(supplierLogIn);
                }
                else if (answer == 2)
                {
                    dao2.viewAllMyProducts(supplierLogIn);
                }
            }
            return(supplierLogIn);
        }
        public void AddNewProduct(string product_name, supplier s)
        {
            Console.WriteLine("enter price");
            int price = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("enter amount");
            int amount = Convert.ToInt32(Console.ReadLine());

            SqlCommand cmd1 = new SqlCommand();

            cmd1.Connection = new SqlConnection(@"Data Source=.;Initial Catalog=DBschool;Integrated Security=True");
            cmd1.Connection.Open();
            cmd1.CommandType = CommandType.Text;
            cmd1.CommandText = ($"insert into products (product_name, supplier_number, price , amount) values ('{product_name}', {s.supplier_number}, {price}, {amount})");

            SqlDataReader reader = cmd1.ExecuteReader(CommandBehavior.Default);

            cmd1.Connection.Close();
            Console.WriteLine("Adding new products went well(:");
        }