private static void SaveFiles(Int32 jobId, List <FileAttachment> files)
    {
        foreach (FileAttachment item in files)
        {
            if (item.name != "DELETE")
            {
                using (Redi.Utility.SqlText insert = new Redi.Utility.SqlText(
                           "Insert Into ALL_JobFile (JobFileFileName, JobFileLength, JobFileContentType, JobFileCategoryCode, JobId, CreatedOn, CreatedByName, DisplayName, FileSystem, FolderName, VersionNo ) " +
                           "Values (@JobFileFileName, @JobFileLength, @JobFileContentType, @JobFileCategoryCode, @JobId, @CreatedOn, @CreatedByName, @DisplayName, @FileSystem, @FolderName, @VersionNo) ", crmConnectionStringName))
                {
                    string wkContentType = Redi.Utility.MapFileContentType.Do(item.name);
                    if (string.IsNullOrEmpty(wkContentType))
                    {
                        wkContentType = ".";
                    }
                    insert.AddParameter("@JobFileFileName", item.target_name);
                    insert.AddParameter("@JobFileLength", item.size);
                    insert.AddParameter("@JobFileContentType", wkContentType);
                    insert.AddParameter("@JobFileCategoryCode", "Invoice");
                    insert.AddParameter("@JobId", jobId);
                    insert.AddParameter("@CreatedOn", DateTime.Now);
                    insert.AddParameter("@CreatedByName", createdBy);
                    insert.AddParameter("@DisplayName", item.name);
                    insert.AddParameter("@FileSystem", "LOCAL"); // Local to be moved to Amazon
                    insert.AddParameter("@FolderName", "ClientUploadedFiles");
                    insert.AddParameter("@VersionNo", 1);
                    insert.ExecuteNonQuery();
                }
            }
        }

        // Kick off the process that moves files to S3.
        RequestBackgroundProcess("ABLELocalFileToS3", "");
    }
    // Move all LOCAL files to S3
    public static void Do(string requestData)
    {
        using (Redi.Utility.SqlText select = new Redi.Utility.SqlText(
                   "Select JobFileFileName, Id, FolderName, VersionNo, DisplayName " +
                   "From ALL_JobFile " +
                   "Where FileSystem='LOCAL' AND Deleted = 0 "))
        {
            DbDataReader myReader = select.ExecuteReader();
            while (myReader.Read())
            {
                string fileName   = myReader.GetString(0);
                Int32  fileId     = myReader.GetInt32(1);
                string folderName = "";
                if (!myReader.IsDBNull(2))
                {
                    folderName = myReader.GetString(2);
                }
                Int32  version     = myReader.GetInt32(3);
                string displayName = "";
                if (!myReader.IsDBNull(4))
                {
                    displayName = myReader.GetString(4);
                }
                else
                {
                    displayName = fileName;
                }

                string wkCurrentPath = HostingEnvironment.MapPath("\\" + folderName.Trim('/') + "\\" + fileName);
                if (MoveFile(fileName, folderName, version, wkCurrentPath))
                {
                    using (Redi.Utility.SqlText update = new Redi.Utility.SqlText(
                               "Update ALL_JobFile " +
                               "Set FileSystem = 'S3', " +
                               "    DisplayName = @DisplayName " +
                               "Where Id = @Id "))
                    {
                        update.AddParameter("@DisplayName", displayName);
                        update.AddParameter("@Id", fileId);
                        update.ExecuteNonQuery();
                    }
                }
            }
        }
    }
Exemple #3
0
        /// <summary>
        /// Get the next available number from the NextNumber table and prefix with the prefix defined on the same table and the year
        /// prefix-year-number
        /// </summary>
        /// <param name="NextNumberType"></param>
        /// <returns></returns>
        public static string GetNextYearID(string NextNumberType, Int16 NumberLength)
        {
            string wkIDPrefix    = "";
            int    wkCurrentYear = 0;
            Int64  wkNextNumber  = GetNextNumber(NextNumberType);

            using (SqlText SelectID = new SqlText(
                       "Select IDPrefix, CurrentYear " +
                       "from [ALL_NextNumber] " +
                       "Where NextNumberType = @NextNumberType; ", CrmHelper.crmConnectionStringName))
            {
                SelectID.AddParameter("@NextNumberType", NextNumberType);
                DbDataReader myReader = SelectID.ExecuteReader();
                if (myReader.Read())
                {
                    wkIDPrefix = myReader.GetString(0);
                    if (!myReader.IsDBNull(1))
                    {
                        wkCurrentYear = myReader.GetInt32(1);
                    }
                }
            }

            if (wkCurrentYear != DateTime.Now.Year)
            {
                wkCurrentYear = DateTime.Now.Year;
                using (SqlText UpdateNext = new SqlText(
                           "Update [ALL_NextNumber] " +
                           "Set NextNumber = 1 " +
                           "   ,CurrentYear = @CurrentYear " +
                           "Where NextNumberType = @NextNumberType; ", CrmHelper.crmConnectionStringName))
                {
                    UpdateNext.AddParameter("@NextNumberType", NextNumberType);
                    UpdateNext.AddParameter("@CurrentYear", wkCurrentYear);
                    UpdateNext.ExecuteNonQuery();
                }
                wkNextNumber = 1;
            }

            string wkNum = "";

            if (wkNextNumber.ToString().Length > NumberLength)
            {
                NumberLength = (Int16)wkNextNumber.ToString().Length;
            }

            switch (NumberLength)
            {
            case 0: wkNum = wkNextNumber.ToString();
                break;

            case 7: wkNum = wkNextNumber.ToString("0000000");
                break;

            case 6: wkNum = wkNextNumber.ToString("000000");
                break;

            case 5: wkNum = wkNextNumber.ToString("00000");
                break;

            case 4: wkNum = wkNextNumber.ToString("0000");
                break;

            case 3: wkNum = wkNextNumber.ToString("000");
                break;

            default: wkNum = wkNextNumber.ToString();
                break;
            }

            return(wkIDPrefix + wkCurrentYear.ToString().Substring(2, 2) + "-" + wkNum);
        }