Example #1
0
        public static void UpdateProduct(Product updatedProduct)
        {
            ProyectConnection NewConnection = new ProyectConnection();

            NewConnection.ConnectToday();
            SqlCommand com = new SqlCommand();

            com.Connection  = ProyectConnection.conn;
            com.CommandText = "update Product set Name=(@name), Category=(@cate), Price=(@price), Description=(@desc), Quantity=(@quan) where Id=(@id)";
            com.Parameters.AddWithValue("name", updatedProduct.Name);
            com.Parameters.AddWithValue("cate", updatedProduct.Category);
            com.Parameters.AddWithValue("price", updatedProduct.Price);
            com.Parameters.AddWithValue("desc", updatedProduct.Description);
            com.Parameters.AddWithValue("quan", updatedProduct.Quantity);
            com.Parameters.AddWithValue("id", updatedProduct.Id);
            int cant;

            cant = com.ExecuteNonQuery();
            if (cant == 1)
            {
                Alert.ShowAlert("Product updated successfully.", ConsoleColor.Green);
            }
            else
            {
                Alert.ShowAlert("Product doesn't exist on database.", ConsoleColor.Red);
            }
        }
Example #2
0
        public static bool SearchEmployeeDocument(string document)
        {
            bool exists = false;
            ProyectConnection NewConnection = new ProyectConnection();

            NewConnection.ConnectToday();
            SqlCommand com = new SqlCommand();

            com.Connection = ProyectConnection.conn;
            string xdoc = document;

            com.CommandText = "select Name, Address from Employee where Document = (@doc);";
            com.Parameters.AddWithValue("doc", xdoc);

            try
            {
                SqlDataReader register = com.ExecuteReader();
                if (register.Read())
                {
                    exists = true;
                    return(exists);
                }
                else
                {
                    Alert.ShowAlert("Client doesn't exist on database.", ConsoleColor.Red);
                    return(exists);
                }
            }
            catch (Exception)
            {
                Alert.ShowAlert("Database Error", ConsoleColor.Red);
                return(exists);
            }
        }
Example #3
0
        public static void ReadEmployee(string document)
        {
            ProyectConnection NewConnection = new ProyectConnection();

            NewConnection.ConnectToday();
            SqlCommand com = new SqlCommand();

            com.Connection = ProyectConnection.conn;
            string xdoc = document;

            com.CommandText = "select Name, Address from Employee where Document = (@doc);";
            com.Parameters.AddWithValue("doc", xdoc);
            try
            {
                SqlDataReader register = com.ExecuteReader();
                if (register.Read())
                {
                    Console.Write("\n");
                    Alert.ShowMessage($"Client Found", ConsoleColor.Blue);
                    Alert.ShowMessage($"---------------------------------------", ConsoleColor.Blue);
                    Alert.ShowMessage($"Name: {register["Name"]}", ConsoleColor.Blue);
                    Alert.ShowMessage($"Address: {register["Address"]}", ConsoleColor.Blue);
                }
                else
                {
                    Alert.ShowAlert("Client doesn't exist on database.", ConsoleColor.Red);
                }
            }
            catch (Exception)
            {
                Alert.ShowAlert("Database Error", ConsoleColor.Red);
            }
        }
Example #4
0
        //TO DO---------------------------

        public static void CreateOrder(Order newOrder)
        {
            try
            {
                ProyectConnection NewConnection = new ProyectConnection();
                NewConnection.ConnectToday();
                SqlCommand com = new SqlCommand();
                com.Connection  = ProyectConnection.conn;
                com.CommandText = "insert into Order values (@id, @doc)";
                com.Parameters.AddWithValue("@id", newOrder.Id);
                com.Parameters.AddWithValue("@doc", newOrder.ClientDocument);
                com.ExecuteNonQuery();
                Alert.ShowAlert("Order Saved on Database.", ConsoleColor.Green);
            }
            catch (Exception)
            {
                Alert.ShowAlert("Something is wrong, Order couldn't be saved.", ConsoleColor.Red);
            }
        }
Example #5
0
        public static void ReadAllEmployees()
        {
            ProyectConnection NewConnection = new ProyectConnection();

            NewConnection.ConnectToday();
            SqlCommand com = new SqlCommand();

            com.Connection  = ProyectConnection.conn;
            com.CommandText = "select Document, Name, Address from Employee";
            SqlDataReader register = com.ExecuteReader();

            while (register.Read())
            {
                Alert.ShowMessage($"----------------------------", ConsoleColor.DarkCyan);
                Alert.ShowMessage($"Document: {register["Document"]}", ConsoleColor.Blue);
                Alert.ShowMessage($"Name: {register["Name"]}", ConsoleColor.Blue);
                Alert.ShowMessage($"Address: {register["Address"]}", ConsoleColor.Blue);
            }
        }
