Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBoxTime.Text == "")
            {
                MessageBox.Show("Выберите специальность, врача, день и время");
            }
            else
            {
                using (ModelMedDBContainer db = new ModelMedDBContainer())
                {
                    Doctor tempDoctor = (Doctor)db.PersonSet.Find(DoctorsList[index].BirthDate, DoctorsList[index].NameHashID);


                    FreeTime freeTi = (FreeTime)(from times in tempDoctor.FreeTimes
                                                 where (times.Start.Date.ToShortDateString() == comboBoxDate.Text &&
                                                        times.Start.TimeOfDay.ToString() == comboBoxTime.Text)
                                                 select(times)).ToArray()[0];;

                    comboBoxTime.Items.Remove(comboBoxTime.Text);
                    WorkTime workTi = new WorkTime {
                        Start = freeTi.Start, Doctor = tempDoctor, Finish = freeTi.Finish, BirthDate = tempDoctor.BirthDate, NameHashID = tempDoctor.NameHashID
                    };

                    db.FreeTimeSet.Remove(freeTi);
                    Patient t = (Patient)(db.PersonSet.Find(thisPatient.BirthDate, thisPatient.NameHashID));
                    workTi.VisitInfo = new VisitInfo
                    {
                        WorkTimes        = workTi,
                        DateStart        = workTi.Start,
                        DateFinish       = workTi.Finish,
                        DoctorID         = tempDoctor.NameHashID,
                        Patient          = t,
                        PatientBirthDate = t.BirthDate,
                        PatientFullName  = t.FullName
                    };
                    t.VisitInfo.Add(workTi.VisitInfo);
                    tempDoctor.WorkTimes.Add(workTi);
                    db.WorkTimeSet.Add(workTi);
                    db.VisitInfoSet.Add(workTi.VisitInfo);



                    db.SaveChanges();
                    MessageBox.Show("Запись совершена");
                    button1.Enabled = false;
                }
            }
        }
Exemplo n.º 2
0
        public static void GenerateRandomDataBase(int N = 50)
        {
            int doctorNum = random.Next(1, N / 5 + 2);

            string[] Vacancies = { "Главврач", "Хирург", "Эндокринолог", "Невролог", "Участковый врач", "Окуляринголог", "Дантист" };
            string[] NamesM    = { "Иван", "Денис", "Вячеслав", "Владимир", "Константин", "Александр", "Михаил", "Игнат", "Артём" };
            string[] NamesW    = { "Алёна", "Арина", "Елизавета", "Екатерина", "Александра", "Кристина", "Татьяна", "Людмила" };
            string[] Genders   = { "Мужской", "Женский" };
            string[] Surnames  = { "Иванов", "Александров", "Степанов", "Семёнов", "Удальцов", "Молодцов", "Бобров", "Медведев" };

            string[] BirthPlaces   = { "Уфа", "Барнаул", "Екатеринбург", "Йошкар-Ола", "Таганрог", "Егоров", "Москва", "Евпатория", "Новороссийск", "Якутск" };
            string[] DocumentTypes =
            {
                "Паспорт гражданина РФ",
                "Свидетельство о рождении",
                "Дипломатический паспорт",
                "Паспорт моряка",
                "Военный билет",
                "Удостоверение личности военнослужащего",
                "Удостоверение беженца",
                "Служебное удостоверение работника прокуратуры"
            };

            string[] Nationalities = { "Российская Федерация", "Англия", "Бавария", "Российская Федерация" };

            string[] Educations = { "Мед.образование1", "Мед.образование2", "Мед.образование3" };

            for (int i = 0; i < N; i++)
            {
                using (ModelMedDBContainer db = new ModelMedDBContainer())
                {
                    Person temp = new Person();
                    temp.BirthPlace = BirthPlaces[random.Next(0, 10)];
                    temp.BirthDate  = new DateTime(random.Next(1950, 2018), random.Next(1, 13), random.Next(1, 28));
                    temp.RegDate    = new DateTime(random.Next(1950, 2018), random.Next(1, 13), random.Next(1, 28));
                    temp.Documents  = new Documents {
                        DocumentName = DocumentTypes[random.Next(0, 8)], DocumentNum = random.Next(0, Int32.MaxValue), Person = temp
                    };
                    if (random.Next(0, 2) == 0)
                    {
                        temp.Gender   = Genders[0];
                        temp.FullName = Surnames[random.Next(0, 8)] + " " + NamesM[random.Next(0, 9)] + " " + NamesM[random.Next(0, 9)] + "ович";
                    }
                    else
                    {
                        temp.Gender   = Genders[1];
                        temp.FullName = Surnames[random.Next(0, 8)] + "а " + NamesW[random.Next(0, 8)] + " " + NamesM[random.Next(0, 9)] + "овна";
                    }
                    temp.InsuranceBillNum = random.Next(0, Int32.MaxValue).ToString();
                    temp.LiveAdress       = random.Next(0, 4).ToString();
                    temp.RegAdress        = random.Next(10, 20).ToString();
                    temp.NameHashID       = temp.FullName.GetHashCode();

                    if (temp.Documents.DocumentName == "Удостоверение беженца")
                    {
                        temp.Nationality = Nationalities[random.Next(1, 4)];
                    }
                    else
                    {
                        temp.Nationality = Nationalities[0];
                    }

                    temp.Password = "******";

                    if (doctorNum > 0)
                    {
                        doctorNum--;

                        Doctor t = new Doctor();
                        (t as Person).BirthDate        = temp.BirthDate;
                        (t as Person).Documents        = temp.Documents;
                        (t as Person).Documents.Person = t;
                        (t as Person).FullName         = temp.FullName;
                        (t as Person).Gender           = temp.Gender;
                        (t as Person).InsuranceBillNum = temp.InsuranceBillNum;
                        (t as Person).LiveAdress       = temp.LiveAdress;
                        (t as Person).NameHashID       = temp.NameHashID;
                        (t as Person).Nationality      = temp.Nationality;
                        (t as Person).Password         = temp.Password;
                        (t as Person).RegAdress        = temp.RegAdress;
                        (t as Person).RegDate          = temp.RegDate;
                        (t as Person).BirthPlace       = temp.BirthPlace;

                        t.Memberships = "";
                        if (0 == random.Next(0, 6))
                        {
                            t.Memberships = "Médecins Sans Frontières";
                        }
                        t.Education = Educations[random.Next(0, 3)];
                        t.Job       = Vacancies[random.Next(0, 7)];

                        int week = random.Next(0, 4);
                        if (0 == week)
                        {
                            t.FreeTimes = makeJob(new int[] { 0, 3, 5 }, DateTime.Today, t, random.Next(3, 8), random.Next(5, 10), random.Next(10, 20));
                        }
                        if (1 == week)
                        {
                            t.FreeTimes = makeJob(new int[] { 0, 1, 2, 5 }, DateTime.Today, t, random.Next(3, 8), random.Next(5, 10), random.Next(10, 20));
                        }
                        if (2 == week)
                        {
                            t.FreeTimes = makeJob(new int[] { 0, 1, 2, 3, 4, 5, 6 }, DateTime.Today, t, random.Next(3, 8), random.Next(5, 10), random.Next(10, 20));
                        }
                        if (3 == week)
                        {
                            t.FreeTimes = makeJob(new int[] { 4 }, DateTime.Today, t, random.Next(3, 8), random.Next(5, 10), random.Next(10, 20));
                        }

                        t.WorkTimes    = new List <WorkTime>();
                        t.DoctorRecord = new List <DoctorRecord>();
                        db.PersonSet.Add(t);
                        db.SaveChanges();
                    }
                    else
                    {
                        Patient t = new Patient();
                        (t as Person).BirthDate        = temp.BirthDate;
                        (t as Person).Documents        = temp.Documents;
                        (t as Person).FullName         = temp.FullName;
                        (t as Person).Gender           = temp.Gender;
                        (t as Person).InsuranceBillNum = temp.InsuranceBillNum;
                        (t as Person).LiveAdress       = temp.LiveAdress;
                        (t as Person).NameHashID       = temp.NameHashID;
                        (t as Person).Nationality      = temp.Nationality;
                        (t as Person).Password         = temp.Password;
                        (t as Person).RegAdress        = temp.RegAdress;
                        (t as Person).RegDate          = temp.RegDate;
                        (t as Person).Documents.Person = t;
                        (t as Person).BirthPlace       = temp.BirthPlace;

                        t.BloodType = (byte)random.Next(1, 5);
                        t.Rhesus    = "+";
                        if (random.Next(0, 100) < 50)
                        {
                            t.Rhesus = "-";
                        }
                        t.WorkIncapacityListNum = random.Next(0, int.MaxValue).ToString();
                        t.InsurancePolicyNum    = random.Next(0, int.MaxValue).ToString();
                        for (int j = 0; j < random.Next(0, 4); j++)
                        {
                            Illness ill = new Illness {
                                Name = random.Next(0, 100).ToString()
                            };
                            ill.Hash = ill.Name.GetHashCode();
                            if (db.IllnessSet.Find(ill.Hash) != null)
                            {
                                ill = db.IllnessSet.Find(ill.Hash);
                            }
                            ill.Patient.Add(t);
                            t.Illness.Add(ill);
                        }
                        t.MedCard         = new MedCard();
                        t.MedCard.Patient = t;
                        for (int j = 0; j < random.Next(0, 3); j++)
                        {
                            int      r      = random.Next(0, db.FreeTimeSet.Count());
                            FreeTime freeTi = db.FreeTimeSet.ToArray()[r];
                            //FreeTime freeTi = db.FreeTimeSet.Local.ToArray()[r];
                            //Doctor tempDoctor = (Doctor)(from docs in db.PersonSet.Local where (docs.BirthDate == freeTi.Doctor.BirthDate && docs.NameHashID == freeTi.Doctor.NameHashID) select docs).ToList()[0];

                            Doctor tempDoctor = (Doctor)db.PersonSet.Find(freeTi.Doctor.BirthDate, freeTi.Doctor.NameHashID);

                            WorkTime workTi = new WorkTime {
                                Start = freeTi.Start, Doctor = tempDoctor, Finish = freeTi.Finish, BirthDate = tempDoctor.BirthDate, NameHashID = tempDoctor.NameHashID
                            };

                            db.FreeTimeSet.Remove(freeTi);

                            workTi.VisitInfo = new VisitInfo
                            {
                                WorkTimes        = workTi,
                                DateStart        = workTi.Start,
                                DateFinish       = workTi.Finish,
                                DoctorID         = tempDoctor.NameHashID,
                                Patient          = t,
                                PatientBirthDate = t.BirthDate,
                                PatientFullName  = t.FullName
                            };
                            t.VisitInfo.Add(workTi.VisitInfo);
                            tempDoctor.WorkTimes.Add(workTi);
                            db.WorkTimeSet.Add(workTi);
                            db.VisitInfoSet.Add(workTi.VisitInfo);
                        }
                        db.PersonSet.Add(t);

                        db.SaveChanges();
                    }
                }
            }
        }