コード例 #1
0
    private int ProcessUploadedFile(string fileName)
    {
        int    idImport      = ApplicationConstants.INT_NULL_VALUE;
        string cleanFileName = ApplicationUtils.GetCleanFileName(fileName);
        string shareFilePath = string.Empty;

        // get the directory from appsettings
        string dirUrl    = ConfigurationManager.AppSettings["UploadFolderRevised"];
        string dirPath   = Server.MapPath(dirUrl);
        string shareName = @"\\" + Server.MachineName + @"\" + dirUrl;

        shareFilePath = shareName + @"\" + cleanFileName;
        ImportRevisedBudget revisedBudgetUpload = new ImportRevisedBudget(SessionManager.GetSessionValueNoRedirect(this.Page, SessionStrings.CONNECTION_MANAGER));

        try
        {
            idImport = revisedBudgetUpload.WriteToRevisedBudgetImportTable(shareFilePath, currentUser.IdAssociate);
            if (idImport > 0)
            {
                RevisedBudgetFileName = filUpload.UploadedFiles[0].FileName;
                btnProcess.Enabled    = true;
                ProcessIdHdn.Value    = idImport.ToString();
                MoveFileToDirectory(TargetDirectoryEnum.DIRECTORY_PROCESSED, shareFilePath);
            }
            return(idImport);
        }
        catch (Exception ex)
        {
            btnProcess.Enabled = false;
            MoveFileToDirectory(TargetDirectoryEnum.DIRECTORY_CANCELLED, shareFilePath);
            throw new IndException(ex);
        }
    }
コード例 #2
0
    protected void btnProcess_Click(object sender, EventArgs e)
    {
        try
        {
            int idImport = default(int);
            Int32.TryParse(ProcessIdHdn.Value.ToString(), out idImport);

            ImportRevisedBudget revisedBudgetUpload = new ImportRevisedBudget(SessionManager.GetSessionValueNoRedirect(this.Page, SessionStrings.CONNECTION_MANAGER));
            string cleanFileName = RevisedBudgetFileName;

            if (cleanFileName != null && !FilesWithSkipExistRevisedBudgetError.Contains(cleanFileName) && ExistsInProgressRevisedBudget())
            {
                FilesWithSkipExistRevisedBudgetError.Add(cleanFileName);
                revisedBudgetUpload.SkipExistRevisedBudgetError = false;
                throw new IndException("There is a revised budget in-progress. Do you want to process to the replacement?");
            }
            else
            {
                if (FilesWithSkipExistRevisedBudgetError.Contains(cleanFileName))
                {
                    FilesWithSkipExistRevisedBudgetError.Remove(cleanFileName);
                    revisedBudgetUpload.SkipExistRevisedBudgetError = true;
                }
            }

            try
            {
                int retVal = revisedBudgetUpload.InsertToRevisedBudgetTable(idImport);
                if (retVal >= 0)
                {
                    this.ShowError(new IndException(string.Format(ApplicationMessages.IMPORT_FILE_PROCESSED, idImport.ToString())));

                    bool          isFake;
                    string        versionNo;
                    RevisedBudget revBudget = new RevisedBudget(SessionManager.GetConnectionManager(this.Page));
                    revBudget.IdProject = currentProject.Id;
                    versionNo           = revBudget.GetVersionNumber(out isFake);
                    if (!string.IsNullOrEmpty(versionNo))
                    {
                        currentProject.IdVersion = int.Parse(versionNo);
                    }

                    TrackingActivityLog tkl = new TrackingActivityLog(SessionManager.GetConnectionManager(this));
                    tkl.InsertTrackingActivityLog(currentProject, currentUser, ETrackingActivity.UploadedRevisedBudget);
                }
            }
            catch (Exception ex)
            {
                this.ShowError(new IndException(ex.Message.ToString()));
            }
        }
        catch (Exception ex)
        {
            ShowError(new IndException(ex));
            return;
        }
    }