Esempio n. 1
0
        public void runStoreProcedure(String downloadSessionId, int syncDetailId)
        {
            CRUD          sql = new CRUD();
            SqlConnection con = ckon.sqlConMsg();

            try
            {
                con.Open();
                String     cmd_sp = "DatadownloadtoApplied";
                SqlCommand cmd    = new SqlCommand(cmd_sp, con);
                cmd.CommandType    = CommandType.StoredProcedure;
                cmd.CommandTimeout = 120;
                cmd.Parameters.Add("@Downloadsessionid", DbType.Guid).Value = downloadSessionId;
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                String delete = "DELETE FROM JobSynchDetailDownloadStatus WHERE SynchDetail = '" + syncDetailId + "'";
                sql.ExecuteNonQueryMsg(delete);

                MessageBox.Show(e.ToString(), "No Connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
        }
Esempio n. 2
0
        //==========================================================================================================

        public void clearUploadSyncHist()
        {
            CRUD sql = new CRUD();

            try
            {
                string cmd_uploadStatus = "delete from JobSynchDetailUploadStatus where SynchDetail not in (select top 2 SynchDetail from JobTabletoSynchDetailUpload order by SynchDetail desc)";
                sql.ExecuteNonQueryMsg(cmd_uploadStatus);

                string cmd_uploadDetail = "delete from JobTabletoSynchDetailUpload where SynchDetail not in (select top 2 SynchDetail from JobTabletoSynchDetailUpload order by SynchDetail desc)";
                sql.ExecuteNonQueryMsg(cmd_uploadDetail);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
        public void uploadToFTP(String fileName, String storeId, String syncDetail, String rowFatch)
        {
            CRUD           sql              = new CRUD();
            String         ftpWebReq        = "";
            String         uploadFilePath   = "";
            String         fileToExtract    = "";
            API_UploadSync uploadSyncDetail = new API_UploadSync();

            ftpWebReq = ftpServer + "Uploadfile" + "/" + storeId + "/" + fileName + ".bcp";

            uploadFilePath = getFilePath(storeId);

            try
            {
                FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(ftpWebReq);

                request.Method      = WebRequestMethods.Ftp.UploadFile;
                request.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
                request.UsePassive  = true;
                request.UseBinary   = true;
                request.KeepAlive   = false;

                FileStream stream = File.OpenRead(uploadFilePath + @"\" + fileName + ".bcp");
                byte[]     buffer = new byte[stream.Length];

                stream.Read(buffer, 0, buffer.Length);
                stream.Close();

                Stream reqStream = request.GetRequestStream();
                reqStream.Write(buffer, 0, buffer.Length);
                reqStream.Close();

                uploadSyncDetail.uploadSync(syncDetail);

                string cmd_insert = "IF NOT EXISTS (SELECT * FROM JobSynchDetailUploadStatus WHERE SynchDetail = '" + syncDetail + "') " +
                                    "BEGIN " +
                                    "INSERT INTO JobSynchDetailUploadStatus(SynchDetail, RowFatch, RowApplied, Status) " +
                                    "VALUES('" + syncDetail + "', '" + rowFatch + "', 0, 1) " +
                                    "END";

                sql.ExecuteNonQueryMsg(cmd_insert);
            }
            catch (Exception e)
            {
                using (EventLog eventLog = new EventLog("Application"))
                {
                    eventLog.Source = "Application";
                    eventLog.WriteEntry("Upload background " + e.Message.ToString(), EventLogEntryType.Information, 101, 1);
                }
                MessageBox.Show(e.ToString());
            }
        }
Esempio n. 4
0
        public void downloadFromFTP(String downloadPath, String fileName, String id, String jobId, String storeId, String rowFatch, Guid downloadSessionId, int syncType)
        {
            CRUD   sql              = new CRUD();
            String ftpWebReq        = "";
            String downloadFilePath = "";
            String fileToExtract    = "";
            String extractFilePath  = "";

            downloadFilePath = getDownloadFilePath(downloadPath, syncType);

            ftpWebReq = ftpServer + downloadFilePath;

            createFilePath(downloadPath);

            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpWebReq);

                request.Method = WebRequestMethods.Ftp.DownloadFile;

                request.Credentials = new NetworkCredential(ftpUsername, ftpPassword);

                if (!File.Exists(downloadPath))
                {
                    FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                    Stream responseStream = response.GetResponseStream();

                    FileStream file   = File.Create(downloadPath);
                    byte[]     buffer = new byte[32 * 1024];
                    int        read;

                    while ((read = responseStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        file.Write(buffer, 0, read);
                    }

                    file.Close();
                    responseStream.Close();
                    response.Close();
                }

                extractFilePath = getExtactFilePath(downloadPath);

                if (!File.Exists(extractFilePath + @"\" + fileName + ".bcp") && syncType == 0)
                {
                    fileToExtract = extractFilePath + @"\" + fileName + ".zip";
                    ExtractFile(fileToExtract, extractFilePath + @"\");
                }

                String cmd_insert = "IF NOT EXISTS (SELECT * FROM JobSynchDetailDownloadStatus WHERE SynchDetail = '" + id + "') " +
                                    "BEGIN " +
                                    "INSERT INTO JobSynchDetailDownloadStatus(SynchDetail, RowFatch, RowApplied, Status, Downloadsessionid) " +
                                    "VALUES('" + id + "', '" + rowFatch + "', 0, 1, '" + downloadSessionId + "') " +
                                    "END";
                sql.ExecuteNonQueryMsg(cmd_insert);
            }
            catch (Exception e)
            {
                if (e.Message.IndexOf("550") != -1)
                {
                    MessageBox.Show("File " + fileName + " not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }