/// <summary> /// This method returns the Extensions /// </summary> public static List <string> GetExtensions(string text) { // initial value List <string> extensions = new List <string>(); // If the text string exists if (TextHelper.Exists(text)) { // only use commas or semicolons char[] delimiterChars = { ',', ';' }; // Parse the words List <Word> words = WordParser.GetWords(text, delimiterChars); // if there are one or more words if (ListHelper.HasOneOrMoreItems(words)) { // Iterate the collection of Word objects foreach (Word word in words) { // Add this extension extensions.Add(word.Text); } } } // return value return(extensions); }
/// <summary> /// This method Parse Numbers /// </summary> public static void ParseNumbers(string text, ref int number1, ref int number2, ref int number3, ref int number4) { // locals int count = 0; // only use a space as a delimiter character char[] delimiterChars = { ' ' }; // if the words exists List <Word> words = WordParser.GetWords(text, delimiterChars); // If the words collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(words)) { // Iterate the collection of Word objects foreach (Word word in words) { // if this word is a number if (NumericHelper.IsNumeric(word.Text)) { // Increment the value for count count++; // if this is the firstNumber if (count == 1) { // set number1 number1 = NumericHelper.ParseInteger(word.Text, -1000, -1001); } else if (count == 2) { // set number2 number2 = NumericHelper.ParseInteger(word.Text, -1000, -1001); } else if (count == 3) { // set number3 number3 = NumericHelper.ParseInteger(word.Text, -1000, -1001); } else if (count == 4) { // set number4 number4 = NumericHelper.ParseInteger(word.Text, -1000, -1001); } } } } }
/// <summary> /// This method returns the Valid Email /// </summary> public bool CheckValidEmail(string emailAddress) { // initial value bool isValidEmail = false; try { // If the emailAddress string exists if (TextHelper.Exists(emailAddress)) { // find the at Sign int atSignIndex = emailAddress.IndexOf("@"); // if found if (atSignIndex > 0) { // get the wordBefore string wordBefore = emailAddress.Substring(0, atSignIndex - 1); // get the words after string wordsAfter = emailAddress.Substring(atSignIndex + 1); // get the delimiters char[] delimiters = { '.' }; // get the words List <Word> words = WordParser.GetWords(wordsAfter, delimiters); // if there are 2 or more words, this should be valid isValidEmail = ((TextHelper.Exists(wordBefore)) && (ListHelper.HasXOrMoreItems(words, 2))); } } } catch (Exception error) { // not valid isValidEmail = false; // for debugging only DebugHelper.WriteDebugError("CheckValidEmail", "Join.razor.cs", error); } // return value return(isValidEmail); }
/// <summary> /// event is fired when the 'GetCommitButton' is clicked. /// </summary> private void GetCommitButton_Click(object sender, EventArgs e) { // local string commitRawText = ""; try { // get the client using (var client = new WebClient()) { // get the result string webPageText = client.DownloadString(RepoUrl); // If the webPageText string exists if (TextHelper.Exists(webPageText)) { // string we are looking for string href = @"DataJuggler/DataTier.Net/commit/"; // parse the textLines List <TextLine> textLines = WordParser.GetTextLines(webPageText); // If the textLines collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(textLines)) { // Iterate the collection of TextLine objects foreach (TextLine textLine in textLines) { // is this is the line we are looking for if (textLine.Text.Contains(href)) { // get the full text commitRawText = textLine.Text; // break out of the loop break; } } } } // If the commitRawText string exists if (TextHelper.Exists(commitRawText)) { // convert to words List <Word> words = WordParser.GetWords(commitRawText); // If the words collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(words)) { // local bool nextWord = false; // Iterate the collection of Word objects foreach (Word word in words) { // if the value for nextWord is true if ((nextWord) && (word.HasText) && (word.Text.Length > 7)) { // set the commitText string commitText = word.Text; // Set the text this.CommitTextBox.Text = commitText.Substring(0, 7); // break out of the loop break; } else { // we must check for the word commit if (TextHelper.IsEqual("commit", word.Text)) { // Set the value for the nextWord to true nextWord = true; } } } } } } } catch (Exception error) { // for debugging only DebugHelper.WriteDebugError("GetCommitButton_Click", this.Name, error); } }
/// <summary> /// This method returns the Links With Href /// </summary> public string ReplaceLinksWithHref(string text) { // initial value string formattedText = text; // delimiters char[] delimiters = { ' ', '\n', }; // If the text string exists if (ContainsLink(text)) { // if the NewLine is not found if (!text.Contains(Environment.NewLine)) { // The parsing on lines isn't working, this is a good hack till // I rewrite the parser to be more robust someday text = text.Replace("\n", Environment.NewLine); } // just in case, fix for the hack text = text.Replace("\r\r", "\r"); // Get the text lines List <TextLine> lines = WordParser.GetTextLines(text); // If the lines collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(lines)) { // iterate the textLines foreach (TextLine line in lines) { // Get the words - parse only on space List <Word> words = WordParser.GetWords(line.Text, delimiters); // If the words collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(words)) { // iterate each word foreach (Word word in words) { // if this is a link if (StartsWithLink(word.Text, true)) { // set the word as a href string temp = "<a href=" + word.Text + " target=_blank>" + word.Text + "</a>"; // if the word.Text ends with a known extension, but does not start with http or https if ((TextEndsWithKnownExtension(word.Text)) && (!StartsWithLink(word.Text, false))) { // send the user to https. Its 2020, and if the user is send someone to an insecure site, // they must specify http:// in the link, otherwise don't post a link to an insecure site. temp = "<a href=https://" + word.Text + " target=_blank>" + word.Text + "</a>"; } // Replace out the word with the link formattedText = formattedText.Replace(word.Text, temp); } } } } } } // return value return(formattedText); }
/// <summary> /// This method Parse Projects /// </summary> public List <VSProject> ParseProjects(Solution solution) { // initial value List <VSProject> projects = new List <VSProject>(); // typical delimiter characters char[] commaDelimiter = { ',' }; // If the solutionFilePath string exists if ((NullHelper.Exists(solution)) && (File.Exists(solution.Path))) { // read the text of the file string fileText = File.ReadAllText(solution.Path); // parse the textLines List <TextLine> lines = WordParser.GetTextLines(fileText); // If the lines collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(lines)) { // get the projectLines List <TextLine> projectLines = lines.Where(x => x.Text.StartsWith("Project")).Where(x => x.Text.Contains(".csproj")).ToList(); // if there are one or more projectLines if (ListHelper.HasOneOrMoreItems(projectLines)) { // Iterate the collection of TextLine objects foreach (TextLine line in projectLines) { // if the line.Text exists if (TextHelper.Exists(line.Text)) { // get the equalSignIndex int equalSignIndex = line.Text.IndexOf("="); // if the EqualSignIndex exists if (equalSignIndex >= 0) { // get the text of the word on the right side of the equal sign string wordsOnRightSideOfEqualSign = line.Text.Substring(equalSignIndex + 1).Trim(); // If the wordsOnRightSideOfEqualSign string exists if (TextHelper.Exists(wordsOnRightSideOfEqualSign)) { // get the words List <Word> words = WordParser.GetWords(wordsOnRightSideOfEqualSign, commaDelimiter); // if there are at least two words if ((words != null) && (words.Count >= 3)) { // create a project VSProject project = new VSProject(); // get the text string projectPath = words[1].Text.Substring(2, words[1].Text.Length - 3); // Create a directory DirectoryInfo directory = new DirectoryInfo(solution.Path); // combine the solutoin and the path string path = Path.Combine(directory.Parent.FullName, projectPath); // set the path project.Path = path; // Get the projectName project.Name = words[0].Text.Replace("\"", ""); // set the solution project.Solution = solution; string temp = words[2].Text.Substring(2, words[2].Text.Length - 3).Replace(@"\", "").Replace("{", "").Replace("}", "").Trim(); // get the tempId Guid tempId = Guid.Empty; // parse the Guid Guid.TryParse(temp, out tempId); // set the projectId project.Id = tempId; // now find the index of this project so the same project is not added twice int index = GetProjectIndex(project.Id); // if the index was found if (index < 0) { // Add this project projects.Add(project); } } } } } } } } } // return value return(projects); }
/// <summary> /// This method returns the number of items imported /// </summary> /// <param name="text">The contents to be imported.</param> /// <param name="tableName">Only used in cases where more than one import takes place.</param> /// <param name="expectedCount">Number of expected columns in the csv file</param> /// <param name="callback">The method to call to update progress</param> /// <returns></returns> public static int ImportData(string text, string tableName, int expectedCount, ImportProgressCallback callback) { // initial value int savedCount = 0; // locals char[] delimiters = { ',' }; int count = 0; int totalCount = 0; int refreshRate = 5; List <Word> words = null; RawImport rawImport = null; // if the fileExists if (TextHelper.Exists(text)) { // Create a new instance of a 'Gateway' object. Gateway gateway = new Gateway(); // set the textLines List <TextLine> textLines = WordParser.GetTextLines(text.Trim()); // If the textLines collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(textLines)) { // If the callback object exists if (NullHelper.Exists(callback)) { // notify the delegate to setup the Graph callback(textLines.Count, tableName); } // change the RefreshRate if (textLines.Count > 1000) { // change this to whatever makes since for your app refreshRate = 25; } // set the totalCount totalCount = textLines.Count - 1; // Iterate the collection of TextLine objects foreach (TextLine textLine in textLines) { // Increment the value for count count++; // skip the first row if (count > 1) { // get the list of words words = WordParser.GetWords(textLine.Text, delimiters, true); // if the words collection has exactly the right amount if ((ListHelper.HasOneOrMoreItems(words)) && (words.Count == expectedCount)) { // Create a new instance of a 'RawImport' object. rawImport = new RawImport(); // Load the RawImport with the words SetRawImportProperties(ref rawImport, words); // save the rawImport object bool saved = gateway.SaveRawImport(ref rawImport); // if the value for saved is true if (saved) { // Increment the value for savedCount savedCount++; // refresh every x number of records if (savedCount % refreshRate == 0) { // update the graph (for a large project, you might want to update every 25, 50 or 100 records or so callback(savedCount, tableName); } } } } } } } // return value return(savedCount); }
public EmptyGame(TextAsset a_WordList, int a_NumberOfLetters) { m_Words = m_Parser.GetWords(a_WordList); SetNumberOfLetters(a_NumberOfLetters); }
/// <summary> /// event is fired when the 'ImportButton' is clicked. /// </summary> private void CreateSQL_Click(object sender, EventArgs e) { // set the fileName string fileName = SourceFileControl.Text; // locals TextLine firstRowContent = null; List <Word> words = null; char[] delimiters = { ',' }; StringBuilder sb = new StringBuilder(); string alterTableTemplate = "Alter Table RawImport"; string alterTableTemplate2 = "Add [ColumnName] nvarchar(255) null"; string alterTable = ""; // if the fileName exists if ((TextHelper.Exists(fileName)) && (File.Exists(fileName))) { // read the text of the file string fileText = File.ReadAllText(fileName); // set the textLines List <TextLine> textLines = WordParser.GetTextLines(fileText); // If the textLines collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(textLines)) { // set the first row contents firstRowContent = textLines[0]; } // If the firstRowContent object exists if (NullHelper.Exists(firstRowContent)) { // parse the words from the first column words = WordParser.GetWords(firstRowContent.Text, delimiters); } // If the words collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(words)) { // Iterate the collection of Word objects foreach (Word word in words) { // remove any spaces and special characters from the column names. This may have to be modified as more files are tested. word.Text = word.Text.Replace(" ", "").Replace("(", "").Replace(")", "").Replace(".", "").Replace("_", "").Replace("<", "").Replace(">", ""); // Start on a new line sb.Append(Environment.NewLine); // add this one sb.Append(alterTableTemplate); // Start on a new line sb.Append(Environment.NewLine); // replace out the text of the template alterTable = alterTableTemplate2.Replace("[ColumnName]", TextHelper.CapitalizeFirstChar(word.Text)); // add this one sb.Append(alterTable); // Start on a new line sb.Append(Environment.NewLine); // Append Go sb.Append("Go"); } // set the sqlQuery and trim off the last line string sqlQuery = sb.ToString().Trim(); // copy to clipboard Clipboard.SetText(sqlQuery); // Show finished message MessageBoxHelper.ShowMessage("Finished", "Done"); } } }
/// <summary> /// This method returns a GatewayInfo object /// </summary> public static GatewayInfo GetGatewayInfo(string gatewayFilePath, List <string> methodNames) { // initial value GatewayInfo gatewayInfo = new GatewayInfo(); // locals List <GatewayMethodInfo> methodInformation = new List <GatewayMethodInfo>(); int index = -1; bool methodRegionOn = false; GatewayMethodInfo methodInfo = null; // Set the MethodInformation gatewayInfo.MethodInformation = methodInformation; // if the gatewayFilePath exists if ((TextHelper.Exists(gatewayFilePath)) && (File.Exists(gatewayFilePath)) && (ListHelper.HasOneOrMoreItems(methodNames))) { // Get the fileText string fileText = File.ReadAllText(gatewayFilePath); // If the fileText string exists if (TextHelper.Exists(fileText)) { // Parse the lines List <TextLine> lines = WordParser.GetTextLines(fileText); // If the lines collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(lines)) { // set the lines gatewayInfo.TextLines = lines; // Iterate the collection of string objects foreach (string methodName in methodNames) { // reset methodRegionOn = false; index = -1; // Iterate the collection of TextLine objects foreach (TextLine line in lines) { // Increment the value for index index++; // Create a codeLine CodeLine codeLine = new CodeLine(line.Text); // if the TextLine exists if (codeLine.HasTextLine) { // Get the words for this line codeLine.TextLine.Words = WordParser.GetWords(line.Text); } // if the value for methodRegionOn is true if (methodRegionOn) { // if this is the if ((codeLine.IsEndRegion) && (NullHelper.Exists(methodInfo))) { // turn this off methodRegionOn = false; // Set the methodInfo methodInfo.EndIndex = index; // break out of the loop break; } } else { // if this is a Region if (codeLine.IsRegion) { // if this is the method being sought if (methodName == codeLine.RegionName) { // set to true methodRegionOn = true; // Create a new instance of a 'MethodInfo' object. methodInfo = new GatewayMethodInfo(); // Set the methodName methodInfo.Name = methodName; // Set the startIndex methodInfo.StartIndex = index; // Add this item methodInformation.Add(methodInfo); } } } } } } } } // return value return(gatewayInfo); }
/// <summary> /// This method Set Update Parameters /// </summary> public static void SetUpdateParameters(string updateText, ref PixelQuery pixelQuery) { // if the updateText exists and the pixelQuery object exists if ((TextHelper.Exists(updateText)) && (NullHelper.Exists(pixelQuery))) { // if the updateText starts with the word set (else this is not a proper BQL Update query). if (updateText.StartsWith("set")) { // only use a space as a delimiter character char[] delimiterChars = { ' ' }; // Get a list of words from this text List <Word> words = WordParser.GetWords(updateText); // If the words collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(words)) { // if there are six words. // Example: Set Color 100 150 200 40 - (Red = 100, Green = 150, Blue = 200, Alpha = 40) if (words.Count == 6) { // Set to red pixelQuery.Red = NumericHelper.ParseInteger(words[2].Text, -1, -2); pixelQuery.Green = NumericHelper.ParseInteger(words[3].Text, -1, -2); pixelQuery.Blue = NumericHelper.ParseInteger(words[4].Text, -1, -2); pixelQuery.Alpha = NumericHelper.ParseInteger(words[5].Text, -1, -2); // verify everything is valid if ((pixelQuery.Red >= 0) && (pixelQuery.Green >= 0) && (pixelQuery.Red >= 0) && (pixelQuery.Alpha >= 0)) { // Set the Color pixelQuery.Color = Color.FromArgb(pixelQuery.Alpha, pixelQuery.Red, pixelQuery.Green, pixelQuery.Blue); } } // if there are 5 words // Example: Set Color 100 150 200 - (Red = 100, Green = 150, Blue = 200, Alpha = 255 default value) else if (words.Count == 5) { // Set to red pixelQuery.Red = NumericHelper.ParseInteger(words[2].Text, -1, -2); pixelQuery.Green = NumericHelper.ParseInteger(words[3].Text, -1, -2); pixelQuery.Blue = NumericHelper.ParseInteger(words[4].Text, -1, -2); pixelQuery.Alpha = 255; // verify everything is valid if ((pixelQuery.Red >= 0) && (pixelQuery.Green >= 0) && (pixelQuery.Red >= 0) && (pixelQuery.Alpha >= 0)) { // Set the Color pixelQuery.Color = Color.FromArgb(pixelQuery.Alpha, pixelQuery.Red, pixelQuery.Green, pixelQuery.Blue); } // Set the Color pixelQuery.Color = Color.FromArgb(pixelQuery.Alpha, pixelQuery.Red, pixelQuery.Green, pixelQuery.Blue); } // if there are 3 words // Example: Set Color Orchid (the color must be a named color) else if (words.Count == 3) { // Set the Color pixelQuery.Color = Color.FromName(words[2].Text); pixelQuery.Alpha = 255; } } } } }
/// <summary> /// This method parses the Directions given. /// </summary> public static Directions ParseDirections(string directionsText) { // initial value Directions directions = null; // If the directionsText string exists if (TextHelper.Exists(directionsText)) { // Create a new instance of a 'Directions' object. directions = new Directions(); // only use a space as a delimiter character char[] delimiterChars = { ' ' }; // if the words exists List <Word> words = WordParser.GetWords(directionsText, delimiterChars); // If the words collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(words)) { // Iterate the collection of Word objects foreach (Word word in words) { switch (word.Text) { case "left": // update the directions object directions.Left = true; // required break; case "right": // set to Right directions.Right = true; // required break; case "top": // set to Top directions.Top = true; // required break; case "bottom": // Set to Bottom directions.Bottom = true; // required break; case "all": // set all directions to true directions.Left = true; directions.Top = true; directions.Bottom = true; directions.Right = true; // required break; } } } } // return value return(directions); }
/// <summary> /// This method returns the Pixel Criteria /// </summary> public static PixelCriteria CreatePixelCriteria(string text, ActionTypeEnum actionType, int lineNumber, PixelCriteria existingCriteria = null) { // initial value PixelCriteria pixelCriteria = null; // only use a space as a delimiter character char[] delimiterChars = { ' ' }; // If the text string exists if (TextHelper.Exists(text)) { // Set the BackColor if (actionType == ActionTypeEnum.SetBackColor) { // Create a new instance of a 'PixelCriteria' object. pixelCriteria = new PixelCriteria(); // Get the words List <Word> words = WordParser.GetWords(text, delimiterChars); // If the words collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(words)) { // if there are 3 words if (words.Count == 3) { // if the third word is null if (words[2].Text.ToLower() == "null") { // Set the value for the property 'RemoveBackColor' to true pixelCriteria.RemoveBackColor = true; } else { // Set the BackColor pixelCriteria.BackColor = Color.FromName(words[2].Text); } } else if (words.Count == 5) { // set the value for Red, Green & Blue int red = NumericHelper.ParseInteger(words[2].Text, -1, -1); int green = NumericHelper.ParseInteger(words[3].Text, -1, -1); int blue = NumericHelper.ParseInteger(words[4].Text, -1, -1); // if all the RGB values are set if ((red >= 0) && (green >= 0) && (blue >= 0)) { // Set the BackColor pixelCriteria.BackColor = Color.FromArgb(red, green, blue); } } } } // if this is a draw line else if (actionType == ActionTypeEnum.DrawLine) { // if the existingCriteria if (NullHelper.IsNull(existingCriteria)) { // Create a new instance of a 'PixelCriteria' object. pixelCriteria = new PixelCriteria(); } else { // use the existing criteria so more properties can be set on it pixelCriteria = existingCriteria; } // Set to DrawLine pixelCriteria.PixelType = PixelTypeEnum.DrawLine; // if this is the first line if (lineNumber == 1) { // Get the words List <Word> words = WordParser.GetWords(text, delimiterChars); // If the words collection exists and has one or more items if (ListHelper.HasOneOrMoreItems(words)) { // Get the lastWord Word lastWord = words[words.Count - 1]; // Set the thickness pixelCriteria.Thickness = NumericHelper.ParseInteger(lastWord.Text, -1000, -1001); } } else if (lineNumber == 3) { // Set the RepeatType and the repeating attributes pixelCriteria.RepeatType = SetRepeatType(text); // if the repeat type was found if (pixelCriteria.RepeatType != RepeatTypeEnum.NoRepeat) { // get the text after the repeat string repeatText = GetRepeatText(text, pixelCriteria.RepeatType); // get the words List <Word> words = WordParser.GetWords(repeatText); // if there are exactly two words if ((ListHelper.HasOneOrMoreItems(words)) && (words.Count == 2)) { // set the repititions pixelCriteria.Repititions = NumericHelper.ParseInteger(words[0].Text, 0, -1); // set the Distance pixelCriteria.Distance = NumericHelper.ParseInteger(words[1].Text, 0, -1); } } } } else if (lineNumber > 1) { // Create a new instance of a 'PixelCriteria' object. pixelCriteria = new PixelCriteria(); // if this text contains bluegreen if (text.Contains("x")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.X; } else if (text.Contains("y")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.Y; } else if (text.Contains("bluegreen")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.BlueGreen; } // if this text contains bluegreen else if (text.Contains("bluered")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.BlueRed; } // if this text contains bluegreen else if (text.Contains("greenred")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.GreenRed; } else if (text.Contains("red")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.Red; } else if (text.Contains("green")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.Green; } else if (text.Contains("blue")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.Blue; } else if (text.Contains("total")) { // Set the PixelType pixelCriteria.PixelType = PixelTypeEnum.Total; } } } // return value return(pixelCriteria); }
/// <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); } }
/// <summary> /// event is fired when the 'ImportLastNamesButton' is clicked. /// </summary> private void ImportLastNamesButton_Click(object sender, EventArgs e) { // locals bool saved = false; string fileName = ""; List <Word> words = null; char[] delimiters = { ' ' }; bool skipName = false; try { // get the text of the LastNames.txt file string LastNamesTextFile = LastNamesControl.Text; // attempt to read all the text string textFileContents = File.ReadAllText(LastNamesTextFile); // If the textFileContents string exists if (TextHelper.Exists(textFileContents)) { // create the fileInfo FileInfo fileInfo = new FileInfo(LastNamesTextFile); // 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 Graph2 Graph2.Visible = true; Graph2.Maximum = lines.Count; Graph2.Value = 0; // refresh everything Refresh(); // Create a new instance of a 'Gateway' object. Gateway gateway = new Gateway(); // Iterate the collection of TextLine objects foreach (TextLine line in lines) { // reset skipName = false; // if this name contains weird symbols if (line.Text.Contains("^")) { // skip this name skipName = true; } else if (line.Text.Contains(" or ")) { // skip this name skipName = true; } else if (line.Text.Contains("-")) { // skip any hyphenated names skipName = true; } // if the value for skipName is false if (!skipName) { // Create a LastName instance dataObjects.LastName LastName = new dataObjects.LastName(); // get the words words = WordParser.GetWords(line.Text, delimiters); // if there is a space in the name if ((ListHelper.HasOneOrMoreItems(words)) && (words.Count > 1)) { // Create a new instance of a 'StringBuilder' object. StringBuilder sb = new StringBuilder(); // Iterate the collection of Word objects foreach (Word word in words) { // Capitalize each word sb.Append(TextHelper.CapitalizeFirstChar(word.Text)); sb.Append(" "); } // set the LastName LastName.Name = sb.ToString().Trim(); } else { // set the LastName LastName.Name = TextHelper.CapitalizeFirstChar(line.Text.Trim()); } // save this LastName saved = gateway.SaveLastName(ref LastName); // if the value for saved is true if (saved) { // increment the value for Graph2 Graph2.Value++; } } } // 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("ImportLastNameButton_Click", this.Name, error); } }