示例#1
0
        private static void ModifyCompany()
        {
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("Modify a Company");

            ListCompany();

            Console.WriteLine("Enter the ID you want to modify:");
            string id = Console.ReadLine();

            var sql = $"select id, company_name FROM Company WHERE id = {id}";

            DataEntry data = new DataEntry();

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            string old_company_name = "";

            if (results.Rows.Count > 0)
            {
                foreach (DataRow row in results.Rows)
                {
                    old_company_name = row.Field <string>("company_name");
                }
            }

            string name;
            bool   is_active;

            Console.WriteLine($"Enter new Company Name for ID {id} blank to keep the same:");
            Console.WriteLine($"Old Company Name: {old_company_name}");
            name = Console.ReadLine();

            if (name.Trim() == "")
            {
                name = old_company_name;
            }

            Console.WriteLine($"Is {id} still Active? (y/n)");
            if (Console.ReadLine().ToLower() == "y")
            {
                is_active = true;
            }
            else
            {
                is_active = false;
            }

            sql = $"update Company set company_name='{name}', is_active={is_active} WHERE id = {id}";
            data.ConnectToDatabase();
            data.RunSQL(sql);

            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("");
        }
示例#2
0
        private static void CreateUser()
        {
            // @TODO check to see if currently logged in user is admin if not check to see if there are any users in company
            //       if 0 users in current company then create user and give admin rights
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("Create a new User");

            string    sql  = $"SELECT id FROM Company Where company_name = '{Globals.currentCompany}'";
            DataEntry data = new DataEntry();

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            int company_id = 0;

            if (results.Rows.Count > 0)
            {
                foreach (DataRow row in results.Rows)
                {
                    company_id = row.Field <int>("id");
                }
            }

            string name = "", display_name, email, password;

            do
            {
                Console.WriteLine("Enter User Name:");
                name = Console.ReadLine();
            } while (DoesUserExist(name));

            Console.WriteLine("Enter User Display Name:");
            display_name = Console.ReadLine();

            Console.WriteLine("Enter Email:");
            email = Console.ReadLine();

            Console.WriteLine("Enter Password:"******"key"), password);

            sql = $"INSERT INTO Users (company_id, user_name, display_name, email, password, is_active) VALUES  ('{company_id}', '{name}', '{display_name}', '{email}', '{encryptedPw}', 1)";

            data.ConnectToDatabase();
            data.RunSQL(sql);

            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("");
        }
示例#3
0
        private static void ListCompany()
        {
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("List Companies");

            var sql = "select id, company_name, is_active from Company;";

            DataEntry data = new DataEntry();

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            if (results.Rows.Count > 0)
            {
                foreach (DataRow row in results.Rows)
                {
                    Console.WriteLine("-----------------------------------------------");
                    Console.WriteLine("ID: " + row.Field <int>("id"));
                    Console.WriteLine("Company Name: " + row.Field <string>("company_name"));
                    Console.WriteLine("Is Active: " + row.Field <bool>("is_active"));
                    Console.WriteLine("-----------------------------------------------");
                    Console.WriteLine("");
                }
            }
            else
            {
                Console.WriteLine("No Companies Found");
                CompanyMenu();
            }
        }
示例#4
0
        private static void DeleteCompany()
        {
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("Delete a Company");

            ListCompany();

            Console.WriteLine("Enter the ID you want to delete:");
            string id = Console.ReadLine();

            Console.WriteLine($"Are you sure you would like to delete ID {id}? (y/n)");
            string answer = Console.ReadLine();

            if (answer.ToLower() == "y")
            {
                string sql = $"DELETE FROM Company WHERE id = {id}";

                DataEntry data = new DataEntry();
                data.ConnectToDatabase();
                data.RunSQL(sql);
            }

            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("");
        }
