Beispiel #1
0
        public async Task <List <Content> > GetContentsByCsvFileAsync(string filePath, Site site, Channel channel)
        {
            var contentInfoList = new List <Content>();

            CsvUtils.Import(filePath, out var head, out var rows);

            if (rows.Count <= 0)
            {
                return(contentInfoList);
            }

            var styles = ColumnsManager.GetContentListStyles(await _databaseManager.TableStyleRepository.GetContentStylesAsync(site, channel));
            var nameValueCollection = new NameValueCollection();

            foreach (var style in styles)
            {
                nameValueCollection[style.DisplayName] = StringUtils.ToLower(style.AttributeName);
            }

            var attributeNames = new List <string>();

            foreach (var columnName in head)
            {
                attributeNames.Add(!string.IsNullOrEmpty(nameValueCollection[columnName])
                    ? nameValueCollection[columnName]
                    : columnName);
            }

            foreach (var row in rows)
            {
                if (row.Count != attributeNames.Count)
                {
                    continue;
                }

                var dict = new Dictionary <string, object>();

                for (var i = 0; i < attributeNames.Count; i++)
                {
                    var attributeName = attributeNames[i];
                    if (!string.IsNullOrEmpty(attributeName))
                    {
                        dict[attributeName] = row[i];
                    }
                }

                var content = new Content();
                content.LoadDict(dict);

                if (!string.IsNullOrEmpty(content.Title))
                {
                    content.SiteId    = site.Id;
                    content.ChannelId = channel.Id;

                    contentInfoList.Add(content);
                }
            }

            return(contentInfoList);
        }
Beispiel #2
0
        public static List <ContentInfo> GetContentsByCsvFile(string filePath, SiteInfo siteInfo,
                                                              ChannelInfo nodeInfo)
        {
            var contentInfoList = new List <ContentInfo>();

            CsvUtils.Import(filePath, out var head, out var rows);

            if (rows.Count <= 0)
            {
                return(contentInfoList);
            }

            var styleInfoList       = ContentUtility.GetAllTableStyleInfoList(TableStyleManager.GetContentStyleInfoList(siteInfo, nodeInfo));
            var nameValueCollection = new NameValueCollection();

            foreach (var styleInfo in styleInfoList)
            {
                nameValueCollection[styleInfo.DisplayName] = styleInfo.AttributeName.ToLower();
            }

            var attributeNames = new List <string>();

            foreach (var columnName in head)
            {
                attributeNames.Add(!string.IsNullOrEmpty(nameValueCollection[columnName])
                    ? nameValueCollection[columnName]
                    : columnName);
            }

            foreach (var row in rows)
            {
                if (row.Count != attributeNames.Count)
                {
                    continue;
                }

                var dict = new Dictionary <string, object>();

                for (var i = 0; i < attributeNames.Count; i++)
                {
                    var attributeName = attributeNames[i];
                    if (!string.IsNullOrEmpty(attributeName))
                    {
                        dict[attributeName] = row[i];
                    }
                }

                var contentInfo = new ContentInfo(dict);

                if (!string.IsNullOrEmpty(contentInfo.Title))
                {
                    contentInfo.SiteId       = siteInfo.Id;
                    contentInfo.ChannelId    = nodeInfo.Id;
                    contentInfo.LastEditDate = DateTime.Now;

                    contentInfoList.Add(contentInfo);
                }
            }

            return(contentInfoList);
        }
