public IHttpActionResult DownLoadTemplate(string projectID)
        {
            var    current = System.Web.HttpContext.Current;
            string path    = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.FAWrite_offTool_Template;


            Excel  excel        = new Excel();
            string templatePath = path;

            string tempFilePath = current.Server.MapPath("~/") + "Temp\\" + Guid.NewGuid() + ".xlsx";

            var closure = ClosureInfo.GetByProjectId(projectID);

            excel.Open(path);
            excel.Save(tempFilePath);

            var store = _db.StoreBasicInfo.First(e => e.StoreCode == closure.USCode);


            Excel tempExcel = new Excel();

            tempExcel.Open(tempFilePath);
            var sheet = tempExcel.Sheets["PMT"];

            sheet.Cells[1, 1].StrValue = store.RegionENUS;
            sheet.Cells[2, 1].StrValue = store.MarketENUS;
            sheet.Cells[3, 1].StrValue = store.NameENUS;
            sheet.Cells[4, 1].StrValue = store.StoreCode;
            sheet.Cells[5, 1].StrValue = store.StoreTypeName;
            if (closure.ActualCloseDate != null)
            {
                sheet.Cells[6, 1].StrValue = closure.ActualCloseDate.Value.ToString("yyyy-MM-dd");
            }
            sheet.Cells[7, 1].StrValue = closure.PMNameZHCN;

            tempExcel.Save(tempFilePath);

            var currentNode = NodeInfo.GetCurrentNode(projectID, FlowCode.Closure_WOCheckList);
            var newNode     = NodeInfo.GetNodeInfo(NodeCode.Closure_WOCheckList_DownLoadTemplate);

            if (newNode.Sequence > currentNode.Sequence)
            {
                ProjectInfo.FinishNode(projectID, FlowCode.Closure_WOCheckList, NodeCode.Closure_WOCheckList_DownLoadTemplate);
            }


            current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + SiteFilePath.GetTemplateFileName(closure.USCode, FlowCode.Closure_WOCheckList, SiteFilePath.FAWrite_offTool_Template));
            current.Response.ContentType = "application/octet-stream";
            current.Response.WriteFile("" + tempFilePath + "");
            current.Response.End();
            return(Ok());
        }
示例#2
0
        public void DownloadToolTemplate(string projectId)
        {
            var renewalTool = RenewalTool.Get(projectId);
            var renewalInfo = RenewalInfo.Get(projectId);
            var fileName    = renewalTool.DownloadToolTemplate();
            var current     = HttpContext.Current;

            current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + SiteFilePath.GetTemplateFileName(renewalInfo.USCode, FlowCode.Renewal_Tool, "RenewalToolTemplate.xlsx"));
            current.Response.ContentType = "application/octet-stream";
            current.Response.WriteFile(fileName);
            current.Response.End();
        }
