Code review please!

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi and thanks in advance for your help.
Im trying to improve my codeing technique. I was wondering if anyone out there is willing to do a review of my code and give me some pointers. he code is long but I included it in this message. Or if you want me to email it to you here is my email address:
mailto:steve_kershaw@yahoo.com steve_kershaw@yahoo.com
Here is the code:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Xml;
<span style="color:Blue; using System.Xml.Linq;
<span style="color:Blue; using System.IO;


<span style="color:Blue; namespace CostpointIntegrationLibrary
{
<span style="color:Blue; public <span style="color:Blue; class BusinessLogicLayer
{
DataAccessLayer dataAccessLayer;
<span style="color:Blue; public SharedLibrary.IntegrationTools thisIntegrationToolsClient;
<span style="color:Blue; private XElement topElement;
<span style="color:Blue; private XElement entryElement;
XElement topLinesElement;
<span style="color:Blue; private <span style="color:Blue; bool firstTime = <span style="color:Blue; true;
<span style="color:Blue; public <span style="color:Blue; static DateTime nextCutOffDateTime;
<span style="color:Blue; private <span style="color:Blue; int daysSince2000 = 0;

<span style="color:Blue; public BusinessLogicLayer()
{
<span style="color:Blue; try
{
dataAccessLayer = <span style="color:Blue; new DataAccessLayer();
thisIntegrationToolsClient = <span style="color:Blue; new SharedLibrary.IntegrationTools();
}
<span style="color:Blue; catch (Exception ex)
{
<span style="color:Blue; if (thisIntegrationToolsClient != <span style="color:Blue; null)
{
<span style="color:Blue; string errorLogFileLocation = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService",<span style="color:#A31515; "Config",<span style="color:#A31515; "Config",<span style="color:#A31515; "ErrorLogFileLocation");
<span style="color:Blue; string errorFileLogging = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "Config", <span style="color:#A31515; "Config", <span style="color:#A31515; "ErrorFileLogging");
<span style="color:Blue; if (errorFileLogging.ToLower() == <span style="color:#A31515; "true")
{
thisIntegrationToolsClient.LogErrors(<span style="color:#A31515; " Error: " + ex.Message, errorLogFileLocation, <span style="color:#A31515; "BusinessLogicLayer() - CostpointIntegrationService");
}
}
<span style="color:Blue; throw <span style="color:Blue; new Exception(<span style="color:#A31515; "Failed to instantiate BusinessLogicLayer() error: " + ex.Message);
}
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; StartXElement creates the "Root" tag and resets the entry and lines element from previous attempts.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; public <span style="color:Blue; void StartXElement()
{
<span style="color:Blue; if (firstTime)
{
topElement = <span style="color:Blue; new XElement(<span style="color:#A31515; "Root");
ResetEntryElement();
ResetLinesElement();
firstTime = <span style="color:Blue; false;
}
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; EndXElement inserts all the records on or after the last process date into the XML file thats sent to PeopleSoft
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <returns><span style="color:Green; The completed XElement</returns>
<span style="color:Blue; public XElement EndXElement()
{
<span style="color:Green; // Here we are sending the string XML file directly to the PeoplesoftIntegrationService method ConvertToFILMSFromXML
<span style="color:Green; // through IPS.
<span style="color:Green; // Just for module testing....
<span style="color:Blue; if (topElement != <span style="color:Blue; null)
{
<span style="color:Green; // Reset the date.
<span style="color:Blue; if (nextCutOffDateTime != <span style="color:Blue; null)
{
<span style="color:Green; // Set the previous data transfer date to the current last data transfer date.
<span style="color:Green; // Set the last data transfer date to the datetime when the transfer started + 24 hours.
<span style="color:Blue; string lastDataTransferDate = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "GetJournalEntryData", <span style="color:#A31515; "Config", <span style="color:#A31515; "LastDataTransferDate");
IPSData.SharedLibrary.SetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "GetJournalEntryData", <span style="color:#A31515; "Config", <span style="color:#A31515; "PreviousDataTransferDate", lastDataTransferDate);
IPSData.SharedLibrary.SetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "GetJournalEntryData", <span style="color:#A31515; "Config", <span style="color:#A31515; "LastDataTransferDate", nextCutOffDateTime.ToString());
}
<span style="color:Blue; else
{
<span style="color:Blue; throw <span style="color:Blue; new Exception(<span style="color:#A31515; "The next Costpoint data transfer date/time was null");
}
}
<span style="color:Blue; else
{
<span style="color:Green; //memoryStream.
}
<span style="color:Blue; return topElement;
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; ConvertDBJournalEntryDataToXML grabs all entries from the database that are dated on or later than the last process date and
<span style="color:Gray; ///<span style="color:Green; inserts them into the XML stream.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="systemParameters <span style="color:Gray; </param>
<span style="color:Gray; /// <span style="color:Gray; <returns><span style="color:Green; XElement containing the database entries</returns>
<span style="color:Blue; public XElement ConvertDBJournalEntryDataToXML(List<IPSData.SystemParameter> systemParameters)
{
XElement thisElement;
<span style="color:Blue; try
{
nextCutOffDateTime = DateTime.Now.AddHours(24);
thisElement = dataAccessLayer.GetDbData(systemParameters);
}
<span style="color:Blue; catch (Exception ex)
{
<span style="color:Blue; if (thisIntegrationToolsClient != <span style="color:Blue; null)
{
<span style="color:Blue; string errorLogFileLocation;
<span style="color:Blue; string errorFileLogging;

errorLogFileLocation = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "Config", <span style="color:#A31515; "Config", <span style="color:#A31515; "ErrorLogFileLocation");
errorFileLogging = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "Config", <span style="color:#A31515; "Config", <span style="color:#A31515; "ErrorFileLogging");

<span style="color:Blue; if (errorFileLogging.ToLower() == <span style="color:#A31515; "true")
{
thisIntegrationToolsClient.LogErrors(ex.Message, errorLogFileLocation, <span style="color:#A31515; "PostJournalEntryDataToPeoplesoft() - CostpointIntegrationService/BusinessLogicLayer");
}
}
<span style="color:Blue; throw <span style="color:Blue; new Exception(ex.Message);
}

<span style="color:Blue; return thisElement;
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Converts the passed XML file to 2 flat files.
<span style="color:Gray; ///<span style="color:Green; 1 - "raw" data that just holds the data in the XML file.
<span style="color:Gray; ///<span style="color:Green; 2 - A flat file thats generated by applying Costpoint business rules.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="xmlFile <span style="color:Green; XML file input </param>
<span style="color:Blue; public <span style="color:Blue; string ConvertToFilesFromXML(List<IPSData.SystemParameter> systemParameters, XElement thisElement)
{
<span style="color:Blue; string flatFileNotConverted = <span style="color:#A31515; "";
TextWriter swraw;
TextWriter swbus;
IEnumerable<XElement> journalEntries;
XElement journalEntry;
<span style="color:Blue; string businessLogicFlatFileName, businessLogicFlatFileLocation;
<span style="color:Blue; string rawFlatFileLocation = <span style="color:#A31515; "", rawFlatFileName = <span style="color:#A31515; "";
XElement saveElements = <span style="color:Blue; new XElement(<span style="color:#A31515; "entries");
<span style="color:Blue; int currentLineNumber = 1;
<span style="color:Green; //string OrgId41372 = "";
<span style="color:Green; //string OrgId43350 = "";
<span style="color:Blue; string tempTest = <span style="color:#A31515; "";
StringBuilder sb = <span style="color:Blue; new StringBuilder();
<span style="color:Blue; try
{
rawFlatFileName = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "Config", <span style="color:#A31515; "Config", <span style="color:#A31515; "RawFlatFileName");
rawFlatFileLocation = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "Config", <span style="color:#A31515; "Config", <span style="color:#A31515; "RawFlatFileLocation");

<span style="color:Blue; if(daysSince2000 == 0)
daysSince2000 = ((DateTime.Now.Year - 2000) * 365) + DateTime.Now.DayOfYear;

<span style="color:Blue; using (swraw = <span style="color:Blue; new StreamWriter(@rawFlatFileLocation +
rawFlatFileName + daysSince2000.ToString() + <span style="color:#A31515; ".csv", <span style="color:Blue; false))
{
<span style="color:Blue; if (swraw == <span style="color:Blue; null)
{
<span style="color:Blue; throw <span style="color:Blue; new Exception(<span style="color:#A31515; "Unable to open the flat file " + rawFlatFileName);
}
<span style="color:Blue; if (thisElement.IsEmpty)
{
<span style="color:Blue; throw <span style="color:Blue; new Exception(<span style="color:#A31515; "The PeopleSoft XML file cant be blank. ");
}

<span style="color:Green; // The Raw flat file must be in CSV format
XElement entries = thisElement.Element(<span style="color:#A31515; "entries");
IEnumerable<XElement> currentEntries = entries.Elements();
<span style="color:Blue; foreach (<span style="color:Blue; var thisEntry <span style="color:Blue; in currentEntries)
{
<span style="color:Green; // On the <entry> level here
sb.Clear();
IEnumerable<XElement> thisData = thisEntry.Elements();
<span style="color:Blue; foreach (<span style="color:Blue; var data <span style="color:Blue; in thisData)
{
<span style="color:Green; // All the child elements of the <entry> element here
sb.Append(data.Value + <span style="color:#A31515; ",");
}
<span style="color:Green; // remove the trailing "," from the string
sb.Remove(sb.Length - 1, 1);
swraw.WriteLine(sb.ToString());
}
<span style="color:Green; //swraw.Write(thisElement.ToString());
<span style="color:Green; //swraw.Close();
}

<span style="color:Green; // Find the OrgID for each BusinessUnit (41372, 43350)
<span style="color:Green; //dataAccessLayer.GetOrdIds(ref OrgId41372, ref OrgId43350, systemParameters);

<span style="color:Green; // Create the Costpoint business rules flat file
journalEntry = thisElement.Element(<span style="color:#A31515; "entries");
<span style="color:Blue; if(journalEntry == <span style="color:Blue; null)
<span style="color:Blue; throw <span style="color:Blue; new Exception(<span style="color:#A31515; "Possibly malformed XML file input. ");
<span style="color:Blue; else
journalEntries = journalEntry.Elements(<span style="color:#A31515; "entry");

<span style="color:Green; // parse out each indivitual Entry Line
<span style="color:Green; // Create the file
businessLogicFlatFileName = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "Config", <span style="color:#A31515; "Config", <span style="color:#A31515; "BusinessLogicFlatFileName");
businessLogicFlatFileLocation = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "Config", <span style="color:#A31515; "Config", <span style="color:#A31515; "BusinessLogicFlatFileLocation");


<span style="color:Blue; using (swbus = <span style="color:Blue; new StreamWriter(@businessLogicFlatFileLocation + businessLogicFlatFileName + daysSince2000.ToString() + <span style="color:#A31515; ".csv", <span style="color:Blue; false))
{
StringBuilder attributeString = <span style="color:Blue; new StringBuilder();
<span style="color:Blue; foreach (<span style="color:Blue; var thisJournalEntry <span style="color:Blue; in journalEntries)
{
<span style="color:Blue; if (CheckBusinessRules(thisJournalEntry, <span style="color:Blue; ref tempTest))
{
<span style="color:Green; // Business rules verified
<span style="color:Green; // Has this entry been processed before?
<span style="color:Blue; if (ThisEntryProcessed(thisJournalEntry, systemParameters))
{
<span style="color:Green; // Been entered before, just set the error message
attributeString.Append(String.Format(<span style="color:#A31515; " The entry with DATE:{0}, ACCOUNT:{1}, UNPOST_SEQ:{2}, BUSINESS_UNIT:{3}, OPRID:{4} and AMOUNT:{5} has been processed before. ",
thisJournalEntry.Element(<span style="color:#A31515; "JOURNAL_DATE").Value,
thisJournalEntry.Element(<span style="color:#A31515; "ACCOUNT").Value,
thisJournalEntry.Element(<span style="color:#A31515; "UNPOST_SEQ").Value,
thisJournalEntry.Element(<span style="color:#A31515; "BUSINESS_UNIT").Value,
thisJournalEntry.Element(<span style="color:#A31515; "OPRID").Value,
thisJournalEntry.Element(<span style="color:#A31515; "MONETARY_AMOUNT").Value));
}
<span style="color:Blue; else
{
<span style="color:Green; // Not been entered before...
<span style="color:Green; // Add tags for Costpoint Database requirements
thisJournalEntry.Add(<span style="color:Blue; new XElement(<span style="color:#A31515; "JE_NO"));
thisJournalEntry.Element(<span style="color:#A31515; "JE_NO").Value = <span style="color:#A31515; "1";

thisJournalEntry.Add(<span style="color:Blue; new XElement(<span style="color:#A31515; "JE_LN_NO"));
thisJournalEntry.Element(<span style="color:#A31515; "JE_LN_NO").Value = (currentLineNumber++).ToString();

thisJournalEntry.Add(<span style="color:Blue; new XElement(<span style="color:#A31515; "ORG_ID"));
thisJournalEntry.Element(<span style="color:#A31515; "ORG_ID").Value = GetOrgID(thisJournalEntry, systemParameters);

thisJournalEntry.Add(<span style="color:Blue; new XElement(<span style="color:#A31515; "FY_CD"));
thisJournalEntry.Element(<span style="color:#A31515; "FY_CD").Value = DateTime.Now.Year.ToString();

swbus.WriteLine(ConvertXMLToCSVString(thisJournalEntry, systemParameters));
saveElements.Add(thisJournalEntry);
}
}
}
<span style="color:Blue; if (attributeString.Length != 0)
{
<span style="color:Green; // Entry has been processed before so set the Root attribute
thisElement.SetAttributeValue(<span style="color:#A31515; "ProcessedErrors", attributeString);
}
dataAccessLayer.MarkTheseEntriesAsProcessed(saveElements);
}
}
<span style="color:Blue; catch (Exception ex)
{
<span style="color:Green; //
SharedLibrary.IntegrationTools thisIntegrationToolsClient;
thisIntegrationToolsClient = <span style="color:Blue; new SharedLibrary.IntegrationTools();
<span style="color:Blue; if (thisIntegrationToolsClient != <span style="color:Blue; null)
{
<span style="color:Blue; string errorLogFileLocation = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "Config", <span style="color:#A31515; "Config", <span style="color:#A31515; "ErrorLogFileLocation");
<span style="color:Blue; string errorFileLogging = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "Config", <span style="color:#A31515; "Config", <span style="color:#A31515; "ErrorFileLogging");
<span style="color:Blue; if (errorFileLogging.ToLower() == <span style="color:#A31515; "true")
{
thisIntegrationToolsClient.LogErrors(ex.Message, errorLogFileLocation, <span style="color:#A31515; "ConvertToFilesFromXML(xmlFile) - CostpointIntegrationService filename: " +
rawFlatFileName + <span style="color:#A31515; " Exception message = " + ex.Message);
}
}
}

<span style="color:Blue; return flatFileNotConverted;
}

<span style="color:Blue; private <span style="color:Blue; string GetOrgID(XElement thisJournalEntry, List<IPSData.SystemParameter> systemParameters)
{
<span style="color:Blue; return dataAccessLayer.GetOrgID(thisJournalEntry, systemParameters);
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; ConvertXMLToCSVString converts the PeopleSoft XML file entry into a CSV line string
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="thisJournalEntry <span style="color:Gray; </param>
<span style="color:Gray; /// <span style="color:Gray; <returns><span style="color:Green; CSV line string</returns>
<span style="color:Blue; private <span style="color:Blue; string ConvertXMLToCSVString(XElement thisJournalEntry, List<IPSData.SystemParameter> systemParameters)
{
StringBuilder sb = <span style="color:Blue; new StringBuilder();
<span style="color:Blue; string projectId = <span style="color:#A31515; "";
<span style="color:Blue; string abbreviatedProjectId = <span style="color:#A31515; "";
<span style="color:Blue; string billProjectFlag = <span style="color:#A31515; "T";
<span style="color:Blue; string notes = thisJournalEntry.Element(<span style="color:#A31515; "DESCR").Value + <span style="color:#A31515; " " + thisJournalEntry.Element(<span style="color:#A31515; "LINE_DESCR").Value;

GetProjectID(thisJournalEntry, systemParameters, <span style="color:Blue; out projectId, <span style="color:Blue; out abbreviatedProjectId, <span style="color:Blue; out billProjectFlag);
<span style="color:Blue; if(daysSince2000 == 0)
daysSince2000 = ((DateTime.Now.Year - 2000) * 365) + DateTime.Now.DayOfYear;

<span style="color:Green; // Add each element inturn to the CSV file
sb.Append(<span style="color:#A31515; "L,"); <span style="color:Green; // Record type
sb.Append(thisJournalEntry.Element(<span style="color:#A31515; "JE_LN_NO").Value); <span style="color:Green; // JE transaction line number
sb.Append(<span style="color:#A31515; ",");
sb.Append(daysSince2000.ToString()); <span style="color:Green; // Input Journal Number
sb.Append(<span style="color:#A31515; ",");
<span style="color:Green; // Should always be "AJE" not Reversal
<span style="color:Gray; ///<span style="color:Green; / if (thisJournalEntry.Element("REVERSAL_FL").Value == "N") // Journal type code (REVERSAL_FL = "N" then "AJE" otherwise "RJE"
sb.Append(<span style="color:#A31515; "AJE");
<span style="color:Green; //else
<span style="color:Green; // sb.Append("RJE");
sb.Append(<span style="color:#A31515; ",");
sb.Append(thisJournalEntry.Element(<span style="color:#A31515; "FY_CD").Value); <span style="color:Green; // Fiscal year code
sb.Append(<span style="color:#A31515; ",");
sb.Append(thisJournalEntry.Element(<span style="color:#A31515; "ACCOUNTING_PERIOD").Value); <span style="color:Green; // Period number 1 - 12
sb.Append(<span style="color:#A31515; ",");
sb.Append(<span style="color:#A31515; "1"); <span style="color:Green; // Sub period number (always 1)
sb.Append(<span style="color:#A31515; ",");

<span style="color:Blue; if(thisJournalEntry.Element(<span style="color:#A31515; "REVERSAL_FL").Value != <span style="color:#A31515; "N")
sb.Append(<span style="color:#A31515; "Y"); <span style="color:Green; // Reverse flag
<span style="color:Blue; else
sb.Append(thisJournalEntry.Element(<span style="color:#A31515; "REVERSAL_FL").Value); <span style="color:Green; // Reverse flag

sb.Append(<span style="color:#A31515; ",");
sb.Append(<span style="color:#A31515; "PSJE" + daysSince2000.ToString()); <span style="color:Green; // JE description versus Line Description
sb.Append(<span style="color:#A31515; ",");
sb.Append(thisJournalEntry.Element(<span style="color:#A31515; "MONETARY_AMOUNT").Value); <span style="color:Green; // Amount #10
sb.Append(<span style="color:#A31515; ",");
sb.Append(GetAccountID(thisJournalEntry)); <span style="color:Green; // Account ID
sb.Append(<span style="color:#A31515; ",");
sb.Append(thisJournalEntry.Element(<span style="color:#A31515; "ORG_ID").Value); <span style="color:Green; // Org Id
sb.Append(<span style="color:#A31515; ",");
sb.Append(GetJournalEntryID(thisJournalEntry, systemParameters)); <span style="color:Green; // Transaction description #13
sb.Append(<span style="color:#A31515; ",");
<span style="color:Gray; ///<span style="color:Green; //sb.Append(projectId); // Project ID #14
sb.Append(<span style="color:#A31515; ""); <span style="color:Green; // Project ID #14, should be blank (optional) - Abbreviation not found - error fix
sb.Append(<span style="color:#A31515; ",");
sb.Append(<span style="color:#A31515; "PS." + thisJournalEntry.Element(<span style="color:#A31515; "SOURCE").Value);<span style="color:Green; // Reference 1
sb.Append(<span style="color:#A31515; ",");
<span style="color:Green; //sb.Append();// Reference 2
sb.Append(<span style="color:#A31515; ",");
sb.Append(<span style="color:#A31515; " "); <span style="color:Green; // Recurring cycle?
sb.Append(<span style="color:#A31515; ",");
sb.Append(thisJournalEntry.Element(<span style="color:#A31515; "DEPTID").Value); <span style="color:Green; // Org Abbreviation code #18
sb.Append(<span style="color:#A31515; ",");
sb.Append(abbreviatedProjectId); <span style="color:Green; // Project abbreviation code
sb.Append(<span style="color:#A31515; ",");
<span style="color:Green; //sb.Append(GetAccountID(thisJournalEntry)); // Project account abbreviation code (Not needed)
sb.Append(<span style="color:#A31515; ",");
sb.Append(billProjectFlag); <span style="color:Green; // Billable flag defaults to "Y"
sb.Append(<span style="color:#A31515; ",");
sb.Append(notes); <span style="color:Green; // Notes
<span style="color:Green; // sb.Append(",");

<span style="color:Blue; return sb.ToString();
}

<span style="color:Blue; private <span style="color:Blue; string GetJournalEntryID(XElement thisJournalEntry, List<IPSData.SystemParameter> systemParameters)
{
<span style="color:Blue; string journalEntryId = <span style="color:#A31515; "";
DateTime current = DateTime.Now;
<span style="color:Blue; string month = current.Month.ToString();
<span style="color:Blue; string day = current.Day.ToString();
<span style="color:Blue; string year = current.Year.ToString().Substring(2,2);

<span style="color:Blue; if(month.Length != 2)
month = <span style="color:#A31515; "0" + month;
<span style="color:Blue; if(day.Length != 2)
day = <span style="color:#A31515; "0" + day;

journalEntryId = month + day + year;
<span style="color:Blue; return journalEntryId;
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Returns the Costpoint PROJ_ID according to the following rules:
<span style="color:Gray; ///<span style="color:Green; First find the Abbreviated Project ID:
<span style="color:Gray; ///<span style="color:Green; If the PeopleSoft PROJECT_ID is a number then:
<span style="color:Gray; ///<span style="color:Green; If the number is between 88200 and 88499 then return the PeopleSoft PROJECT_ID
<span style="color:Gray; ///<span style="color:Green; If the number is not between 88200 and 88499 return the PROJ_ID found when the
<span style="color:Gray; ///<span style="color:Green; ORG_ABBRV_CD contains the PeopleSoft DEPTID:
<span style="color:Gray; ///<span style="color:Green; If the L3_ORG_SEG_ID is either "40" or "60" return "OHEXP"
<span style="color:Gray; ///<span style="color:Green; If not then return "GAEXP"
<span style="color:Gray; ///<span style="color:Green; If the PeopleSoft PROJECT_ID is not a number then:
<span style="color:Gray; ///<span style="color:Green; If the PROJECT_ID and the DEPTID are both blank then return PeopleSofts PROJECT_ID as the Abbreviated Project ID
<span style="color:Gray; ///<span style="color:Green; If the PROJECT_ID is blank and the DEPTID is not then return the result from:
<span style="color:Gray; ///<span style="color:Green; If ORG_ABBRV_CD contains the PeopleSoft DEPTID:
<span style="color:Gray; ///<span style="color:Green; If the L3_ORG_SEG_ID is either "40" or "60" return "OHEXP"
<span style="color:Gray; ///<span style="color:Green; If not then return "GAEXP"
<span style="color:Gray; ///<span style="color:Green; If the PROJECT_ID is not blank then return the
<span style="color:Gray; ///<span style="color:Green;
<span style="color:Gray; ///<span style="color:Green;
<span style="color:Gray; ///<span style="color:Green;
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="thisJournalEntry <span style="color:Gray; </param>
<span style="color:Gray; /// <span style="color:Gray; <param name="systemParameters <span style="color:Gray; </param>
<span style="color:Gray; /// <span style="color:Gray; <param name="projectId <span style="color:Gray; </param>
<span style="color:Gray; /// <span style="color:Gray; <param name="abbreviatedProjectId <span style="color:Gray; </param>
<span style="color:Gray; /// <span style="color:Gray; <param name="billProjectFlag <span style="color:Gray; </param>
<span style="color:Blue; private <span style="color:Blue; void GetProjectID(XElement thisJournalEntry, List<IPSData.SystemParameter> systemParameters, <span style="color:Blue; out <span style="color:Blue; string projectId, <span style="color:Blue; out <span style="color:Blue; string abbreviatedProjectId, <span style="color:Blue; out <span style="color:Blue; string billProjectFlag)
{
<span style="color:Blue; int parsedInt = 0;
<span style="color:Green; // Is the PS Project Id a number?
<span style="color:Blue; if( Int32.TryParse(thisJournalEntry.Element(<span style="color:#A31515; "PROJECT_ID").Value, <span style="color:Blue; out parsedInt))
{
<span style="color:Green; // Is a number so see if it lies between 88200 and 88499 inclusive.
<span style="color:Blue; if(parsedInt >= 88200 && parsedInt <= 88499)
abbreviatedProjectId = thisJournalEntry.Element(<span style="color:#A31515; "PROJECT_ID").Value;
<span style="color:Blue; else
{
<span style="color:Green; // Project ID is out of the allowed range so we must convert it to the appropriate value
abbreviatedProjectId = dataAccessLayer.GetAbbreviatedProjectID(thisJournalEntry, systemParameters);
}
}
<span style="color:Blue; else
{
<span style="color:Green; // Here the Project ID is not a number. It can be a string, like "WISLETOFFY" or it can be blank.
<span style="color:Blue; if ((thisJournalEntry.Element(<span style="color:#A31515; "PROJECT_ID").Value.Length == 0) || (thisJournalEntry.Element(<span style="color:#A31515; "PROJECT_ID").Value == <span style="color:#A31515; " "))
{
<span style="color:Green; // Here the Project ID is blank.
<span style="color:Blue; if (thisJournalEntry.Element(<span style="color:#A31515; "DEPTID").Value.Length > 0) <span style="color:Green; // Is the Department ID blank also?
{
<span style="color:Green; // Here the Department ID is not blank
<span style="color:Green; // If the Project ID is blank and the Department ID is not blank then the logic needs to be run to get the correct Project ID.
abbreviatedProjectId = dataAccessLayer.GetAbbreviatedProjectID(thisJournalEntry, systemParameters);
}
<span style="color:Blue; else
{
<span style="color:Green; // Here the Department ID is blank
<span style="color:Green; // If the Project ID is blank and the Department ID is blank also then the just pass the Project ID on.
abbreviatedProjectId = thisJournalEntry.Element(<span style="color:#A31515; "PROJECT_ID").Value;
}
}
<span style="color:Blue; else
{
<span style="color:Green; // If the Project ID is not blank then its robably some Project ID like "OHEXP" or "GAEXP" so just return it
abbreviatedProjectId = thisJournalEntry.Element(<span style="color:#A31515; "PROJECT_ID").Value;
}
}

<span style="color:Green; // Get the actual Project Id using the Abbreviated Project Id
projectId = dataAccessLayer.GetProjectID(abbreviatedProjectId, <span style="color:Blue; out billProjectFlag, systemParameters);
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Returns the Account ID according to the following rules:
<span style="color:Gray; ///<span style="color:Green; First Find the First Segment of the Account Id:
<span style="color:Gray; ///<span style="color:Green; If the XML Source is "DIR" or "WIP" then the First Segment of the Account Id is "5000"
<span style="color:Gray; ///<span style="color:Green; Else call dataAccessLayer.GetFirstSegment(thisJournalEntry) to get the First Segment.
<span style="color:Gray; ///<span style="color:Green; Query the ORG tables ORG_ABBRV_CD with the XML DEPTID.
<span style="color:Gray; ///<span style="color:Green; With the return record if L3_ORG_SEG_ID is "40" or "60" then the First Segment is "7000"
<span style="color:Gray; ///<span style="color:Green; Else the First Segment is "8000"
<span style="color:Gray; ///<span style="color:Green;
<span style="color:Gray; ///<span style="color:Green; After we have the First Segment then
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="thisJournalEntry <span style="color:Gray; </param>
<span style="color:Gray; /// <span style="color:Gray; <returns><span style="color:Gray; </returns>
<span style="color:Blue; private <span style="color:Blue; string GetAccountID(XElement thisJournalEntry)
{
<span style="color:Blue; string firstSegment = <span style="color:#A31515; "";

<span style="color:Green; // If SOURCE is either "DIR" or "WIP" then Account ID is 5000
<span style="color:Blue; if(thisJournalEntry.Element(<span style="color:#A31515; "SOURCE").Value == <span style="color:#A31515; "DIR" || thisJournalEntry.Element(<span style="color:#A31515; "SOURCE").Value == <span style="color:#A31515; "WIP")
{
firstSegment = <span style="color:#A31515; "5000";
}
<span style="color:Blue; else
{
<span style="color:Green; // Derive the Account Id from the Department Id
firstSegment = dataAccessLayer.GetFirstSegment(thisJournalEntry);
}

<span style="color:Green; // Now we have the first segment we can use that to find the Account Id in the ACCT table
<span style="color:Blue; return dataAccessLayer.GetAccountId(thisJournalEntry, firstSegment);
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; ThisEntryProcessed calls the data access layers IsTransfered method which determines if this entry has been processed previously.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="thisJournalEntry <span style="color:Green; Current journal entry to be tested</param>
<span style="color:Gray; /// <span style="color:Gray; <param name="systemParameters <span style="color:Green; The SystemParameters </param>
<span style="color:Gray; /// <span style="color:Gray; <returns><span style="color:Gray; </returns>
<span style="color:Blue; private <span style="color:Blue; bool ThisEntryProcessed(XElement thisJournalEntry, List<IPSData.SystemParameter> systemParameters)
{
<span style="color:Blue; return dataAccessLayer.IsTransfered(thisJournalEntry, systemParameters);
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Checks against the business rules (05/12/2011):
<span style="color:Gray; ///<span style="color:Green;
<span style="color:Gray; ///<span style="color:Green; The rules for Journal Line entry for the Costpoint business rules flat file are:
<span style="color:Gray; ///<span style="color:Green; Retrieve all financial entry information for the combination of business units 43350 and 41372
<span style="color:Gray; ///<span style="color:Green; and where the operating unit is either blank or equal to 06230.
<span style="color:Gray; ///<span style="color:Green; However, source code entries TWS and CON will be excluded from transfer to the journal entry preprocessor.
<span style="color:Gray; ///<span style="color:Green;
<span style="color:Gray; ///<span style="color:Green; True is returned if this Journal Line Entrys/Header combination can be included.
<span style="color:Gray; ///<span style="color:Green; False otherwise.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="thisElement <span style="color:Green; The current XML file in XElement format</param>
<span style="color:Gray; /// <span style="color:Gray; <returns><span style="color:Green; True if this particular journal entry/header combination can be added. False otherwise.</returns>
<span style="color:Blue; private <span style="color:Blue; bool CheckBusinessRules(XElement thisElement, <span style="color:Blue; ref <span style="color:Blue; string tempTest)
{
<span style="color:Blue; string thisLineOperatingUnit;
<span style="color:Blue; string thisSourceCode;
<span style="color:Blue; string thisBusinessUnit;
<span style="color:Blue; string thisJournalId;
<span style="color:Blue; try
{
<span style="color:Green; // XElement thisJournalLineEntry = thisElement.Element("entry");

thisBusinessUnit = thisElement.Element(<span style="color:#A31515; "BUSINESS_UNIT").Value; tempTest = tempTest + thisBusinessUnit;
thisSourceCode = thisElement.Element(<span style="color:#A31515; "SOURCE").Value; tempTest = tempTest + thisSourceCode;
thisJournalId = thisElement.Element(<span style="color:#A31515; "JOURNAL_ID").Value; tempTest = tempTest + thisJournalId;
thisLineOperatingUnit = thisElement.Element(<span style="color:#A31515; "OPERATING_UNIT").Value; tempTest = tempTest + thisLineOperatingUnit;

<span style="color:Green; // Any BusinessUnit of 43350 or 41372 is accepted. Otherwise reject
<span style="color:Blue; if ((thisBusinessUnit != <span style="color:#A31515; "43350") && (thisBusinessUnit != <span style="color:#A31515; "41372"))
{
<span style="color:Green; // Not in the businessUnit group (43350, 41372) so reject
<span style="color:Blue; return <span style="color:Blue; false;
}
<span style="color:Blue; else
{
<span style="color:Green; // Here BusinessUnit is either 43350 or 31372
<span style="color:Green; // Source code of CSH, HTR are eliminated
<span style="color:Green; // Source code of CON is rejected if the Journal Id is CONEXP
<span style="color:Green; // source code TWS is rejected if the Business unit is 43350
<span style="color:Blue; if (
(thisSourceCode.ToLower() == <span style="color:#A31515; "csh") ||
(thisSourceCode.ToLower() == <span style="color:#A31515; "htr") ||
(thisSourceCode.ToLower() == <span style="color:#A31515; "ima") ||
((thisSourceCode.ToLower() == <span style="color:#A31515; "con") && (thisJournalId.Contains(<span style="color:#A31515; "CONEXP"))) ||
((thisSourceCode.ToLower() == <span style="color:#A31515; "tws") && (thisBusinessUnit == <span style="color:#A31515; "43350"))
)
{
<span style="color:Blue; return <span style="color:Blue; false;
}
<span style="color:Blue; else
{
<span style="color:Green; // Correct Source code here
<span style="color:Green; // The OperatingUnit must be either blank or 06230
<span style="color:Blue; if ((thisLineOperatingUnit == <span style="color:#A31515; "") || (thisLineOperatingUnit == <span style="color:#A31515; "06230") || (thisLineOperatingUnit == <span style="color:#A31515; "6230"))
{
<span style="color:Green; // Here we have passed all the tests
<span style="color:Blue; return <span style="color:Blue; true;
}
<span style="color:Blue; else
{
<span style="color:Green; // OperatingUnit is not in range so reject
<span style="color:Blue; return <span style="color:Blue; false;
}
}
}
}
<span style="color:Blue; catch (Exception ex)
{
SharedLibrary.IntegrationTools thisIntegrationToolsClient;
thisIntegrationToolsClient = <span style="color:Blue; new SharedLibrary.IntegrationTools();
<span style="color:Blue; if (thisIntegrationToolsClient != <span style="color:Blue; null)
{
<span style="color:Blue; string errorLogFileLocation = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "Config", <span style="color:#A31515; "Config", <span style="color:#A31515; "ErrorLogFileLocation");
<span style="color:Blue; string errorFileLogging = IPSData.SharedLibrary.GetSystemParameter(<span style="color:#A31515; "CostpointIntegrationService", <span style="color:#A31515; "Config", <span style="color:#A31515; "Config", <span style="color:#A31515; "ErrorFileLogging");
<span style="color:Blue; if (errorFileLogging.ToLower() == <span style="color:#A31515; "true")
{
thisIntegrationToolsClient.LogErrors(ex.Message, errorLogFileLocation, <span style="color:#A31515; "CheckBusinessRules(xmlFile) - CostpointIntegrationService");
}
}
<span style="color:Blue; return <span style="color:Blue; false;
}
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Saves the control section to the XML <Control> tag.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="tagNameToValueClass <span style="color:Green; Holds the results of the entry processing</param>
<span style="color:Blue; internal <span style="color:Blue; void SaveThisControlToXMLFile(TagNameToValueClass tagNameToValueClass)
{
XElement topControlElement = <span style="color:Blue; new XElement(<span style="color:#A31515; "Control");

<span style="color:Blue; foreach (KeyValuePair<<span style="color:Blue; string, <span style="color:Blue; string> thisKeyValuePair <span style="color:Blue; in tagNameToValueClass.controlTagNameToValue)
{
topControlElement.Add(<span style="color:Blue; new XElement(thisKeyValuePair.Key, thisKeyValuePair.Value));
}

entryElement.Add(topControlElement);

<span style="color:Green; // entryElement now holds all the Header, Journal and Control entry data
<span style="color:Green; // with the FILMS appropriate tags.
<span style="color:Green; // Insert this entryElement into the topElement
topElement.Add(entryElement);
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Saves the control section to the XML <Header> tag.
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="tagNameToValueClass <span style="color:Green; Holds the results of the entry processing</param>
<span style="color:Blue; internal <span style="color:Blue; void SaveThisHeaderToXMLFile(TagNameToValueClass tagNameToValueClass)
{
XElement topHeaderElement = <span style="color:Blue; new XElement(<span style="color:#A31515; "Header");

<span style="color:Blue; foreach (KeyValuePair<<span style="color:Blue; string, <span style="color:Blue; string> thisKeyValuePair <span style="color:Blue; in tagNameToValueClass.headerTagNameToValue)
{
topHeaderElement.Add(<span style="color:Blue; new XElement(thisKeyValuePair.Key, thisKeyValuePair.Value));
}

<span style="color:Green; // The entryElement (<Entry></Entry>) element holds the header and lines elements.
<span style="color:Green; // This Entry element is later added to the topElement
entryElement.Add(topHeaderElement);
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Saves all the entry lines in the <Entries> section
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Gray; /// <span style="color:Gray; <param name="tagNameToValueClass <span style="color:Green; Holds the results of the entry processing</param>
<span style="color:Blue; internal <span style="color:Blue; void SaveThisLineToXMLFile(TagNameToValueClass thisTagNameToValueClass)
{
<span style="color:Blue; string currentValue = <span style="color:#A31515; "";
XElement thisLineElement = <span style="color:Blue; new XElement(<span style="color:#A31515; "Line");

<span style="color:Green; // cycle through each linesTagNameToValueList which holds all the
<span style="color:Green; // XML tag names and the values from the database
<span style="color:Blue; foreach (<span style="color:Blue; var thisLineTag <span style="color:Blue; in thisTagNameToValueClass.linesTagNameToValueList)
{
<span style="color:Green; // Take each line tag and add it to the XML thisLineElement
<span style="color:Blue; foreach (Dictionary<<span style="color:Blue; string, <span style="color:Blue; string> thisLineKeyValuePair <span style="color:Blue; in thisLineTag.thisLineEntryList)
{
<span style="color:Blue; foreach (<span style="color:Blue; var currentKey <span style="color:Blue; in thisLineKeyValuePair.Keys)
{
<span style="color:Blue; if (currentKey != <span style="color:#A31515; "")
{
thisLineKeyValuePair.TryGetValue(currentKey, <span style="color:Blue; out currentValue);
thisLineElement.Add(<span style="color:Blue; new XElement(currentKey, currentValue));
}
}
}
}
topLinesElement.Add(thisLineElement);
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Saves the actual XML lines to the top entry XElement
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; internal <span style="color:Blue; void SaveTheseLinesToXMLFile()
{
entryElement.Add(topLinesElement);
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Clears the entry XElement
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; internal <span style="color:Blue; void ResetEntryElement()
{
entryElement = <span style="color:Blue; new XElement(<span style="color:#A31515; "Entry"); <span style="color:Green; // Holds <Header> <Lines> and <Control> elements
}

<span style="color:Gray; /// <span style="color:Gray; <summary>
<span style="color:Gray; ///<span style="color:Green; Clears the lines XElement
<span style="color:Gray; /// <span style="color:Gray; </summary>
<span style="color:Blue; internal <span style="color:Blue; void ResetLinesElement()
{
topLinesElement = <span style="color:Blue; new XElement(<span style="color:#A31515; "Lines");
}
}
}
[/code]


<hr class="sig stevekershaw

View the full article
 

Similar threads

Back
Top