Esempio n. 1
0
        private void AttachFile()
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Multiselect = false;
                
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string fileName = System.IO.Path.GetFileName(ofd.FileName);
                    string filePath = System.IO.Path.GetFullPath(ofd.FileName);

                    string strNewFileName = SalesTransactionItemDetails.TransactionID.ToString() + "_" + SalesTransactionItemDetails.TransactionItemsID + "_" + fileName;

                    Data.SalesTransactionItemAttachmentDetails clsDetails = new Data.SalesTransactionItemAttachmentDetails();
                    clsDetails.TransactionItemAttachmentsID = 0;
                    clsDetails.TransactionItemsID = SalesTransactionItemDetails.TransactionItemsID;
                    clsDetails.TransactionID = SalesTransactionItemDetails.TransactionID;
                    clsDetails.OrigFileName = fileName;
                    clsDetails.FileName = strNewFileName;
                    clsDetails.UploadedByName = CashierName;
                    clsDetails.CreatedOn = DateTime.Now;
                    clsDetails.LastModified = clsDetails.CreatedOn;

                    Data.SalesTransactionItemAttachments clsSalesTransactionItemAttachments = new Data.SalesTransactionItemAttachments();
                    clsSalesTransactionItemAttachments.Insert(clsDetails);
                    clsSalesTransactionItemAttachments.CommitAndDispose();

                    try
                    {
                        string strServer = "127.0.0.1";
                        if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPIPAddress"] != null)
                        {
                            try { strServer = System.Configuration.ConfigurationManager.AppSettings["VersionFTPIPAddress"].ToString(); }
                            catch { }
                        }

                        int intPort = 21;
                        if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"] != null)
                        {
                            try { intPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"]); }
                            catch { }
                        }

                        string strUserName = "******";
                        string strPassword = "******";
                        string strFTPDirectory = "attachment";

                        string destinationDirectory = Application.StartupPath;
                        //string strConstantRemarks = "Please contact your system administrator immediately.";

                        FtpClient ftpClient = new FtpClient();
                        ftpClient.Host = strServer;
                        ftpClient.Port = intPort;
                        ftpClient.Credentials = new NetworkCredential(strUserName, strPassword);

                        IEnumerable<FtpListItem> lstFtpListItem = ftpClient.GetListing(strFTPDirectory, FtpListOption.Modify | FtpListOption.Size);


                        Event clsEvent = new Event();

                        bool bolIsFileExist = false;
                        clsEvent.AddEventLn("Checking file if already exist...", true);
                        try
                        {
                            foreach (FtpListItem ftpListItem in lstFtpListItem)
                            {
                                if (ftpListItem.Name.ToUpper() == Path.GetFileName(strNewFileName).ToUpper())
                                { bolIsFileExist = true; break; }
                            }
                        }
                        catch (Exception excheck)
                        {
                            clsEvent.AddEventLn("checking error..." + excheck.Message, true);
                        }

                        if (bolIsFileExist)
                        {
                            clsEvent.AddEventLn("exist...", true);
                            clsEvent.AddEventLn("uploading now...", true);
                        }
                        else
                        {
                            clsEvent.AddEventLn("does not exist...", true);
                            clsEvent.AddEventLn("uploading now...", true);
                        }

                        using (var fileStream = File.OpenRead(filePath))
                        using (var ftpStream = ftpClient.OpenWrite(string.Format("{0}/{1}", strFTPDirectory, Path.GetFileName(strNewFileName))))
                        {
                            var buffer = new byte[8 * 1024];
                            int count;
                            while ((count = fileStream.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                ftpStream.Write(buffer, 0, count);
                            }
                            clsEvent.AddEventLn("Upload Complete: TotalBytes: " + buffer.ToString(), true);
                        }

                        ftpClient.Disconnect();
                        ftpClient.Dispose();
                        ftpClient = null;
                    }
                    catch { }

                    LoadData();

                    MessageBox.Show("The attachment: " + fileName + " has been uploaded.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
        private void AttachFile()
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Multiselect = false;

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string fileName = System.IO.Path.GetFileName(ofd.FileName);
                    string filePath = System.IO.Path.GetFullPath(ofd.FileName);

                    string strNewFileName = SalesTransactionItemDetails.TransactionID.ToString() + "_" + SalesTransactionItemDetails.TransactionItemsID + "_" + fileName;

                    Data.SalesTransactionItemAttachmentDetails clsDetails = new Data.SalesTransactionItemAttachmentDetails();
                    clsDetails.TransactionItemAttachmentsID = 0;
                    clsDetails.TransactionItemsID           = SalesTransactionItemDetails.TransactionItemsID;
                    clsDetails.TransactionID  = SalesTransactionItemDetails.TransactionID;
                    clsDetails.OrigFileName   = fileName;
                    clsDetails.FileName       = strNewFileName;
                    clsDetails.UploadedByName = CashierName;
                    clsDetails.CreatedOn      = DateTime.Now;
                    clsDetails.LastModified   = clsDetails.CreatedOn;

                    Data.SalesTransactionItemAttachments clsSalesTransactionItemAttachments = new Data.SalesTransactionItemAttachments();
                    clsSalesTransactionItemAttachments.Insert(clsDetails);
                    clsSalesTransactionItemAttachments.CommitAndDispose();

                    try
                    {
                        string strServer = "127.0.0.1";
                        if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPIPAddress"] != null)
                        {
                            try { strServer = System.Configuration.ConfigurationManager.AppSettings["VersionFTPIPAddress"].ToString(); }
                            catch { }
                        }

                        int intPort = 21;
                        if (System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"] != null)
                        {
                            try { intPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["VersionFTPPort"]); }
                            catch { }
                        }

                        string strUserName     = "******";
                        string strPassword     = "******";
                        string strFTPDirectory = "attachment";

                        string destinationDirectory = Application.StartupPath;
                        //string strConstantRemarks = "Please contact your system administrator immediately.";

                        FtpClient ftpClient = new FtpClient();
                        ftpClient.Host        = strServer;
                        ftpClient.Port        = intPort;
                        ftpClient.Credentials = new NetworkCredential(strUserName, strPassword);

                        IEnumerable <FtpListItem> lstFtpListItem = ftpClient.GetListing(strFTPDirectory, FtpListOption.Modify | FtpListOption.Size);


                        Event clsEvent = new Event();

                        bool bolIsFileExist = false;
                        clsEvent.AddEventLn("Checking file if already exist...", true);
                        try
                        {
                            foreach (FtpListItem ftpListItem in lstFtpListItem)
                            {
                                if (ftpListItem.Name.ToUpper() == Path.GetFileName(strNewFileName).ToUpper())
                                {
                                    bolIsFileExist = true; break;
                                }
                            }
                        }
                        catch (Exception excheck)
                        {
                            clsEvent.AddEventLn("checking error..." + excheck.Message, true);
                        }

                        if (bolIsFileExist)
                        {
                            clsEvent.AddEventLn("exist...", true);
                            clsEvent.AddEventLn("uploading now...", true);
                        }
                        else
                        {
                            clsEvent.AddEventLn("does not exist...", true);
                            clsEvent.AddEventLn("uploading now...", true);
                        }

                        using (var fileStream = File.OpenRead(filePath))
                            using (var ftpStream = ftpClient.OpenWrite(string.Format("{0}/{1}", strFTPDirectory, Path.GetFileName(strNewFileName))))
                            {
                                var buffer = new byte[8 * 1024];
                                int count;
                                while ((count = fileStream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    ftpStream.Write(buffer, 0, count);
                                }
                                clsEvent.AddEventLn("Upload Complete: TotalBytes: " + buffer.ToString(), true);
                            }

                        ftpClient.Disconnect();
                        ftpClient.Dispose();
                        ftpClient = null;
                    }
                    catch { }

                    LoadData();

                    MessageBox.Show("The attachment: " + fileName + " has been uploaded.", "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "RetailPlus", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }