Example #1
0
        public int Compare(object x, object y)
        {
            PhoneInfo first  = x as PhoneInfo;
            PhoneInfo second = y as PhoneInfo;

            return(first.Name.CompareTo(second.Name)); //역순 -1
        }
        public int Compare(object x, object y)
        {
            PhoneInfo first = (PhoneInfo)x;
            PhoneInfo other = (PhoneInfo)y;

            return(first.Phone.CompareTo(other.Phone));
        }
Example #3
0
        }//이름으로 찾기

        public void DeleteData()
        {
            if (infostorge.Count == 0)
            {
                throw new Exception("정보를 먼저 넣어주세요");
            }
            Console.WriteLine("주소록을 삭제을 시작합니다........");

            int data = SearchName();

            if (data == -1)
            {
                throw new Exception("삭제할 데이터가 없습니다.");
            }


            else
            {
                PhoneInfo[] a_infostorge = infostorge.ToArray();
                PhoneInfo   removed      = a_infostorge[data];

                infostorge.Remove(removed);

                Console.WriteLine("주소록 삭제가 완료되었습니다.");
            }
        }//삭제하기
Example #4
0
        public void SearchData()
        {
            Console.WriteLine("주소록 검색을 시작합니다......");
            PhoneInfo ereum = SearchName();

            if (ereum == null)
            {
                Console.WriteLine("검색된 데이터가 없습니다");
            }
            else
            {
                ereum.ShowPhoneInfo();
            }

            #region 모두 찾기
            //int findCnt = 0;
            //for(int i=0; i<curCnt; i++)
            //{
            //    // ==, Equals(), CompareTo()
            //    if (infoStorage[i].Name.Replace(" ","").CompareTo(name) == 0)
            //    {
            //        infoStorage[i].ShowPhoneInfo();
            //        findCnt++;
            //    }
            //}
            //if (findCnt < 1)
            //{
            //    Console.WriteLine("검색된 데이터가 없습니다");
            //}
            //else
            //{
            //    Console.WriteLine($"총 {findCnt} 명이 검색되었습니다.");
            //}
            #endregion
        }
Example #5
0
        public int Compare(object x, object y)
        {
            PhoneInfo first  = x as PhoneInfo;
            PhoneInfo second = y as PhoneInfo;

            return(first.PhoneNumber.CompareTo(second.PhoneNumber)); //역순 -1
        }
Example #6
0
        public void InputData()
        {
            Console.Write("이름을 입력하세요 : ");
            name = Console.ReadLine();
            Console.Write("전화번호를 입력하세요 : ");
            phoneNumber = Console.ReadLine();

            for (curCnt = 0; curCnt < infoStorage.Length; curCnt++)
            {
                infoStorage[curCnt] = new PhoneInfo(name, phoneNumber);
            }
        }
Example #7
0
        public override bool Equals(object obj)
        {
            PhoneInfo input = (PhoneInfo)obj;

            if (this.name == input.name)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void InputData()
        {
            Console.WriteLine("1.일반  2.대학  3.회사");
            Console.Write("선택 >> ");
            int choice;

            while (true)
            {
                if (int.TryParse(Console.ReadLine(), out choice))
                {
                    break;
                }
            }
            if (choice < 1 || choice > 3)
            {
                Console.WriteLine("1.일반  2.대학  3.회사 중에 선택하십시오.");
                return;
            }

            PhoneInfo info = null;

            switch (choice)
            {
            case 1:
                info = InputFriendInfo();
                break;

            case 2:
                info = InputUnivInfo();
                break;

            case 3:
                info = InputCompanyInfo();
                break;
            }
            if (info != null)
            {
                //infoStorage[curCnt++] = info;

                bool isAdded = infoStorage.Add(info); //컬렉션 HashSet사용
                //Add가 bool타입인 이유는 HashSet특성이 같은값이 들어오면 무시하고 다른값이 들어와야 처리해주기때문
                if (isAdded)                          // 그래서 실효성체크를 해주는 좋은코딩을 하자
                {
                    Console.WriteLine("데이터 입력이 완료되었습니다");
                }
                else
                {
                    Console.WriteLine("이미 저장된 데이터입니다.");
                }
            }
        }
        }   //전화번호부 보기 메서드

        public void SearchData()
        {
            Console.Write("찾을 번호 : ");
            PhoneInfo searchInfo = SearchNumber();

            if (searchInfo == null)
            {
                Console.WriteLine("해당되는 데이터가 없습니다.");
            }
            else
            {
                searchInfo.ToString();
            }
        }   //전화번호 찾기 메서드
        //private int SearchName(string name)
        // {
        //  for (int i = 0; i < curCnt; i++)
        // {
        // if (infoStorage[i].Name.Replace(" ", "").CompareTo(name) == 0)
        // {
        //  return i;
        //    }
        //     }

        //    return -1;
        //   }
        #endregion

        #region 배열과 HashSet DeleteData

        public void DeleteData()
        {
            Console.WriteLine("주소록 삭제를 시작합니다......");

            PhoneInfo delInfo = SearchName();

            if (delInfo == null)
            {
                Console.WriteLine("삭제할 데이터가 없습니다.");
            }
            else
            {
                infoStorage.Remove(delInfo);
            }
        }
        public void SearchData()
        {
            Console.WriteLine("주소록 검색을 시작합니다......");
            PhoneInfo findInfo = SearchName();

            if (findInfo == null)
            {
                Console.WriteLine("검색된 데이터가 없습니다");
                return;
            }
            else
            {
                findInfo.ShowPhoneInfo();
                Console.WriteLine();
            }
        }