Beispiel #3
0
        public static List <InputContentInfo> GetInputContentsByCsvFile(string filePath, PublishmentSystemInfo publishmentSystemInfo,
                                                                        InputInfo inputInfo)
        {
            var contentInfoList = new List <InputContentInfo>();

            List <string>         head;
            List <List <string> > rows;

            CsvUtils.Import(filePath, out head, out rows);

            if (rows.Count > 0)
            {
                var relatedidentityes = RelatedIdentities.GetRelatedIdentities(ETableStyle.InputContent,
                                                                               publishmentSystemInfo.PublishmentSystemId, inputInfo.InputID);
                var tableStyleInfoList = TableStyleManager.GetTableStyleInfoList(ETableStyle.InputContent,
                                                                                 DataProvider.InputContentDao.TableName, relatedidentityes);

                var nameValueCollection = new NameValueCollection();

                foreach (var styleInfo in tableStyleInfoList)
                {
                    nameValueCollection[styleInfo.DisplayName] = styleInfo.AttributeName.ToLower();
                }

                nameValueCollection["回复"]   = InputContentAttribute.Reply.ToLower();
                nameValueCollection["添加时间"] = InputContentAttribute.AddDate.ToLower();

                var attributeNames = new List <string>();
                foreach (var columnName in head)
                {
                    if (!string.IsNullOrEmpty(nameValueCollection[columnName]))
                    {
                        attributeNames.Add(nameValueCollection[columnName]);
                    }
                    else
                    {
                        attributeNames.Add(columnName);
                    }
                }

                foreach (var row in rows)
                {
                    if (row.Count != attributeNames.Count)
                    {
                        continue;
                    }

                    var contentInfo = new InputContentInfo(0, inputInfo.InputID, 0, true, string.Empty, string.Empty,
                                                           DateTime.Now, string.Empty);

                    for (var i = 0; i < attributeNames.Count; i++)
                    {
                        var attributeName = attributeNames[i];
                        if (!string.IsNullOrEmpty(attributeName))
                        {
                            var value = row[i];
                            contentInfo.SetExtendedAttribute(attributeName, value);
                        }
                    }

                    contentInfoList.Add(contentInfo);
                }
            }

            return(contentInfoList);
        }
Beispiel #4
0
        public static List <BackgroundContentInfo> GetContentsByCsvFile(string filePath, PublishmentSystemInfo publishmentSystemInfo,
                                                                        NodeInfo nodeInfo)
        {
            var contentInfoList = new List <BackgroundContentInfo>();

            List <string>         head;
            List <List <string> > rows;

            CsvUtils.Import(filePath, out head, out rows);

            if (rows.Count > 0)
            {
                var relatedidentityes =
                    RelatedIdentities.GetChannelRelatedIdentities(
                        publishmentSystemInfo.PublishmentSystemId, nodeInfo.NodeId);
                var modelInfo = ContentModelManager.GetContentModelInfo(publishmentSystemInfo,
                                                                        nodeInfo.ContentModelId);
                var tableStyle = EAuxiliaryTableTypeUtils.GetTableStyle(modelInfo.TableType);
                // ArrayList tableStyleInfoArrayList = TableStyleManager.GetTableStyleInfoArrayList(ETableStyle.BackgroundContent, publishmentSystemInfo.AuxiliaryTableForContent, relatedidentityes);

                var tableStyleInfoList = TableStyleManager.GetTableStyleInfoList(tableStyle,
                                                                                 modelInfo.TableName, relatedidentityes);
                tableStyleInfoList = ContentUtility.GetAllTableStyleInfoList(publishmentSystemInfo,
                                                                             tableStyle, tableStyleInfoList);
                var nameValueCollection = new NameValueCollection();

                foreach (var styleInfo in tableStyleInfoList)
                {
                    nameValueCollection[styleInfo.DisplayName] = styleInfo.AttributeName.ToLower();
                }

                var attributeNames = new List <string>();
                foreach (var columnName in head)
                {
                    if (!string.IsNullOrEmpty(nameValueCollection[columnName]))
                    {
                        attributeNames.Add(nameValueCollection[columnName]);
                    }
                    else
                    {
                        attributeNames.Add(columnName);
                    }
                }

                foreach (var row in rows)
                {
                    var contentInfo = new BackgroundContentInfo();
                    if (row.Count != attributeNames.Count)
                    {
                        continue;
                    }

                    for (var i = 0; i < attributeNames.Count; i++)
                    {
                        var attributeName = attributeNames[i];
                        if (!string.IsNullOrEmpty(attributeName))
                        {
                            var value = row[i];
                            contentInfo.SetExtendedAttribute(attributeName, value);
                        }
                    }

                    if (!string.IsNullOrEmpty(contentInfo.Title))
                    {
                        contentInfo.PublishmentSystemId = publishmentSystemInfo.PublishmentSystemId;
                        contentInfo.NodeId       = nodeInfo.NodeId;
                        contentInfo.LastEditDate = DateTime.Now;

                        contentInfoList.Add(contentInfo);
                    }
                }
            }

            return(contentInfoList);
        }
