예제 #1
0
 public bool addState(State s)
 {
     for(int i=0; i<States.Count; i++){
         if(s.Name == States[i].Name){
             return false;
         }
     }
     States.Add(s);
     return true;
 }
예제 #2
0
        private void createButton_Click(object sender, EventArgs e)
        {
            State s = new State();
            if(File.Exists(fileBox.Text)) {

                using(CsvReader csv = new CsvReader(new StreamReader(fileBox.Text), true)) {
                    //extract field count and headers from csv
                    int fieldCount = csv.FieldCount;
                    string[] headers = csv.GetFieldHeaders();
                    bool area = false;

                    #region Header
                    csv.ReadNextRecord();

                    headers = csv[0].Split(',');
                    s.Name = headers[2].Trim();

                    //quarter based off of headers[3] in format Jun, 20XX
                    int quarter = 20;

                    headers = headers[3].Split(' ');

                    switch(headers[1]) {
                        case "Mar":
                            quarter = 1;
                            break;
                        case "Jun":
                            quarter = 2;
                            break;
                        case "Sep":
                            quarter = 3;
                            break;
                        case "Dec":
                            quarter = 4;
                            break;
                    }

                    quarters.Remove(quarter);
                    #endregion

                    for(int i=0; i<3; i++) {
                        csv.ReadNextRecord();
                    }
                    Region r = null;
                    while(csv.ReadNextRecord()) {
                        #region Region Name

                        int room;
                        int bed;
                        int employee;
                        double octOcc;
                        double novOcc;
                        double decOcc;
                        double octStay;
                        double novStay;
                        double decStay;
                        if(csv[0].Contains("(TR)")) {
                            if(csv[0].Contains("Total")) {
                                area = false;

                                //Region Data
                                string n = csv[0].Trim();

                                string rString = csv[2].Trim().Replace(",", "");
                                if(rString.Equals("") != true) {
                                    room = int.Parse(rString);
                                } else {
                                    room = 0;
                                }
                                string bString = csv[3].Trim().Replace(",", "");
                                if(bString.Equals("") != true) {
                                    bed = int.Parse(bString);
                                } else {
                                    bed = 0;
                                }

                                string eString = csv[4].Trim().Replace(",", "");
                                if(eString.Equals("") != true) {
                                    employee = int.Parse(eString);
                                } else {
                                    employee = 0;
                                }

                                try {
                                    // CultureInfo.InvariantCulture
                                    Double.TryParse(csv[9].Trim(), out octOcc);
                                } catch(Exception ex) {
                                    octOcc =0.0;
                                }
                                try {
                                    Double.TryParse(csv[10].Trim(), out novOcc);
                                } catch(Exception ex) {
                                    novOcc =0.0;
                                }
                                try {
                                    Double.TryParse(csv[11].Trim(), out decOcc);
                                } catch(Exception ex) {
                                    decOcc =0.0;
                                }
                                try {
                                    Double.TryParse(csv[24].Trim(), out octStay);
                                } catch(Exception ex) {
                                    octStay =0.0;
                                }
                                try {
                                    Double.TryParse(csv[25].Trim(), out novStay);
                                } catch(Exception ex) {
                                    novStay =0.0;
                                }
                                try {
                                    Double.TryParse(csv[26].Trim(), out decStay);
                                } catch(Exception ex) {
                                    decStay =0.0;
                                }
                                r.Rooms = room;
                                r.Beds = bed;
                                r.Employees = employee;

                                r.Occupancy[9] = octOcc;
                                r.Occupancy[10] = novOcc;
                                r.Occupancy[11] = decOcc;
                                r.Stay[9] = octStay;
                                r.Stay[10] = novStay;
                                r.Stay[11] = decStay;

                                Regions.Add(r);

                            } else {
                                string n = csv[0].Replace(" (TR)", "");
                                r= new Region(n);
                                area = true;
                            }
                        #endregion
                        } else if(area) {
                            #region RegionArea
                            string n = csv[0].Trim();
                            //
                            string rString = csv[2].Trim().Replace(",", "");
                            if(rString.Equals("") != true) {
                                room = int.Parse(rString);
                            } else {
                                room = 0;
                            }
                            string bString = csv[3].Trim().Replace(",", "");
                            if(bString.Equals("") != true) {
                                bed = int.Parse(bString);
                            } else {
                                bed = 0;
                            }

                            string eString = csv[4].Trim().Replace(",", "");
                            if(eString.Equals("") != true) {
                                employee = int.Parse(eString);
                            } else {
                                employee = 0;
                            }

                            try {
                                // CultureInfo.InvariantCulture
                                Double.TryParse(csv[9].Trim(), out octOcc);
                            } catch(Exception ex) {
                                octOcc =0.0;
                            }
                            try {
                                Double.TryParse(csv[10].Trim(), out novOcc);
                            } catch(Exception ex) {
                                novOcc =0.0;
                            }
                            try {
                                Double.TryParse(csv[11].Trim(), out decOcc);
                            } catch(Exception ex) {
                                decOcc =0.0;
                            }
                            try {
                                Double.TryParse(csv[24].Trim(), out octStay);
                            } catch(Exception ex) {
                                octStay =0.0;
                            }
                            try {
                                Double.TryParse(csv[25].Trim(), out novStay);
                            } catch(Exception ex) {
                                novStay =0.0;
                            }
                            try {
                                Double.TryParse(csv[26].Trim(), out decStay);
                            } catch(Exception ex) {
                                decStay =0.0;
                            }

                            r.addArea(new Area(n, quarter, room, bed, employee, octOcc, novOcc, decOcc, octStay, novStay, decStay));
                        }
                            #endregion
                    }
                }
                createButton.Visible = false;
                updateButton.Visible = true;
            }
            s.Regions = Regions;
            country.addState(s);
        }
예제 #3
0
 public bool selectState(string name)
 {
     for(int i=0; i<country.States.Count; i++) {
         if(country.States[i].Name.Equals(name)) {
             selectedState = country.States[i];
             return true;
         }
     }
     return false;
 }