Ejemplo n.º 1
0
        /// <summary>
        /// This method returns the Member With DTN
        /// </summary>
        public DTN.Member CreateMemberWithDTN()
        {
            // initial value
            DTN.Member member = new DTN.Member();

            // Locals
            DTN.ZipCode zipCode = null;

            // locals
            string unit = "";

            try
            {
                // set each property
                member.Active = true;

                // Create Address
                member.Address = new DTN.Address();

                // get the AddressNumber
                int addressNumber = AddressNumberShuffler.PullNumber();

                // if the AddressNumber
                if (addressNumber % 100 < Info.PercentInApartments)
                {
                    // now get a number % 26
                    int isUnitNumericValue = ((addressNumber * 67) % 100) + 1;

                    // If this value is higher than percent needed for UnitNumeric
                    if (isUnitNumericValue > Info.PercentUnitNumeric)
                    {
                        // This is a letter instead of a number
                        unit = "Unit " + ((char)((isUnitNumericValue % 26) + 65)).ToString();
                    }
                    else
                    {
                        // split half up to say 'Apt.' and half up to say #'
                        if (addressNumber % 2 == 0)
                        {
                            unit = "Apt. #" + isUnitNumericValue.ToString();
                        }
                        else if (addressNumber % 3 == 1)
                        {
                            unit = "#" + isUnitNumericValue.ToString();
                        }
                    }
                }

                // Set the properties on the Address
                member.Address.StreetAddress = (addressNumber.ToString() + " " + DTNStreetNames[StreetNameShuffler.PullNumber()].Name);
                member.Address.Unit          = unit;

                // set the ZipCode
                zipCode = DTNZipCodes[ZipCodeShuffler.PullNumber()];

                // if the zipCode exists
                if (NullHelper.Exists(zipCode))
                {
                    // Set the City
                    member.Address.City    = zipCode.CityName;
                    member.Address.StateId = zipCode.StateId;
                    member.Address.ZipCode = zipCode.Name;
                }

                // Seft the FirstName & LastName
                member.FirstName = DTNFirstNames[FirstNameShuffler.PullNumber()].Name;
                member.LastName  = DTNLastNames[LastNameShuffler.PullNumber()].Name;
            }
            catch (Exception error)
            {
                // for debugging only
                DebugHelper.WriteDebugError("CreateMemberWithDTN", "MemberGenerator", error);
            }

            // return value
            return(member);
        }
        /// <summary>
        /// event is fired when the 'ImportZipButton' is clicked.
        /// </summary>
        private void ImportZipButton_Click(object sender, EventArgs e)
        {
            // locals
            bool        zipCodeSaved = false;
            string      fileName     = "";
            string      temp         = "";
            List <Word> words        = null;

            char[] delimiter     = { '\t' };
            string zip           = "";
            string cityName      = "";
            string stateName     = "";
            int    lineCount     = 0;
            int    stateId       = 0;
            string lastStateName = "";

            try
            {
                // get the text of the USA-Zip.txt file
                string zipTextFile = ZipCodeControl.Text;

                // attempt to read all the text
                string textFileContents = File.ReadAllText(zipTextFile);

                // If the textFileContents string exists
                if (TextHelper.Exists(textFileContents))
                {
                    // create the fileInfo
                    FileInfo fileInfo = new FileInfo(zipTextFile);

                    // set the name of the file
                    fileName = fileInfo.Name;

                    // get the text lines (this file is one entry per row)
                    List <TextLine> lines = WordParser.GetTextLines(textFileContents);

                    // If the lines collection exists and has one or more items
                    if (ListHelper.HasOneOrMoreItems(lines))
                    {
                        // Setup Graph4
                        Graph4.Visible = true;
                        Graph4.Maximum = lines.Count;
                        Graph4.Value   = 0;

                        // refresh everything
                        Refresh();

                        // Create a new instance of a 'Gateway' object.
                        Gateway gateway = new Gateway();

                        // first pass handle only columns 0 - 3
                        // Iterate the collection of TextLine objects
                        foreach (TextLine line in lines)
                        {
                            // Increment the value for lineCount
                            lineCount++;

                            // get the current line
                            temp = line.Text.Trim();

                            // get the words
                            words = WordParser.GetWords(temp, delimiter);

                            // If the words collection exists and has one or more items
                            if ((ListHelper.HasOneOrMoreItems(words)) && (words.Count == 4))
                            {
                                // Append columns 0 - 3
                                zip       = words[0].Text;
                                cityName  = words[1].Text;
                                stateName = words[2].Text;

                                // if we just reached a new stateId
                                if (stateName != lastStateName)
                                {
                                    // find the state
                                    dataObjects.State state = gateway.FindStateByName(stateName);

                                    // If the state object exists
                                    if (NullHelper.Exists(state))
                                    {
                                        // set the StateId
                                        stateId = state.Id;
                                    }
                                }

                                // if the stateId were set
                                if (stateId > 0)
                                {
                                    // insert a ZipCode object
                                    dataObjects.ZipCode zipCode = new dataObjects.ZipCode();

                                    // set the properties on the zipCode object
                                    zipCode.Name     = zip;
                                    zipCode.CityName = cityName;
                                    zipCode.StateId  = stateId;

                                    // perform the save
                                    zipCodeSaved = gateway.SaveZipCode(ref zipCode);
                                }

                                // if the zipCode was saved
                                if (zipCodeSaved)
                                {
                                    // increment the value for the graph
                                    Graph4.Value++;
                                }

                                // set the lastStateName
                                lastStateName = stateName;
                            }
                        }

                        // Show finished
                        MessageBoxHelper.ShowMessage("The file '" + fileName + "' has been imported.", "Import Complete");
                    }
                }
                else
                {
                    // Show an error
                    MessageBoxHelper.ShowMessage("The selected import file could not be read.", "Import File Error");
                }
            }
            catch (Exception error)
            {
                // for debugging only
                DebugHelper.WriteDebugError("ImportZipButton_Click", this.Name, error);
            }
        }