public string Download(int c3SysNo, string companyCode) { m_companyCode = companyCode; string c3Name = ExternalDomainBroker.GetCategory3Info(c3SysNo).CategoryName.Content; string fileName = BulidResponseFileName(c3Name); //生成模版 DataFeedTemplate template = BulidTemplate(c3SysNo, c3Name); //输出模版 return(GetTemplateUrl(template, fileName)); }
string GetTemplateUrl(DataFeedTemplate template, string fileName) { string path = Path.Combine( AppDomain.CurrentDomain.SetupInformation.ApplicationBase , AppSettingHelper.Get("DataFeedFilesTemplatePath") ); template.LoadWorkbook(path); template.InitWorkbook(); byte[] buf = template.GetBytes(); return(FileUploadManager.UploadFileAndGetUrl(fileName, buf)); }
DataFeedTemplate BulidTemplate(int c3SysNo, string c3Name) { string configPath = Path.Combine( AppDomain.CurrentDomain.SetupInformation.ApplicationBase , AppSettingHelper.Get("DataFeedFilesConfigPath") ); m_dataFeed = SerializationUtility.LoadFromXml <DataFeedFileMapping>(configPath).Mappings[0]; DataFeedTemplate template = new DataFeedTemplate(); template.C3Name = c3Name; template.C3SysNo = c3SysNo; template.C3RowIndex = int.Parse(m_dataFeed.C3RowIndex); //填充列分组信息 template.HeaderGroups = new List <HeaderGroup>(); foreach (var item in m_dataFeed.HeaderGroups) { template.HeaderGroups.Add(item); } template.BasicColumns = BuildBasicColumns(c3SysNo); var list = ExternalDomainBroker.GetCategoryPropertyByCategorySysNo(c3SysNo); if (list != null) { template.Properties = new List <DataFeedColumn>(); var activeList = list.Where(p => p.Property.Status == PropertyStatus.Active); if (activeList.Count() > 0) { var propertySysNoList = activeList.Select(p => p.Property.SysNo.Value).ToList(); var propertyValues = ExternalDomainBroker.GetPropertyValueInfoByPropertySysNoList(propertySysNoList); foreach (var item in activeList) { DataFeedColumn column = new DataFeedColumn(); column.Number = item.Property.SysNo.Value; // item.PropertyType == "D"? 没有这个属性? if (item.PropertyType == PropertyType.Grouping) { column.Name = string.Format("{0}_列表", item.Property.PropertyName.Content); } else { column.Name = item.Property.PropertyName.Content; } column.Type = DataType.LIST; column.Width = column.Name.Length; if (item.IsMustInput == CategoryPropertyStatus.Yes) { column.IsMustInput = true; } else { column.IsMustInput = false; } if (item.IsInAdvSearch == CategoryPropertyStatus.Yes) { column.IsInAdvSearch = true; } column.List = new List <string>(); var propertyList = propertyValues.FirstOrDefault(p => p.Key == item.Property.SysNo.Value).Value; if (propertyList != null) { foreach (var value in propertyList.Where(p => p.PropertyInfo.Status == PropertyStatus.Active)) { column.List.Add(value.ValueDescription.Content); } } template.Properties.Add(column); //分组属性需要多加一列 // item.PropertyType == "D"? 没有这个属性? if (item.PropertyType == PropertyType.Grouping) { column = new DataFeedColumn(); column.Name = string.Format("{0}_自定义", item.Property.PropertyName.Content); column.Width = column.Name.Length; column.Type = DataType.TEXT_LENGTH; template.Properties.Add(column); } //HACK:Bob.H.Li 如果Item.Type==G,那么添加一列“是否分组属性” if (item.PropertyType == PropertyType.Grouping) { column = new DataFeedColumn(); column.Number = template.Properties.Count; column.Name = DataFeedConstString.EXCEL_ADDSELECTGROUPSTRING; column.Width = column.Name.Length; column.Type = DataType.LIST; column.List = new List <string>() { GroupPropertyType.OnlyGroupText, GroupPropertyType.OnlyGroupPicture, GroupPropertyType.GroupAggregationText, GroupPropertyType.GroupAggregationPicture }; template.Properties.Add(column); } } } } return(template); }