Beispiel #5
0
        public static List <ContentInfo> GetContentsByCsvFile(string filePath, SiteInfo siteInfo,
                                                              ChannelInfo nodeInfo)
        {
            var contentInfoList = new List <ContentInfo>();

            List <string>         head;
            List <List <string> > rows;

            CsvUtils.Import(filePath, out head, out rows);

            if (rows.Count <= 0)
            {
                return(contentInfoList);
            }

            var relatedidentityes =
                RelatedIdentities.GetChannelRelatedIdentities(
                    siteInfo.Id, nodeInfo.Id);
            var tableName = ChannelManager.GetTableName(siteInfo, nodeInfo);
            // ArrayList tableStyleInfoArrayList = TableStyleManager.GetTableStyleInfoArrayList(ETableStyle.BackgroundContent, siteInfo.AuxiliaryTableForContent, relatedidentityes);

            var styleInfoList       = ContentUtility.GetAllTableStyleInfoList(TableStyleManager.GetTableStyleInfoList(tableName, relatedidentityes));
            var nameValueCollection = new NameValueCollection();

            foreach (var styleInfo in styleInfoList)
            {
                nameValueCollection[styleInfo.DisplayName] = styleInfo.AttributeName.ToLower();
            }

            var attributeNames = new List <string>();

            foreach (var columnName in head)
            {
                attributeNames.Add(!string.IsNullOrEmpty(nameValueCollection[columnName])
                    ? nameValueCollection[columnName]
                    : columnName);
            }

            foreach (var row in rows)
            {
                var contentInfo = new ContentInfo();
                if (row.Count != attributeNames.Count)
                {
                    continue;
                }

                for (var i = 0; i < attributeNames.Count; i++)
                {
                    var attributeName = attributeNames[i];
                    if (!string.IsNullOrEmpty(attributeName))
                    {
                        var value = row[i];
                        contentInfo.Set(attributeName, value);
                    }
                }

                if (!string.IsNullOrEmpty(contentInfo.Title))
                {
                    contentInfo.SiteId       = siteInfo.Id;
                    contentInfo.ChannelId    = nodeInfo.Id;
                    contentInfo.LastEditDate = DateTime.Now;

                    contentInfoList.Add(contentInfo);
                }
            }

            return(contentInfoList);
        }
Beispiel #6
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            var isChanged = false;

            try
            {
                if (_flg == 0)
                {
                    var totalNum = TranslateUtils.ToInt(TbTotalNum.Text);
                    if (totalNum > 1000)
                    {
                        FailMessage("新增失败,一次最多只能新增1000张优惠劵");
                    }
                    else
                    {
                        DataProviderWx.CouponSnDao.Insert(PublishmentSystemId, _couponId, totalNum);

                        Body.AddSiteLog(PublishmentSystemId, "新增优惠劵数量", $"数量:{totalNum}");
                        isChanged = true;
                    }
                }
                if (_flg == 1)
                {
                    //string filehou = this.hifUpload.PostedFile.FileName.Split('.')[1].ToString();

                    //if (filehou != "xls" || filehou != "xlsx")
                    //{
                    //    base.FailMessage("请检查上传文件的类型.必须为EXCEL文件.");
                    //}

                    var filePath = PathUtils.GetTemporaryFilesPath("coupon_sn_upload.csv");
                    FileUtils.DeleteFileIfExists(filePath);

                    HifUpload.PostedFile.SaveAs(filePath);

                    try
                    {
                        List <List <string> > snList;
                        List <string>         head;
                        CsvUtils.Import(filePath, out head, out snList);

                        if (snList.Count > 0)
                        {
                            //DataProviderWx.CouponSnDao.Insert(PublishmentSystemId, _couponId, snList);
                            Body.AddSiteLog(PublishmentSystemId, "新增优惠劵数量", $"数量:{snList.Count}");
                            isChanged = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        FailMessage(ex, "失败:" + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                FailMessage(ex, "失败:" + ex.Message);
            }

            if (isChanged)
            {
                PageUtils.CloseModalPage(Page);
            }
        }