Example #12
0
        internal void SortData()
        {
            Console.WriteLine("1.이름 ASC  2.이름 DESC  3.전화번호 ASC 4.전화번호 DESC");
            Console.Write("선택 >> ");
            int choice;

            while (true)
            {
                if (int.TryParse(Console.ReadLine(), out choice))
                {
                    break;
                }
                else
                {
                    throw new Exception("1~4의 숫자를 입력하세요");
                }
            }
            if (choice < 1 || choice > 4)
            {
                throw new Exception("1.이름 ASC  2.이름 DESC  3.전화번호 ASC 4.전화번호 DESC 중에 선택하십시오.");
            }
            PhoneInfo[] new_arr = new PhoneInfo[curCnt];
            Array.Copy(infoStorage, new_arr, curCnt);
            if (choice == 1)
            {
                Array.Sort(new_arr);
            }
            else if (choice == 2)
            {
                Array.Sort(new_arr);
                Array.Reverse(new_arr);
            }
            else if (choice == 3)
            {
                Array.Sort(new_arr, new PhoneComparator());
            }
            else
            {
                Array.Sort(new_arr, new PhoneComparator());
                Array.Reverse(new_arr);
            }
        }
Example #13
0
        public void DeleteData()
        {
            Console.WriteLine("주소록 삭제를 시작합니다......");

            PhoneInfo gagchae = SearchName();

            if (gagchae == null)
            {
                Console.WriteLine("삭제할 데이터가 없습니다");
            }
            else
            {
                infoStorage.Remove(gagchae);
                //for (int i = dataIdx; i < infoStorage.Count; i++)
                //{
                //    infoStorage[i] = infoStorage[i + 1];
                //}
                // infoStorage.Count--;
                Console.WriteLine("주소록 삭제가 완료되었습니다");
            }
        }
        public void InputData()
        {
            Console.Write("이름을 입력해주세요(필수). :");
            string name = Console.ReadLine().Trim();

            if (string.IsNullOrEmpty(name)) // if (name == "");   if(name.Length <1)    if(name.Equals(""))
            {
                Console.WriteLine("이름을 입력해주세요.");
                return;
            }
            else
            {
                int dataIdx = SearchName(name);
                if (dataIdx > -1)
                {
                    Console.WriteLine("이미 등록된 이름입니다. 다른 이름으로 입력해주세요.");
                    return;
                }
            }
            Console.Write("전화번호를 입력해주세요(필수). :");
            string phone = Console.ReadLine().Trim();

            if (string.IsNullOrEmpty(phone)) // if (name == "");   if(name.Length <1)    if(name.Equals(""))
            {
                Console.WriteLine("전화번호를 입력해주세요.");
                return;
            }
            Console.Write("생일을 입력해주세요(선택). :");
            string birth = Console.ReadLine().Trim();

            if (birth.Length < 1)
            {
                infoStorage[curCnt++] = new PhoneInfo(name, phone);
            }
            else
            {
                infoStorage[curCnt++] = new PhoneInfo(name, phone, birth);
            }
        }
        }   //전화번호 찾기 메서드

        public void DeleteData()
        {
            this.error[0] = true;

            Console.WriteLine("\n※삭제할 정보를 입력하시오.※");

            Console.Write("번호 : ");
            try
            {
                PhoneInfo delete = SearchNumber();
                if (delete == null)
                {
                    Console.WriteLine("삭제할 데이터가 없습니다.");
                }
                else
                {
                    infoStorage.Remove(delete);
                }
            }
            catch (Exception err)
            {
                Console.WriteLine(err.Message);
            }
        }   //전화번호 삭제 메서드
Example #16
0
        public void InputData()
        {
            Console.WriteLine("1.일반   2.대학   3.회사");
            Console.Write("선택 >>>  ");
            int choice;

            while (true)
            {
                if (int.TryParse(Console.ReadLine(), out choice))
                {
                    break;
                }
            }
            if (choice < 1 || choice > 3)
            {
                Console.WriteLine("1.일반   2.대학   3.회사 중에 선택하십시오.");
                return;
            }

            PhoneInfo info = null;

            switch (choice)
            {
            case 1: info = IuPutFriendInfo(); break;

            case 2: info = IuPutUnivInfo(); break;

            case 3: info = IuPutCompanyInfo(); break;
            }

            if (info != null)
            {
                infoStorage.Add(info);
                Console.WriteLine("데이터 입력이 완료되었습니다.");
            }
        }
