Exemplo n.º 1
0
 public Competitor()
 {
     LastName = "unknown";
     FirstName = "unknown";
     Address = new Address();
     Phone = new PhoneNumber();
     DOB = DateTime.Now;
     Age = 21;
     Gender = true;
     Sponsors = "";
     BikeBrand = "";
     BikeNumber = "1234";
     TagNumber = new TagId();
     TagNumber2 = new TagId();
 }
Exemplo n.º 2
0
 public Competitor(int id, String lastName, String firstName, Address address, PhoneNumber phone,
     DateTime dob, int age, bool gender, String sponsors, String bikeBrand, String bikeNumber, TagId tagNumber, TagId tagNumber2)
     : this()
 {
     this.ID = id;
     this.LastName = lastName;
     this.FirstName = firstName;
     this.Address = address;
     this.Phone = phone;
     this.DOB = dob;
     this.Age = age;
     this.Gender = gender;
     this.Sponsors = sponsors;
     this.BikeBrand = bikeBrand;
     this.BikeNumber = bikeNumber;
     this.TagNumber = tagNumber;
     this.TagNumber2 = tagNumber2;
 }
Exemplo n.º 3
0
        //TODO: rename to ImportCompetitorsCSV
        public bool ImportCompetitorsXLS(String filename, bool append)
        {
            try
            {
                //DataSet ds = new DataSet();
                //string strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                //    "Data Source=" + System.IO.Path.GetDirectoryName(filename) + ";" + "Extended Properties=\"Text;HDR=Yes;FMT=Delimited\"";
                //using (System.Data.OleDb.OleDbConnection conText = new System.Data.OleDb.OleDbConnection(strConnectionString))
                //{
                //    System.Data.OleDb.OleDbDataAdapter oleb = new System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [" + System.IO.Path.GetFileName(filename) + "]", conText);
                //    oleb.Fill(ds, "whatever");
                //    oleb.Dispose();
                //}

                if(!append)
                    this.competitors.Clear();

                //OleDB has a nasty problem - if it reads a field, say 20, it assumes that it is number, and
                //in the following rows this fields is supposed to be integer
                //the way to enforce certain data types is to have schema file (.ini) in the same directory as the
                //original file; unfortunately it looks like there is no other (nicer) way to achieve this
                //
                //Thus, instead of using OleDB, we use a free library for reading CSV files:
                //http://www.codeproject.com/KB/database/CsvReader.aspx
                //
                using (CsvReader csv = new CsvReader(new StreamReader(filename), true))
                {
                    //int fieldCount = csv.FieldCount;
                    //string[] headers = csv.GetFieldHeaders();

                    csv.MissingFieldAction = MissingFieldAction.ReplaceByNull;

                    while (csv.ReadNextRecord())
                    {
                        String idStr = (csv["ID"] != null) ? csv["ID"].ToString() : "";
                        String lastNameStr = (csv["lastName"] != null) ? csv["lastName"].ToString() : "";
                        String firstNameStr = (csv["firstName"] != null) ? csv["firstName"].ToString() : "";
                        String addressStr = (csv["address"] != null) ? csv["address"].ToString() : "";
                        String phoneStr = (csv["phoneNumber"] != null) ? csv["phoneNumber"].ToString() : "";
                        String dobStr = (csv["dob"] != null) ? csv["dob"].ToString() : "";
                        String ageStr = (csv["age"] != null) ? csv["age"].ToString() : "";
                        String genderStr = (csv["gender"] != null) ? csv["gender"].ToString() : "";
                        String sponsorsStr = (csv["sponsors"] != null) ? csv["sponsors"].ToString() : "";
                        String bikeBrandStr = (csv["bikeBrand"] != null) ? csv["bikeBrand"].ToString() : "";
                        String bikeNumberStr = (csv["compNumber"] != null) ? csv["compNumber"].ToString() : "";
                        String tagNumberStr = (csv["tagNumber"] != null) ? csv["tagNumber"].ToString() : "";
                        String tagNumber2Str = (csv["tagNumber2"] != null) ? csv["tagNumber2"].ToString() : "";

                        //for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        //{
                        //    String idStr = ds.Tables[0].Rows[i]["ID"].ToString();
                        //    String lastNameStr = ds.Tables[0].Rows[i]["lastName"].ToString();
                        //    String firstNameStr = ds.Tables[0].Rows[i]["firstName"].ToString();
                        //    String addressStr = ds.Tables[0].Rows[i]["address"].ToString();
                        //    String phoneStr = ds.Tables[0].Rows[i]["phoneNumber"].ToString();
                        //    String dobStr = ds.Tables[0].Rows[i]["dob"].ToString();
                        //    String ageStr = ds.Tables[0].Rows[i]["age"].ToString();
                        //    String genderStr = ds.Tables[0].Rows[i]["gender"].ToString();
                        //    String sponsorsStr = ds.Tables[0].Rows[i]["sponsors"].ToString();
                        //    String bikeBrandStr = ds.Tables[0].Rows[i]["bikeBrand"].ToString();
                        //    String bikeNumberStr = ds.Tables[0].Rows[i]["bikeNumber"].ToString();
                        //    String tagNumberStr = ds.Tables[0].Rows[i]["tagNumber"].ToString();
                        //    String tagNumber2Str = ds.Tables[0].Rows[i]["tagNumber2"].ToString();

                        String[] addressArr = new String[] { "", "", "", "12345" };
                        try
                        {
                            String[] adrAr = addressStr.Split(new char[] { ';' });
                            if (adrAr[0] != null)
                                addressArr[0] = adrAr[0];
                            if (adrAr[1] != null)
                                addressArr[1] = adrAr[1];
                            if (adrAr[2] != null)
                                addressArr[2] = adrAr[2];
                            if (adrAr[3] != null)
                                addressArr[3] = adrAr[3];
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.StackTrace);
                            DataManager.Log(e.StackTrace);
                        }

                        int cID = 0;
                        String lastName = "";
                        String firstName = "";
                        Address address = new Address("", "", "", 12345);
                        PhoneNumber phoneNumber = new PhoneNumber("");
                        DateTime dob = DateTime.Now;
                        int age = 20;
                        bool gender = true;
                        String sponsors = "";
                        String bikeBrand = "";
                        String bikeNumber = "0";
                        TagId tagNumber = new TagId();
                        TagId tagNumber2 = new TagId();

                        try
                        {
                            try
                            {
                                cID = int.Parse(idStr);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.StackTrace);
                                DataManager.Log(e.StackTrace);
                            }
                            lastName = lastNameStr;
                            firstName = firstNameStr;
                            try
                            {
                                address = new Address(addressArr[0].Trim(), addressArr[1].Trim(), addressArr[2].Trim(), int.Parse(addressArr[3].Trim()));
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.StackTrace);
                                DataManager.Log(e.StackTrace);
                            }
                            phoneNumber = new PhoneNumber(phoneStr);

                            try
                            {
                                dob = DateTime.Parse(dobStr);

                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.StackTrace);
                                DataManager.Log(e.StackTrace);
                            }

                            try
                            {
                                age = int.Parse(ageStr);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.StackTrace);
                                DataManager.Log(e.StackTrace);
                            }
                            gender = genderStr.ToLower().Equals("true") ? true : false;
                            if (genderStr.ToLower().Equals(""))
                                gender = true;
                            sponsors = sponsorsStr;
                            bikeBrand = bikeBrandStr;

                            bikeNumber = bikeNumberStr;
                            //try
                            //{
                            //    bikeNumber = int.Parse(bikeNumberStr);
                            //}
                            //catch (Exception e)
                            //{
                            //    Console.WriteLine(e.StackTrace);
                            //    DataManager.Log(e.StackTrace);
                            //}

                            tagNumber = new TagId(tagNumberStr);
                            tagNumber2 = new TagId(tagNumber2Str);
                        }
                        catch (Exception exc)
                        {
                            Console.WriteLine(exc.StackTrace);
                            DataManager.Log("Exception caught!" + exc.StackTrace);
                        }
                        Competitor c = new Competitor(cID, lastName, firstName, address, phoneNumber,
                            dob, age, gender, sponsors, bikeBrand, bikeNumber, tagNumber, tagNumber2);
                        this.competitors.Add(c);
                    }
                }
            }
            catch (Exception exc)
            {
                return false;
            }

            return true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Populate the UI controls with the given data. Please note that there is no
        /// error checking, we assume that the data is properly formatted, etc.
        /// </summary>
        public void SetData(String lastName, String firstName, Address address,
            PhoneNumber phoneNumber, DateTime dob, int age, bool gender, String sponsors,
            String bikeBrand, String bikeNumber, TagId tagID, TagId tagID2)
        {
            lastNameTextBox.Text = lastName;
            firstNameTextBox.Text = firstName;
            addressLineTextBox.Text = address.AddressLine;
            cityTextBox.Text = address.City;
            stateComboBox.SelectedValue = address.State;
            if ((address.Zip + "").Length == 5)
                zipTextBox.Text = address.Zip + "";
            else
            {
                if ((address.Zip + "").Length >= 5)
                {
                    zipTextBox.Text = (address.Zip + "").Substring(0, 5);
                    zipTextBoxAdd.Text = (address.Zip + "").Substring(5);
                }
            }
            phoneTextBox.Text = phoneNumber.Number;
            dobSelector.Value = dob;
            ageTextBox.Text = age + "";
            if (gender)
                genderComboBox.SelectedIndex = 0;//male
            else
                genderComboBox.SelectedIndex = 1;

            sponsorsTextBox.Text = sponsors;
            bikeBrandTextBox.Text = bikeBrand;
            bikeNumberTextBox.Text = bikeNumber + "";
            bikeTagTextBox.Text = tagID + "";
            bikeTag2TextBox.Text = tagID2 + "";
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns all the values from the UI elements.
        /// </summary>
        /// <returns>Returns false if there was a problem retrieving data from the gui components.</returns>
        public bool GetData(
            out int ID, out String lastName, out String firstName, out Address address,
            out PhoneNumber phoneNumber, out DateTime dob, out int age, out bool gender, out String sponsors,
            out String bikeBrand, out String bikeNumber, out TagId tagNumber, out TagId tagNumber2, out String errorMessage, out bool propagateChanges)
        {
            errorMessage = "";
            String errorControlString = "";//changed to inform where was a problem with UI
            try
            {
                //ID = 0;//debug
                propagateChanges = syncChangesCheckBox.Checked;
                ID = DataManager.getNextID();
                lastName = lastNameTextBox.Text;
                firstName = firstNameTextBox.Text;
                errorControlString = "ZIP";
                int zipInt = 0;
                try
                {
                    zipInt = int.Parse(zipTextBox.Text + zipTextBoxAdd.Text);
                }
                catch {}
                address = new Address(addressLineTextBox.Text, cityTextBox.Text, stateComboBox.Text, zipInt);
                errorControlString = "Phone number";
                phoneNumber = new PhoneNumber(phoneTextBox.Text);
                dob = dobSelector.Value;
                errorControlString = "Age";
                age = 20;
                try
                {
                    age = int.Parse(ageTextBox.Text);
                }
                catch {}
                errorControlString = "Gender";
                gender = (genderComboBox.Text == "Male") ? true : false;
                if (genderComboBox.SelectedIndex == -1)
                    throw new Exception("Gender not selected!");
                sponsors = sponsorsTextBox.Text;
                bikeBrand = bikeBrandTextBox.Text;
                errorControlString = "Bike Number";
                //bikeNumber = "0";
                bikeNumber = bikeNumberTextBox.Text;
                //try
                //{
                //    bikeNumber = int.Parse(bikeNumberTextBox.Text);
                //}
                //catch { }
                tagNumber = new TagId(bikeTagTextBox.Text);
                tagNumber2 = new TagId(bikeTag2TextBox.Text);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception caught!" + e.StackTrace);
                DataManager.Log("Exception Caught!" + e.StackTrace);

                //populate with some default values; out keyword enforces us
                //to put at least something in these values

                propagateChanges = false;
                ID = 0;
                lastName = "";
                firstName = "";
                address = new Address("", "", "", 12345);
                phoneNumber = new PhoneNumber("");
                dob = DateTime.Now;
                age = 20;
                gender = true;
                sponsors = "";
                bikeBrand = "";
                bikeNumber = "0";
                tagNumber = new TagId();
                tagNumber2 = new TagId();

                errorMessage = "Sorry, there was a problem with field " + errorControlString + ".";

                return false;
            }

            return true;
        }