示例#3
0
        public IHttpActionResult DownLoadTemplate(string projectId)
        {
            var current = System.Web.HttpContext.Current;
            //string path = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.FAWrite_offTool_Template;


            //Excel excel = new Excel();
            //string templatePath = path;

            //string tempFilePath = current.Server.MapPath("~/") + "Temp\\" + Guid.NewGuid() + ".xls";

            //var closure = ClosureInfo.GetByProjectId(projectId);
            //excel.Open(path);
            //excel.Save(tempFilePath);

            //var store = StoreBasicInfo.FirstOrDefault(e => e.StoreCode == closure.USCode);


            //Excel tempExcel = new Excel();
            //tempExcel.Open(tempFilePath);
            //var sheet = tempExcel.Sheets["PMT"];

            //sheet.Cells[1, 1].StrValue = store.RegionENUS;
            //sheet.Cells[2, 1].StrValue = store.MarketENUS;
            //sheet.Cells[3, 1].StrValue = store.NameZHCN;
            //sheet.Cells[4, 1].StrValue = closure.USCode;
            //sheet.Cells[5, 1].StrValue = store.StoreTypeName;
            //if (closure.ActualCloseDate != null)
            //{
            //    sheet.Cells[6, 1].StrValue = closure.ActualCloseDate.Value.ToString("yyyy-MM-dd");
            //}
            //sheet.Cells[7, 1].StrValue = "";//TODO::-Cary  GetPM

            //sheet.Cells[0, 7].StrValue = ConsInvtCheckingVersion;

            //tempExcel.Save(tempFilePath);


            //直接下载writeoff文件
            McdAMEntities _db         = new McdAMEntities();
            var           closureInfo = ClosureInfo.GetByProjectId(projectId);
            var           wo          = ClosureWOCheckList.Get(projectId);

            if (wo != null)
            {
                var att = _db.Attachment.FirstOrDefault(a => a.RefTableID == wo.Id.ToString() && a.TypeCode == "Template");

                string absolutePath = current.Server.MapPath("~/") + "UploadFiles/" + att.InternalName;
                string tempFilePath = current.Server.MapPath("~/") + "Temp\\" + Guid.NewGuid() + Path.GetExtension(absolutePath);

                File.Copy(absolutePath, tempFilePath);
                ExcelHelper.UpdateExcelVersionNumber(tempFilePath, ConsInvtCheckingVersion);

                var currentNode = NodeInfo.GetCurrentNode(projectId, FlowCode.Closure_ConsInvtChecking);
                var newNode     = NodeInfo.GetNodeInfo(NodeCode.Closure_ConsInvtChecking_DownLoadTemplate);
                if (newNode.Sequence > currentNode.Sequence)
                {
                    ProjectInfo.FinishNode(projectId, FlowCode.Closure_ConsInvtChecking, NodeCode.Closure_ConsInvtChecking_DownLoadTemplate);
                }

                current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + SiteFilePath.GetTemplateFileName(closureInfo.USCode, FlowCode.Closure_ConsInvtChecking, SiteFilePath.FAWrite_offTool_Template));
                current.Response.ContentType = "application/octet-stream";
                current.Response.WriteFile("" + tempFilePath + "");
                current.Response.End();
            }
            else
            {
                string path = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.FAWrite_offTool_Template;
                current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + SiteFilePath.GetTemplateFileName(closureInfo.USCode, FlowCode.Closure_ConsInvtChecking, SiteFilePath.FAWrite_offTool_Template));
                current.Response.ContentType = "application/octet-stream";
                current.Response.WriteFile("" + path + "");
                current.Response.End();
            }
            return(Ok());
        }
        public IHttpActionResult DownLoadTemplate(string templateType, string projectId, string consInfoID = "", string NormType = "", string flowCode = "")
        {
            var current = HttpContext.Current;
            ExcelDataInputType outputType;

            if (!Enum.TryParse(templateType, out outputType))
            {
                throw new Exception("Cannot find the specific template type!");
            }

            if (string.IsNullOrEmpty(projectId))
            {
                throw new Exception("Porject Id is Empty !");
            }
            var siteFilePath = default(string);

            switch (outputType)
            {
            case ExcelDataInputType.WriteOffAmount:
                siteFilePath = SiteFilePath.FAWrite_offTool_Template_X;
                break;

            case ExcelDataInputType.ReinvestmentCost:
                siteFilePath = SiteFilePath.FATool_Update_Template;
                break;

            case ExcelDataInputType.ClosureWOCheckList:
                siteFilePath = SiteFilePath.Closure_FAWrite_offTool_Template;
                break;
            }
            var path = string.Format(@"{0}\{1}", SiteFilePath.Template_DIRECTORY, siteFilePath);

            var tempFilePath = current.Server.MapPath("~/") + "Temp\\" + Guid.NewGuid() + ".xlsx";

            bool isNotUploadExcel = false;

            if (!string.IsNullOrEmpty(consInfoID))
            {
                string refTableName = "MajorLeaseConsInfo";
                if (projectId.ToLower().IndexOf("rebuild") != -1)
                {
                    refTableName = "RebuildConsInfo";
                }
                if (projectId.ToLower().IndexOf("reimage") != -1)
                {
                    refTableName = "ReimageConsInfo";
                }

                var strFileName = GetAttatchFile(refTableName, templateType, consInfoID);//download consifno upload file
                if (string.IsNullOrEmpty(strFileName))
                {
                    isNotUploadExcel = true;
                    tempFilePath     = current.Server.MapPath("~/") + "UploadFiles\\" + Guid.NewGuid() + ".xlsx";
                }
                else
                {
                    tempFilePath = current.Server.MapPath("~/") + "UploadFiles\\" + strFileName;
                }
            }

            if (isNotUploadExcel)
            {
                consInfoID = null;// if not upload file in consinfo flow,then we get empty template
            }
            var projectInfo = ProjectInfo.FirstOrDefault(e => e.ProjectId == projectId);

            if (projectInfo == null)
            {
                throw new Exception("Cannot find the project info!");
            }
            if (string.IsNullOrEmpty(consInfoID))
            {
                File.Copy(path, tempFilePath);

                var excelOutputDirector = new ExcelDataInputDirector(new FileInfo(tempFilePath), outputType);
                var store = StoreBasicInfo.Search(e => e.StoreCode == projectInfo.USCode).FirstOrDefault();
                if (store == null)
                {
                    throw new Exception("Cannot find Store info!");
                }

                var inputInfo = new ExcelInputDTO
                {
                    Region        = store.RegionENUS,
                    Market        = store.MarketENUS,
                    City          = store.CityENUS,
                    StoreNameCN   = store.NameZHCN,
                    StoreNameEN   = store.NameENUS,
                    StoreName     = store.NameZHCN,
                    USCode        = store.StoreCode,
                    StoreType     = store.StoreType,
                    StoreTypeName = store.StoreTypeName,
                    OpenDate      = store.OpenDate,
                    ClosureDate   = store.CloseDate.HasValue ? store.CloseDate.Value : default(DateTime)
                };

                switch (outputType)
                {
                case ExcelDataInputType.ReinvestmentCost:
                    Guid consInfoId = Guid.Empty;
                    if (projectId.ToLower().IndexOf("rebuild") != -1)
                    {
                        var rbdInfo = new RebuildConsInfo();
                        consInfoId = rbdInfo.GetConsInfo(projectId).Id;
                    }
                    else if (projectId.ToLower().IndexOf("majorlease") != -1)
                    {
                        var mjInfo = new MajorLeaseConsInfo();
                        consInfoId = mjInfo.GetConsInfo(projectId).Id;
                    }
                    else if (projectId.ToLower().IndexOf("reimage") != -1)
                    {
                        consInfoId = ReimageConsInfo.GetConsInfo(projectId).Id;
                    }
                    var reinvestmentBasicInfo = ReinvestmentBasicInfo.FirstOrDefault(e => e.ConsInfoID == consInfoId);
                    if (reinvestmentBasicInfo != null)
                    {
                        inputInfo.NewDesignType      = reinvestmentBasicInfo.NewDesignType;
                        inputInfo.NormType           = MappingNormType(NormType);
                        inputInfo.GBDate             = reinvestmentBasicInfo.GBDate;
                        inputInfo.ConsCompletionDate = reinvestmentBasicInfo.ConsCompletionDate;
                        inputInfo.EstimatedSeatNO    = reinvestmentBasicInfo.EstimatedSeatNo;
                        inputInfo.NewDTSiteArea      = reinvestmentBasicInfo.NewDTSiteArea;
                        inputInfo.NewOperationArea   = reinvestmentBasicInfo.NewOperationSize;
                        inputInfo.NewDiningArea      = reinvestmentBasicInfo.NewDiningArea;
                        inputInfo.WallPanelArea      = reinvestmentBasicInfo.WallPanelArea;
                        inputInfo.WallGraphicArea    = reinvestmentBasicInfo.WallGraphicArea;
                        inputInfo.FacadeACMArea      = reinvestmentBasicInfo.FacadeACMArea;
                        inputInfo.NewRemoteKiosk     = reinvestmentBasicInfo.NewRemoteKiosk;
                        inputInfo.NewAttachedKiosk   = reinvestmentBasicInfo.NewAttachedKiosk;
                        inputInfo.NewMcCafe          = reinvestmentBasicInfo.NewMcCafe;
                        inputInfo.NewMDS             = reinvestmentBasicInfo.NewMDS;
                    }

                    break;

                case ExcelDataInputType.WriteOffAmount:
                    string pmName = string.Empty;
                    if (projectId.ToLower().IndexOf("rebuild") != -1)
                    {
                        var rbdInfo = new RebuildInfo();
                        pmName = rbdInfo.GetRebuildInfo(projectId).PMNameENUS;
                    }
                    else if (projectId.ToLower().IndexOf("majorlease") != -1)
                    {
                        var mjInfo = new MajorLeaseInfo();
                        pmName = mjInfo.GetMajorLeaseInfo(projectId).PMNameENUS;
                    }
                    else if (projectId.ToLower().IndexOf("reimage") != -1)
                    {
                        pmName = ReimageInfo.GetReimageInfo(projectId).PMNameENUS;
                    }
                    inputInfo.PMNameENUS = pmName;
                    break;

                case ExcelDataInputType.ClosureWOCheckList:
                    var closure = ClosureInfo.GetByProjectId(projectId);
                    if (closure != null)
                    {
                        inputInfo.ActualCloseDate = closure.ActualCloseDate.HasValue ? closure.ActualCloseDate.Value.ToString("yyyy-MM-dd") : "";
                        inputInfo.PMNameENUS      = closure.PMNameENUS;
                    }
                    break;
                }

                excelOutputDirector.Input(inputInfo);
            }

            current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + SiteFilePath.GetTemplateFileName(projectInfo.USCode, flowCode, siteFilePath));
            current.Response.ContentType = "application/octet-stream";
            current.Response.WriteFile("" + tempFilePath + "");
            current.Response.End();

            return(Ok());
        }