Exemplo n.º 1
0
        /* main buttons */

        private void bt_start_Click(object sender, EventArgs e)
        {
            if (this.tb_budget.Text == "" || this.tb_population.Text == "")
            {
                MessageBox.Show("Required parameters missing.");
            }
            else
            {
                int chb, chp;
                if (int.TryParse(this.tb_budget.Text, out chb) && int.TryParse(this.tb_population.Text, out chp))
                {
                    stopwatch = Stopwatch.StartNew();

                    this.inputType               = false;
                    this.tb_budget.ReadOnly      = true;
                    this.tb_population.ReadOnly  = true;
                    this.bt_start.Enabled        = false;
                    this.bt_custom_start.Enabled = false;

                    ILockdownPolicy terra = new Policy_none();
                    community = new Community(chp);
                    hospital  = new Hospital(chp, chb, terra);

                    accountForOptionalInput();
                    community.populateMemberList();
                    Qualification q = Qualification.InfectiousDisease;
                    if (!hospital.initiateHospitalList(community.getDistrictCount(), q))
                    {
                        if (chb > 4500)
                        {
                            MessageBox.Show("Simulation failure: population too small.");
                        }
                        else
                        {
                            MessageBox.Show("Simulation failure: budget too small.");
                        }
                        this.tb_budget.ReadOnly      = false;
                        this.tb_population.ReadOnly  = false;
                        this.bt_start.Enabled        = true;
                        this.bt_custom_start.Enabled = true;
                        restateOptionalInput();
                    }
                    else
                    {
                        this.timer_general.Enabled     = true;
                        this.gb_time.Enabled           = true;
                        this.gb_lockdownPolicy.Enabled = true;
                        this.rb_noLockdown.Select();
                        this.bt_save.Enabled             = true;
                        this.timer_label_updator.Enabled = true;
                        update_labels();
                        this.timer_socialEvent.Enabled = true;
                    }
                }
                else
                {
                    MessageBox.Show("Parameter format invalid.");
                }
            }
        }
Exemplo n.º 2
0
 private void update_labels()
 {
     this.lb_comm_pop_status.Text   = $"Number of Members: {community.getMemberListSize()}";
     (double f, double m)           = community.getGenderPercentages();
     this.lb_comm_gender.Text       = $"Gender Distribution: {f.ToString("F2")}% Females, {m.ToString("F2")}% Males.";
     (double y, double a, double o) = community.getAgePercentages();
     this.bl_comm_age_distr.Text    = $"Age Distribution: {y.ToString("F2")}% [0-20], {a.ToString("F2")}% [20-60], {o.ToString("F2")}% [60+].";
     this.lb_remainingBudget.Text   = $"Remaining Budget: {hospital.getBudget()}";
     this.lb_hosp_nrOfDocs.Text     = $"Number of Doctors: {hospital.getNrOfDocs()}";
     this.lb_hosp_nrOfNurses.Text   = $"Number of Nurses: {hospital.getNrOfNurses()}";
     this.lb_hosp_potDoc.Text       = $"Potential Doctors: {hospital.getPotentialDoctors()}";
     this.lb_hosp_potNus.Text       = $"Potential Nurses: {hospital.getPotentialNurses()}";
     this.lb_hm_nrOfSq.Text         = $"Number of Districts: {community.getDistrictCount()} (Population/Density)";
     this.lb_host_nrPat.Text        = "Number of Patients: " + hospital.getPatientCount().ToString();
     this.lb_hosp_yCaseNr.Text      = "Yesterday's Cases: " + (community.getTransmitedNr()).ToString();
     this.lbl_dece_pat.Text         = "Deceased Patients: " + (hospital.getDeceased().ToString());
     this.lbl_recov_pat.Text        = "Recovered Patients: " + (hospital.getRecovered().ToString());
 }
Exemplo n.º 3
0
        private void bt_custom_start_Click(object sender, EventArgs e)
        {
            if (this.tb_budget.Text == "")
            {
                MessageBox.Show("Required budget parameter missing.");
            }
            else
            {
                int chb, chp = 0;
                if (int.TryParse(this.tb_budget.Text, out chb))
                {
                    customCommunity = new List <int>();
                    var fileContent = string.Empty;
                    var filePath    = string.Empty;
                    using (OpenFileDialog openFileDialog = new OpenFileDialog())
                    {
                        openFileDialog.InitialDirectory = @"..\..\"; //"c:\\";
                        openFileDialog.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                        openFileDialog.FilterIndex      = 2;
                        openFileDialog.RestoreDirectory = true;
                        if (openFileDialog.ShowDialog() == DialogResult.OK)
                        {
                            filePath = openFileDialog.FileName;
                            var fileStream = openFileDialog.OpenFile();
                            using (StreamReader reader = new StreamReader(fileStream))
                            {
                                while (!reader.EndOfStream)
                                {
                                    var line   = reader.ReadLine();
                                    var values = line.Split(',');
                                    foreach (var v in values)
                                    {
                                        int temp;
                                        if (int.TryParse(v, out temp))
                                        {
                                            customCommunity.Add(temp);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Expecting correct comma separated values file.");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    foreach (int i in customCommunity)
                    {
                        chp += i;
                    }
                    MessageBox.Show($"District count {customCommunity.Count.ToString()}. " +
                                    $"\nTotal population {chp}.\nClose to begin.", "Custom Map Read Successful");

                    this.inputType = true;
                    //MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);
                    stopwatch = Stopwatch.StartNew();
                    this.tb_budget.ReadOnly      = true;
                    this.tb_population.ReadOnly  = true;
                    this.bt_start.Enabled        = false;
                    this.bt_custom_start.Enabled = false;
                    ILockdownPolicy terra = new Policy_none();
                    //community = new Community(chp);
                    community = new Community(chp, customCommunity);
                    hospital  = new Hospital(chp, chb, terra);
                    accountForOptionalInput();
                    community.populateMemberListCustom();
                    Qualification q = Qualification.InfectiousDisease;
                    if (!hospital.initiateHospitalList(community.getDistrictCount(), q))
                    {
                        if (chb > 4500)
                        {
                            MessageBox.Show("Simulation failure: population too small.");
                        }
                        else
                        {
                            MessageBox.Show("Simulation failure: budget too small.");
                        }
                        this.tb_budget.ReadOnly      = false;
                        this.tb_population.ReadOnly  = false;
                        this.bt_start.Enabled        = true;
                        this.bt_custom_start.Enabled = true;
                        restateOptionalInput();
                    }
                    else
                    {
                        this.timer_general.Enabled     = true;
                        this.gb_time.Enabled           = true;
                        this.gb_lockdownPolicy.Enabled = true;
                        this.rb_noLockdown.Select();
                        this.bt_save.Enabled             = true;
                        this.timer_label_updator.Enabled = true;
                        update_labels();
                        this.timer_socialEvent.Enabled = true;
                    }
                }
                else
                {
                    MessageBox.Show("Parameter format invalid.");
                }
            }
        }