示例#5
0
        private static void ListUsers()
        {
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("List Users");

            var sql = $"select U.id, U.user_name, U.display_name, U.email, U.is_active from Users U, Company C WHERE U.company_id = C.id AND C.company_name = '{Globals.currentCompany}';";

            DataEntry data = new DataEntry();

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            if (results.Rows.Count > 0)
            {
                foreach (DataRow row in results.Rows)
                {
                    Console.WriteLine("-----------------------------------------------");
                    Console.WriteLine("Id: " + row.Field <int>("id"));
                    Console.WriteLine("User Name: " + row.Field <string>("user_name"));
                    Console.WriteLine("Display Name: " + row.Field <string>("display_name"));
                    Console.WriteLine("Email: " + row.Field <string>("email"));
                    Console.WriteLine("Is Active: " + row.Field <bool>("is_active"));
                    Console.WriteLine("-----------------------------------------------");
                    Console.WriteLine("");
                }
            }
            else
            {
                Console.WriteLine("No Users Found");
                UserMenu();
            }
        }
示例#6
0
        private static void DeleteUser()
        {
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("Delete a User");

            ListUsers();

            Console.WriteLine("Enter the ID you want to delete:");
            string id = Console.ReadLine();

            Console.WriteLine($"Are you sure you would like to delete ID {id}? (y/n)");
            string answer = Console.ReadLine();

            if (answer.ToLower() == "y")
            {
                string sql = $"DELETE FROM Users U, Company C WHERE U.company_id = C.id AND C.company_name = '{Globals.currentCompany}' AND U.id = {id}";

                DataEntry data = new DataEntry();
                data.ConnectToDatabase();
                data.RunSQL(sql);
            }

            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("");
        }
示例#7
0
        private static void ListProject()
        {
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("List Projects");

            var sql = $"select P.id, P.project_name, P.is_active from Project P, Company C WHERE P.company_id = C.id AND C.company_name = '{Globals.currentCompany}';";

            DataEntry data = new DataEntry();

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            if (results.Rows.Count > 0)
            {
                foreach (DataRow row in results.Rows)
                {
                    Console.WriteLine("-----------------------------------------------");
                    Console.WriteLine("Id: " + row.Field <int>("id"));
                    Console.WriteLine("Project Name: " + row.Field <string>("project_name"));
                    Console.WriteLine("Is Active: " + row.Field <bool>("is_active"));
                    Console.WriteLine("-----------------------------------------------");
                    Console.WriteLine("");
                }
            }
            else
            {
                Console.WriteLine("No Projects Found");
                ProjectMenu();
            }
        }
示例#8
0
        private static void ChangeProject()
        {
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("Change Current Project");

            ListProject();

            Console.WriteLine("Enter the ID for current project selection");
            string id = Console.ReadLine();

            string sql = $"SELECT P.id, P.project_name FROM Project P, Company C WHERE P.company_id = C.id AND C.company_name = '{Globals.currentCompany}' AND P.id = {id}";

            DataEntry data = new DataEntry();

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            if (results.Rows.Count > 0)
            {
                foreach (DataRow row in results.Rows)
                {
                    Globals.currentProject = row.Field <string>("project_name");
                    Users.SetUserDefaultProject(row.Field <int>("id"));
                }
            }
        }
示例#9
0
        public static void SetUserDefaultProject(int project_id)
        {
            DataEntry data = new DataEntry();

            data.ConnectToDatabase();

            string sql = $"update Users U, Company C set default_active_project='{project_id}' WHERE U.company_id = C.id AND C.company_name = '{Globals.currentCompany}' AND U.user_name = '{Globals.currentUser}'";

            data.ConnectToDatabase();
            data.RunSQL(sql);
        }
示例#10
0
        private static void CreateProject()
        {
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("Create a new Project");

            string    sql  = $"SELECT id FROM Company WHERE company_name = '{Globals.currentCompany}'";
            DataEntry data = new DataEntry();

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            int company_id = 0;

            if (results.Rows.Count > 0)
            {
                foreach (DataRow row in results.Rows)
                {
                    company_id = row.Field <int>("id");
                }
            }

            string name = "";

            do
            {
                Console.WriteLine("Enter Project Name:");
                name = Console.ReadLine();
            } while (DoesProjectExist(name));

            sql = $"INSERT INTO Project (company_id, project_name, is_active) VALUES ({company_id}, '{name}', 1)";

            data.ConnectToDatabase();
            data.RunSQL(sql);

            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("");
        }
