public DateTime CreateBirthDateFromId(Patient p)
        {
            StringBuilder birth = new StringBuilder();
            DateTime birthdate;

            string errmsg = String.Format(" ID {0}: {1} {2}", p.ID, p.Surname, p.Name);

            if (p.ID.Length < 9 || p.ID.Length > 10)
                throw new ApplicationException(ErrorMessages.Messages["SERVICE_P_id_format"] + errmsg);

            //Day
            birth.Append(p.ID.Substring(4, 2)).Append('.');

            //Month
            int gender;
            if (Int32.TryParse(p.ID.Substring(2, 1), out gender))
            {
                if (gender == 5)
                {
                    birth.Append(p.ID.Substring(3, 1));
                }
                else if (gender == 6)
                {
                    birth.Append('1').Append(p.ID.Substring(3, 1));
                }
                else
                {
                    birth.Append(p.ID.Substring(2, 2));
                }
            }
            else
            {
                throw new ApplicationException(ErrorMessages.Messages["SERVICE_P_id_month"] + errmsg);
            }
            birth.Append(".");

            //Year
            string year = p.ID.Substring(0, 2);
            int y;
            if (!Int32.TryParse(year, out y))
            {
                throw new ApplicationException(ErrorMessages.Messages["SERVICE_P_id_year"] + errmsg);
            }
            if (p.ID.Length == 9 || (p.ID.Length == 10 && y >= 54))
            {
                birth.Append("19").Append(year);
            }
            else
            {
                birth.Append("20").Append(year);
            }

            if (!DateTime.TryParse(birth.ToString(), out birthdate))
            {
                throw new ApplicationException(ErrorMessages.Messages["SERVICE_P_id_date"] + errmsg);
            }
            return birthdate;
        }
 public RequestList()
 {
     InitializeComponent();
     this.service = new PatientCardService();
     Patient p = new Patient();
     p.ID = "7509223123";
     this.patient = p;
     List<Prescription> prs;
     try
     {
         prs = service.GetPatientPrescriptions(patient);
         prs.ForEach(x => prescriptionBindingSource.Add(x));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         this.Close();
     }
     this.prescriptionList.RowsAdded += prescriptionList_RowsAdded;
     this.prescriptionList.UserDeletingRow += prescriptionList_UserDeletingRow;
 }
 public void DeletePatient(Patient p)
 {
     this.pm.Delete(p);
 }
 public void AddPrescription(Patient p, Prescription pres)
 {
     pm.InsertRequest(p, pres);
 }
 public void RegisterPatient(Patient p)
 {
     this.pm.Insert(p);
 }
 public List<Prescription> GetPatientPrescriptions(Patient p)
 {
     List<Prescription> prs = new List<Prescription>();
     foreach (Request r in pm.SelectRequests(p, "prescription"))
     {
         prs.Add((Prescription)r);
     }
     return prs;
 }
 public void EditPatient(Patient p)
 {
     this.pm.Update(p);
 }
        private void Register()
        {
            Patient p = new Patient();
            Console.Write("Rodné číslo: ");
            string id = Console.ReadLine();
            while (!this.pcs.isId(id))
            {
                Console.Write("Neplatné rodné číslo! Zadejte znovu: ");
                id = Console.ReadLine();
            }
            p.ID = id;
            Console.Write("Příjmení: ");
            p.Surname = Console.ReadLine();
            Console.Write("Jméno: ");
            p.Name = Console.ReadLine();

            Console.WriteLine("Zdravotní pojišťovny:");
            HealthInsuranceService his = new HealthInsuranceService();
            foreach (HealthInsurance hi in his.GetInsurances())
            {
                Console.WriteLine("{0} - {1}", hi.Code, hi.Name);
            }
            Console.Write("Zdravotní pojišťovna: ");
            string code = Console.ReadLine();
            int code_int;
            bool test = true;
            while (test)
            {
                while (!Int32.TryParse(code, out code_int))
                {
                    Console.Write("Neplatný kód! Zadejte správný: ");
                    code = Console.ReadLine();
                }

                HealthInsurance insurance = his.Find(code_int);
                if (insurance == null)
                {
                    Console.Write("Neexistující pojišťovna! Zadejte jiný kód: ");
                    code = Console.ReadLine();
                }
                else
                {
                    test = false;
                    p.Insurance = insurance;
                }
            }

            Console.Write("Ulice: ");
            p.Street = Console.ReadLine();
            Console.Write("Město: ");
            p.Town = Console.ReadLine();
            Console.Write("PSČ: ");
            int zipCode;
            while (!Int32.TryParse(Console.ReadLine(), out zipCode))
            {
                Console.Write("Neplatné PSČ! Zadejte znovu: ");
            }
            p.ZipCode = zipCode;
            Console.Write("Telefon: ");
            int phone;
            while (!Int32.TryParse(Console.ReadLine(), out phone))
            {
                Console.Write("Neplatné telefonní číslo! Zadejte znovu: ");
            }
            p.PhoneNumber = phone;

            Console.WriteLine("\nSHRNUTÍ ÚDAJŮ");
            Console.WriteLine(" RČ: {0}\n Příjmení: {1}\n Jméno: {2}\n Zdravotní pojišťovna: {3}\n Ulice: {4}\n Město: {5}\n PSČ: {6}\n Telefon: {7}",
                    p.ID,
                    p.Surname,
                    p.Name,
                    p.Insurance.Code,
                    p.Street,
                    p.Town,
                    p.ZipCode,
                    p.PhoneNumber);
            Console.Write("A - Potvrdit, N - Zadat vše znovu. Akce: ");
            string decision = Console.ReadLine();
            while (!decision.Equals("A"))
            {
                if (decision.Equals("N"))
                {
                    this.Register();
                    return;
                }
                Console.WriteLine(Strings.PM_command);
                Console.Write("A - Potvrdit, N - Zadat vše znovu. Akce: ");
                decision = Console.ReadLine();
            }
            try
            {
                this.pcs.RegisterPatient(p);
                this.patients.Add(p);
                this.PrintScreen("Pacient byl registrován!");
            }
            catch (Exception ex)
            {
                this.PrintScreen(ex.Message);
            }
        }