コード例 #1
0
ファイル: Program.cs プロジェクト: 21440/DataRegisterV7
        public static void Procedure(ArraySet arrset, bool editing)
        {
            while (true)
            {
                char   sex, maritalsts, grade;
                int    csex, cmaritalsts, cgrade = 0;
                string fname, lname, saving, fpw, spw, id = "";
                Person person = new Person("", "", "", 0, "", 0);

                if (!editing)
                {
                    id = numInput("\nEnter the ID: ");
                }
                else
                {
                    id = numInput("\nEnter the ID of the record you want to edit: ");
                    //editing = !editing;
                    Console.WriteLine();
                    person = Finder(arrset, id);
                    if (person.Id == "")
                    {
                        return;
                    }
                    else
                    {
                        id = person.Id;
                    }
                    Console.WriteLine("\nProceed to make the changes!");
                }

                if (UniqueID(id) && !editing)
                {
                    Console.WriteLine("\nThis ID has already been recorded.");
                    continue;
                }

                fname = stdInput("\nEnter the First Name: ");
                lname = stdInput("\nEnter the Last Name: ");
                int age = Convert.ToInt32(numInput("\nEnter the Age: "));
                while (age < 7 || age > 120)
                {
                    age = Convert.ToInt32(numInput("\nEnter the Age: "));
                }

                do
                {
                    Console.WriteLine("\nEnter the Sex: [M|F]");
                    sex = Convert.ToChar(Console.ReadLine().ToUpper());
                } while (sex != 'M' && sex != 'F');

                if (sex == 'M')
                {
                    csex = 1;
                }
                else
                {
                    csex = 0;
                }

                do
                {
                    Console.WriteLine("\nEnter the Marital Status: [S|M]");
                    maritalsts = Convert.ToChar(Console.ReadLine().ToUpper());
                } while (maritalsts != 'S' && maritalsts != 'M');

                if (maritalsts == 'M')
                {
                    cmaritalsts = 1;
                }
                else
                {
                    cmaritalsts = 0;
                }

                do
                {
                    Console.WriteLine("\nEnter the Education Level: [I|M|G|P]");
                    grade = Convert.ToChar(Console.ReadLine().ToUpper());
                } while (grade != 'I' && grade != 'M' && grade != 'G' && grade != 'P');

                switch (grade)
                {
                case 'M':
                    cgrade = 1;
                    break;

                case 'G':
                    cgrade = 2;
                    break;

                case 'P':
                    cgrade = 3;
                    break;
                }

                saving = decInput("\nEnter the Savings: ");
                do
                {
                    fpw = pwInput("\nEnter the Password: "******"\nConfirm the Password: "******"\nPasswords do not match!");
                    }
                } while (fpw != spw);

                int data = Encode(age, sex, maritalsts, grade);

                Console.WriteLine("\nSave [S]; Discard[D]; Exit[E]");
                string Selection = Console.ReadLine();

                switch (Selection.ToLower())
                {
                case "s":

                    Console.Clear();
                    if (!editing)
                    {
                        Person nperson = Person.FromCsvFile($"{id},{fname},{lname},{saving},{fpw},{data}");
                        bool   add     = arrset.Add(nperson);

                        if (add)
                        {
                            Console.WriteLine("\nRecord registered correctly!\n");
                        }

                        else
                        {
                            Console.WriteLine("\nRecord couldn't be registered!\n");
                        }
                    }

                    else
                    {
                        if (person.FullName != fname + " " + lname)
                        {
                            Console.WriteLine("\nChanges in the Full Name made successfully!");
                        }

                        if (person.Savings != Convert.ToDouble(saving))
                        {
                            Console.WriteLine("\nChanges in the Savings made successfully!");
                        }

                        if (person.Password != fpw)
                        {
                            Console.WriteLine("\nChanges in the Password made successfully!");
                        }

                        if (person.Age != age)
                        {
                            Console.WriteLine("\nChanges in the Age made successfully!");
                        }

                        if ((int)person.Sex != csex)
                        {
                            Console.WriteLine("\nChanges in the Sex made successfully!");
                        }

                        if ((int)person.MaritalStatus != cmaritalsts)
                        {
                            Console.WriteLine("\nChanges in the Marital Status made successfully!");
                        }

                        if ((int)person.Grade != cgrade)
                        {
                            Console.WriteLine("\nChanges in the Grade made successfully!");
                        }

                        if ((person.FullName == fname + " " + lname) && (person.Savings == Convert.ToDouble(saving)) && (person.Password == fpw) && (person.Age == age) && ((int)person.Sex == csex) && ((int)person.MaritalStatus == cmaritalsts) && ((int)person.Grade == cgrade))
                        {
                            Console.WriteLine("\nIt appears no changes has been made.");
                        }

                        var nperson = Person.FromCsvFile($"{id},{fname},{lname},{saving},{fpw},{data}");

                        bool edit = arrset.Edit(person, nperson);

                        if (edit)
                        {
                            Console.WriteLine("\nThe task was completed successfully.");
                        }

                        else
                        {
                            Console.WriteLine("\nThe task was not completed.");
                        }
                    }

                    break;

                case "d":

                    Console.Clear();
                    if (editing)
                    {
                        Procedure(set, false);
                    }
                    else
                    {
                        Procedure(set, true);
                    }

                    break;

                case "e":

                    Console.Clear();
                    break;

                default:

                    Console.Clear();
                    Console.WriteLine("\nSomething went wrong, try again.");

                    break;
                }

                break;
            }
        }