示例#11
0
        public static bool DoesCompanyExist(string name)
        {
            var sql = $"select company_name from Company WHERE company_name = '{name}';";

            DataEntry data = new DataEntry();

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            if (results.Rows.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#12
0
        public static bool DoesUserExist(string name)
        {
            var sql = $"select user_name from Users U, Company C WHERE U.company_id = C.id AND C.company_name = '{Globals.currentCompany}' AND U.user_name = '{name}';";

            DataEntry data = new DataEntry();

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            if (results.Rows.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#13
0
        private static bool DoesProjectExist(string name)
        {
            var sql = $"select P.project_name from Project P, Company C WHERE P.company_id = C.id AND C.company_name = '{Globals.currentCompany}' AND P.project_name = '{name}';";

            DataEntry data = new DataEntry();

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            if (results.Rows.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#14
0
        public static void GetUserDefaultProject()
        {
            DataEntry data = new DataEntry();

            data.ConnectToDatabase();

            string sql = $"SELECT P.project_name FROM Project P, Users U, Company C WHERE P.id = U.default_active_project AND U.company_id = C.id AND C.company_name = '{Globals.currentCompany}' AND U.user_name = '{Globals.currentUser}'";

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            if (results.Rows.Count > 0)
            {
                foreach (DataRow row in results.Rows)
                {
                    Globals.currentProject = row.Field <string>("project_name");
                }
            }
        }
示例#15
0
        private static void CreateCompany()
        {
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("Create a new Company");

            string name = "";

            DataEntry data = new DataEntry();

            do
            {
                Console.WriteLine("Enter Company Name:");
                name = Console.ReadLine();
            } while (DoesCompanyExist(name));

            string sql = $"INSERT INTO Company (company_name, is_active) VALUES  ('{name}', 1)";

            data.ConnectToDatabase();
            data.RunSQL(sql);

            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("");
        }
示例#16
0
        private static void ModifyUser()
        {
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("Modify a User");

            ListUsers();

            Console.WriteLine("Enter the ID you want to modify:");
            string id = Console.ReadLine();

            string sql = $"select U.id, U.company_id, U.user_name, U.display_name, U.email, U.is_active from Users U, Company C WHERE U.company_id = C.id AND C.company_name = '{Globals.currentCompany}' AND U.id = {id}";

            DataEntry data = new DataEntry();

            data.ConnectToDatabase();
            var results = data.RunSQL(sql);

            string old_name = "", old_display_name = "", old_email = "";
            int    company_id = 0;

            if (results.Rows.Count > 0)
            {
                foreach (DataRow row in results.Rows)
                {
                    company_id       = row.Field <int>("company_id");
                    old_name         = row.Field <string>("user_name");
                    old_display_name = row.Field <string>("display_name");
                    old_email        = row.Field <string>("email");
                }
            }

            string name, display_name, email, password;
            bool   is_active;

            Console.WriteLine($"Enter new User Name for ID {id} blank to keep the same:");
            Console.WriteLine($"Old User Name: {old_name}");
            name = Console.ReadLine();

            if (name.Trim() == "")
            {
                name = old_name;
            }

            Console.WriteLine($"Enter new User Display Name for ID {id} blank to keep the same:");
            Console.WriteLine($"Old User Display Name: {old_display_name}");
            display_name = Console.ReadLine();

            if (display_name.Trim() == "")
            {
                display_name = old_display_name;
            }

            Console.WriteLine($"Enter new Email for ID {id} blank to keep the same:");
            Console.WriteLine($"Old Email: {old_email}");
            email = Console.ReadLine();

            if (email.Trim() == "")
            {
                email = old_email;
            }

            Console.WriteLine($"Enter new Password for ID {id}:");
            password = Console.ReadLine();

            string encryptedPw = EncryptionDecryptionService.Encrypt(data.getResource("key"), password);

            Console.WriteLine($"Is {id} still Active? (y/n)");
            if (Console.ReadLine().ToLower() == "y")
            {
                is_active = true;
            }
            else
            {
                is_active = false;
            }

            sql = $"update Users set user_name='{name}', display_name='{display_name}', email='{email}', password='******', is_active={is_active} WHERE id = {id} AND company_id = {company_id}";
            data.ConnectToDatabase();
            data.RunSQL(sql);

            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("");
        }