Пример #1
0
        void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                ApplicationAssert.CheckCondition(ctrlUpload.HasFile, "Please select document to attach.");

                var sFileName      = Server.HtmlEncode(ctrlUpload.FileName);
                var sFilePath      = ctrlUpload.PostedFile.FileName;
                var sFileExtension = Path.GetExtension("@" + sFilePath);
                //sFileExtension = sFileExtension.Replace(".", "");
                if (sFileExtension.ToLower() == ".docx" || sFileExtension.ToLower() == ".xlsx" || sFileExtension.ToLower() == ".docm" || sFileExtension.ToLower() == ".dotx" || sFileExtension.ToLower() == ".xlsm" || sFileExtension.ToLower() == ".xlsb")
                {
                    throw new Exception("The ULO application can not upload file with the'" + sFileExtension + "' extension. Please see the 'extention rules' above.");
                }

                if (sFileExtension.ToLower() == ".tiff" || sFileExtension.ToLower() == ".tif")
                {
                    throw new Exception("The ULO application can not upload file with the'" + sFileExtension + "' extension. Please see the 'extention rules' above.");
                }

                if (sFileExtension.ToLower() == ".zip")
                {
                    throw new Exception("The ULO application can not upload file with the'" + sFileExtension + "' extension.");
                }

                var file_length  = (int)ctrlUpload.PostedFile.InputStream.Length;
                var file_data    = new byte[file_length];
                var content_type = ctrlUpload.PostedFile.ContentType;

                ctrlUpload.PostedFile.InputStream.Read(file_data, 0, file_length);

                var intDocID = FilesBO.AddNewFile(sFileName, file_length, file_data, content_type, CurrentUserLogin);

                txtDocID.Value = intDocID.ToString();

                lblFileName.Text   = sFileName;
                lblUploadDate.Text = String.Format("{0:MMM dd, yyyy}", DateTime.Now);
                lblUploadUser.Text = CurrentUserName + " (" + CurrentUserOrganization + ")";
                lblDocType.Text    = "";
                lstDocTypes.ClearSelection();
                lblLineNum.Text   = "";
                txtLineNum.Text   = "";
                lblEmailDate.Text = "";
                lblComments.Text  = "";
                txtComments.Text  = "";

                NewDocument = true;
                EnableDocProperties(true);
            }
            catch (Exception ex)
            {
                AddError(ex);
            }
            finally
            {
                if (Errors.Count > 0)
                {
                    lblMessage.Visible  = true;
                    lblMessage.CssClass = "errorsum";
                    lblMessage.Text     = GetErrors();
                }
            }
        }
Пример #2
0
        void btnUpload_Click(object sender, EventArgs e)
        {
            string sPath;
            var    sError = "";

            sError = ValidateCalendarControl(dtDue, "Due Date", sError);
            sError = ValidateTextBox(txtReviewName, "Review Name", sError);

            var report_date = DateTime.Now;

            //if (ddlItemType.SelectedIndex == 6)
            //{
            //    sError = ValidateCalendarControl(dtReportDate, "Date of Report", sError);
            //    report_date = dtReportDate.Date;
            //}

            try
            {
                var due_date = dtDue.Date;



                ApplicationAssert.CheckCondition(ddlDataSource.SelectedIndex > -1, "Please select the data source.");
                ApplicationAssert.CheckCondition(ctrlFileUpload.HasFile, "Please select Excel file to upload.");
                var sFileName  = Server.HtmlEncode(ctrlFileUpload.FileName);
                var sExtension = System.IO.Path.GetExtension(sFileName);
                ApplicationAssert.CheckCondition(sExtension == ".xls", "Only Excel files may be uploaded.");

                sPath = Server.MapPath("~\\UploadedFiles\\" + sFileName);

                //if previous Excel file with the same name exists in the directory UploadFiles - delete it
                var fInfo = new FileInfo(sPath);
                if (fInfo.Exists)
                {
                    fInfo.Delete();
                }

                int file_length;
                file_length = (int)ctrlFileUpload.PostedFile.InputStream.Length;

                var file_data = new byte[file_length];

                var content_type = ctrlFileUpload.PostedFile.ContentType;

                ctrlFileUpload.PostedFile.InputStream.Read(file_data, 0, file_length);

                //int intFileID = DataFile.AddNewFile(sFileName, file_length, file_data, content_type);

                var intFileID = FilesBO.AddNewFile(sFileName, file_length, file_data, content_type, CurrentUserLogin);

                ctrlFileUpload.SaveAs(sPath);

                var intDataSource = Int32.Parse(ddlDataSource.SelectedValue);
                var intOIType     = Int32.Parse(ddlItemType.SelectedValue);

                var intParentLoadID = Int32.Parse(ddlPrevLoad.SelectedValue);
                var intRound        = Int32.Parse(ddlRound.SelectedValue);

                if (sError == "")
                {
                    UploadService.LoadData(sPath, intFileID, sFileName, intDataSource, intOIType, due_date, intParentLoadID, intRound, CurrentUserID, txtReviewName.Text, report_date);
                    //don't keep these files on the hard disk:
                    fInfo = new FileInfo(sPath);
                    if (fInfo.Exists)
                    {
                        fInfo.Delete();
                    }
                }
                else
                {
                    lblMsg.CssClass = "error";
                    lblMsg.Text     = sError;
                }
            }
            catch (Exception ex)
            {
                AddError(ex);
            }
            finally
            {
                if (Errors.Count > 0)
                {
                    lblMsg.CssClass = "error";
                    //lblError.Text = "SQL Transaction has failed. " + GetErrors() + sError;
                }
                else
                {
                    if (sError == "")
                    {
                        //enabled_textbox
                        lblMsg.CssClass = "green_text_14";
                        lblMsg.Text     = "The data was successfully uploaded into the system. Thank you.";
                    }
                }
            }
        }