Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace SCCInvoicing
  10. {
  11. class Program
  12. {
  13.  
  14. static string strSQLLiveConn = "Data Source=production-Server;" +
  15. "Initial Catalog=Production;" +
  16. "Persist Security Info=True;" +
  17. "user Id=CF;" +
  18. "Password=ENCTS";
  19.  
  20. static string strSQLConnectionString = strSQLLiveConn;
  21. static string strSqlstmt = "";
  22. static SqlConnection myConn;
  23. static SqlCommand cmd;
  24. static SqlDataReader rs;
  25. static string logfile = "SCCInvoice_LOG_" + String.Format(DateTime.Now.Year.ToString(), "0000")
  26. + String.Format(DateTime.Now.Month.ToString("00"), "00")
  27. + String.Format(DateTime.Now.Day.ToString("00"), "00") + ".txt";
  28.  
  29. static string strRoot = @"W:\SCC Passenger Assistant\Invoices\";
  30. static string strInvoiceFile = "SCCPassengerInvoice_" + String.Format(DateTime.Now.Year.ToString(), "0000")
  31. + String.Format(DateTime.Now.Month.ToString("00"), "00")
  32. + String.Format(DateTime.Now.Day.ToString("00"), "00") + ".csv";
  33.  
  34. static void Main(string[] args)
  35. {
  36. addtoLogFile("*****************", logfile);
  37. addtoLogFile("SCC Invoicing 1.0", logfile);
  38. addtoLogFile("*****************", logfile);
  39. addtoLogFile("", logfile);
  40. //jobtype PassengerAssistant
  41. //sql orders
  42. getOrders();
  43.  
  44. addtoLogFile("********************", logfile);
  45. addtoLogFile("End of SCC Invoicing", logfile);
  46. addtoLogFile("********************", logfile);
  47.  
  48. System.Console.WriteLine("\nPress any key to exit");
  49. System.Console.ReadKey();
  50. }
  51.  
  52. static void addtoLogFile(string textToAdd, string filename, bool addDateTime = true)
  53. {
  54. // this procedure will add the "textToAdd" to the "filename" and also write to the console
  55. // Warning!!! Optional parameters not supported
  56. System.IO.StreamWriter logWriter = new System.IO.StreamWriter(strRoot + logfile, true);
  57. string dateTime = "";
  58. if ((addDateTime == true))
  59. {
  60. dateTime = (DateTime.Now + " ");
  61. }
  62. Console.WriteLine((dateTime + ('\t' + textToAdd)));
  63. logWriter.WriteLine((dateTime + ('\t' + textToAdd)));
  64. logWriter.Close();
  65. }
  66.  
  67. static void getOrders()
  68. {
  69. strSqlstmt = "SELECT * from orders with (nolock) WHERE jobtype = 'PassengerAssistant' AND DateInvoiced IS NULL ORDER BY OrderDate;";
  70. myConn = new SqlConnection(strSQLConnectionString);
  71. myConn.Open();
  72. cmd = new SqlCommand(strSqlstmt, myConn);
  73. rs = cmd.ExecuteReader();
  74. System.IO.StreamWriter objWriter = new System.IO.StreamWriter(strRoot + strInvoiceFile, false);
  75. objWriter.WriteLine("SCC Invoicing v1.0\n");
  76. string orderDate = "";
  77. while (rs.Read())
  78. {
  79. addtoLogFile("Importing batch " + rs["ID"].ToString(),logfile);
  80. addtoLogFile("Success! Found " + rs["OrderQTY"].ToString() + " records", logfile);
  81. addtoLogFile("", logfile);
  82. objWriter.WriteLine("\nDate Received" + "," + "BatchID" + ',' + "BatchIdentifier" + "," + "Cards Issued" + "," + "Cards Posted" + "," + "Invoiced" + "," + "Invoice No.");
  83.  
  84. orderDate = rs["OrderDate"].ToString();
  85. orderDate = orderDate.Substring(6, 2) + "/" + orderDate.Substring(4, 2) + "/" + orderDate.Substring(0, 4);
  86. //objWriter.WriteLine(rs["ID"].ToString() + "," + rs["OrderQTY"].ToString() + "," + orderDate);
  87. objWriter.WriteLine(orderDate + "," + rs["ID"].ToString() + "," + rs["BatchIdentifier"].ToString() + "," + rs["OrderQTY"].ToString() + "," + "BLANK" + "," + DateTime.Now.ToShortDateString() + "");
  88.  
  89. }
  90. objWriter.Close();
  91. objWriter.Dispose();
  92. }
  93.  
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement