public string GenerateAttachment() { var records = RenewalLLNegotiationRecord.GetRecords(Id); var templateName = HttpContext.Current.Server.MapPath("~/Template/Renewal_LLNegotiationRecord_Template.xlsx"); string fileName = string.Concat(HttpContext.Current.Server.MapPath("~/UploadFiles/"), Guid.NewGuid(), ".xlsx"); File.Copy(templateName, fileName); FileInfo file = new FileInfo(fileName); ExcelDataInputDirector excelDirector = new ExcelDataInputDirector(file, ExcelDataInputType.RenewalLLNegotiationRecord); List <ExcelInputDTO> datas = records.Select(r => new ExcelInputDTO { McdParticipants = r.McdParticipants, Content = r.Content, LLParticipants = r.LLParticipants, Topic = r.Topic, Location = r.Location, MeetingDate = r.Date.Value.ToString("yyyy-MM-dd"), CreateDate = r.CreateTime.ToString("yyyy-MM-dd") }).ToList(); excelDirector.ListInput(datas); Guid reqId = new Guid("f314bf06-f557-4893-ae78-af3b0b561885"); Attachment att = Attachment.Get(Id.ToString(), reqId); if (att == null) { att = new Attachment(); att.InternalName = Path.GetFileName(fileName); att.RefTableName = this.TableName; att.RefTableID = Id.ToString(); att.RelativePath = "//"; att.Name = "Negotiation Record List"; att.Extension = ".xlsx"; att.Length = (int)file.Length; att.CreateTime = DateTime.Now; att.CreatorNameZHCN = ClientCookie.UserNameZHCN; att.CreatorNameENUS = ClientCookie.UserNameENUS; att.CreatorID = ClientCookie.UserCode; att.ID = Guid.NewGuid(); att.RequirementId = reqId; att.TypeCode = ""; Attachment.Add(att); } else { att.InternalName = Path.GetFileName(fileName); att.RefTableName = this.TableName; att.RefTableID = Id.ToString(); att.RelativePath = "//"; att.Name = "Negotiation Record List"; att.Extension = ".xlsx"; att.Length = (int)file.Length; att.CreateTime = DateTime.Now; att.CreatorNameZHCN = ClientCookie.UserNameZHCN; att.CreatorNameENUS = ClientCookie.UserNameENUS; att.CreatorID = ClientCookie.UserCode; Attachment.Update(att); } return(fileName); }
public void ConfirmUploadTool(string SerialNumber) { Save(null); var renewalToolAttachment = Attachment.FirstOrDefault(att => att.RefTableID == this.Id.ToString() && att.TypeCode == "RenewalTool"); if (renewalToolAttachment == null) { throw new Exception("Please upload Renewal Tool first!"); } var fileName = SiteFilePath.UploadFiles_DIRECTORY + "\\" + renewalToolAttachment.InternalName; var fileInfo = new FileInfo(fileName); var excelDirector = new ExcelDataInputDirector(fileInfo, ExcelDataInputType.RenewalTool); var excelDto = new ExcelInputDTO(); excelDto.ComSalesDesc = ComSalesDesc; excelDirector.Edit(excelDto); var project = ProjectInfo.Get(this.ProjectId, this.WorkflowCode); if (project.Status != ProjectStatus.Finished) { string comment = "upload Renewal Tool"; K2FxContext.Current.ApprovalProcess(SerialNumber, ClientCookie.UserCode, "Approve", comment); ProjectInfo.FinishNode(this.ProjectId, this.WorkflowCode, NodeCode.Finish, ProjectStatus.Finished); } }
public IHttpActionResult ExportExcel(NotificationSearchCondition searchCondition) { var current = HttpContext.Current; int totalSize; searchCondition.PageSize = 1000000; var data = Notification.GetNotificationList(searchCondition, out totalSize); //if (!string.IsNullOrEmpty(searchCondition.FlowCode)) //{ // var tmpList = GetProjectComments(searchCondition, out totalSize); // if (tmpList != null && tmpList.Count > 0) // { // foreach (var l in tmpList) // { // data.Add(new NotificationDTO() // { // FlowCode = l.SourceCode, // Message = l.Content, // SenderZHCN = l.CreateUserNameZHCN, // SenderENUS = l.CreateUserNameENUS, // CreateTime = l.CreateTime.HasValue ? l.CreateTime.Value : DateTime.Now, // PositionENUS = l.TitleNameENUS, // HasRead = true // }); // } // } //} var siteFilePath = SiteFilePath.CommentsList_Template; var path = string.Format(@"{0}\{1}", SiteFilePath.Template_DIRECTORY, siteFilePath); var fileName = Guid.NewGuid() + ".xlsx"; var tempFilePath = current.Server.MapPath("~/") + "Temp\\" + fileName; File.Copy(path, tempFilePath); var excelOutputDirector = new ExcelDataInputDirector(new FileInfo(tempFilePath), ExcelDataInputType.CommentsList); var dataList = data.Select(e => new ExcelInputDTO() { Form = e.FlowCode, Comments = e.Message, CreateBy = e.SenderZHCN + "(" + e.SenderENUS + ")", CreateDate = e.CreateTime == null?"":e.CreateTime.Value.ToShortDateString(), SendTo = e.ReceiverZHCN + "(" + e.ReceiverENUS + ")", SenderPosition = e.PositionENUS, IsRead = e.HasRead ? "Yes" : "No" }).ToList(); excelOutputDirector.ListInput(dataList); return(Ok(new { fileName = fileName } )); }
public void GenerateCover() { if (!Attachment.Any(att => att.RefTableID == this.Id.ToString() && att.RequirementId == new Guid("9D1E247C-AAE0-44F6-869E-F50B3E633C1C"))) { var info = RenewalInfo.Get(this.ProjectId); var store = StoreBasicInfo.GetStorInfo(info.USCode); var contract = StoreContractInfo.Get(info.USCode); var context = HttpContext.Current; var templateFileName = context.Server.MapPath("~/Template/RenewalCover_Template_v20130922.xlsx"); var fileName = context.Server.MapPath(string.Format("~/UploadFiles/{0}.xlsx", Guid.NewGuid())); File.Copy(templateFileName, fileName); var fileInfo = new FileInfo(fileName); ExcelDataInputDirector excelDirector = new ExcelDataInputDirector(fileInfo, ExcelDataInputType.RenewalCover); ExcelInputDTO excelInput = new ExcelInputDTO(); excelInput.Region = store.RegionENUS; excelInput.Province = store.ProvinceZHCN; excelInput.City = store.CityENUS; excelInput.Market = store.MarketENUS; excelInput.StoreName = store.NameZHCN; excelInput.USCode = store.StoreCode; excelInput.OpenDate = store.OpenDate; excelInput.LeaseExpirationDate = contract.EndDate.Value; excelInput.Priority = info.Priority; excelDirector.Input(excelInput); var att = new Attachment(); att.ID = Guid.NewGuid(); att.RefTableID = this.Id.ToString(); att.RefTableName = this.TableName; att.RelativePath = "/"; att.TypeCode = "Cover"; att.RequirementId = Guid.Parse("9D1E247C-AAE0-44F6-869E-F50B3E633C1C"); att.Name = "Cover"; att.Extension = fileInfo.Extension; att.InternalName = fileInfo.Name; att.ContentType = "application/vnd.ms-excel"; att.Length = (int)fileInfo.Length; att.CreatorID = ClientCookie.UserCode; att.CreatorNameENUS = ClientCookie.UserNameENUS; att.CreatorNameZHCN = ClientCookie.UserNameZHCN; att.CreateTime = DateTime.Now; att.Add(); } }
public IHttpActionResult OutputExcel(ProjectSearchCondition condition) { int totalItems = 0; var list = VProject.Search(-1, -1, condition, ref totalItems); var current = System.Web.HttpContext.Current; var fileName = "AM_Project_List_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"; string tempFilePath = current.Server.MapPath("~/") + "Temp\\" + fileName; ExcelDataInputDirector.SaveToExcel <VProject>(list, tempFilePath); //current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"); //current.Response.ContentType = "application/octet-stream"; //current.Response.WriteFile("" + tempFilePath + ""); //current.Response.End(); return(Ok(new { fileName = fileName })); }
public static string ExportRecords(string projectId) { var nego = RenewalLLNegotiation.Get(projectId); var records = GetRecords(nego.Id); var templateName = HttpContext.Current.Server.MapPath("~/Template/Renewal_LLNegotiationRecord_Template.xlsx"); string fileName = string.Concat(HttpContext.Current.Server.MapPath("~/Temp/"), Guid.NewGuid(), ".xlsx"); File.Copy(templateName, fileName); FileInfo file = new FileInfo(fileName); ExcelDataInputDirector excelDirector = new ExcelDataInputDirector(file, ExcelDataInputType.RenewalLLNegotiationRecord); List <ExcelInputDTO> datas = records.Select(r => new ExcelInputDTO { McdParticipants = r.McdParticipants, Content = r.Content, LLParticipants = r.LLParticipants, Topic = r.Topic, Location = r.Location, MeetingDate = r.Date.Value.ToString("yyyy-MM-dd"), CreateDate = r.CreateTime.ToString("yyyy-MM-dd") }).ToList(); excelDirector.ListInput(datas); return(fileName); }
public string DownloadToolTemplate() { var templateFileName = string.Concat(SiteFilePath.Template_DIRECTORY, "/", SiteFilePath.RenewalTool_Template); string fileName = string.Format("{0}/{1}.xlsx", SiteFilePath.TEMP_DIRECTORY, Guid.NewGuid()); File.Copy(templateFileName, fileName); FileInfo fileInfo = new FileInfo(fileName); ExcelDataInputDirector excelDirector = new ExcelDataInputDirector(fileInfo, ExcelDataInputType.RenewalTool); ExcelInputDTO excelDto = new ExcelInputDTO(); var info = RenewalInfo.Get(this.ProjectId); var storeBasic = StoreBasicInfo.GetStorInfo(info.USCode); var storeContract = StoreContractInfo.Get(info.USCode); var finInput = RenewalToolFinMeasureInput.Get(this.ProjectId, this.Id); var wfAndReinCost = RenewalToolWriteOffAndReinCost.Get(this.ProjectId, this.Id); excelDto.USCode = info.USCode; excelDto.Market = storeBasic.Market; excelDto.StoreName = storeBasic.NameZHCN + "/" + storeBasic.NameENUS; excelDto.OpenDate = storeBasic.OpenDate; if (storeContract.EndDate.HasValue) { excelDto.LeaseExpirationDate = storeContract.EndDate.Value; } excelDto.RenewalYears = info.RenewalYears; excelDto.ProductSales = finInput.ProductSalesAdjustment; excelDto.Pac = finInput.PacAdjustment; excelDto.Rent = finInput.RentAdjustment; excelDto.DepreciationLhi = finInput.DepreciationLhiAdjustment; excelDto.InterestLhi = finInput.InterestLhiAdjustment; excelDto.ServiceFee = finInput.ServiceFeeAdjustment; excelDto.Accounting = finInput.AccountingAdjustment; excelDto.Insurance = finInput.InsuranceAdjustment; excelDto.TaxesAndLicenses = finInput.TaxesAndLicensesAdjustment; excelDto.DepreciationEssd = finInput.DepreciationEssdAdjustment; excelDto.InterestEssd = finInput.InterestEssdAdjustment; excelDto.OtherIncExp = finInput.OtherIncExpAdjustment; excelDto.NonProductSales = finInput.NonProductSalesAdjustment; excelDto.NonProductCosts = finInput.NonProductCostsAdjustment; excelDto.REII = wfAndReinCost.REII; excelDto.LHIII = wfAndReinCost.LHIII; excelDto.ESSDII = wfAndReinCost.ESSDII; excelDto.RENBV = wfAndReinCost.RENBV; if (wfAndReinCost.LHINBV.HasValue) { excelDto.LHINBV = wfAndReinCost.LHINBV.Value; } if (wfAndReinCost.ESSDNBV.HasValue) { excelDto.ESSDNBV = wfAndReinCost.ESSDNBV.Value; } excelDto.RECost = wfAndReinCost.RECost; excelDto.LHICost = wfAndReinCost.LHICost; excelDto.ESSDCost = wfAndReinCost.ESSDCost; excelDto.TotalWriteOff = wfAndReinCost.REWriteOff + wfAndReinCost.LHIWriteOff + wfAndReinCost.ESSDWriteOff; excelDto.RentalStructure = !string.IsNullOrEmpty(finInput.RentalStructure) ? (Nullable <decimal>)decimal.Parse(finInput.RentalStructure) : null; excelDto.ContributionMargin = finInput.ContributionMargin; excelDto.SalesCompYr1 = finInput.SalesCompYr1; excelDto.SalesCompYr2 = finInput.SalesCompYr2; excelDto.SalesCompYr3 = finInput.SalesCompYr3; excelDto.SalesCompYr4 = finInput.SalesCompYr4; excelDto.SalesCompYr5 = finInput.SalesCompYr5; excelDto.SalesCompYr6 = finInput.SalesCompYr6; excelDto.SalesCompYr7 = finInput.SalesCompYr7; excelDto.SalesCompYr8 = finInput.SalesCompYr8; excelDto.SalesCompYr9 = finInput.SalesCompYr9; excelDto.SalesCompYr10 = finInput.SalesCompYr10; excelDto.SalesCompYr11 = finInput.SalesCompYr11; excelDto.SalesCompYr12 = finInput.SalesCompYr12; excelDto.SalesCompYr13 = finInput.SalesCompYr13; excelDto.SalesCompYr14 = finInput.SalesCompYr14; excelDto.SalesCompYr15 = finInput.SalesCompYr15; excelDto.SalesCompYr16 = finInput.SalesCompYr16; excelDto.SalesCompYr17 = finInput.SalesCompYr17; excelDto.SalesCompYr18 = finInput.SalesCompYr18; excelDto.SalesCompYr19 = finInput.SalesCompYr19; excelDto.SalesCompYr20 = finInput.SalesCompYr20; excelDto.ComSalesDesc = this.ComSalesDesc; excelDto.CompSales = finInput.CompSalesAdjustment; excelDto.FinanceYear = finInput.FinanceYear; excelDto.FinanceMonth = finInput.FinanceMonth; excelDirector.Input(excelDto); return(fileName); }
public void GenerateAttachment() { var info = RenewalInfo.Get(this.ProjectId); var storeInfo = PrepareStoreInfo(this.ProjectId, info.USCode); string templateFileName = string.Concat(SiteFilePath.Template_DIRECTORY, "/", SiteFilePath.RenewalAnalysis_Template); string fileName = HttpContext.Current.Server.MapPath(string.Format("~/UploadFiles/{0}.xlsx", Guid.NewGuid())); var extetion = Path.GetExtension(fileName); var internalName = Path.GetFileName(fileName); File.Copy(templateFileName, fileName); FileInfo fileInfo = new FileInfo(fileName); ExcelDataInputDirector excelDirector = new ExcelDataInputDirector(fileInfo, ExcelDataInputType.RenewalAnalysis); ExcelInputDTO excelDto = new ExcelInputDTO(); excelDto.USCode = storeInfo.UsCode; excelDto.StoreNameEN = storeInfo.NameENUS; excelDto.StoreNameCN = storeInfo.NameZHCN; excelDto.MinimarketPriority = string.IsNullOrEmpty(storeInfo.MinimarketPriority) ? null : Dictionary.GetDictionary(storeInfo.MinimarketPriority).NameENUS; excelDto.TADesrability = string.IsNullOrEmpty(storeInfo.TADesrability) ? null : Dictionary.GetDictionary(storeInfo.TADesrability).NameENUS; excelDto.MMTADescription = this.MMTADescription; excelDto.MajorGenerators = this.MajorGenerators; excelDto.SitePortfolioType = storeInfo.SitePortfolioType; excelDto.SiteRerating = string.IsNullOrEmpty(storeInfo.SiteRerating) ? null : Dictionary.GetDictionary(storeInfo.SiteRerating).NameENUS; excelDto.SiteDescription = this.SiteDescription; excelDto.TADesrabilityNew = string.IsNullOrEmpty(this.TADesirability) ? null : Dictionary.GetDictionary(this.TADesirability).NameENUS; excelDto.MMTADescriptionNew = this.MMTADescriptionNew; excelDto.MajorGeneratorsNew = this.MajorGeneratorsNew; excelDto.SiteRERatingFuture = string.IsNullOrEmpty(this.SiteRERating) ? null : Dictionary.GetDictionary(this.SiteRERating).NameENUS; excelDto.LeasedArea = storeInfo.LeasedArea; excelDto.OperationSize = storeInfo.OperationSize; excelDto.Floors = storeInfo.Floors; excelDto.Seats = storeInfo.Seats; excelDto.BEType = storeInfo.BEType; excelDto.LeaseTenureAndTerm = storeInfo.LeaseTenureAndTerm; excelDto.FreeRentalPeriod = storeInfo.FreeRentalPeriod; excelDto.RentStructure = storeInfo.RentStructure; excelDto.MFStructure = this.MFStructure; excelDto.LeasedAreaNew = this.LeasedArea; excelDto.OperationSizeNew = this.OperationSize; excelDto.FloorsNew = this.Floors; excelDto.SeatsNew = this.Seats; excelDto.BETypeNew = this.BEType; excelDto.LeaseTenureAndTermNew = this.LeaseTenureAndTerm; excelDto.FreeRentalPeriodNew = this.FreeRentalPeriod; excelDto.RentStructureNew = this.RentStructure; excelDto.MFStructureNew = this.MFStructureNew; excelDto.DRMFLastTY = this.DRMFLastTY; excelDto.DRMFLastTYSales = this.DRMFLastTYSales; excelDto.DRMF1stTY = this.DRMF1stTY; excelDto.DRMF1stTYSales = this.DRMF1stTYSales; excelDto.SRMFLastTY = storeInfo.SRMFLastTY; excelDto.SRMFLastTYSales = storeInfo.SRMFLastTYSales; excelDto.SRMF1stTY = storeInfo.SRMF1stTY; excelDto.SRMF1stTYSales = storeInfo.SRMF1stTYSales; excelDto.FairMarketRentAmount = this.FairMarketRentAmount; excelDto.FairMarketRentAgent = this.FairMarketRentAgent; excelDto.DR1stTYAmount = this.DR1stTYAmount; excelDto.AnnualSOILastTY = this.AnnualSOILastTY; excelDto.AnnualSOIAvg = storeInfo.AnnualSOIAvg; excelDto.CashROILastTY = this.CashROILastTY; excelDto.CashROIAvg = storeInfo.CashROIAvg; excelDto.LastRemodeling = this.LastRemodeling; excelDto.OriginalInvestment = storeInfo.OriginalInvestment; excelDto.NBV = storeInfo.NBV; excelDto.AdditionalInvestmentCost = storeInfo.AdditionalInvestmentCost; excelDto.ExclusivityClause = DataConverter.ToYesNo(storeInfo.ExclusivityClause); excelDto.McDsEarlyTerminationRight = storeInfo.McDsEarlyTerminationRight; excelDto.McDsEPRight = this.McDsEPRight; excelDto.LandlordEntity = storeInfo.LandlordEntity; excelDto.SpecialClauses = this.SpecialClauses; excelDto.OtherIssues = this.OtherIssues; excelDto.ExclusivityClauseNew = this.ExclusivityClauseNew; excelDto.McDsEarlyTerminationRightNew = this.McDsEarlyTerminationRightNew; excelDto.McDsEPRightNew = this.McDsEPRightNew; excelDto.LandlordEntityNew = this.LandlordEntityNew; excelDto.SpecialClausesNew = this.SpecialClausesNew; excelDto.OtherIssuesNew = this.OtherIssuesNew; excelDto.DecisionLogic = this.DecisionLogic; excelDto.SpecialApprovalRequired = this.SpecialApprovalRequired; excelDirector.Input(excelDto); var att = Attachment.FirstOrDefault(e => e.RefTableID == this.Id.ToString() && e.TypeCode == "RenewalAnalysis"); bool hasAttach = true; if (att == null) { hasAttach = false; att = new Attachment(); att.ID = Guid.NewGuid(); } att.TypeCode = "RenewalAnalysis"; att.RefTableID = this.Id.ToString(); att.RefTableName = "RenewalAnalysis"; att.Name = "Renewal Analysis"; att.Extension = extetion; att.RelativePath = "/"; att.InternalName = internalName; att.ContentType = "application/vnd.ms-excel"; att.Length = (int)fileInfo.Length; att.CreatorID = ClientCookie.UserCode; att.CreatorNameENUS = ClientCookie.UserNameENUS; att.CreatorNameZHCN = ClientCookie.UserNameZHCN; att.CreateTime = DateTime.Now; att.RequirementId = new Guid("06F33F98-76B9-440F-8E8C-9167B4C202B9"); if (hasAttach) { att.Update(); } else { att.Add(); } }
private void GenerateCover(string projectId, string refTableName) { string coverPath = string.Empty; string coverName = "Cover"; string coverTempPath = SiteFilePath.UploadFiles_DIRECTORY + "\\" + Guid.NewGuid() + ".xlsx"; string coverExtention = Path.GetExtension(coverTempPath); switch (refTableName) { case "MajorLeaseChangePackage": coverPath = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.MajorLeaseChangeCove_Template; var majorLeaseChangePackage = MajorLeaseChangePackage.GetMajorPackageInfo(projectId); majorLeaseChangePackage.GenerateCoverEexcel(coverPath, coverTempPath); break; case "ReimagePackage": var rmgPackage = ReimagePackage.Get(projectId); if (rmgPackage == null) { return; } if (!Attachment.Any(i => i.TypeCode == "Cover" && i.RefTableName == ReimagePackage.TableName && i.RefTableID.ToString() == rmgPackage.Id.ToString())) { var reimageInfoEntity = ReimageInfo.GetReimageInfo(projectId); //生成cover文件 coverPath = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.Store_Reimage_Cover_Template; var store = StoreBasicInfo.FirstOrDefault(e => e.StoreCode == reimageInfoEntity.USCode); File.Copy(coverPath, coverTempPath); var excelOutputDirector = new ExcelDataInputDirector(new FileInfo(coverTempPath), ExcelDataInputType.ReimageCover); var inputInfo = new ExcelInputDTO { Region = store.Region, Province = store.ProvinceENUS, City = store.CityENUS, StoreName = store.NameENUS, USCode = reimageInfoEntity.USCode, OpenDate = store.OpenDate }; excelOutputDirector.Input(inputInfo); var coverItem = new Attachment(); coverItem.Name = coverName + coverExtention; coverItem.InternalName = Path.GetFileName(coverTempPath); coverItem.RefTableName = ReimagePackage.TableName; coverItem.RefTableID = rmgPackage.Id.ToString(); coverItem.RelativePath = "//"; coverItem.Extension = coverExtention; coverItem.CreateTime = DateTime.Now; coverItem.TypeCode = coverName; coverItem.CreatorID = ClientCookie.UserCode; coverItem.RequirementId = AttachmentRequirement.FirstOrDefault(e => e.FlowCode == FlowCode.Reimage_Package && e.NameENUS == "Cover").Id; coverItem.CreatorNameENUS = ClientCookie.UserNameENUS; coverItem.CreatorNameZHCN = ClientCookie.UserNameZHCN; using (FileStream stream = new FileStream(coverTempPath, FileMode.Open)) { coverItem.Length = (int)stream.Length; } Attachment.SaveSigleFile(coverItem); } break; case "TempClosurePackage": var tempClosurePackage = TempClosurePackage.Get(projectId); if (tempClosurePackage == null) { return; } if (!Attachment.Any(i => i.TypeCode == "Cover" && i.RefTableName == tempClosurePackage.TableName && i.RefTableID.ToString() == tempClosurePackage.Id.ToString())) { var tempClosureInfoEntity = TempClosureInfo.Get(projectId); //生成cover文件 coverPath = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.Store_TempClosure_Cover_Template; var store = StoreBasicInfo.FirstOrDefault(e => e.StoreCode == tempClosureInfoEntity.USCode); File.Copy(coverPath, coverTempPath); var excelOutputDirector = new ExcelDataInputDirector(new FileInfo(coverTempPath), ExcelDataInputType.TempClosureCover); var inputInfo = new ExcelInputDTO { StoreNameEN = store.NameENUS, USCode = tempClosureInfoEntity.USCode, City = store.CityENUS, Market = store.MarketENUS, ActualCloseDate = tempClosureInfoEntity.ActualTempClosureDate.ToString("yyyy-MM-dd") }; excelOutputDirector.Input(inputInfo); var coverItem = new Attachment(); coverItem.Name = coverName + coverExtention; coverItem.InternalName = Path.GetFileName(coverTempPath); coverItem.RefTableName = tempClosurePackage.TableName; coverItem.RefTableID = tempClosurePackage.Id.ToString(); coverItem.RelativePath = "//"; coverItem.Extension = coverExtention; coverItem.CreateTime = DateTime.Now; coverItem.TypeCode = coverName; coverItem.CreatorID = ClientCookie.UserCode; //coverItem.RequirementId = AttachmentRequirement.FirstOrDefault(e => e.FlowCode == FlowCode.TempClosure_ClosurePackage && e.NameENUS == "Cover").Id; coverItem.CreatorNameENUS = ClientCookie.UserNameENUS; coverItem.CreatorNameZHCN = ClientCookie.UserNameZHCN; using (FileStream stream = new FileStream(coverTempPath, FileMode.Open)) { coverItem.Length = (int)stream.Length; } Attachment.SaveSigleFile(coverItem); } break; case "ClosurePackage": var closurePackage = ClosurePackage.Get(projectId); if (closurePackage == null) { return; } if (!Attachment.Any(i => i.TypeCode == "Cover" && i.RefTableName == ClosurePackage.TableName && i.RefTableID.ToString() == closurePackage.Id.ToString())) { var closureInfoEntity = ClosureInfo.GetByProjectId(projectId); //生成cover文件 coverPath = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.Store_Closure_Cover_Template; var store = StoreBasicInfo.FirstOrDefault(e => e.StoreCode == closureInfoEntity.USCode); File.Copy(coverPath, coverTempPath); var excelOutputDirector = new ExcelDataInputDirector(new FileInfo(coverTempPath), ExcelDataInputType.ClosureCover); var inputInfo = new ExcelInputDTO { StoreNameEN = store.NameENUS, USCode = closureInfoEntity.USCode, City = store.CityENUS, Market = store.MarketENUS, ActualCloseDate = closureInfoEntity.ActualCloseDate.Value.ToString("yyyy-MM-dd") }; excelOutputDirector.Input(inputInfo); var coverItem = new Attachment(); coverItem.Name = coverName + coverExtention; coverItem.InternalName = Path.GetFileName(coverTempPath); coverItem.RefTableName = ClosurePackage.TableName; coverItem.RefTableID = closurePackage.Id.ToString(); coverItem.RelativePath = "//"; coverItem.Extension = coverExtention; coverItem.CreateTime = DateTime.Now; coverItem.TypeCode = coverName; coverItem.CreatorID = ClientCookie.UserCode; //coverItem.RequirementId = AttachmentRequirement.FirstOrDefault(e => e.FlowCode == FlowCode.TempClosure_ClosurePackage && e.NameENUS == "Cover").Id; coverItem.CreatorNameENUS = ClientCookie.UserNameENUS; coverItem.CreatorNameZHCN = ClientCookie.UserNameZHCN; using (FileStream stream = new FileStream(coverTempPath, FileMode.Open)) { coverItem.Length = (int)stream.Length; } Attachment.SaveSigleFile(coverItem); } break; } }
public IHttpActionResult DownLoadTemplate(string projectID) { var current = System.Web.HttpContext.Current; string path = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.Executive_Summary_Template; string tempFilePath = current.Server.MapPath("~/") + "Temp\\" + Guid.NewGuid() + ".xlsx"; File.Copy(path, tempFilePath); var fileInfo = new FileInfo(tempFilePath); var excelDirector = new ExcelDataInputDirector(fileInfo, ExcelDataInputType.ClosureExecutiveSummary); var closure = ClosureInfo.GetByProjectId(projectID); var store = StoreBasicInfo.GetStore(closure.USCode); var inputInfo = new ExcelInputDTO { StoreNameCN = store.StoreBasicInfo.NameZHCN, USCode = store.StoreBasicInfo.StoreCode, City = store.StoreBasicInfo.CityENUS, Market = store.StoreBasicInfo.MarketENUS, OpenDate = store.StoreBasicInfo.OpenDate, Floor = store.StoreSTLocation.Floor, TotalArea = store.StoreSTLocation.TotalArea, TotalSeatsNo = store.StoreSTLocation.TotalSeatsNo, BE = store.StoreBEInfoList.Count, RentType = store.StoreContractInfo.RentType, RentStructure = store.StoreContractInfo.RentStructure }; var leaseRecapID = StoreContractInfo.SearchByProject(projectID).FirstOrDefault().LeaseRecapID ?? 0; var storeAtt = StoreContractInfoAttached.Search(c => c.LeaseRecapID == leaseRecapID.ToString()).OrderByDescending(e => e.CreateDate).FirstOrDefault(); if (storeAtt != null) { inputInfo.LeasingTerm = store.StoreContractInfo.LeasePurchaseTerm; } if (store.StoreContractInfo.RentCommencementDate.HasValue) { inputInfo.RentCommencementDate = store.StoreContractInfo.RentCommencementDate.Value; } if (store.StoreContractInfo.EndDate.HasValue) { inputInfo.LeaseExpirationDate = store.StoreContractInfo.EndDate.Value; } var toolEntity = ClosureTool.Get(closure.ProjectId); if (toolEntity != null) { if (toolEntity.TotalSales_Adjustment_RMB != null) { inputInfo.TotalSales_TTM = string.Format("{0:f}", toolEntity.TotalSales_Adjustment_RMB); } if (toolEntity.CompSales_Adjustment != null) { inputInfo.SalesComp_TTM = string.Format("{0:f}", toolEntity.CompSales_Adjustment); } if (toolEntity.CompCG_Adjustment != null) { inputInfo.GCComp_TTM = string.Format("{0:f}", toolEntity.CompCG_Adjustment); } if (toolEntity.PAC_RMB_Adjustment != null) { inputInfo.PAC_TTM = string.Format("{0:f}", toolEntity.PAC_RMB_Adjustment); } if (toolEntity.SOI_Adjustment != null) { inputInfo.SOI_TTM = string.Format("{0:f}", toolEntity.SOI_Adjustment); } if (toolEntity.CashFlow_RMB_Adjustment != null) { inputInfo.CASHFLOW_TTM = string.Format("{0:f}", toolEntity.CashFlow_RMB_Adjustment); } if (toolEntity.TotalSales_TTMY1 != null) { inputInfo.TotalSales_TTMY1 = string.Format("{0:f}", toolEntity.TotalSales_TTMY1); } if (toolEntity.CompSales_TTMY1 != null) { inputInfo.CompSales_TTMY1 = string.Format("{0:f}", toolEntity.CompSales_TTMY1); } if (toolEntity.CompGC_TTMY1 != null) { inputInfo.CompGC_TTMY1 = string.Format("{0:f}", toolEntity.CompGC_TTMY1); } if (toolEntity.PAC_TTMY1 != null) { inputInfo.PAC_TTMY1 = string.Format("{0:f}", toolEntity.PAC_TTMY1); } if (toolEntity.SOI_TTMY1 != null) { inputInfo.SOI_TTMY1 = string.Format("{0:f}", toolEntity.SOI_TTMY1); } if (toolEntity.CashFlow_TTMY1 != null) { inputInfo.CashFlow_TTMY1 = string.Format("{0:f}", toolEntity.CashFlow_TTMY1); } if (toolEntity.TotalSales_TTMY2 != null) { inputInfo.TotalSales_TTMY2 = string.Format("{0:f}", toolEntity.TotalSales_TTMY2); } if (toolEntity.CompSales_TTMY2 != null) { inputInfo.CompSales_TTMY2 = string.Format("{0:f}", toolEntity.CompSales_TTMY2); } if (toolEntity.CompGC_TTMY2 != null) { inputInfo.CompGC_TTMY2 = string.Format("{0:f}", toolEntity.CompGC_TTMY2); } if (toolEntity.PAC_TTMY2 != null) { inputInfo.PAC_TTMY2 = string.Format("{0:f}", toolEntity.PAC_TTMY2); } if (toolEntity.SOI_TTMY2 != null) { inputInfo.SOI_TTMY2 = string.Format("{0:f}", toolEntity.SOI_TTMY2); } if (toolEntity.CashFlow_TTMY2 != null) { inputInfo.CashFlow_TTMY2 = string.Format("{0:f}", toolEntity.CashFlow_TTMY2); } List <StoreBEInfo> remoteBeList = new List <StoreBEInfo>(); List <StoreBEInfo> attachedBeList = new List <StoreBEInfo>(); StoreBEInfo mds = null; StoreBEInfo mcCafe = null; StoreBEInfo hour24 = null; if (store.StoreBEInfoList.Count > 0) { foreach (var beInfo in store.StoreBEInfoList) { switch (beInfo.BETypeName) { case "Remote Kiosk": remoteBeList.Add(beInfo); break; case "Attached Kiosk": attachedBeList.Add(beInfo); break; case "MDS": mds = beInfo; break; case "McCafe": mcCafe = beInfo; break; case "24 Hour": hour24 = beInfo; break; } } } if (remoteBeList.Count > 0) { inputInfo.RemoteKiosk1_Status = remoteBeList[0].IsSingleContract == 1 ? "Yes" : "No"; inputInfo.RemoteKiosk1_OpenDate = remoteBeList[0].LaunchDate; if (remoteBeList.Count > 1) { inputInfo.RemoteKiosk2_Status = remoteBeList[1].IsSingleContract == 1 ? "Yes" : "No"; inputInfo.RemoteKiosk2_OpenDate = remoteBeList[1].LaunchDate; if (remoteBeList.Count > 2) { inputInfo.RemoteKiosk3_Status = remoteBeList[2].IsSingleContract == 1 ? "Yes" : "No"; inputInfo.RemoteKiosk3_OpenDate = remoteBeList[2].LaunchDate; } } } if (attachedBeList.Count > 0) { inputInfo.AttachedKiosk1_Status = attachedBeList[0].IsSingleContract == 1 ? "Yes" : "No"; inputInfo.AttachedKiosk1_OpenDate = attachedBeList[0].LaunchDate; if (attachedBeList.Count > 1) { inputInfo.AttachedKiosk2_Status = attachedBeList[1].IsSingleContract == 1 ? "Yes" : "No"; inputInfo.AttachedKiosk2_OpenDate = attachedBeList[1].LaunchDate; if (attachedBeList.Count > 2) { inputInfo.AttachedKiosk3_Status = attachedBeList[2].IsSingleContract == 1 ? "Yes" : "No"; inputInfo.AttachedKiosk3_OpenDate = attachedBeList[2].LaunchDate; } } } if (mds != null) { inputInfo.MDS_Status = mds.IsSingleContract == 1 ? "Yes" : "No"; inputInfo.MDS_OpenDate = mds.LaunchDate; } if (mcCafe != null) { inputInfo.McCafe_Status = mcCafe.IsSingleContract == 1 ? "Yes" : "No"; inputInfo.McCafe_OpenDate = mcCafe.LaunchDate; } if (hour24 != null) { inputInfo.TwentyFourHour_Status = hour24.IsSingleContract == 1 ? "Yes" : "No"; inputInfo.TwentyFourHour_OpenDate = hour24.LaunchDate; } var woEntity = ClosureWOCheckList.Get(closure.ProjectId); if (woEntity != null) { if (woEntity.LHI_NBV != null) { inputInfo.LHI_NBV = string.Format("{0:f}", woEntity.LHI_NBV); } if (woEntity.ESSD_NBV != null) { inputInfo.ESSD_NBV = string.Format("{0:f}", woEntity.ESSD_NBV); } if (woEntity.TotalCost_NBV != null) { inputInfo.TotalCost_NBV = string.Format("{0:f}", woEntity.TotalCost_NBV); } } } excelDirector.Input(inputInfo); current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + DataConverter.ToHexString(SiteFilePath.Executive_Summary_Template)); current.Response.ContentType = "application/octet-stream"; current.Response.WriteFile("" + tempFilePath + ""); current.Response.End(); return(Ok()); }
public IHttpActionResult GenExecutiveSummaty(ClosureExecutiveSummary entity) { if (!ClosureExecutiveSummary.Any(i => i.ProjectId == entity.ProjectId && i.IsHistory == false)) { if (entity.Id == Guid.Empty || entity.Id == null) { entity.Id = Guid.NewGuid(); } entity.CreateTime = DateTime.Now; entity.CreatorAccount = ClientCookie.UserCode; ClosureExecutiveSummary.Add(entity); } else { ClosureExecutiveSummary.Update(entity); } var current = System.Web.HttpContext.Current; string path = SiteFilePath.Template_DIRECTORY + "\\" + SiteFilePath.Executive_Summary_Template; string internalFileName = Guid.NewGuid() + ".xlsx"; string filePath = SiteFilePath.UploadFiles_DIRECTORY + "\\" + internalFileName; File.Copy(path, filePath); var fileInfo = new FileInfo(filePath); var excelPMTDirector = new ExcelDataInputDirector(fileInfo, ExcelDataInputType.ClosureExecutiveSummary); var closure = ClosureInfo.GetByProjectId(entity.ProjectId); var store = StoreBasicInfo.GetStore(closure.USCode); var inputInfo = new ExcelInputDTO { StoreNameCN = store.StoreBasicInfo.NameZHCN, USCode = store.StoreBasicInfo.StoreCode, City = store.StoreBasicInfo.CityENUS, Market = store.StoreBasicInfo.MarketENUS, OpenDate = store.StoreBasicInfo.OpenDate, Floor = store.StoreSTLocation.Floor, TotalArea = store.StoreSTLocation.TotalArea, TotalSeatsNo = store.StoreSTLocation.TotalSeatsNo, BE = store.StoreBEInfoList.Count, RentType = store.StoreContractInfo.RentType, RentStructure = store.StoreContractInfo.RentStructure, MiniMarket = entity.MiniMarket, StoreLocation = entity.StoreLocation, CurrentSituation = entity.CurrentSituation, NegotiationHistory = entity.NegotiationHistory, ProposedSolution = entity.ProposedSolution, SalesTransfer = entity.SalesTransfer }; var leaseRecapID = StoreContractInfo.SearchByProject(entity.ProjectId).FirstOrDefault().LeaseRecapID ?? 0; var storeAtt = StoreContractInfoAttached.Search(c => c.LeaseRecapID == leaseRecapID.ToString()).OrderByDescending(e => e.CreateDate).FirstOrDefault(); if (storeAtt != null) { inputInfo.LeasingTerm = store.StoreContractInfo.LeasePurchaseTerm; } if (store.StoreContractInfo.RentCommencementDate.HasValue) { inputInfo.RentCommencementDate = store.StoreContractInfo.RentCommencementDate.Value; } if (store.StoreContractInfo.EndDate.HasValue) { inputInfo.LeaseExpirationDate = store.StoreContractInfo.EndDate.Value; } var toolEntity = ClosureTool.Get(closure.ProjectId); if (toolEntity != null) { if (toolEntity.TotalSales_Adjustment_RMB != null) { inputInfo.TotalSales_TTM = string.Format("{0:f}", toolEntity.TotalSales_Adjustment_RMB); } if (toolEntity.CompSales_Adjustment != null) { inputInfo.SalesComp_TTM = string.Format("{0:f}", toolEntity.CompSales_Adjustment); } if (toolEntity.CompCG_Adjustment != null) { inputInfo.GCComp_TTM = string.Format("{0:f}", toolEntity.CompCG_Adjustment); } if (toolEntity.PAC_Adjustment != null) { inputInfo.PAC_TTM = string.Format("{0:f}", toolEntity.PAC_Adjustment); } if (toolEntity.SOI_Adjustment != null) { inputInfo.SOI_TTM = string.Format("{0:f}", toolEntity.SOI_Adjustment); } if (toolEntity.CashFlow_RMB_Adjustment != null) { inputInfo.CASHFLOW_TTM = string.Format("{0:f}", toolEntity.CashFlow_RMB_Adjustment); } if (toolEntity.TotalSales_TTMY1 != null) { inputInfo.TotalSales_TTMY1 = string.Format("{0:f}", toolEntity.TotalSales_TTMY1); } if (toolEntity.CompSales_TTMY1 != null) { inputInfo.CompSales_TTMY1 = string.Format("{0:f}", toolEntity.CompSales_TTMY1); } if (toolEntity.CompGC_TTMY1 != null) { inputInfo.CompGC_TTMY1 = string.Format("{0:f}", toolEntity.CompGC_TTMY1); } if (toolEntity.PAC_TTMY1 != null) { inputInfo.PAC_TTMY1 = string.Format("{0:f}", toolEntity.PAC_TTMY1); } if (toolEntity.SOI_TTMY1 != null) { inputInfo.SOI_TTMY1 = string.Format("{0:f}", toolEntity.SOI_TTMY1); } if (toolEntity.CashFlow_TTMY1 != null) { inputInfo.CashFlow_TTMY1 = string.Format("{0:f}", toolEntity.CashFlow_TTMY1); } if (toolEntity.TotalSales_TTMY2 != null) { inputInfo.TotalSales_TTMY2 = string.Format("{0:f}", toolEntity.TotalSales_TTMY2); } if (toolEntity.CompSales_TTMY2 != null) { inputInfo.CompSales_TTMY2 = string.Format("{0:f}", toolEntity.CompSales_TTMY2); } if (toolEntity.CompGC_TTMY2 != null) { inputInfo.CompGC_TTMY2 = string.Format("{0:f}", toolEntity.CompGC_TTMY2); } if (toolEntity.PAC_TTMY2 != null) { inputInfo.PAC_TTMY2 = string.Format("{0:f}", toolEntity.PAC_TTMY2); } if (toolEntity.SOI_TTMY2 != null) { inputInfo.SOI_TTMY2 = string.Format("{0:f}", toolEntity.SOI_TTMY2); } if (toolEntity.CashFlow_TTMY2 != null) { inputInfo.CashFlow_TTMY2 = string.Format("{0:f}", toolEntity.CashFlow_TTMY2); } List <StoreBEInfo> remoteBeList = new List <StoreBEInfo>(); List <StoreBEInfo> attachedBeList = new List <StoreBEInfo>(); StoreBEInfo mds = null; StoreBEInfo mcCafe = null; StoreBEInfo hour24 = null; if (store.StoreBEInfoList.Count > 0) { foreach (var beInfo in store.StoreBEInfoList) { switch (beInfo.BETypeName) { case "Remote Kiosk": remoteBeList.Add(beInfo); break; case "Attach Kiosk": attachedBeList.Add(beInfo); break; case "MDS": mds = beInfo; break; case "McCafe": mcCafe = beInfo; break; case "24 Hour": hour24 = beInfo; break; } } } inputInfo.RemoteKiosk1_Status = "No"; inputInfo.RemoteKiosk2_Status = "No"; inputInfo.RemoteKiosk3_Status = "No"; inputInfo.AttachedKiosk1_Status = "No"; inputInfo.AttachedKiosk2_Status = "No"; inputInfo.AttachedKiosk3_Status = "No"; inputInfo.MDS_Status = "No"; inputInfo.McCafe_Status = "No"; inputInfo.TwentyFourHour_Status = "No"; if (remoteBeList.Count > 0) { inputInfo.RemoteKiosk1_Status = "Yes"; inputInfo.RemoteKiosk1_OpenDate = remoteBeList[0].LaunchDate; if (remoteBeList.Count > 1) { inputInfo.RemoteKiosk2_Status = "Yes"; inputInfo.RemoteKiosk2_OpenDate = remoteBeList[1].LaunchDate; if (remoteBeList.Count > 2) { inputInfo.RemoteKiosk3_Status = "Yes"; inputInfo.RemoteKiosk3_OpenDate = remoteBeList[2].LaunchDate; } } } if (attachedBeList.Count > 0) { inputInfo.AttachedKiosk1_Status = "Yes"; inputInfo.AttachedKiosk1_OpenDate = attachedBeList[0].LaunchDate; if (attachedBeList.Count > 1) { inputInfo.AttachedKiosk2_Status = "Yes"; inputInfo.AttachedKiosk2_OpenDate = attachedBeList[1].LaunchDate; if (attachedBeList.Count > 2) { inputInfo.AttachedKiosk3_Status = "Yes"; inputInfo.AttachedKiosk3_OpenDate = attachedBeList[2].LaunchDate; } } } if (mds != null) { inputInfo.MDS_Status = "Yes"; inputInfo.MDS_OpenDate = mds.LaunchDate; } if (mcCafe != null) { inputInfo.McCafe_Status = "Yes"; inputInfo.McCafe_OpenDate = mcCafe.LaunchDate; } if (hour24 != null) { inputInfo.TwentyFourHour_Status = "Yes"; inputInfo.TwentyFourHour_OpenDate = hour24.LaunchDate; } var woEntity = ClosureWOCheckList.Get(closure.ProjectId); if (woEntity != null) { if (woEntity.LHI_NBV != null) { inputInfo.LHI_NBV = string.Format("{0:f}", woEntity.LHI_NBV); } if (woEntity.ESSD_NBV != null) { inputInfo.ESSD_NBV = string.Format("{0:f}", woEntity.ESSD_NBV); } if (woEntity.TotalCost_NBV != null) { inputInfo.TotalCost_NBV = string.Format("{0:f}", woEntity.TotalCost_NBV); } } } excelPMTDirector.Input(inputInfo); Attachment att = Attachment.GetAttachment("ClosureExecutiveSummary", entity.Id.ToString(), "Template"); if (att == null) { att = new Attachment(); att.RefTableName = "ClosureExecutiveSummary"; att.RefTableID = entity.Id.ToString(); att.CreateTime = DateTime.Now; att.ID = Guid.NewGuid(); att.TypeCode = "Template"; att.CreatorID = ClientCookie.UserCode; att.CreatorNameENUS = ClientCookie.UserNameENUS; att.CreatorNameZHCN = ClientCookie.UserNameZHCN; att.Name = SiteFilePath.Executive_Summary_Template; att.InternalName = internalFileName; att.Extension = fileInfo.Extension; att.Length = Convert.ToInt32(fileInfo.Length); att.RequirementId = new Guid("79258ffb-c2ef-4eff-897d-ba8376c90071"); Attachment.Add(att); } else { att.CreateTime = DateTime.Now; att.CreatorID = ClientCookie.UserCode; att.CreatorNameENUS = ClientCookie.UserNameENUS; att.CreatorNameZHCN = ClientCookie.UserNameZHCN; att.Name = SiteFilePath.Executive_Summary_Template; att.InternalName = internalFileName; att.Extension = fileInfo.Extension; att.Length = Convert.ToInt32(fileInfo.Length); att.RequirementId = new Guid("79258ffb-c2ef-4eff-897d-ba8376c90071"); Attachment.Update(att); } ProjectInfo.FinishNode(entity.ProjectId, FlowCode.Closure_ExecutiveSummary, NodeCode.Closure_ExecutiveSummary_Generate); return(Ok()); }
public Attachment GenerateAttachment(out string filePath) { var info = ReimageInfo.FirstOrDefault(e => e.ProjectId == this.ProjectId); _refId = GetRefId(this.ProjectId); var storeInfo = StoreBasicInfo.GetStorInfo(info.USCode); string templateFileName = string.Concat(SiteFilePath.Template_DIRECTORY, "/", SiteFilePath.Reimage_Summary_Template); string fileName = HttpContext.Current.Server.MapPath(string.Format("~/UploadFiles/{0}.xlsx", Guid.NewGuid())); var extetion = Path.GetExtension(fileName); var internalName = Path.GetFileName(fileName); File.Copy(templateFileName, fileName); FileInfo fileInfo = new FileInfo(fileName); ExcelDataInputDirector excelDirector = new ExcelDataInputDirector(fileInfo, ExcelDataInputType.ReimageSummary); ExcelInputDTO excelDto = new ExcelInputDTO(); excelDto.USCode = info.USCode; excelDto.ProjectId = info.ProjectId; excelDirector.Input(excelDto); var att = Attachment.FirstOrDefault(e => e.RefTableID == this.Id.ToString() && e.TypeCode == "ReimageSummary"); bool hasAttach = true; if (att == null) { hasAttach = false; att = new Attachment(); att.ID = Guid.NewGuid(); } att.TypeCode = "ReimageSummary"; att.RefTableID = this.Id.ToString(); att.RefTableName = "ReimageSummary"; att.Name = "Reimage Summary"; att.Extension = extetion; att.RelativePath = "/"; att.InternalName = internalName; att.ContentType = "application/vnd.ms-excel"; att.Length = (int)fileInfo.Length; att.CreatorID = ClientCookie.UserCode; att.CreatorNameENUS = ClientCookie.UserNameENUS; att.CreatorNameZHCN = ClientCookie.UserNameZHCN; att.CreateTime = DateTime.Now; att.RequirementId = new Guid("5647BDBB-5B5F-47CD-9AD2-3E35A16DD303"); if (hasAttach) { att.Update(); } else { att.Add(); } //fileInfo = new FileInfo(fileName); //var importDirector = new ExcelDataImportDirector(fileInfo, ExcelDataImportType.FinancialPreAnalysis); //importDirector.FillEntityEvent += FillFinancialPreAnalysisEntity; //using (var scope = new TransactionScope()) //{ // importDirector.ParseAndImport(); // scope.Complete(); //} filePath = fileName; return(att); }
public IHttpActionResult GenerateExcel(string templateType, string flowCode, string projectId) { 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 fileName = Guid.NewGuid() + ".xlsx"; 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.ReimageSummary: siteFilePath = SiteFilePath.Reimage_Summary_Template; //AddUpdateAttachment(name + fileExtension, "ReimageSummary", "Reimage_Summary", fileCollection); break; } var path = string.Format(@"{0}\{1}", SiteFilePath.Template_DIRECTORY, siteFilePath); var tempFilePath = current.Server.MapPath("~/") + "Temp\\" + fileName; File.Copy(path, tempFilePath); var excelOutputDirector = new ExcelDataInputDirector(new FileInfo(tempFilePath), outputType); var inputInfo = new ExcelInputDTO { ProjectId = projectId, FlowCode = flowCode }; excelOutputDirector.Input(inputInfo); //switch (outputType) //{ // case ExcelDataInputType.ReimageSummary: // var refTableId = ProjectInfo.GetRefTableId("ReimageSummary",projectId); // Attachment attachment = Attachment.GetAttachment("ReimageSummary", refTableId, "ReimageSummary"); // if (attachment == null) // { // attachment = new Attachment(); // attachment.ID = Guid.NewGuid(); // attachment.ContentType = "application/ms-excel"; // attachment.CreateTime = DateTime.Now; // attachment.CreatorID = ClientCookie.UserCode; // attachment.CreatorNameENUS = ClientCookie.UserNameENUS; // attachment.CreatorNameZHCN = ClientCookie.UserNameZHCN; // attachment.Extension = ".xlsx"; // attachment.InternalName = "ReimageSummary.xlsx"; // } // break; //} current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(siteFilePath, System.Text.Encoding.GetEncoding("utf-8"))); current.Response.ContentType = "application/octet-stream"; current.Response.WriteFile("" + tempFilePath + ""); 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()); }