protected void btnDownloadImportTemplate_Click(object sender, EventArgs e)
        {
            string appFolder       = Server.MapPath("/" + GeneralPage.GetSettingByCode(ETEMEnums.AppSettings.WebApplicationName).SettingValue);
            string resourcesFolder = GeneralPage.GetSettingByCode(ETEMEnums.AppSettings.ResourcesFolderName).SettingValue;
            string templateFolder  = GeneralPage.GetSettingByCode(ETEMEnums.AppSettings.FolderTemplates).SettingValue;
            string templateName    = GeneralPage.GetSettingByCode(ETEMEnums.AppSettings.Template_SAP_ProductivityAndScrap).SettingValue;

            string templatePath = string.Empty;

            if (Directory.Exists(appFolder + "\\" + templateFolder))
            {
                templatePath = appFolder + "\\" + templateFolder;
            }
            else if (Directory.Exists(resourcesFolder + "\\" + templateFolder))
            {
                templatePath = resourcesFolder + "\\" + templateFolder;
            }
            else
            {
                this.ownerPage.ShowMSG("Template folder not found!", false);
                return;
            }

            string templateFullName = templatePath + "\\" + templateName;

            DirectoryInfo dirInfoTemplates = new DirectoryInfo(resourcesFolder + "\\" + templateFolder + "\\Downloads");

            if (!Directory.Exists(dirInfoTemplates.FullName))
            {
                Directory.CreateDirectory(dirInfoTemplates.FullName);
            }

            string fileNameOnly = Path.GetFileNameWithoutExtension(templateFullName);

            string fileFullNameToDownload = dirInfoTemplates.FullName + "\\" + fileNameOnly + "_" + DateTime.Now.ToString(Constants.DATE_PATTERN_FOR_FILE_SUFFIX) + Constants.FILE_XLSX_EXTENSION;

            File.Copy(templateFullName, fileFullNameToDownload);

            FileInfo fiFileToDownload = new FileInfo(fileFullNameToDownload);

            if (fiFileToDownload.Exists)
            {
                fiFileToDownload.IsReadOnly = false;
            }

            string param = "FilePath=" + fileFullNameToDownload + "&ContentType=" + BaseHelper.GetMimeType(Constants.FILE_XLSX_EXTENSION) + "&Delete=true";

            this.ownerPage.OpenPageForDownloadFile(Constants.DOWNLOAD_PAGE_PATH, param);
        }
        protected void btnImport_Click(object sender, EventArgs e)
        {
            if (!this.ownerPage.CheckUserActionPermission(ETEMEnums.SecuritySettings.ProductivityAndScrapImport, false))
            {
                return;
            }

            base.RunJavaScriptModalWindow();

            if (this.fuImport.HasFile)
            {
                string selectedFileMimeType = this.fuImport.PostedFile.ContentType;

                string excelMimeType = BaseHelper.GetMimeType(Constants.FILE_XLSX_EXTENSION);

                if (!string.Equals(selectedFileMimeType, excelMimeType, StringComparison.InvariantCultureIgnoreCase))
                {
                    this.ownerPage.ShowMSG("Selected file is in incorrect format, it must be Excel-2007 or newer version!", false);
                    return;
                }

                string fileFullName = string.Empty;
                string folderPath   = string.Empty;

                folderPath = GeneralPage.GetSettingByCode(ETEMModel.Helpers.ETEMEnums.AppSettings.ResourcesFolderName).SettingValue;

                folderPath += "\\CostCalculation\\ProductivityAndScrap\\Import\\" + DateTime.Today.Year + "\\";

                if (!Directory.Exists(folderPath))
                {
                    Directory.CreateDirectory(folderPath);
                }

                fileFullName = folderPath + "\\Import_ProductivityAndScrap_" +
                               DateTime.Now.ToString(Constants.DATE_PATTERN_FOR_FILE_SUFFIX) +
                               Constants.FILE_XLSX_EXTENSION;

                this.fuImport.PostedFile.SaveAs(fileFullName);

                this.ownerPage.CallContext = this.ownerPage.CostCalculationRef.ImportProductivityAndScrapCostData(fileFullName, this.hdnRowMasterKey.Value, this.ownerPage.CallContext);

                if (this.ownerPage.CallContext.ResultCode == ETEMEnums.ResultEnum.Success)
                {
                    base.AddMessage(this.lbResultContext, this.ownerPage.CallContext.Message);

                    this.currentEntity = this.ownerPage.CostCalculationRef.GetProductivityAndScrapById(this.hdnRowMasterKey.Value);

                    if (this.ownerPage is ProductivityAndScrapList)
                    {
                        ((ProductivityAndScrapList)this.ownerPage).LoadFilteredList();
                    }
                }
                else
                {
                    if (!ShowErrors(new List <CallContext>()
                    {
                        this.ownerPage.CallContext
                    }))
                    {
                        return;
                    }
                }
            }
            else
            {
                this.ownerPage.ShowMSG("Please select file to import!", false);
            }
        }