public static List <CustomerName> GetAllCustomerNames() { string query = "select DISTINCT client_name from FC_LocalContract;"; //Create Command MySqlCommand cmd = new MySqlCommand(query, connection); //Create a data reader and Execute the command MySqlDataReader dataReader = cmd.ExecuteReader(); List <CustomerName> inData = new List <CustomerName>(); while (dataReader.Read()) { CustomerName temp = new CustomerName(); temp.CustName = dataReader["client_name"] + ""; inData.Add(temp); } dataReader.Close(); TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "GetAllCustomerNames" + " | " + "Confirmation" + " | " + "Customer names loaded" + " | "); return(inData); }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn SelectFromCMP * \brief This will connection to the contract market place, query, and store the results in a * list * \param[in] ParentTable tabletyp * \param[out] None * \return List<object> * ---------------------------------------------------------------------------------------------------- */ public static List <object> SelectFromCMP(ParentTable tabletype) { SQL.close(); string connectionString = string.Empty; connectionString = "SERVER=" + CMPserver + ";" + "DATABASE=" + CMPdatabase + ";" + "UID=" + CMPuid + ";" + "PASSWORD="******";"; //set up the connection connection = new MySqlConnection(connectionString); SQL.open(); List <object> RetrunedContracts = Select(tabletype, "SELECT * FROM Contract;"); SQL.close(); SQL.init(); SQL.open(); TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "SelectFromCMP" + " | " + "Confirmation" + " | " + "Data selected from CMP" + " | "); return(RetrunedContracts); }
static public bool RecoverRestorePoint(TMSBackup b) { bool readSuccess = true; try { FileInfo restoreFile = new FileInfo(b.filePath); if (restoreFile.Exists == true) { List <string> AllTableName = new List <string>(); // Reset database string query = "DROP DATABASE IF EXISTS duane_test; CREATE DATABASE duane_test;"; SQL.GenericFunction(query); // Run table builder string SQL.GenericFunction(BuildTables.tableBuilder); // Run CSV! // Run all queries since the database started string restoreQueries = System.IO.File.ReadAllText(b.filePath); SQL.GenericFunction(restoreQueries); } } /// If an exception is thrown here, create a log for it. catch (Exception e) { TMSLogger.LogIt(" | " + "AdminClasses.cs" + " | " + "TMSBackup" + " | " + "RecoverRestorePoint" + " | " + e.GetType().ToString() + " | " + e.Message + " | "); readSuccess = false; } return(readSuccess); }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn Insert * \brief this method will be able to insert into any table that using the corresponding * ParentTable * \param[in] ParentTable input * \param[out] none * \return bool * ---------------------------------------------------------------------------------------------------- */ public static bool Insert(ParentTable input) { try { //get the insert statement string query = input.GetInsertStatment(); //create command and assign the query and connection from the constructor MySqlCommand cmd = new MySqlCommand(query, connection); //Execute command if (cmd.ExecuteNonQuery() > 0) { TMSBackup.WriteQueryToCurrentFile(new TMSBackupQuery(query)); } TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "Insert" + " | " + "Confirmation" + " | " + "Data inserted into SQL database" + " | "); return(true); } catch (Exception e) { //logit TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "Insert" + " | " + e.GetType().ToString() + " | " + e.Message + " | "); return(false); } }
static public bool WriteQueryToCurrentFile(TMSBackupQuery bq) { // writeQuery to file bool appendSuccess = true; try { /// Open the file stream to append to the file. FileStream fileStream = new FileStream((writeFilePath), FileMode.Append, FileAccess.Write); StreamWriter fileWriter = new StreamWriter(fileStream); fileWriter.WriteLine("\n/*" + bq.BackupDate.ToString() + "*/\n"); fileWriter.WriteLine(bq.queryString); fileWriter.Flush(); /// Close the file fileWriter.Close(); fileStream.Close(); } /// If an exception is thrown here, catch it catch (Exception e) { /// This could become problematic as it calls itself TMSLogger.LogIt("|" + "/AdminClasses.cs" + "|" + "TMSBackup" + "|" + "WriteQuery" + "|" + "Exception" + "|" + e.Message + "|"); appendSuccess = false; } return(appendSuccess); }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn CreatTripInfo * \brief This inserts data into the columns for the Trip Ticket table * \param[in] FC_LocalContract inContract, FC_Carrier inCarrier, FC_TripTicket partTicket * \param[out] None * \return None * ---------------------------------------------------------------------------------------------------- */ public CreateTripInfo(FC_LocalContract inContract, FC_Carrier inCarrier, FC_TripTicket partTicket) { FC_TripTicket theTicket = new FC_TripTicket(); theTicket.FC_TripTicketID = SQL.GetNextID("FC_TripTicket"); theTicket.FC_CarrierID = inCarrier.FC_CarrierID; theTicket.Days_Passes = 0; theTicket.Size_in_Palettes = partTicket.Size_in_Palettes; theTicket.Is_Complete = 0; //0 is not done. 1 is done theTicket.CurrentLocation = inContract.Origin; SQL.Insert(theTicket); MappingClass mapping = new MappingClass(); List <FC_RouteSeg> routeSegs = mapping.GetTravelData(inContract.Origin, inContract.Destination, inContract.Job_type, theTicket.FC_TripTicketID); foreach (FC_RouteSeg x in routeSegs) { SQL.Insert(x); } FC_TripTicketLine tripTicketLine = new FC_TripTicketLine(theTicket.FC_TripTicketID, inContract.FC_LocalContractID, partTicket.Size_in_Palettes); SQL.Insert(tripTicketLine); TMSLogger.LogIt(" | " + "CreateTripInfo.cs" + " | " + "CreateTripInfo" + " | " + "CreateTripInfo" + " | " + "Confirmation" + " | " + "Trip info created" + " | "); }
public static FC_Invoice GenerateInvoice(FC_LocalContract InContract) { double OtherContractCost = GenerateInvoiceTotal(InContract); TMSLogger.LogIt(" | " + "PlannerClass.cs" + " | " + "PlannerClass" + " | " + "GenerateInvoice" + " | " + "Confirmation" + " | " + "Invoice generated" + " | "); return(new FC_Invoice(-1, OtherContractCost)); }
static public void SetDefaultBackupFilePath() { try { (writeFilePath) = Environment.CurrentDirectory + "/TMStempBackup.sql"; thisFileDir = Environment.CurrentDirectory; } catch (Exception e) { TMSLogger.LogIt("|" + "/AdminClasses.cs" + "|" + "TMSBackup" + "|" + "SetDefaultBackupFilePath" + "|" + "Exception" + "|" + e.Message + "|"); } }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn close * \brief this method will close the connection * \param[in] none * \param[out] none * \return bool * ---------------------------------------------------------------------------------------------------- */ public static bool close() { try { connection.Close(); TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "close" + " | " + "Confirmation" + " | " + "SQL connection closed" + " | "); return(true); } catch (Exception e) { TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "close" + " | " + e.GetType().ToString() + " | " + e.Message + " | "); return(false); } }
public static void AddContractToInvoices(FC_Invoice inInvoice, FC_LocalContract InContract) { double OtherContractCost = GenerateInvoiceTotal(InContract); string query = "update FC_Invoice set TotalCost = " + Math.Round((inInvoice.TotalCost + OtherContractCost), 2) + " where FC_InvoiceID = " + inInvoice.FC_InvoiceID.ToString() + ";"; SQL.GenericFunction(query); FC_InvoiceContractLine newLine = new FC_InvoiceContractLine(InContract.FC_LocalContractID, inInvoice.FC_InvoiceID); SQL.Insert(newLine); TMSLogger.LogIt(" | " + "PlannerClass.cs" + " | " + "PlannerClass" + " | " + "AddContractToInvoices" + " | " + "Confirmation" + " | " + "Contract added to invoices" + " | "); }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn init * \brief This method will be used to initialize the connection * \param[in] None * \param[out] None * \return Void * ---------------------------------------------------------------------------------------------------- */ public static void init() { //This is a prototype application, so this data will not ever change server = "35.193.37.75"; database = "duane_test"; //uid = "test"; //password = "******"; string connectionString; connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD="******";"; //set up the connection connection = new MySqlConnection(connectionString); TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "init" + " | " + "Confirmation" + " | " + "SQL connection initialized" + " | "); }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn Select * \brief This select statement will take in a table type and a optional Id number for the table * It will return a list of objects that can then be cast to the correct class type * \param[in] ParentTable tabletype, int TableID = -1 * \param[out] None * \return List<object> * ---------------------------------------------------------------------------------------------------- */ public static List <object> Select(ParentTable tabletype, int TableID = -1) { //get the select statement for the table string query = tabletype.GetSelectStatment(); if (TableID != -1) { //if a id was passed in, add a where class to the select statement string sufix = " where " + tabletype.GetTableName() + "ID = " + TableID.ToString() + ";"; query = query.Replace(";", sufix); } //Create as array list to store the result List <string>[] list = new List <string> [tabletype.GetColoumInt()]; for (int i = 0; i < list.Length; i++) { list[i] = new List <string>(); } //Create Command MySqlCommand cmd = new MySqlCommand(query, connection); //Create a data reader and Execute the command MySqlDataReader dataReader = cmd.ExecuteReader(); //get the column names from the List <string> ColomNames = tabletype.GetColoumNames(); //Read the data and store them in the array of lists while (dataReader.Read()) { for (int i = 0; i < list.Length; i++) { list[i].Add(dataReader[ColomNames[i]] + ""); } } //close Data Reader dataReader.Close(); //take the array of lists, and convert it to a list of objects List <object> outList = tabletype.PackageClasses(list); TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "Select" + " | " + "Confirmation" + " | " + "Data selected with SQL" + " | "); //return the list return(outList); }
static public void ReadInBackupsList() { try { TMSBackup.backupPoints.Clear(); foreach (string file in Directory.EnumerateFiles(thisFileDir, "*.sql")) { FileInfo fi = new FileInfo(file); backupPoints.Add(new TMSBackup(fi.FullName, fi.CreationTime)); } } catch (Exception e) { TMSLogger.LogIt(" | " + "AdminClasses.cs" + " | " + "TMSBackup" + " | " + "ReadInBackupsList" + " | " + e.GetType().ToString() + " | " + e.Message + " | "); } }
public static List <FC_TripTicket> CreateTicketsFromContract(FC_LocalContract InContract) { List <FC_TripTicket> ReturnTickets = new List <FC_TripTicket>(); if (InContract != null) { int TempTickedID = -10; if (InContract.Quantity == 0 || InContract.Quantity == 26) { FC_TripTicket newTicket = new FC_TripTicket(TempTickedID, -1, InContract.Origin, 0, 0, 0); ReturnTickets.Add(newTicket); } else if (InContract.Quantity < 26) { FC_TripTicket newTicket = new FC_TripTicket(TempTickedID, -1, InContract.Origin, InContract.Quantity, 0, 0); ReturnTickets.Add(newTicket); } else if (InContract.Quantity > 26) { FC_TripTicket newTicket = new FC_TripTicket(); do { if (InContract.Quantity >= 26) { newTicket = new FC_TripTicket(TempTickedID--, -1, InContract.Origin, 0, 0, 0); } else if (InContract.Quantity < 26) { newTicket = new FC_TripTicket(TempTickedID--, -1, InContract.Origin, InContract.Quantity, 0, 0); } ReturnTickets.Add(newTicket); InContract.Quantity -= 26; } while (InContract.Quantity > 0); } } TMSLogger.LogIt(" | " + "PlannerClass.cs" + " | " + "PlannerClass" + " | " + "CreateTicketsFromContract" + " | " + "Confirmation" + " | " + "Ticket created from contract" + " | "); return(ReturnTickets); }
static public void ChangeBackupPath() { string oldFileDir = thisFileDir; string copyFileName = ""; bool saveSuccess = true; // Open a folder browser to choose the new folder FolderBrowserDialog browser = new FolderBrowserDialog(); DialogResult res = browser.ShowDialog(); if (res == DialogResult.OK && (string.IsNullOrWhiteSpace(browser.SelectedPath.ToString()) == false)) { thisFileDir = browser.SelectedPath; } // Copy over the newest restore point to the new folder try { /// Open file streams FileStream newFile = new FileStream((thisFileDir + "/TMStempBackup.sql"), FileMode.Create); FileStream oldFile = new FileStream(writeFilePath, FileMode.Open); StreamReader streamReader = new StreamReader(oldFile); StreamWriter streamWriter = new StreamWriter(newFile); /// Read and copy through the files while (!streamReader.EndOfStream) { streamWriter.WriteLine(streamReader.ReadLine()); streamWriter.Flush(); } /// Close all the streams streamWriter.Close(); streamReader.Close(); newFile.Close(); oldFile.Close(); // Set the write file path to the new path writeFilePath = thisFileDir + copyFileName; } catch (Exception ex) { TMSLogger.LogIt(" | " + "AdminClasses.cs" + " | " + "TMSBackup" + " | " + "ChangeBackupPath" + " | " + ex.GetType().ToString() + " | " + ex.Message + " | "); saveSuccess = false; } }
public static void WipeEverything() { List <string> AllTableName = new List <string>(); string query = "DROP DATABASE IF EXISTS duane_test; CREATE DATABASE duane_test;"; SQL.GenericFunction(query); // View Save As File Dialog OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "sql Files (*.sql)|*.sql"; if (openFileDialog.ShowDialog() == true) { string text = System.IO.File.ReadAllText(openFileDialog.FileName); SQL.GenericFunction(text); } TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "WipeEverything" + " | " + "Confirmation" + " | " + "Database was wiped" + " | "); }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn SummerizeTrip * \brief This method generates a summary of route trip data * \param[in] List<FC_RouteSeg> inData * \param[out] none * \return RouteSumData * ---------------------------------------------------------------------------------------------------- */ public RouteSumData SummerizeTrip(List <FC_RouteSeg> inData) { RouteSumData outData = new RouteSumData(); foreach (FC_RouteSeg x in inData) { outData.totalDriveTime += x.DrivenTime; outData.totalTripTime += x.DrivenTime; outData.totalTripTime += x.PickUpTime; outData.totalTripTime += x.DropOffTime; outData.totalTripTime += x.LtlTime; outData.totalKM += x.KM; } TMSLogger.LogIt(" | " + "MappingClass.cs" + " | " + "RouteSumData" + " | " + "SummerizeTrip" + " | " + "Confirmation" + " | " + "Trip summarized" + " | "); return(outData); }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn PushToDataBase * \brief This method inserts a new contract into the database * \param[in] none * \param[out] none * \return bool * ---------------------------------------------------------------------------------------------------- */ public bool PushToDataBase() { TheContract = new FC_LocalContract(SQL.GetNextID("FC_LocalContract"), InContract.Client_Name, InContract.Job_type, InContract.Quantity, InContract.Origin, InContract.Destination, InContract.Van_type, 0); SQL.Insert(TheContract); FC_BuyerToPlannerContract B2PC = new FC_BuyerToPlannerContract(); B2PC.FC_BuyerToPlannerContractID = SQL.GetNextID("FC_BuyerToPlannerContract"); B2PC.FC_LocalContractID = TheContract.FC_LocalContractID; SQL.Insert(B2PC); foreach (FC_Carrier x in TheCarriers) { SQL.Insert(new FC_CarrierNom(B2PC.FC_BuyerToPlannerContractID, x.FC_CarrierID)); } TMSLogger.LogIt(" | " + "NominateForPlanner.cs" + " | " + "NominateForPlanner" + " | " + "PushToDataBase" + " | " + "Confirmation" + " | " + "Contract pushed to database" + " | "); return(true); }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn GenericFunction * \brief This method will be called if for a generic query * \param[in] string Query * \param[out] none * \return bool * ---------------------------------------------------------------------------------------------------- */ public static bool GenericFunction(string Query) { try { //create command and assign the query and connection from the constructor MySqlCommand cmd = new MySqlCommand(Query, connection); //Execute command if (cmd.ExecuteNonQuery() > 0) { TMSBackup.WriteQueryToCurrentFile(new TMSBackupQuery(Query)); } TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "GenericFunction" + " | " + "Confirmation" + " | " + "Query executed successfully" + " | "); return(true); } catch (Exception e) { TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "GenericFunction" + " | " + e.GetType().ToString() + " | " + e.Message + " | "); return(false); } }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn Select * \brief This select statement will take in a table type and specific select statement * It will return a list of objects that can then be cast to the correct class type * \param[in] ParentTable tabletype, String InputStatment * \param[out] None * \return List<object> * ---------------------------------------------------------------------------------------------------- */ public static List <object> Select(ParentTable tabletype, String InputStatment) { //Create an array of lists to store the result List <string>[] list = new List <string> [tabletype.GetColoumInt()]; for (int i = 0; i < list.Length; i++) { list[i] = new List <string>(); } //set up the command and reader MySqlCommand cmd = new MySqlCommand(InputStatment, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); //get all the column names in the table List <string> ColomNames = tabletype.GetColoumNames(); //Read the data and store them in the array of lists while (dataReader.Read()) { for (int i = 0; i < list.Length; i++) { list[i].Add(dataReader[ColomNames[i]] + ""); } } //close Data Reader dataReader.Close(); //take the array of lists, and convert it to a list of objects List <object> outList = tabletype.PackageClasses(list); TMSLogger.LogIt(" | " + "SQL.cs" + " | " + "SQL" + " | " + "Select" + " | " + "Confirmation" + " | " + "Data selected with SQL" + " | "); //return the list return(outList); }
public static int AddContractToTicket(FC_TripTicket OriginalTick, FC_TripTicket TempTicket, FC_LocalContract TheContract) { string Query = "select * from FC_RouteSeg where FC_TripTicketID = " + OriginalTick.FC_TripTicketID + ";"; FC_RouteSeg r = new FC_RouteSeg(); List <FC_RouteSeg> OriginalSegs = r.ObjToTable(SQL.Select(r, Query)); MappingClass map = new MappingClass(); List <FC_RouteSeg> NewSegs = map.GetTravelData(TheContract.Origin, TheContract.Destination, 0, -1); //check that these tickets are going in the same direction if (OriginalSegs[0].CityA == NewSegs[0].CityA && OriginalSegs[0].CityB == NewSegs[0].CityB && TempTicket.Size_in_Palettes != 0) { int PalletesAddedToOgrinal = 26 - OriginalTick.Size_in_Palettes; if (PalletesAddedToOgrinal > TempTicket.Size_in_Palettes) { PalletesAddedToOgrinal = TempTicket.Size_in_Palettes; } int OrignalTickNewSize = OriginalTick.Size_in_Palettes + PalletesAddedToOgrinal; if (OrignalTickNewSize == 26) { OrignalTickNewSize = 0; } string query = "update FC_TripTicket " + "set Size_in_Palettes = " + OrignalTickNewSize + " where FC_TripTicketID = " + OriginalTick.FC_TripTicketID + ";"; SQL.GenericFunction(query); int FTL = 0; List <FC_RouteSeg> NewSegmentsFTL = new List <FC_RouteSeg>(); List <FC_RouteSeg> NewSegmentsLTL = new List <FC_RouteSeg>(); if (NewSegs.Count > OriginalSegs.Count) { string orginCity = LoadCSV.ToCityName(OriginalSegs[0].CityA); string EndOfFTL = LoadCSV.ToCityName(OriginalSegs[OriginalSegs.Count - 1].CityB); string startLTL = LoadCSV.ToCityName(NewSegs[OriginalSegs.Count].CityA); string endCity = LoadCSV.ToCityName(NewSegs[NewSegs.Count - 1].CityB); NewSegmentsFTL = map.GetTravelData(orginCity, EndOfFTL, FTL, OriginalTick.FC_TripTicketID); NewSegmentsLTL = map.GetTravelData(startLTL, endCity, 1, OriginalTick.FC_TripTicketID); } else if (NewSegs.Count < OriginalSegs.Count) { string orginCity = LoadCSV.ToCityName(OriginalSegs[0].CityA); string EndOfFTL = LoadCSV.ToCityName(NewSegs[NewSegs.Count - 1].CityB); string startLTL = LoadCSV.ToCityName(OriginalSegs[NewSegs.Count].CityA); string endCity = LoadCSV.ToCityName(OriginalSegs[OriginalSegs.Count - 1].CityB); NewSegmentsFTL = map.GetTravelData(orginCity, EndOfFTL, FTL, OriginalTick.FC_TripTicketID); NewSegmentsLTL = map.GetTravelData(startLTL, endCity, 1, OriginalTick.FC_TripTicketID); } else { string orginCity = LoadCSV.ToCityName(OriginalSegs[0].CityA); string endCity = LoadCSV.ToCityName(OriginalSegs[NewSegs.Count - 1].CityB); NewSegmentsLTL = map.GetTravelData(orginCity, endCity, FTL, OriginalTick.FC_TripTicketID); } if (NewSegmentsLTL != null) { NewSegmentsLTL[0].PickUpTime = 0; } query = "delete from FC_RouteSeg where FC_TripTicketID = " + OriginalTick.FC_TripTicketID + ";"; SQL.GenericFunction(query); foreach (FC_RouteSeg x in NewSegmentsFTL) { SQL.Insert(x); } foreach (FC_RouteSeg x in NewSegmentsLTL) { SQL.Insert(x); } FC_TripTicketLine NewLine = new FC_TripTicketLine(OriginalTick.FC_TripTicketID, TheContract.FC_LocalContractID, PalletesAddedToOgrinal); SQL.Insert(NewLine); TMSLogger.LogIt(" | " + "PlannerClass.cs" + " | " + "PlannerClass" + " | " + "AddContractToTicket" + " | " + "Confirmation" + " | " + "Contract added to ticket" + " | "); return(PalletesAddedToOgrinal); } return(-1); }
static public bool CreateRestorePoint() { // Copy current file to a new one with the restore date. // Change the write file path to the new file // Start appending to the new file. bool saveSuccess = true; // View Save As File Dialog SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Text Files|*.sql"; saveFileDialog.DefaultExt = ".sql"; saveFileDialog.InitialDirectory = thisFileDir; saveFileDialog.FileName = "RestoreTo_" + DateTime.Now.ToString().Replace(':', '-').Replace(' ', '_'); // Set a text range using the textbox name // TextRange textRange = new TextRange(myTextbox.Document.ContentStart, myTextbox.Document.ContentEnd); DialogResult res = saveFileDialog.ShowDialog(); if ((res == DialogResult.OK) && (string.IsNullOrWhiteSpace(saveFileDialog.FileName.ToString()) == false)) { /// Get the new path string newFilePath = (saveFileDialog.FileName); /// Open both files to copy try { /// Open file streams FileStream newFile = new FileStream(newFilePath, FileMode.Create); FileStream oldFile = new FileStream(writeFilePath, FileMode.Open); StreamReader streamReader = new StreamReader(oldFile); StreamWriter streamWriter = new StreamWriter(newFile); /// Read and copy through the files while (!streamReader.EndOfStream) { streamWriter.WriteLine(streamReader.ReadLine()); streamWriter.Flush(); } /// Close all the streams streamWriter.Close(); streamReader.Close(); newFile.Close(); oldFile.Close(); // Set the write file path to the new path writeFilePath = newFilePath; } catch (Exception ex) { TMSLogger.LogIt(" | " + "AdminClasses.cs" + " | " + "TMSBackup" + " | " + "CreateRestorePoint" + " | " + ex.GetType().ToString() + " | " + ex.Message + " | "); saveSuccess = false; } if (saveSuccess == true) { /// Set location of LogFilePath to new path FileInfo tmpfi = new FileInfo(newFilePath); backupPoints.Add(new TMSBackup(newFilePath, tmpfi.CreationTime)); } } return(true); }
// METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn Load * \brief This method loads the carrier csv, parses it for the carrier info and depot city * \param[in] none * \param[out] none * \return bool * ---------------------------------------------------------------------------------------------------- */ public static bool Load() { bool worked = true; if (CSVLocation != "") { try { string localResourcePath = CSVLocation; string ReadInData = System.IO.File.ReadAllText(localResourcePath); ReadInData = ReadInData.Replace("\r\n", ","); ReadInData = ReadInData.Replace(",,", ","); String[] SeperaterStrings = ReadInData.Split(','); List <FC_Carrier> ReadInCarriers = new List <FC_Carrier>(); List <FC_DepotCity> InDeoptCities = new List <FC_DepotCity>(); int index = 7; bool CarrierFound = true; index = 7; do { int CurrentCarrierID = SQL.GetNextID("FC_Carrier"); FC_Carrier current = new FC_Carrier(CurrentCarrierID, SeperaterStrings[index]); index++; bool cityFound = true; do { if (ToCityID(SeperaterStrings[index]) != -1) { FC_DepotCity tempDepot = new FC_DepotCity(CurrentCarrierID, SeperaterStrings[index], int.Parse(SeperaterStrings[index + 1]), int.Parse(SeperaterStrings[index + 2]), double.Parse(SeperaterStrings[index + 3]), double.Parse(SeperaterStrings[index + 4]), double.Parse(SeperaterStrings[index + 5])); InDeoptCities.Add(tempDepot); index += 6; } else { cityFound = false; } } while (cityFound); ReadInCarriers.Add(current); if (SeperaterStrings[index] == "") { CarrierFound = false; } SQL.Insert(current); } while (CarrierFound); foreach (FC_DepotCity x in InDeoptCities) { SQL.Insert(x); } } catch (Exception e) { //Console.WriteLine(e.ToString()); TMSLogger.LogIt(" | " + "LoadCSV.cs" + " | " + "LoadCSV" + " | " + "Load" + " | " + e.GetType().ToString() + " | " + e.Message + " | "); worked = false; } } TMSLogger.LogIt(" | " + "LoadCSV.cs" + " | " + "LoadCSV" + " | " + "Load" + " | " + "Confirmation" + " | " + "CSV Loaded" + " | "); return(worked); }
// GetTravelData METHOD HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn List<RouteData> GetTravelData(int OriginID, int DestinationID, bool FLTorLTL) * \brief This method will determine the info for a trip the between to cities. * \details A list of RouteData structs, each struct will hold all timing and KM data. * The timing for each element will keep track of the pick up time at the origin city, the drop off time at the destination, and the LTL time at intermediate cities. * \param[in] int OriginID, int DestinationID, bool FLTorLTL The origin and destination cities, and if the trip is Flt or Ltl. * \param[out] null * \exception null * \see Struct: RouteData * \return List<RouteData> A list of the RouteData structs. The list all together will hold all the data for a trip. * * ---------------------------------------------------------------------------------------------------- */ public List <FC_RouteSeg> GetTravelData(string Origin, string Destination, int inFTL, int InTicketID) //one is ltl { int OriginID = LoadCSV.ToCityID(Origin); int DestinationID = LoadCSV.ToCityID(Destination); bool FTL = true; if (inFTL == 1) { FTL = false; } try { //figure out if we need to travel east or west CityNode current = nodes.Find(x => x.CityID == OriginID); CityNode nextCity; List <FC_RouteSeg> returnList = new List <FC_RouteSeg>(); if (OriginID >= 0 && OriginID < Number_of_Cities && DestinationID >= 0 && DestinationID < Number_of_Cities && OriginID != DestinationID) { do { FC_RouteSeg tripDataPassBack = new FC_RouteSeg(InTicketID, 0, 0, 0, 0, 0, 0, 0); if (OriginID > DestinationID) { //going west nextCity = current.West; tripDataPassBack.KM = current.WestKM; tripDataPassBack.DrivenTime = current.WestHour; } else { //going east nextCity = current.East; tripDataPassBack.KM = current.EastKM; tripDataPassBack.DrivenTime = current.EastHour; } tripDataPassBack.CityA = current.CityID; tripDataPassBack.CityB = nextCity.CityID; if (current.CityID == OriginID) { tripDataPassBack.PickUpTime += 2; } if (nextCity.CityID == DestinationID) { tripDataPassBack.DropOffTime += 2; } if (!FTL && (nextCity.CityID != DestinationID)) { tripDataPassBack.LtlTime += 2; } returnList.Add(tripDataPassBack); current = nextCity; } while (nextCity.CityID != DestinationID); TMSLogger.LogIt(" | " + "MappingClass.cs" + " | " + "MappingClass" + " | " + "GetTravelData" + " | " + "Confirmation" + " | " + "Route List calculated" + " | "); return(returnList); } } catch (Exception e) { TMSLogger.LogIt(" | " + "MappingClass.cs" + " | " + "MappingClass" + " | " + "GetTravelData" + " | " + e.GetType().ToString() + " | " + e.Message + " | "); } return(null); }
// MappingClass Constructor HEADER COMMENT ------------------------------------------------------------------------------- /** * \fn MappingClass() Constructor * \brief The constructor for the Mapping Class * \details The data for each city will be read out of the database. It will then converted into a List datastructure so that it can be steped though easily. * \param[in] null * \param[out] null * \exception null * \see na * \return null * ---------------------------------------------------------------------------------------------------- */ public MappingClass() { CityNode Windsor = new CityNode("Windsor", 0); CityNode London = new CityNode("London", 1); CityNode Hamilton = new CityNode("Hamilton", 2); CityNode Toronto = new CityNode("Toronto", 3); CityNode Oshawa = new CityNode("Oshawa", 4); CityNode Belleville = new CityNode("Belleville", 5); CityNode Kingston = new CityNode("Kingston", 6); CityNode Ottawa = new CityNode("Ottawa", 7); Windsor.West = null; London.West = Windsor; Hamilton.West = London; Toronto.West = Hamilton; Oshawa.West = Toronto; Belleville.West = Oshawa; Kingston.West = Belleville; Ottawa.West = Kingston; Windsor.East = London; London.East = Hamilton; Hamilton.East = Toronto; Toronto.East = Oshawa; Oshawa.East = Belleville; Belleville.East = Kingston; Kingston.East = Ottawa; Ottawa.East = null; nodes.Add(Windsor); nodes.Add(London); nodes.Add(Hamilton); nodes.Add(Toronto); nodes.Add(Oshawa); nodes.Add(Belleville); nodes.Add(Kingston); nodes.Add(Ottawa); int[] eastKMArray = new int[Number_of_Cities] { 191, 128, 68, 60, 134, 82, 196, -1 }; for (int i = 0; i < Number_of_Cities; i++) { nodes[i].EastKM = eastKMArray[i]; } int[] westKMArray = new int[Number_of_Cities] { -1, 191, 128, 68, 60, 134, 82, 196 }; for (int i = 0; i < Number_of_Cities; i++) { nodes[i].WestKM = westKMArray[i]; } double[] eastHourArray = new double[Number_of_Cities] { 2.5, 1.75, 1.25, 1.3, 1.65, 1.2, 2.5, -1 }; for (int i = 0; i < Number_of_Cities; i++) { nodes[i].EastHour = eastHourArray[i]; } double[] WestHourArray = new double[Number_of_Cities] { -1, 2.5, 1.75, 1.25, 1.3, 1.65, 1.2, 2.5 }; for (int i = 0; i < Number_of_Cities; i++) { nodes[i].WestHour = WestHourArray[i]; } TMSLogger.LogIt(" | " + "MappingClass.cs" + " | " + "MappingClass" + " | " + "Constructor" + " | " + "Confirmation" + " | " + "Mapping Class created" + " | "); int k = 0; }
public static double GenerateInvoiceTotal(FC_LocalContract inContract) { List <FC_TripTicket> AllTickets = ConnectedTickets_Populate(inContract); MappingClass map = new MappingClass(); List <FC_RouteSeg> TempRouteSegs = map.GetTravelData(inContract.Origin, inContract.Destination, 1, 1); double Total_Cost = 0; foreach (FC_TripTicket x in AllTickets) { List <FC_RouteSeg> TotalContractSegments = new List <FC_RouteSeg>(); List <FC_RouteSeg> segments = RoutSegsPerTicket_Populate(x); for (int i = 0; i < TempRouteSegs.Count; i++) { TotalContractSegments.Add(segments[i]); } RouteSumData sumData = new RouteSumData(); sumData = sumData.SummerizeTrip(TotalContractSegments); string query = "select FC_CarrierID, CityName, FTL_Availibility, LTL_Availibility, FTL_Rate, LTL_Rate, Reefer_Charge " + "from FC_DepotCity " + "where FC_CarrierID = " + x.FC_CarrierID.ToString() + " and CityName = \"" + inContract.Origin + "\";"; FC_DepotCity d = new FC_DepotCity(); List <FC_DepotCity> theDepotCity = d.ObjToTable(SQL.Select(d, query)); double tempPrice = 0; if (inContract.Job_type == 0) { tempPrice = sumData.totalKM * theDepotCity[0].FTL_Rate * 1.08; } else { query = "select * from FC_TripTicketLine where FC_TripTicketID = " + x.FC_TripTicketID.ToString() + " and FC_LocalContractID = " + inContract.FC_LocalContractID.ToString() + " ;"; FC_TripTicketLine t = new FC_TripTicketLine(); List <FC_TripTicketLine> theTicketLine = t.ObjToTable(SQL.Select(t, query)); int QuantityOnTruck = theTicketLine[0].PalletsOnTicket; if (QuantityOnTruck == 0) { QuantityOnTruck = 26; } tempPrice = sumData.totalKM * theDepotCity[0].LTL_Rate * QuantityOnTruck * 1.05; } if (inContract.Van_type == 1) { tempPrice *= (theDepotCity[0].Reefer_Charge + 1); } Total_Cost += tempPrice; } try { Total_Cost = Math.Round(Total_Cost, 2); } catch (Exception e) { TMSLogger.LogIt(" | " + "PlannerClass.cs" + " | " + "PlannerClass" + " | " + "GenerateInvoiceTotal" + " | " + e.GetType().ToString() + " | " + e.Message + " | "); } TMSLogger.LogIt(" | " + "PlannerClass.cs" + " | " + "PlannerClass" + " | " + "GenerateInvoiceTotal" + " | " + "Confirmation" + " | " + "Invoice total generated" + " | "); return(Total_Cost); }
public static void IncrementOneDay() { try { string FirstQuery = "Select * from FC_TripTicket where not Is_Complete = 0;"; FC_TripTicket t = new FC_TripTicket(); List <FC_TripTicket> AllTickets = t.ObjToTable(SQL.Select(t, FirstQuery)); foreach (FC_TripTicket x in AllTickets) { x.Days_Passes++; FC_RouteSeg s = new FC_RouteSeg(); string query = "Select FC_TripTicketID, CityA, CityB, PickUpTime, DropOffTime, LtlTime, DrivenTime, KM from FC_RouteSeg where FC_TripTicketID = " + x.FC_TripTicketID + ";"; List <FC_RouteSeg> AllSegments = s.ObjToTable(SQL.Select(s, query)); double totalTime = x.Days_Passes * 12; double DriveTime = x.Days_Passes * 8; int SegIndex = 0; FC_RouteSeg currentSegment = AllSegments[SegIndex]; while (true) { totalTime -= currentSegment.PickUpTime; totalTime -= currentSegment.DrivenTime; DriveTime -= currentSegment.DrivenTime; totalTime -= currentSegment.LtlTime; totalTime -= currentSegment.DropOffTime; if (totalTime <= 0 || DriveTime <= 0) { x.CurrentLocation = LoadCSV.ToCityName(currentSegment.CityA); break; } else { SegIndex++; if (SegIndex >= AllSegments.Count) { x.CurrentLocation = LoadCSV.ToCityName(currentSegment.CityB); break; } else { currentSegment = AllSegments[SegIndex]; } x.CurrentLocation = LoadCSV.ToCityName(currentSegment.CityB); } } PlannerClass.UpdateTicketLocation(x); } string Query = "select FC_LocalContractID, Client_Name, Job_type, Quantity, Origin, Destination, Van_type, Contract_Status from " + "FC_LocalContract where Contract_Status = 1"; FC_LocalContract l = new FC_LocalContract(); List <FC_LocalContract> OnrouteContracts = l.ObjToTable(SQL.Select(l, Query)); MappingClass map = new MappingClass(); foreach (FC_LocalContract x in OnrouteContracts) { bool isComplete = true; List <FC_TripTicket> theTickets = PlannerClass.ConnectedTickets_Populate(x); foreach (FC_TripTicket y in theTickets) { if (!map.AtOrPastCity(x, y)) { isComplete = false; break; } } if (isComplete) { PlannerClass.UpdateContratState(x, 2); } } string theQuery = "Select * from FC_TripTicket where Is_Complete = 1"; FC_TripTicket w = new FC_TripTicket(); List <FC_TripTicket> ActiveTickets = t.ObjToTable(SQL.Select(t, theQuery)); foreach (FC_TripTicket x in ActiveTickets) { bool foundNotComple = false; List <FC_LocalContract> ContactsPerTick = PlannerClass.ContractsPerTicket_Populate(x); foreach (FC_LocalContract y in ContactsPerTick) { if (y.Contract_Status < 2) { foundNotComple = true; } } if (!foundNotComple) { theQuery = "Update FC_TripTicket set Is_Complete = 2 where FC_TripTicketID = " + x.FC_TripTicketID + ";"; SQL.GenericFunction(theQuery); } } TMSLogger.LogIt(" | " + "TimePass.cs" + " | " + "TimePass" + " | " + "IncrementOneDay" + " | " + "Confirmation" + " | " + "Day incremented" + " | "); } catch (Exception e) { TMSLogger.LogIt(" | " + "TimePass.cs" + " | " + "TimePass" + " | " + "IncrementOneDay" + " | " + e.GetType().ToString() + " | " + e.Message + " | "); } }