Example #6
0
 public static void CreateEmployee(Employee newEmployee)
 {
     try
     {
         ProyectConnection NewConnection = new ProyectConnection();
         NewConnection.ConnectToday();
         SqlCommand com = new SqlCommand();
         com.Connection  = ProyectConnection.conn;
         com.CommandText = "insert into Employee(Document, Name, Address) values (@doc, @name, @add);";
         com.Parameters.AddWithValue("doc", newEmployee.Document);
         com.Parameters.AddWithValue("name", newEmployee.Name);
         com.Parameters.AddWithValue("add", newEmployee.Address);
         com.ExecuteNonQuery();
         Alert.ShowAlert("Client Saved on Database.", ConsoleColor.Green);
     }
     catch (Exception)
     {
         Alert.ShowAlert("Something is wrong, client couldn't be saved.", ConsoleColor.Red);
     }
 }
Example #7
0
        public static void GetProduct(int id, string user)
        {
            ProyectConnection NewConnection = new ProyectConnection();

            NewConnection.ConnectToday();
            SqlCommand com = new SqlCommand();

            com.Connection = ProyectConnection.conn;
            int xid = id;

            com.CommandText = "select Id, Name, Category, Price, Description, Quantity from Product where Id = (@id);";
            com.Parameters.AddWithValue("id", xid);
            try
            {
                SqlDataReader register = com.ExecuteReader();
                if (register.Read())
                {
                    Console.Write("\n");
                    Alert.ShowMessage($"Product Added to Shopping Cart", ConsoleColor.Blue);
                    Alert.ShowMessage($"---------------------------------------", ConsoleColor.Blue);
                    Product myProduct = new Product(register.GetInt32(0), register["Name"].ToString(), register.GetInt32(3), register.GetString(4));
                    Alert.ShowMessage(myProduct.ToString2(), ConsoleColor.DarkGreen);

                    String path = @"C:\Users\bline\Documents\Codes\Visual Studio\Oreo\Oreo\DataFiles\ShoppingCart.txt";

                    using (StreamWriter sr = File.AppendText(path))
                    {
                        sr.WriteLine(myProduct.ToString2());
                        sr.Close();
                    }
                }
                else
                {
                    Alert.ShowAlert("Product doesn't exist on database.", ConsoleColor.Red);
                }
            }
            catch (Exception)
            {
                Alert.ShowAlert("Database Error", ConsoleColor.Red);
            }
        }
Example #8
0
        public static void DeleteProduct(int id)
        {
            ProyectConnection NewConnection = new ProyectConnection();

            NewConnection.ConnectToday();
            SqlCommand com = new SqlCommand();

            com.Connection = ProyectConnection.conn;
            int xid = id;

            com.CommandText = "delete from Product where Id=(@id)";
            com.Parameters.AddWithValue("id", xid);
            if (com.ExecuteNonQuery() == 1)
            {
                Alert.ShowAlert("Product deleted successfully.", ConsoleColor.Green);
            }
            else
            {
                Alert.ShowAlert("Product doesn't exist on database.", ConsoleColor.Red);
            }
        }
Example #9
0
        public static void DeleteEmployee(string documment)
        {
            ProyectConnection NewConnection = new ProyectConnection();

            NewConnection.ConnectToday();
            SqlCommand com = new SqlCommand();

            com.Connection = ProyectConnection.conn;
            string xdoc = documment;

            com.CommandText = "delete from Employee where Document=(@doc)";
            com.Parameters.AddWithValue("doc", xdoc);
            if (com.ExecuteNonQuery() == 1)
            {
                Alert.ShowAlert("Client deleted successfully.", ConsoleColor.Green);
            }
            else
            {
                Alert.ShowAlert("Client doesn't exist on database.", ConsoleColor.Red);
            }
        }
