private void autoMatchNumbers(DataTable TableWithNumbers) { if (TableWithNumbers.Rows.Count == 0) { MessageBox.Show("No Data Found in Data Table"); } else { List <ColumnMetaData> validColumnsWithNumbersList = new List <ColumnMetaData> { }; List <char> phoneCharacters = new List <char> { '*', '#', '+', ' ', '(', ')', '?', '-' }; ////>>>>>>>>>>>>>>>>>>>>>>>>> START FILTERING_OUT VALID CONTACTS //////////////////////////// foreach (DataColumn inPutTableColum in TableWithNumbers.Columns) { tbxDebuging.AppendText(inPutTableColum.ColumnName + " COLUMN is NOW being Processed\n"); if (inPutTableColum.ColumnName.ToLower().Contains("phone") | inPutTableColum.ColumnName.ToLower().Contains("mobile") | inPutTableColum.ColumnName.ToLower().Contains("number")) { //tbxDebuging.AppendText(inPutTableColum.ColumnName + " COLUMN Contains PHONE or MOBILE...hence is tobe analysed...\n"); ColumnMetaData colMetaData = new ColumnMetaData(inPutTableColum.ColumnName); int colIndex = inPutTableColum.Ordinal; colMetaData.ColIndex = inPutTableColum.Ordinal; int TotalElems = 0; int rowCounterNew = 0; foreach (DataRow tableRow in inputTable.Rows) { rowCounterNew++; if (inPutTableColum.ColumnName == "Mobile Phone") { tbxDebuging.AppendText(tableRow["First Name"].ToString() + " has Number ===> " + tableRow["Mobile Phone"] + "===>" + rowCounterNew.ToString() + "\n"); } Boolean isAllDigit = true; Boolean isAllChars = true; Boolean isMixed = false; if (tableRow[inPutTableColum.ColumnName].ToString() != "") { TotalElems++; colMetaData.ColTotalElems++; foreach (char letter in tableRow[inPutTableColum.ColumnName].ToString()) { if (char.IsDigit(letter) | phoneCharacters.Contains(letter)) { isAllChars = false; } else if (!char.IsDigit(letter) | !phoneCharacters.Contains(letter)) { isAllDigit = false; } } if (!isAllDigit & !isAllChars) { isMixed = true; } if (isAllChars) { colMetaData.TotalNonDigitalElems++; } if (isAllDigit) { colMetaData.TotalDigitalElems++; } if (isMixed) { colMetaData.ColTotalMixedElems++; if (inPutTableColum.ColumnName == "Mobile Phone") { tbxDebuging.AppendText(tableRow["First Name"].ToString() + " has MIXED Number ===> " + tableRow["Mobile Phone"] + "===>" + rowCounterNew.ToString() + "\n"); } } } } // tbxDebuging.AppendText(inPutTableColum.ColumnName + "COLUMN has " + colMetaData.ColTotalElems + " elements \n"); //Console.WriteLine(inPutTableColum.ColumnName); string columnName = inPutTableColum.ColumnName; float NonDigitalElemsPercantage = (colMetaData.TotalNonDigitalElems / (float)colMetaData.ColTotalElems) * 100; float DigitalElemPercentage = ((colMetaData.TotalDigitalElems / (float)colMetaData.ColTotalElems) * 100); if (((colMetaData.TotalNonDigitalElems / (float)colMetaData.ColTotalElems) * 100) > 2.0 | ((colMetaData.TotalDigitalElems / (float)colMetaData.ColTotalElems) * 100) < 90.0) { } else { if (colMetaData.ColTotalElems != 0) { validColumnsWithNumbersList.Add(colMetaData); //tbxDebuging.AppendText(inPutTableColum.ColumnName + " COLUMN has been added to list of valid cols \n"); } else { // tbxDebuging.AppendText(inPutTableColum.ColumnName + " COLUMN has NOT been added to list of valid cols \n"); } } } tbxDebuging.AppendText("------------------------------------------------------------------------\n"); tbxDebuging.AppendText("\n"); } //////////////>>>>>>>>>>>>>>>>>>>>>>> DONE FILTERING >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>///////////////////////////////////// if (cbxPhone1.SelectedItem.ToString() == "Not Set") { int Phone1TotalItems = -1; int selectedColIndex = -1; int ColumnindexCounter = -1; foreach (ColumnMetaData columnItem in validColumnsWithNumbersList) { ColumnindexCounter++; if (!columnItem.Assigned) { if (columnItem.ColTotalElems > Phone1TotalItems) { selectedColIndex = ColumnindexCounter; Phone1TotalItems = columnItem.ColTotalElems; } } } if (selectedColIndex > -1) { cbxPhone1.SelectedItem = validColumnsWithNumbersList[selectedColIndex].ColName; validColumnsWithNumbersList[selectedColIndex].Assigned = true; } } if (cbxPhone2.SelectedItem.ToString() == "Not Set") { int Phone2TotalItems = -1; int selectedColIndex = -1; int ColumnindexCounter = -1; foreach (ColumnMetaData columnItem in validColumnsWithNumbersList) { ColumnindexCounter++; if (!columnItem.Assigned) { if (columnItem.ColTotalElems > Phone2TotalItems) { selectedColIndex = ColumnindexCounter; Phone2TotalItems = columnItem.ColTotalElems; } } } if (selectedColIndex > -1) { cbxPhone2.SelectedItem = validColumnsWithNumbersList[selectedColIndex].ColName; validColumnsWithNumbersList[selectedColIndex].Assigned = true; } } if (cbxPhone3.SelectedItem.ToString() == "Not Set") { int Phone3TotalItems = -1; int selectedColIndex = -1; int ColumnindexCounter = -1; foreach (ColumnMetaData columnItem in validColumnsWithNumbersList) { ColumnindexCounter++; if (!columnItem.Assigned) { if (columnItem.ColTotalElems > Phone3TotalItems) { selectedColIndex = ColumnindexCounter; Phone3TotalItems = columnItem.ColTotalElems; } } } if (selectedColIndex > -1) { cbxPhone3.SelectedItem = validColumnsWithNumbersList[selectedColIndex].ColName; validColumnsWithNumbersList[selectedColIndex].Assigned = true; } } if (cbxPhone4.SelectedItem.ToString() == "Not Set") { int Phone4TotalItems = -1; int selectedColIndex = -1; int ColumnindexCounter = -1; foreach (ColumnMetaData columnItem in validColumnsWithNumbersList) { ColumnindexCounter++; if (!columnItem.Assigned) { if (columnItem.ColTotalElems > Phone4TotalItems) { selectedColIndex = ColumnindexCounter; Phone4TotalItems = columnItem.ColTotalElems; } } } if (selectedColIndex > -1) { cbxPhone4.SelectedItem = validColumnsWithNumbersList[selectedColIndex].ColName; validColumnsWithNumbersList[selectedColIndex].Assigned = true; } } if (cbxPhone5.SelectedItem.ToString() == "Not Set") { int Phone5TotalItems = -1; int selectedColIndex = -1; int ColumnindexCounter = -1; foreach (ColumnMetaData columnItem in validColumnsWithNumbersList) { ColumnindexCounter++; if (!columnItem.Assigned) { if (columnItem.ColTotalElems > Phone5TotalItems) { selectedColIndex = ColumnindexCounter; Phone5TotalItems = columnItem.ColTotalElems; } } } if (selectedColIndex > -1) { cbxPhone5.SelectedItem = validColumnsWithNumbersList[selectedColIndex].ColName; validColumnsWithNumbersList[selectedColIndex].Assigned = true; } } if (cbxPhone6.SelectedItem.ToString() == "Not Set") { int Phone6TotalItems = -1; int selectedColIndex = -1; int ColumnindexCounter = -1; foreach (ColumnMetaData columnItem in validColumnsWithNumbersList) { ColumnindexCounter++; if (!columnItem.Assigned) { if (columnItem.ColTotalElems > Phone6TotalItems) { selectedColIndex = ColumnindexCounter; Phone6TotalItems = columnItem.ColTotalElems; } } } if (selectedColIndex > -1) { cbxPhone6.SelectedItem = validColumnsWithNumbersList[selectedColIndex].ColName; validColumnsWithNumbersList[selectedColIndex].Assigned = true; } } } }
private void autoMatchNames(DataTable TableWithData) { if (TableWithData.Rows.Count == 0) { MessageBox.Show("No Data Found in Data Table"); } else { List <ColumnMetaData> ValidColums = new List <ColumnMetaData> { }; ///<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<//// foreach (DataColumn inPutTableColum in TableWithData.Columns) { tbxDebuging.AppendText(inPutTableColum.ColumnName + " COLUMN is NOW being Processed\n"); if (inPutTableColum.ColumnName.ToLower().Contains("name")) { tbxDebuging.AppendText(inPutTableColum.ColumnName + " COLUMN Contains name...hence is tobe analysed...\n"); ColumnMetaData colMetaData = new ColumnMetaData(inPutTableColum.ColumnName); //create column object to hold col info int colIndex = inPutTableColum.Ordinal; colMetaData.ColIndex = inPutTableColum.Ordinal; int TotalElems = 0; foreach (DataRow tableRow in inputTable.Rows) {//loop to check type of string in each row of subject Col Boolean isAllDigit = true; Boolean isAllChars = true; Boolean isMixed = false; if (tableRow[inPutTableColum.ColumnName].ToString() != "") {// if empty ignore TotalElems++; colMetaData.ColTotalElems++; foreach (char letter in tableRow[inPutTableColum.ColumnName].ToString()) { if (char.IsDigit(letter)) { isAllChars = false; //check for chars and digits in rows of subject column } else if (!char.IsDigit(letter)) { isAllDigit = false; } } if (!isAllDigit & !isAllChars) { isMixed = true; } if (isAllChars) { colMetaData.TotalNonDigitalElems++; } if (isAllDigit) { colMetaData.TotalDigitalElems++; } if (isMixed) { colMetaData.ColTotalMixedElems++; } } } tbxDebuging.AppendText(inPutTableColum.ColumnName + "COLUMN has " + colMetaData.ColTotalElems + " elements \n"); if (colMetaData.ColTotalElems != 0) { ValidColums.Add(colMetaData); tbxDebuging.AppendText(inPutTableColum.ColumnName + " COLUMN has been added to list of valid cols \n"); } else { tbxDebuging.AppendText(inPutTableColum.ColumnName + " COLUMN has NOT been added to list of valid cols \n"); } } tbxDebuging.AppendText("------------------------------------------------------------------------\n"); tbxDebuging.AppendText("\n"); } ////<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<// if (ValidColums.Count > 0) { foreach (ColumnMetaData selectedColum in ValidColums) { if (selectedColum.ColName.ToLower().Contains("first") & selectedColum.ColName.ToLower().Contains("name") & !selectedColum.Assigned) { // CbxFName.SelectedIndex = selectedColum.ColIndex+1; CbxFName.SelectedItem = selectedColum.ColName; selectedColum.Assigned = true; } else if (selectedColum.ColName.ToLower().Contains("last") & selectedColum.ColName.ToLower().Contains("name") & !selectedColum.Assigned) { //cbxLName.SelectedIndex = selectedColum.ColIndex+1; cbxLName.SelectedItem = selectedColum.ColName; selectedColum.Assigned = true; } else if (selectedColum.ColName.ToLower().Contains("middle") & selectedColum.ColName.ToLower().Contains("name") & !selectedColum.Assigned) { // CbxMidName.SelectedIndex = selectedColum.ColIndex+1; CbxMidName.SelectedItem = selectedColum.ColName; selectedColum.Assigned = true; } } //MessageBox.Show("CbxFName Index: " + CbxFName.SelectedIndex.ToString()); //MessageBox.Show("CbxLName Index: " + cbxLName.SelectedIndex.ToString()); //MessageBox.Show("CbxMidName Index: " + CbxMidName.SelectedIndex.ToString()); if (CbxFName.SelectedItem.ToString() == "Not Set") { int FNameTotalItems = -1; int selectedColIndex = -1; int ColumnindexCounter = -1; foreach (ColumnMetaData columnItem in ValidColums) { ColumnindexCounter++; if (!columnItem.Assigned) { if (columnItem.ColTotalElems > FNameTotalItems) { selectedColIndex = ColumnindexCounter; FNameTotalItems = columnItem.ColTotalElems; } } } if (selectedColIndex > -1) { CbxFName.SelectedItem = ValidColums[selectedColIndex].ColName; ValidColums[selectedColIndex].Assigned = true; } } if (cbxLName.SelectedItem.ToString() == "Not Set") { int LNameTotalItems = -1; int selectedColIndex = -1; int ColumnindexCounter = -1; foreach (ColumnMetaData columnItem in ValidColums) { ColumnindexCounter++; if (!columnItem.Assigned) { if (columnItem.ColTotalElems > LNameTotalItems) { selectedColIndex = ColumnindexCounter; LNameTotalItems = columnItem.ColTotalElems; } } } if (selectedColIndex > 0) { cbxLName.SelectedItem = ValidColums[selectedColIndex].ColName; ValidColums[selectedColIndex].Assigned = true; } } if (CbxMidName.SelectedItem.ToString() == "Not Set") { int MidNameTotalItems = -1; int selectedColIndex = -1; int ColumnindexCounter = -1; foreach (ColumnMetaData columnItem in ValidColums) { ColumnindexCounter++; if (!columnItem.Assigned) { if (columnItem.ColTotalElems > MidNameTotalItems) { selectedColIndex = ColumnindexCounter; MidNameTotalItems = columnItem.ColTotalElems; } } } if (selectedColIndex > 0) { CbxMidName.SelectedItem = ValidColums[selectedColIndex].ColName; ValidColums[selectedColIndex].Assigned = true; } } } } }
private void autoMatchEmail(DataTable TableWithEmails) { if (TableWithEmails.Rows.Count == 0) { MessageBox.Show("No Data Found in Data Table"); } else { List <ColumnMetaData> validColumnsWithEmailList = new List <ColumnMetaData> { }; foreach (DataColumn inPutTableColum in TableWithEmails.Columns) { if ((inPutTableColum.ColumnName.ToLower().Contains("email") | inPutTableColum.ColumnName.ToLower().Contains("e-mail"))) { ColumnMetaData colMetaData = new ColumnMetaData(inPutTableColum.ColumnName); int colIndex = inPutTableColum.Ordinal; colMetaData.ColIndex = inPutTableColum.Ordinal; int TotalElems = 0; foreach (DataRow tableRow in inputTable.Rows) { if (tableRow[inPutTableColum.ColumnName].ToString() != "") { TotalElems++; colMetaData.ColTotalElems++; } } if (colMetaData.ColTotalElems != 0) { validColumnsWithEmailList.Add(colMetaData); } } } if (cbxEmail1.SelectedItem.ToString() == "Not Set") { int Email1TotalItems = -1; int selectedColIndex = -1; int ColumnindexCounter = -1; foreach (ColumnMetaData columnItem in validColumnsWithEmailList) { ColumnindexCounter++; if (!columnItem.Assigned) { if (columnItem.ColTotalElems > Email1TotalItems) { selectedColIndex = ColumnindexCounter; Email1TotalItems = columnItem.ColTotalElems; } } } if (selectedColIndex > -1) { cbxEmail1.SelectedItem = validColumnsWithEmailList[selectedColIndex].ColName; validColumnsWithEmailList[selectedColIndex].Assigned = true; } } if (cbxEmail2.SelectedItem.ToString() == "Not Set") { int Email2TotalItems = -1; int selectedColIndex = -1; int ColumnindexCounter = -1; foreach (ColumnMetaData columnItem in validColumnsWithEmailList) { ColumnindexCounter++; if (!columnItem.Assigned) { if (columnItem.ColTotalElems > Email2TotalItems) { selectedColIndex = ColumnindexCounter; Email2TotalItems = columnItem.ColTotalElems; } } } if (selectedColIndex > -1) { cbxEmail2.SelectedItem = validColumnsWithEmailList[selectedColIndex].ColName; validColumnsWithEmailList[selectedColIndex].Assigned = true; } } } }