Beispiel #1
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.");
                }
            }
        }