public int GetOrCreateColumnNumber(string sColumnTitle) { int iReturn = -1; if (teTitles == null) { teTitles = new TableEntry(new string[] { sColumnTitle, "", "", "" }); teTitles.Columns = 1; iReturn = 0; Console.WriteLine("Warning: Had to create first column header \"" + sColumnTitle + "\""); } else { iReturn = teTitles.IndexOfExactValue(sColumnTitle); if (iReturn < 0) { Console.WriteLine("Warning: Had to create additional column header \"" + sColumnTitle + "\" at column " + teTitles.Columns); teTitles.AppendField(sColumnTitle); } } return(iReturn); } //end GetOrCreateColumnNumber
} //end Maximum public void InitCL() { teTitles = new TableEntry(new string[] { "Company", "Title", "Phone", "Fax", "Email", "ContactPerson", "Methods/DONE (e=email,p=phone,f=fax,m=mail,a=apply-in-person, i=interview, t=thank-you letter; parenthesis means they don't ask to be contacted that way, x=position filled, capitalized=done, repeated in lowercase=ToDo)", "Follow-up", "Compensation", "Description", "Address", "Location", "Apply URL", "Ad URL", "Source", "Date", "PostingID", "NoCalls", "IsContract", "Cost", "AltEmail", "ImageUrl", "Website", "AllowsRecruiters", "NoCommercialInterests" }); }
public bool Load(string sFile, bool FirstRowHasTitles) { sLastFile=sFile; if (sLastFile==null) sLastFile=""; bool bGood=false; bFirstRowLoadAndSaveAsTitles=FirstRowHasTitles; StreamReader fsSource=null; string sLine=null; try { fsSource=new StreamReader(sFile); if (bFirstRowLoadAndSaveAsTitles) { sLine=fsSource.ReadLine(); if ( bShowNewlineWarning && (RString.Contains(sLine,'\n')||RString.Contains(sLine,'\r')) ) { MessageBox.Show("Warning: newline character found in field. File may have been saved in a different operating system and need line breaks converted."); bShowNewlineWarning=false; } teTitles=new TableEntry(RTable.SplitCSV(sLine,cFieldDelimiter,cTextDelimiter)); //Parse TYPE NAME{METANAME:METAVALUE;...} title row notation: if (teTitles.Columns>0) { sarrFieldMetaData=new string[teTitles.Columns]; iarrFieldType=new int[teTitles.Columns]; for (int iColumn=0; iColumn<teTitles.Columns; iColumn++) { string FieldDataNow=teTitles.Field(iColumn); if (FieldDataNow==null) { RReporting.ShowErr("Field is not accessible","loading csv file","Load("+RReporting.StringMessage(sFile,true)+",...){Row 0:Titles; Column:"+iColumn+"}"); } int iType=StartsWithType(FieldDataNow); int iStartName=0; if (iType>-1) { iarrFieldType[iColumn]=iType; iStartName=sarrType[iType].Length+1; //teTitles.SetField(iColumn,RString.SafeSubstring(teTitles.Field(iColumn),sarrType[iType].Length+1)); } else { RReporting.Debug("Unknown type in column#"+iColumn.ToString()+"("+RReporting.StringMessage(FieldDataNow,true)+")"); } int iMetaData=-1; //if (FieldDataNow!=null) { iMetaData=FieldDataNow.IndexOf("{"); //} if (iMetaData>-1) { //string FieldDataNow=teTitles.Field(iColumn); if (FieldDataNow==null) { RReporting.ShowErr("Can't access field","loading csv file","rtable Load("+RReporting.StringMessage(sFile,true)+"){Row:titles; Column:"+iColumn+"}"); } this.sarrFieldMetaData[iColumn]=FieldDataNow.Substring(iMetaData); while (iMetaData>=0 && (FieldDataNow[iMetaData]=='{'||FieldDataNow[iMetaData]==' ')) iMetaData--; teTitles.SetField(iColumn,RString.SafeSubstringByInclusiveEnder(FieldDataNow,iStartName,iMetaData)); } else { teTitles.SetField(iColumn,RString.SafeSubstring(FieldDataNow,iStartName)); } }//end for iColumn in title row }//end if teTitles.Columns>0 }//if bFirstRowLoadAndSaveAsTitles tearr=new TableEntry[256]; for (int iNow=0; iNow<tearr.Length; iNow++) { tearr[iNow]=null; } iRows=0; //if (!bFirstRowLoadAndSaveAsTitles||sLine!=null) { if (bAllowNewLineInQuotes) { bool bInQuotes=false; string sLineCombined=""; while ( (sLine=fsSource.ReadLine()) != null ) { if (iRows>=Maximum) Maximum=iRows+iRows/2+1; for (int iChar=0; iChar<RString.SafeLength(sLine); iChar++) { if (sLine[iChar]==this.cTextDelimiter) bInQuotes=!bInQuotes; } sLineCombined+=sLine; if (!bInQuotes) { tearr[iRows]=new TableEntry(RTable.SplitCSV(sLineCombined,cFieldDelimiter,cTextDelimiter)); iRows++; sLineCombined=""; } }//end while not end of file if (sLineCombined!="") { //get bad data so it doesn't get lost tearr[iRows]=new TableEntry(RTable.SplitCSV(sLineCombined,cFieldDelimiter,cTextDelimiter)); iRows++; } } else { while ( (sLine=fsSource.ReadLine()) != null ) { if (iRows>=Maximum) Maximum=iRows+iRows/2+1; tearr[iRows]=new TableEntry(RTable.SplitCSV(sLine,cFieldDelimiter,cTextDelimiter)); iRows++; } } //}//if any data rows if (iRows<Maximum) { for (int i=iRows; i<Maximum; i++) { tearr[i]=new TableEntry(); } } bGood=true; fsSource.Close(); } catch (Exception exn) { RReporting.ShowExn(exn,"Loading table","rtable Load(\""+RReporting.StringMessage(sFile,true)+"\",FirstRowHasTitles="+(FirstRowHasTitles?"yes":"no")+")"); try { fsSource.Close(); } catch (Exception exn2) { RReporting.ShowExn(exn2,"closing file after exception","rtable Load"); } } return bGood; }//end Load