using Microsoft.VisualBasic.CompilerServices; using System; using System.ComponentModel; using System.Data; using System.Data.Common; using System.Diagnostics; using System.Drawing; using System.IO; using System.Net; using System.Runtime.CompilerServices; using System.Windows.Forms; using System.Data.SqlClient; using Pervasive.Data.SqlClient; namespace ADE_PNP_IDE_V2 { [DesignerGenerated] public class Form1 : Form { private IContainer components; internal virtual RichTextBox edtPROGRESSLOG { get; [MethodImpl(MethodImplOptions.Synchronized)] set; } public Form1() { base.Load += new EventHandler(this.frmMain_Load); this.InitializeComponent(); } [DebuggerNonUserCode] protected override void Dispose(bool disposing) { try { if (disposing && this.components != null) { this.components.Dispose(); } } finally { base.Dispose(disposing); } } private void ExportInvoices() { try { this.edtPROGRESSLOG.AppendText("Checking for invoices"); SqlConnection sqlConnection = new SqlConnection("Data Source=(local);Initial Catalog=ADE - Live;Persist Security Info=True;User ID=sa;Password=Adent23!#;"); DataSet dataSet = new DataSet(); SqlCommand psqlCommand = new SqlCommand("", sqlConnection); psqlCommand.CommandType = CommandType.StoredProcedure; psqlCommand.CommandText = "SUN_INVOICE_spSel"; if (sqlConnection.State == ConnectionState.Closed) { sqlConnection.Open(); } (new SqlDataAdapter(psqlCommand)).Fill(dataSet); if (sqlConnection.State == ConnectionState.Open) { sqlConnection.Close(); } DataTable dataTable = new DataTable(); dataTable = dataSet.Tables[0].Copy(); this.edtPROGRESSLOG.AppendText(string.Concat("Now Exporting ", Conversions.ToString(dataTable.Rows.Count), " Invoices.", Environment.NewLine)); int count = checked(dataTable.Rows.Count - 1); for (int i = 0; i <= count; i = checked(i + 1)) { if (!File.Exists(Conversions.ToString(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject("c:\\xprocure\\uploaded\\", dataTable.Rows[i]["InvoiceNumber"]), ".csv")))) { int num = checked(dataTable.Columns.Count - 1); for (int j = 0; j <= num; j = checked(j + 1)) { File.AppendAllText(Conversions.ToString(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject("c:\\xprocure\\", dataTable.Rows[i]["InvoiceNumber"]), ".csv")), Conversions.ToString(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(dataTable.Rows[i][j], "|"))); } File.AppendAllText(Conversions.ToString(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject("c:\\xprocure\\", dataTable.Rows[i]["InvoiceNumber"]), ".csv")), Environment.NewLine); } } this.edtPROGRESSLOG.AppendText(string.Concat("Process Complete", Environment.NewLine)); } catch (Exception exception1) { ProjectData.SetProjectError(exception1); Exception exception = exception1; this.edtPROGRESSLOG.AppendText(string.Concat("Export Invoices - ", exception.Message, Environment.NewLine)); ProjectData.ClearProjectError(); } } static System.Windows.Forms.Timer tmrCheckFTP = new System.Windows.Forms.Timer(); private void frmMain_Load(object sender, EventArgs e) { this.Text = "ADE - PNP Invoice Export - v7"; this.edtPROGRESSLOG.AppendText(string.Concat("Application Started", Environment.NewLine)); tmrCheckFTP.Tick += new EventHandler(TimerEventProcessor); // Sets the timer interval to 5 seconds. tmrCheckFTP.Interval = 600000; tmrCheckFTP.Start(); } [DebuggerStepThrough] private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.edtPROGRESSLOG = new RichTextBox(); base.SuspendLayout(); this.edtPROGRESSLOG.Dock = DockStyle.Fill; this.edtPROGRESSLOG.Location = new Point(0, 0); this.edtPROGRESSLOG.Name = "edtPROGRESSLOG"; this.edtPROGRESSLOG.Size = new System.Drawing.Size(823, 689); this.edtPROGRESSLOG.TabIndex = 0; this.edtPROGRESSLOG.Text = ""; base.AutoScaleDimensions = new SizeF(12f, 25f); base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; base.ClientSize = new System.Drawing.Size(823, 689); base.Controls.Add(this.edtPROGRESSLOG); base.Name = "Form1"; this.Text = "Form1"; base.ResumeLayout(false); } private void TimerEventProcessor(Object myObject,EventArgs myEventArgs) { this.ExportInvoices(); this.UploadInvoices(); } private void UploadInvoices() { string str = "ADE"; string str1 = "hgSA4Csqlj"; string str2 = "ftp://xpliquor.dyndns.org/PNPInvoices/"; string[] files = Directory.GetFiles("c:\\xprocure\\", "*.csv", SearchOption.TopDirectoryOnly); for (int i = 0; i < (int)files.Length; i = checked(i + 1)) { string str3 = files[i]; try { File.AppendAllText(str3, "|"); FileInfo fileInfo = new FileInfo(str3); FtpWebRequest networkCredential = (FtpWebRequest)WebRequest.Create(string.Concat(str2, fileInfo.Name)); networkCredential.Credentials = new NetworkCredential(str, str1); networkCredential.Method = "STOR"; networkCredential.Proxy = null; byte[] numArray = File.ReadAllBytes(fileInfo.FullName); Stream requestStream = networkCredential.GetRequestStream(); requestStream.Write(numArray, 0, (int)numArray.Length); requestStream.Close(); requestStream.Dispose(); try { File.Move(fileInfo.FullName, fileInfo.FullName.Replace("\\xprocure", "\\xprocure\\uploaded")); } catch (Exception exception1) { ProjectData.SetProjectError(exception1); Exception exception = exception1; this.edtPROGRESSLOG.AppendText(string.Concat("Delete File - ", exception.Message, Environment.NewLine)); ProjectData.ClearProjectError(); } } catch (Exception exception3) { ProjectData.SetProjectError(exception3); Exception exception2 = exception3; this.edtPROGRESSLOG.AppendText(string.Concat("Upload File - ", exception2.Message, Environment.NewLine)); ProjectData.ClearProjectError(); } } } } }