Advertisement
Infiniti_Inter

pr 24 v 0.6.5

Mar 12th, 2020
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 17.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7.  
  8.  
  9. public class Clinic
  10. {
  11.  
  12.  
  13.     private Doctor _doctor = null;
  14.     private Pacient _pacient;
  15.  
  16.     public List<Pacient> pacients = new List<Pacient>();
  17.     public List<Doctor> doctors = new List<Doctor>();
  18.  
  19.  
  20.     private SortedDictionary<int, Doctor> ot = new SortedDictionary<int, Doctor> ();
  21.  
  22.     public Doctor GetDoctorByCode(int code)
  23.     {
  24.         if (ot.ContainsKey(code))
  25.             return ot[code];
  26.         else
  27.             return new Doctor("Wrong Code");
  28.     }
  29.  
  30.     public void AddDoctor(string surname, string name, string secondName, ushort age)
  31.     {
  32.         _doctor = new Doctor(surname, name, secondName, age);
  33.  
  34.         doctors.Add(_doctor);
  35.         ot.Add(_doctor.GetCode(), _doctor);
  36.  
  37.     }
  38.     public void AddDoctor(string surname, string name, string secondName, ushort age,
  39.         ushort qualification, ushort experience, ushort salary)
  40.     {
  41.         _doctor = new Doctor(surname, name, secondName, age, qualification, experience, salary);
  42.         doctors.Add(_doctor);
  43.         ot.Add(_doctor.GetCode(), _doctor);
  44.     }
  45.  
  46.  
  47.     public void AddPacient(string surname, string name, string secondName, ushort age)
  48.     {
  49.         _pacient = new Pacient(surname, name, secondName, age);
  50.  
  51.         pacients.Add(_pacient);
  52.     }
  53.  
  54.  
  55.  
  56.     public void ShowDoctors()
  57.     {
  58.         foreach (Doctor v in doctors)
  59.             Console.WriteLine(_doctor.Show());
  60.     }
  61.  
  62.  
  63.    
  64.  
  65.  
  66. }
  67.  
  68. abstract public class Unit
  69. {
  70.     public string name { get; set; }
  71.     public string surname { get; set; }
  72.     public string secondName { get; set; }
  73.     public ushort age { get; set; }
  74.     public Unit(string surname, string name, string secondName, ushort age)
  75.     {
  76.         this.name = name;
  77.         this.surname = surname;
  78.         this.secondName = secondName;
  79.         this.age = age;
  80.     }
  81.     public Unit() { }
  82.     virtual public string Show()
  83.     {
  84.         return null;
  85.     }
  86.  
  87.     public void EditName(string name) => this.name = name;
  88.     public void EditSurame(string surname) => this.surname = surname;
  89.     public void EditSecondName(string secondName) => this.secondName = secondName;
  90.     public void EditAge(ushort age) => this.age = age;
  91.  
  92. }
  93.  
  94. public class Time : IComparable<Time>
  95. {
  96.     private ushort hour;
  97.     private ushort min;
  98.     public Time(Time a)
  99.     {
  100.         this.min = a.min;
  101.         this.hour = a.hour;
  102.     }
  103.     public Time(int hour, int min)
  104.     {
  105.         this.hour = (ushort)hour;
  106.         this.min = (ushort)min;
  107.     }
  108.     public Time(ushort hour, ushort min)
  109.     {
  110.         this.hour = hour;
  111.         this.min = min;
  112.     }
  113.     public Time(string s)
  114.     {
  115.         string[] tmp = s.Split(':');
  116.         hour = ushort.Parse(tmp[0]);
  117.         min = ushort.Parse(tmp[1]);
  118.     }
  119.  
  120.     public int CompareTo(Time b)
  121.     {
  122.         if (this < b)
  123.             return -1;
  124.         if (this > b)
  125.             return 1;
  126.         return 0;
  127.     }
  128.     public static bool operator >(Time a, Time b)
  129.     {
  130.         return b < a;
  131.     }
  132.     public static bool operator <(Time a, Time b)
  133.     {
  134.         if (a.hour < b.hour)
  135.             return true;
  136.         if (a.hour == b.hour
  137.             && a.min < b.min)
  138.             return true;
  139.         return false;
  140.  
  141.     }
  142.     public void AddMin(int min)
  143.     {
  144.         AddMin((ushort)min);
  145.     }
  146.     public void AddMin(ushort min)
  147.     {
  148.         this.min += min;
  149.         if (this.min >= 60)
  150.         {
  151.             hour++;
  152.             this.min -= 60;
  153.         }
  154.         if (hour == 24)
  155.             hour = 0;
  156.     }
  157.  
  158.     public ushort this[int idx]
  159.     {
  160.         get
  161.         {
  162.             if (idx == 0)
  163.                 return hour;
  164.             else
  165.                 return min;
  166.         }
  167.         set
  168.         {
  169.             if (idx == 0)
  170.                 hour = value;
  171.             else
  172.                 min = value;
  173.         }
  174.     }
  175.     public override string ToString()
  176.     {
  177.         string m = ":";
  178.         if (min < 10)
  179.             m = ":0";
  180.         string h = "";
  181.         if (hour < 10)
  182.             h = "0";
  183.         return h + hour.ToString() + m + min.ToString();
  184.     }
  185.  
  186.  
  187. }
  188. public class Date : IComparable<Date>
  189. {
  190.     ushort day;
  191.     ushort month;
  192.     ushort year;
  193.  
  194.     public Date(Date b)
  195.     {
  196.         day = b.day;
  197.         month = b.month;
  198.         year = b.year;
  199.     }
  200.     public Date(ushort day, ushort month, ushort year)
  201.     {
  202.         this.day = day;
  203.         this.month = month;
  204.         this.year = year;
  205.     }
  206.     public Date(int day, int month, int year) : this((ushort)day, (ushort)month, (ushort)year)
  207.     {
  208.  
  209.     }
  210.  
  211.     public int CompareTo(Date b)
  212.     {
  213.         if (this < b)
  214.             return -1;
  215.         if (this > b)
  216.             return 1;
  217.         return 0;
  218.     }
  219.  
  220.     private int GetMonthCode()
  221.     {
  222.         switch (month)
  223.         {
  224.             case 1:
  225.             case 10:
  226.                 return 1;
  227.             case 5:
  228.                 return 2;
  229.             case 8:
  230.                 return 3;
  231.             case 2:
  232.             case 3:
  233.             case 11:
  234.                 return 4;
  235.             case 6:
  236.                 return 5;
  237.             case 9:
  238.             case 12:
  239.                 return 6;
  240.             case 4:
  241.             case 7:
  242.                 return 0;
  243.             default:
  244.                 return int.MaxValue;
  245.         }
  246.     }
  247.     private int GetYearCode()
  248.     {
  249.         return (6 + (year % 100) + (year % 100) / 4) % 7;
  250.     }
  251.     public int GetDayOfWeek()
  252.     {
  253.         int tmp = day + GetMonthCode() + GetYearCode();
  254.         int res = (tmp + 6) % 7;
  255.         if (res == 0)
  256.             res += 7;
  257.         return res;
  258.     }
  259.  
  260.     static public Date Now
  261.     {
  262.         get
  263.         {
  264.             DateTime tmp = DateTime.Now;
  265.             return new Date(tmp.Day, tmp.Month, tmp.Year);
  266.         }
  267.     }
  268.  
  269.     public void AddDays(object value)
  270.     {
  271.         day += (ushort)((int)value);
  272.     y:
  273.         ushort max = 0;
  274.         switch (month)
  275.         {
  276.             case 1:
  277.             case 3:
  278.             case 5:
  279.             case 6:
  280.             case 7:
  281.             case 9:
  282.             case 11:
  283.                 max = 31;
  284.                 break;
  285.             default:
  286.                 max = 30;
  287.                 break;
  288.         }
  289.         if (month == 2 && (year % 4 == 0 && year % 100 != 0) ^ (year % 400 == 0))
  290.         {
  291.             max = 29;
  292.         }
  293.         else
  294.         {
  295.             max = 28;
  296.         }
  297.         if (day > max)
  298.         {
  299.             day = (ushort)(day - max);
  300.             month++;
  301.             if (month == 13)
  302.             {
  303.                 year++;
  304.                 month = 1;
  305.                 goto y;
  306.             }
  307.         }
  308.  
  309.     }
  310.     public static int CompareYear(Date a, Date b)
  311.     {
  312.         DateTime c = new DateTime(a.year, a.month, a.day);
  313.         DateTime d = new DateTime(b.year, b.month, b.day);
  314.         TimeSpan f = c - d;
  315.         int countOfLeapYear = 0;
  316.         for (int i = c.Year + 1; i <= d.Year; ++i)
  317.             if ((i % 4 == 0 && i % 100 != 0) ^ (i % 400 == 0))
  318.                 countOfLeapYear++;
  319.         return (f.Days + countOfLeapYear - 1) / 365;
  320.     }
  321.     public static bool operator <(Date a, Date b)
  322.     {
  323.         if (a.year < b.year)
  324.             return true;
  325.         if (a.year == b.year
  326.             && a.month < b.month)
  327.             return true;
  328.         if (a.year == b.year
  329.             && a.month == b.month
  330.             && a.day < b.day)
  331.             return true;
  332.         return false;
  333.  
  334.  
  335.     }
  336.     public static bool operator >(Date a, Date b)
  337.     {
  338.         return b < a;
  339.     }
  340.  
  341.     public override string ToString()
  342.     {
  343.         string d = "";
  344.         if (day < 10)
  345.             d = "0";
  346.         string m = "";
  347.         if (month < 10)
  348.             m = "0";
  349.         int yy = year % 100;
  350.         string y = "";
  351.         if (yy < 10)
  352.             y = "0";
  353.         return d + day + "." + m + month + "." + y + yy;
  354.     }
  355. }
  356.  
  357. public class Doctor : Unit
  358. {
  359.  
  360.  
  361.     private int code;
  362.     private static int idx = 0;
  363.     private ushort qualification { get; set; } = 0;
  364.     private ushort experience { get; set; } = 0;
  365.     private ushort salary { get; set; } = 10000;
  366.  
  367.     private Date dateOfEmployment;//дата принятия на работу
  368.     private readonly int was;//cтартовый опыт
  369.     private ushort type = 0;
  370.  
  371.  
  372.     private SortedDictionary<Date, SortedDictionary<Time, Pacient>> schedule
  373.         = new SortedDictionary<Date, SortedDictionary<Time, Pacient>>();
  374.  
  375.     public Doctor(string specieal)
  376.     {
  377.         surname = specieal;
  378.         idx--;
  379.     }
  380.     public Doctor(string surname, string name, string secondName, ushort age)
  381. : base(surname, name, secondName, age)
  382.     {
  383.         dateOfEmployment = Date.Now;
  384.         was = experience;
  385.         Refresh();
  386.         code = idx++;
  387.  
  388.     }
  389.     public Doctor() { }
  390.  
  391.     public Doctor(string surname, string name, string secondName, ushort age, ushort qualification,
  392.         ushort experience, ushort salary) : this(surname, name, secondName, age)
  393.     {
  394.         this.qualification = qualification;
  395.         this.experience = experience;
  396.         this.salary = salary;
  397.         dateOfEmployment = Date.Now;
  398.         was = experience;
  399.         Refresh();
  400.         code = idx++;
  401.     }
  402.  
  403.  
  404.     public int GetCode() => code;
  405.     private void Fill()
  406.     {
  407.  
  408.         Date date = Date.Now;
  409.  
  410.         for (int i = 0; i < 31; ++i)
  411.         {
  412.  
  413.             if (schedule.ContainsKey(date))
  414.                 continue;
  415.             else
  416.             {
  417.                 Date _date = new Date(date);
  418.                 Time time = new Time(8 + type * 6, 0);
  419.                 schedule.Add(_date, new SortedDictionary<Time, Pacient>());
  420.                 if (_date.GetDayOfWeek() < 6)
  421.                 {
  422.                     for (int j = 0; j < 15; ++j)
  423.                     {
  424.                         schedule[_date].Add(new Time(time), new Pacient());
  425.                         time.AddMin(20);
  426.                     }
  427.                 }
  428.  
  429.             }
  430.             date.AddDays(1);
  431.         }
  432.     }
  433.     private void Delete()
  434.     {
  435.         Date now = Date.Now;
  436.         ICollection<Date> keys = schedule.Keys;
  437.  
  438.         foreach (Date v in keys)
  439.         {
  440.             if (v < now)
  441.                 schedule.Remove(v);
  442.             else
  443.                 break;
  444.         }
  445.     }
  446.  
  447.     private void RefreshExperience()
  448.     {
  449.         experience = (ushort)(was + Date.CompareYear(Date.Now, dateOfEmployment));
  450.     }
  451.     public void Refresh()
  452.     {
  453.         Delete();
  454.         Fill();
  455.         RefreshExperience();
  456.     }
  457.     public (Date, Time) CloserDateTime()
  458.     {
  459.         (Date, Time) cur;
  460.         ICollection<Date> keys = schedule.Keys;
  461.         foreach (Date date in keys)
  462.         {
  463.             ICollection<Time> keysTime = schedule[date].Keys;
  464.             foreach (Time time in keysTime)
  465.             {
  466.                 if (schedule[date][time].IsEmpty())
  467.                 {
  468.                     return (date, time);
  469.                 }
  470.             }
  471.         }
  472.         return (null, null);
  473.     }
  474.     public void Set(Date date, Time time, Pacient pacient)
  475.     {
  476.         if (schedule.ContainsKey(date)
  477.             && schedule[date].ContainsKey(time)
  478.                 && schedule[date][time].IsEmpty())
  479.         {
  480.             schedule[date][time] = pacient;
  481.         }
  482.         else
  483.             Console.WriteLine("ERROR");
  484.     }
  485.  
  486.  
  487.     public void GetSchedule(int n)
  488.     {
  489.         n = n > 30 ? 30 : n;
  490.         Refresh();
  491.         Date cur = Date.Now;
  492.  
  493.         Console.WriteLine(Show());
  494.  
  495.         Console.WriteLine(new string('=', 20));
  496.  
  497.         for (int i = 0; i < n; ++i)
  498.         {
  499.             Console.Write("======" + cur + "======" + "\n" + new string('=', 20) + "\n");
  500.             if (cur.GetDayOfWeek() < 6)
  501.             {
  502.                 int tabl = 0;//cчетчик табуляции
  503.                 foreach (var patient in schedule[cur])
  504.                 {
  505.                     tabl++;
  506.  
  507.                     if (patient.Value.IsEmpty())
  508.                     {
  509.                         Console.Write(patient.Key + " ---- ");
  510.                         Console.Write("Empty");
  511.                     }
  512.                     else
  513.                     {
  514.                         Console.Write(patient.Key + " ---- ");
  515.                         Console.WriteLine(patient.Value.Info());
  516.                         tabl = 0;
  517.                         continue;
  518.                     }
  519.                     if (tabl % 4 == 0)
  520.                         Console.WriteLine();
  521.                     else
  522.                         Console.Write("\t");
  523.                 }
  524.             }
  525.             else
  526.             {
  527.                 Console.Write("Holiday");
  528.             }
  529.             cur.AddDays(1);
  530.             Console.WriteLine();
  531.             Console.WriteLine();
  532.             Console.WriteLine();
  533.             Console.WriteLine(new string('=', 20));
  534.         }
  535.     }
  536.  
  537.  
  538.     public void SetDateOfEmployment(Date date)
  539.     {
  540.         dateOfEmployment = date;
  541.         RefreshExperience();
  542.     }
  543.  
  544.  
  545.     override public string Show()
  546.     {
  547.         string show = "Surname : " + surname + "\n" +
  548.                   "Name : " + name + "\n" +
  549.                   "SecondName : " + secondName + "\n" +
  550.                   "qualification : " + qualification + "\n" +
  551.                   "experience : " + experience + "\n";
  552.         return show;
  553.     }
  554.  
  555.  
  556.     public void EditDoctorQualification(ushort qualification) => this.qualification = qualification;
  557.     public void EditDoctorSalary(ushort salary) => this.salary = salary;
  558.  
  559.  
  560.  
  561. }
  562.  
  563.  
  564.  
  565.  
  566. public class Request
  567. {
  568.     public Date date;//when
  569.     public Time time;
  570.     public int doctorCode;
  571.     public int pacientCode;
  572.  
  573.     public Request(Request request)
  574.     {
  575.         this.date = request.date;
  576.         this.time = request.time;
  577.         this.doctorCode = request.doctorCode;
  578.         this.pacientCode = request.pacientCode;
  579.     }
  580.     public Request(Date date, Time time, int doctorCode, int pacientCode)
  581.     {
  582.         this.date = date;
  583.         this.time = time;
  584.         this.doctorCode = doctorCode;
  585.         this.pacientCode = pacientCode;
  586.     }
  587.  
  588.  
  589. }
  590.  
  591. public class Pacient : Unit
  592. {
  593.  
  594.     private int code;
  595.     private List<Request> history = new List<Request>();
  596.  
  597.  
  598.  
  599.  
  600.     private static int idx = 0;
  601.     public void AddRequest(Request req)
  602.     {
  603.         history.Add(req);
  604.     }
  605.  
  606.     bool NULL = false;
  607.     public Pacient()
  608.     {
  609.         NULL = true;
  610.     }
  611.  
  612.     public Pacient(string special)
  613.     {
  614.         surname = special;
  615.         idx--;
  616.     }
  617.     public Pacient(string surname, string name, string secondName, ushort age)
  618.         : base(surname, name, secondName, age)
  619.     {
  620.         idx++;
  621.         code = idx;
  622.     }
  623.  
  624.     public bool IsEmpty() => NULL;
  625.     public int GetCode() => code;
  626.  
  627.     override public string Show()
  628.     {
  629.         string show = "Surname : " + surname + "\n" +
  630.                   "Name : " + name + "\n" +
  631.                   "SecondName : " + secondName + "\n" +
  632.                   "Age : " + age + "\n";
  633.         return show;
  634.     }
  635.  
  636.     public void EnterToSchedule(Date date, Time time, Doctor doctor)
  637.     {
  638.         doctor.Set(date, time, this);
  639.         history.Add(new Request(date, time, doctor.GetCode(), this.GetCode()));
  640.     }
  641.     public void EnterToCloserSchedule(Doctor doctor)
  642.     {
  643.         (Date, Time) a = doctor.CloserDateTime();
  644.         if (a == (null, null))
  645.         {
  646.             Console.WriteLine("Not Enougth Empty Slot");
  647.             return;
  648.         }
  649.         else
  650.             doctor.Set(a.Item1, a.Item2, this);
  651.         history.Add(new Request(a.Item1, a.Item2, doctor.GetCode(), this.GetCode()));
  652.     }
  653.     public string Info()
  654.     {
  655.         return surname + " " + name + " " + secondName + " ID : " + code.ToString();
  656.     }
  657.  
  658.     public  void ShowAllHistory(Clinic clinic)
  659.     {
  660.         ShowHistoryFromDate(new Date(1, 1, 2000), clinic);  
  661.     }
  662.     public void ShowHistory(Clinic clinic)
  663.     {
  664.         ShowHistoryFromDate(Date.Now, clinic);
  665.     }
  666.  
  667.  
  668.     public void ShowHistoryFromDate(Date date, Clinic clinic)
  669.     {
  670.         Console.WriteLine(Show() + "\n--->History : \n" );
  671.         string s = new string('=', 20);
  672.         Console.WriteLine(s + "\n");
  673.         foreach (Request req in history)
  674.         {
  675.             if (req.date < date)
  676.             {
  677.                 continue;
  678.             }
  679.             else
  680.             {
  681.                
  682.                 Console.WriteLine("date :" + req.date);
  683.                 Console.WriteLine("time :" + req.time);
  684.                 Console.WriteLine("doctor :\n" + clinic.GetDoctorByCode(req.doctorCode).Show());
  685.                 Console.WriteLine(s);
  686.             }
  687.         }
  688.     }
  689. }
  690.  
  691.  
  692. class Program
  693. {
  694.     static void Main(string[] args)
  695.     {
  696.         Clinic a = new Clinic();
  697.         a.AddDoctor("Чернышев", "Константин", "Владимирович", 20);
  698.         a.AddDoctor("aba", "caba", "cadaba", 32);
  699.         a.AddPacient("Попов", "Данил", "Валерьевич", 32);
  700.  
  701.         //a.doctors[0].EditDoctorSalary(15000);
  702.         //a.ShowDoctors();
  703.         //Console.WriteLine(a.pacients[0].code);
  704.         Console.WriteLine(a.doctors[0].Show());
  705.         a.doctors[0].SetDateOfEmployment(new Date(14, 03, 2019));
  706.         a.pacients[0].EnterToCloserSchedule(a.doctors[0]);
  707.         a.pacients[0].EnterToSchedule(new Date(17, 03, 2020), new Time(12, 00), a.doctors[0]);
  708.         a.doctors[0].GetSchedule(5);
  709.  
  710.         a.pacients[0].ShowAllHistory(a);
  711.     }
  712.  
  713. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement