private void btnStart_Click(object sender, EventArgs e)
 {
     //lblStartTime.Text = DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss");
     btnStart.Enabled       = false;
     btnStopSending.Enabled = true;
     ExporttoExcel();
     if (System.IO.File.Exists("E:\\ContainerSearch\\ContainerList.xls"))//ContainerList.xls
     {
         Upload(FileName);
     }
     UploadTimer.Interval = (4 * 60 * 60 * 1000);//4 hours//(6 * 60 * 60 * 1000);//6 hours
     UploadTimer.Enabled  = true;
     UploadTimer.Start();
 }
Ejemplo n.º 2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            btnStart.Enabled       = false;
            btnStopSending.Enabled = true;
            UploadTimer.Enabled    = true;
            UploadTimer.Start();

            //ExporttoExcel();
            //if (System.IO.File.Exists("E:\\ContainerSearch\\ContainerList.xls"))//ContainerList.xls
            //{
            //    Upload(FileName);
            //}
            //UploadTimer.Interval = (4 * 60 * 60 * 1000);//4 hours//(6 * 60 * 60 * 1000);//6 hours
            //UploadTimer.Enabled = true;
            //UploadTimer.Start();
        }
        private void UploadTimer_Tick(object sender, EventArgs e)
        {
            UploadTimer.Enabled = false;
            UploadTimer.Stop();
            lblErrorMsg.Text = "";
            ExporttoExcel();

            if (System.IO.File.Exists("E:\\ContainerSearch\\ContainerList.xls"))
            {
                Thread.Sleep(1 * 60 * 1000);

                Upload(FileName);
                lblErrorMsg.Text = "";
            }
            UploadTimer.Enabled = true;
            UploadTimer.Start();
        }
Ejemplo n.º 4
0
        public void uploadtimerfile()
        {
            UploadTimer.Enabled = false;
            UploadTimer.Stop();
            lblErrorMsg.Text = "";
            ExporttoExcel();

            if (System.IO.File.Exists(Path))
            {
                Thread.Sleep(5 * 1000);

                Upload(FileName);
                lblErrorMsg.Text = "";
            }
            UploadTimer.Enabled = true;
            UploadTimer.Start();
        }
        private void Upload(string filename)
        {
            try
            {
                if (System.IO.File.Exists("E:\\ContainerSearch\\ContainerList.xls"))//ContainerList.xls
                {
                    btnStopSending.Enabled = false;
                    FileInfo      fileInf = new FileInfo(filename);
                    string        uri     = "ftp://" + ftpServerIP + "/" + ftpfoldername + "/" + fileInf.Name;
                    FtpWebRequest reqFTP;

                    // Create FtpWebRequest object from the Uri provided
                    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + ftpfoldername + "/" + fileInf.Name));//

                    // Provide the WebPermission Credintials
                    reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);

                    // By default KeepAlive is true, where the control connection is not closed
                    // after a command is executed.
                    reqFTP.KeepAlive = false;

                    // Specify the command to be executed.
                    reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

                    // Specify the data transfer type.
                    reqFTP.UseBinary = true;

                    // Notify the server about the size of the uploaded file
                    reqFTP.ContentLength = fileInf.Length;

                    // The buffer size is set to 2kb
                    int    buffLength = 2048;
                    byte[] buff       = new byte[buffLength];
                    int    contentLen;

                    // Opens a file stream (System.IO.FileStream) to read the file to be uploaded
                    FileStream fs = fileInf.OpenRead();

                    try
                    {
                        // Stream to which the file to be upload is written
                        Stream strm = reqFTP.GetRequestStream();

                        // Read from the file stream 2kb at a time
                        contentLen = fs.Read(buff, 0, buffLength);

                        // Till Stream content ends
                        while (contentLen != 0)
                        {
                            // Write Content from the file stream to the FTP Upload Stream
                            strm.Write(buff, 0, contentLen);
                            contentLen = fs.Read(buff, 0, buffLength);
                        }

                        // Close the file stream and the Request Stream
                        strm.Close();
                        fs.Close();
                        lblSendingStatus.Text = "File Upload Successfully...";
                        try
                        {
                            System.IO.File.Delete("E:\\ContainerSearch\\ContainerList.xls");
                        }
                        catch (System.IO.IOException e)
                        {
                            lblErrorMsg.Text = e.Message;
                        }
                        //Send Confirmation mail after upload data
                        SendMail("CONTAINER LIST IS UPLOADED SUCCESSFULLY");

                        lblCopiedTime.Text     = DateTime.Now.ToString();
                        btnStopSending.Enabled = true;
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.Message, "Upload Error");
                        SendMail("FAILED: CONTAINER LIST NOT UPLOADED DUE TO SOME TECHNICAL PROBLEMS");
                        lblErrorMsg.Text       = ex.Message;
                        btnStopSending.Enabled = true;
                        UploadTimer.Enabled    = true;
                        UploadTimer.Start();
                    }
                }
            }
            catch (Exception ex)
            {
                SendMail("FAILED: CONTAINER LIST NOT UPLOADED DUE TO SOME TECHNICAL PROBLEMS");
                lblErrorMsg.Text       = ex.Message;
                btnStopSending.Enabled = true;
                UploadTimer.Enabled    = true;
                UploadTimer.Start();
            }
        }
Ejemplo n.º 6
0
 public void FileUploadTimeSlot()
 {
     if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "00:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "01:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "02:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "03:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "04:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "05:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "06:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "07:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "08:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "09:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "10:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "11:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "12:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "13:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "14:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "15:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "16:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "17:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "18:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "19:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "20:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "21:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "22:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
     else if ((String.Format(DateTime.Now.ToString("HH:mm:ss"), "HH:mm:ss") == "23:00:00"))
     {
         UploadTimer.Stop();
         uploadtimerfile();
         UploadTimer.Start();
     }
 }