Example #10
0
        public static void ReadAllProducts()
        {
            ProyectConnection NewConnection = new ProyectConnection();

            NewConnection.ConnectToday();
            SqlCommand com = new SqlCommand();

            com.Connection  = ProyectConnection.conn;
            com.CommandText = "select Id, Name, Category, Price, Description, Quantity from Product";
            SqlDataReader register = com.ExecuteReader();

            while (register.Read())
            {
                Alert.ShowMessage($"----------------------------", ConsoleColor.DarkCyan);
                Alert.ShowMessage($"ID: {register["Id"]}", ConsoleColor.Blue);
                Alert.ShowMessage($"Name: {register["Name"]}", ConsoleColor.Blue);
                //Alert.showMessage($"Category: {register["Category"]}", ConsoleColor.Blue);
                Alert.ShowMessage($"Price: {register["Price"]}", ConsoleColor.Blue);
                Alert.ShowMessage($"Description: {register["Description"]}", ConsoleColor.Blue);
                //Alert.showMessage($"Quantity: {register["Quantity"]}", ConsoleColor.Blue);
            }
        }
Example #11
0
 public static void CreateProduct(Product newProduct)
 {
     try
     {
         ProyectConnection NewConnection = new ProyectConnection();
         NewConnection.ConnectToday();
         SqlCommand com = new SqlCommand();
         com.Connection  = ProyectConnection.conn;
         com.CommandText = "insert into Product(Id, Name, Category, Price, Description, Quantity) values (@id, @name, @cate, @price, @desc, @quan);";
         com.Parameters.AddWithValue("id", newProduct.Id);
         com.Parameters.AddWithValue("name", newProduct.Name);
         com.Parameters.AddWithValue("cate", newProduct.Category);
         com.Parameters.AddWithValue("price", newProduct.Price);
         com.Parameters.AddWithValue("desc", newProduct.Description);
         com.Parameters.AddWithValue("quan", newProduct.Quantity);
         com.ExecuteNonQuery();
         Alert.ShowAlert("Product Saved on Database.", ConsoleColor.Green);
     }
     catch (Exception)
     {
         Alert.ShowAlert("Something is wrong, Product couldn't be saved.", ConsoleColor.Red);
     }
 }
Example #12
0
        public static void ReadProduct(int id)
        {
            ProyectConnection NewConnection = new ProyectConnection();

            NewConnection.ConnectToday();
            SqlCommand com = new SqlCommand();

            com.Connection = ProyectConnection.conn;
            int xid = id;

            com.CommandText = "select Id, Name, Category, Price, Description, Quantity from Product where Id = (@id);";
            com.Parameters.AddWithValue("id", xid);
            try
            {
                SqlDataReader register = com.ExecuteReader();
                if (register.Read())
                {
                    Console.Write("\n");
                    Alert.ShowMessage($"Product Found", ConsoleColor.Blue);
                    Alert.ShowMessage($"---------------------------------------", ConsoleColor.Blue);
                    Alert.ShowMessage($"ID: {register["Id"]}", ConsoleColor.Blue);
                    Alert.ShowMessage($"Name: {register["Name"]}", ConsoleColor.Blue);
                    Alert.ShowMessage($"Category: {register["Category"]}", ConsoleColor.Blue);
                    Alert.ShowMessage($"Price: {register["Price"]}", ConsoleColor.Blue);
                    Alert.ShowMessage($"Description: {register["Description"]}", ConsoleColor.Blue);
                    Alert.ShowMessage($"Quantity: {register["Quantity"]}", ConsoleColor.Blue);
                }
                else
                {
                    Alert.ShowAlert("Product doesn't exist on database.", ConsoleColor.Red);
                }
            }
            catch (Exception)
            {
                Alert.ShowAlert("Database Error", ConsoleColor.Red);
            }
        }
Example #13
0
        public static void UpdateEmployee(Employee updatedEmployee)
        {
            ProyectConnection NewConnection = new ProyectConnection();

            NewConnection.ConnectToday();
            SqlCommand com = new SqlCommand();

            com.Connection  = ProyectConnection.conn;
            com.CommandText = "update Employee set Name=(@name), Address=(@add) where Document=(@doc)";
            com.Parameters.AddWithValue("name", updatedEmployee.Name);
            com.Parameters.AddWithValue("add", updatedEmployee.Address);
            com.Parameters.AddWithValue("doc", updatedEmployee.Document);
            int cant;

            cant = com.ExecuteNonQuery();
            if (cant == 1)
            {
                Alert.ShowAlert("Client updated successfully.", ConsoleColor.Green);
            }
            else
            {
                Alert.ShowAlert("Product doesn't exist on database.", ConsoleColor.Red);
            }
        }