Example #17
0
        //입력 함수
        private void ChoInputData(int choice)
        {
            Console.Write("이름(필수) : ");
            string phoName = Console.ReadLine().Replace(" ", "");

            if (string.IsNullOrEmpty(phoName))  // == string.IsNullorEmpty(phoName), phoName.Length < 1
            {
                throw new Exception("이름을 입력하세요");
            }
            else
            {
                int dataInx = SearchName(phoName);
                if (dataInx > -1)
                {
                    throw new Exception("등록된 이름이 있습니다 다른 이름을 입력하세요");
                }
            }
            Console.Write("전화번호(필수) : ");
            string phoNum = Console.ReadLine().Replace(" ", "");

            if (phoNum.Length < 1)
            {
                throw new Exception("전화번호를 입력하세요");
            }
            Console.Write("생일 : ");
            string phoBir = Console.ReadLine().Replace(" ", "");

            //일반

            if (choice == 1)
            {
                if (phoBir.Length < 1)
                {
                    infoStorage[curCnt++] = new PhoneInfo(phoName, phoNum);
                }
                else
                {
                    infoStorage[curCnt++] = new PhoneInfo(phoName, phoNum, phoBir);
                }
            }
            //대학
            else if (choice == 2)
            {
                string phoMajor, phoYear;
                Console.Write("학과(필수) : ");
                phoMajor = Console.ReadLine().Replace(" ", "");
                if (phoMajor.Length < 1)
                {
                    throw new Exception("학과를 입력하세요");
                }
                else
                {
                    Console.Write("학년(1,2,3,4) : ");
                    phoYear = Console.ReadLine().Replace(" ", "");
                }
                if (phoYear.Length < 1)
                {
                    throw new Exception("학년를 입력하세요");
                }
                else
                {
                    infoStorage[curCnt++] = new PhoneUnivInfo(phoName, phoNum, phoMajor, Utility.ConvertInt(phoYear));
                }
            }
            else if (choice == 3)
            {
                Console.Write("회사(필수) : ");
                string phoCompany;
                phoCompany = Console.ReadLine().Replace(" ", "");
                if (phoCompany.Length < 1)
                {
                    throw new Exception("회사명을 입력하세요");
                }
                else
                {
                    infoStorage[curCnt++] = new PhoneCompany(phoName, phoNum, phoCompany);
                }
            }
            else
            {
                throw new Exception("주소 유형 번호을 다시 선택하세요");
            }
        }
Example #18
0
        public void InputData()
        {
            Console.WriteLine("1.일반     2.대학    3.회사");
            Console.Write("선택 >> ");
            int choice = int.Parse(Console.ReadLine().Trim());

            //필수항목들 무조건 실행

            Console.Write("이름: ");
            string name = Console.ReadLine().Trim();

            //if (name == "") or if (name.Length < 1) or if (name.Equals(""))
            if (string.IsNullOrEmpty(name))
            {
                Console.WriteLine("이름은 필수입력입니다");
                return;
            }
            else
            {
                PhoneInfo gagchae = SearchName(name);
                if (gagchae != null)
                {
                    Console.WriteLine(" 이미 있는 이름입니다.");
                    return;
                }
            }

            Console.Write("전화번호: ");
            string phone = Console.ReadLine().Trim();

            if (string.IsNullOrEmpty(phone))
            {
                Console.WriteLine("전화번호는 필수입력입니다");
                return;
            }



            Console.Write("생일: ");
            string birth = Console.ReadLine().Trim();



            if (choice == 1)
            {
                BirthCheck(name, phone, birth);
                foreach (PhoneInfo str in infoStorage)
                {
                    Console.WriteLine($"입력되었습니다. 이름은 {str.Name}, 전화번호는 {str.PhoneNumber}, 생일은{str.Birth}입니다");
                }
            }



            if (choice == 2)
            {
                Console.Write("전공을 입력하세요: ");
                string major = Console.ReadLine().Trim();

                if (major.Equals(""))
                {
                    Console.WriteLine("전공은 필수입력입니다");
                    return;
                }

                Console.Write("학번을 입력하세요 : ");
                string year = Console.ReadLine().Trim();

                if (string.IsNullOrEmpty(year))      //말도 안되는 학번 걸러내기
                {
                    Console.WriteLine("학번은 필수입력입니다.");
                    return;
                }

                BirthCheck(name, phone, birth, major, year);
            }

            else if (choice == 3)
            {
                Console.Write("부서를 입력하세요: ");
                string department = Console.ReadLine().Trim();

                if (string.IsNullOrEmpty(department))
                {
                    Console.WriteLine("부서는 필수입력입니다");
                    return;
                }

                Console.Write("회사를 입력하세요: ");
                string company = Console.ReadLine().Trim();

                if (company.Equals(""))
                {
                    Console.WriteLine("회사는 필수입력입니다");
                    return;
                }
                BirthCheck2(name, phone, birth, department, company);
            }
        }
Example #19
0
        public int CompareTo(object obj)
        {
            PhoneInfo other = (PhoneInfo)obj;

            return(this.name.CompareTo(other.name));
        }