private static void AddAtomEntry(AtomFeed feed, RelatedFieldItemInfo relatedFieldItemInfo, int level)
        {
            var entry = AtomUtility.GetEmptyEntry();

            AtomUtility.AddDcElement(entry.AdditionalElements, new List <string> {
                nameof(RelatedFieldItemInfo.Id), "ID"
            }, relatedFieldItemInfo.Id.ToString());
            AtomUtility.AddDcElement(entry.AdditionalElements, new List <string> {
                nameof(RelatedFieldItemInfo.RelatedFieldId), "RelatedFieldID"
            }, relatedFieldItemInfo.RelatedFieldId.ToString());
            AtomUtility.AddDcElement(entry.AdditionalElements, nameof(RelatedFieldItemInfo.ItemName), relatedFieldItemInfo.ItemName);
            AtomUtility.AddDcElement(entry.AdditionalElements, nameof(RelatedFieldItemInfo.ItemValue), relatedFieldItemInfo.ItemValue);
            AtomUtility.AddDcElement(entry.AdditionalElements, new List <string> {
                nameof(RelatedFieldItemInfo.ParentId), "ParentID"
            }, relatedFieldItemInfo.ParentId.ToString());
            AtomUtility.AddDcElement(entry.AdditionalElements, nameof(RelatedFieldItemInfo.Taxis), relatedFieldItemInfo.Taxis.ToString());
            AtomUtility.AddDcElement(entry.AdditionalElements, "Level", level.ToString());

            feed.Entries.Add(entry);

            var relatedFieldItemInfoList = DataProvider.RelatedFieldItemDao.GetRelatedFieldItemInfoList(relatedFieldItemInfo.RelatedFieldId, relatedFieldItemInfo.Id);

            foreach (var itemInfo in relatedFieldItemInfoList)
            {
                AddAtomEntry(feed, itemInfo, level + 1);
            }
        }
        public void ImportRelatedField(bool overwrite)
        {
            if (!DirectoryUtils.IsDirectoryExists(_directoryPath))
            {
                return;
            }
            var filePaths = DirectoryUtils.GetFilePaths(_directoryPath);

            foreach (var filePath in filePaths)
            {
                var feed = AtomFeed.Load(FileUtils.GetFileStreamReadOnly(filePath));

                var title = AtomUtility.GetDcElementContent(feed.AdditionalElements, new List <string> {
                    nameof(RelatedFieldInfo.Title), "RelatedFieldName"
                });
                var totalLevel = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(feed.AdditionalElements, nameof(RelatedFieldInfo.TotalLevel)));
                var prefixes   = AtomUtility.GetDcElementContent(feed.AdditionalElements, nameof(RelatedFieldInfo.Prefixes));
                var suffixes   = AtomUtility.GetDcElementContent(feed.AdditionalElements, nameof(RelatedFieldInfo.Suffixes));

                var relatedFieldInfo = new RelatedFieldInfo(0, title, _siteId, totalLevel, prefixes, suffixes);

                var srcRelatedFieldInfo = DataProvider.RelatedFieldDao.GetRelatedFieldInfo(_siteId, title);
                if (srcRelatedFieldInfo != null)
                {
                    if (overwrite)
                    {
                        DataProvider.RelatedFieldDao.Delete(srcRelatedFieldInfo.Id);
                    }
                    else
                    {
                        relatedFieldInfo.Title = DataProvider.RelatedFieldDao.GetImportTitle(_siteId, relatedFieldInfo.Title);
                    }
                }

                var relatedFieldId = DataProvider.RelatedFieldDao.Insert(relatedFieldInfo);

                var lastInertedLevel     = 1;
                var lastInsertedParentId = 0;
                var lastInsertedId       = 0;
                foreach (AtomEntry entry in feed.Entries)
                {
                    var itemName  = AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(RelatedFieldItemInfo.ItemName));
                    var itemValue = AtomUtility.GetDcElementContent(entry.AdditionalElements, nameof(RelatedFieldItemInfo.ItemValue));
                    var level     = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(entry.AdditionalElements, "Level"));
                    var parentId  = 0;
                    if (level > 1)
                    {
                        parentId = level != lastInertedLevel ? lastInsertedId : lastInsertedParentId;
                    }

                    var relatedFieldItemInfo = new RelatedFieldItemInfo(0, relatedFieldId, itemName, itemValue, parentId, 0);
                    lastInsertedId       = DataProvider.RelatedFieldItemDao.Insert(relatedFieldItemInfo);
                    lastInsertedParentId = parentId;
                    lastInertedLevel     = level;
                }
            }
        }
        public void Update(RelatedFieldItemInfo info)
        {
            var parms = new IDataParameter[]
            {
                GetParameter(ParmItemName, DataType.VarChar, 255, info.ItemName),
                GetParameter(ParmItemValue, DataType.VarChar, 255, info.ItemValue),
                GetParameter(ParmId, DataType.Integer, info.Id)
            };

            ExecuteNonQuery(SqlUpdate, parms);

            //RelatedFieldManager.ClearCache();
        }
        public int Insert(RelatedFieldItemInfo info)
        {
            info.Taxis = GetMaxTaxis(info.ParentId) + 1;

            const string sqlString = "INSERT INTO siteserver_RelatedFieldItem (RelatedFieldID, ItemName, ItemValue, ParentID, Taxis) VALUES (@RelatedFieldID, @ItemName, @ItemValue, @ParentID, @Taxis)";

            var parms = new IDataParameter[]
            {
                GetParameter(ParmRelatedFieldId, DataType.Integer, info.RelatedFieldId),
                GetParameter(ParmItemName, DataType.VarChar, 255, info.ItemName),
                GetParameter(ParmItemValue, DataType.VarChar, 255, info.ItemValue),
                GetParameter(ParmParentId, DataType.Integer, info.ParentId),
                GetParameter(ParmTaxis, DataType.Integer, info.Taxis)
            };

            return(ExecuteNonQueryAndReturnId(TableName, nameof(RelatedFieldItemInfo.Id), sqlString, parms));

            //RelatedFieldManager.ClearCache();
        }
        public RelatedFieldItemInfo GetRelatedFieldItemInfo(int id)
        {
            RelatedFieldItemInfo info = null;

            string sqlString =
                $"SELECT ID, RelatedFieldID, ItemName, ItemValue, ParentID, Taxis FROM siteserver_RelatedFieldItem WHERE ID = {id}";

            using (var rdr = ExecuteReader(sqlString))
            {
                if (rdr.Read())
                {
                    var i = 0;
                    info = new RelatedFieldItemInfo(GetInt(rdr, i++), GetInt(rdr, i++), GetString(rdr, i++), GetString(rdr, i++), GetInt(rdr, i++), GetInt(rdr, i));
                }
                rdr.Close();
            }

            return(info);
        }
        public List <RelatedFieldItemInfo> GetRelatedFieldItemInfoList(int relatedFieldId, int parentId)
        {
            var list = new List <RelatedFieldItemInfo>();

            string sqlString =
                $"SELECT ID, RelatedFieldID, ItemName, ItemValue, ParentID, Taxis FROM siteserver_RelatedFieldItem WHERE RelatedFieldID = {relatedFieldId} AND ParentID = {parentId} ORDER BY Taxis";

            using (var rdr = ExecuteReader(sqlString))
            {
                while (rdr.Read())
                {
                    var i    = 0;
                    var info = new RelatedFieldItemInfo(GetInt(rdr, i++), GetInt(rdr, i++), GetString(rdr, i++), GetString(rdr, i++), GetInt(rdr, i++), GetInt(rdr, i));
                    list.Add(info);
                }
                rdr.Close();
            }

            return(list);
        }
Beispiel #7
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            bool isChanged;

            try
            {
                var itemNameArray = TbItemNames.Text.Split('\n');
                foreach (var item in itemNameArray)
                {
                    if (string.IsNullOrEmpty(item))
                    {
                        continue;
                    }

                    var itemName  = item.Trim();
                    var itemValue = itemName;

                    if (itemName.IndexOf('|') != -1)
                    {
                        itemValue = itemName.Substring(itemName.IndexOf('|') + 1);
                        itemName  = itemName.Substring(0, itemName.IndexOf('|'));
                    }

                    var itemInfo = new RelatedFieldItemInfo(0, _relatedFieldId, itemName, itemValue, _parentId, 0);
                    DataProvider.RelatedFieldItemDao.Insert(itemInfo);
                }

                isChanged = true;
            }
            catch
            {
                isChanged = false;
                FailMessage("添加字段项出错!");
            }

            if (isChanged)
            {
                LayerUtils.CloseAndRedirect(Page, PageRelatedFieldItem.GetRedirectUrl(SiteId, _relatedFieldId, _parentId, _level));
            }
        }
Beispiel #8
0
        public int Insert(RelatedFieldItemInfo info)
        {
            int id;

            info.Taxis = GetMaxTaxis(info.ParentID) + 1;

            var sqlString = "INSERT INTO siteserver_RelatedFieldItem (RelatedFieldID, ItemName, ItemValue, ParentID, Taxis) VALUES (@RelatedFieldID, @ItemName, @ItemValue, @ParentID, @Taxis)";

            var parms = new IDataParameter[]
            {
                GetParameter(ParmRelatedFieldId, EDataType.Integer, info.RelatedFieldID),
                GetParameter(ParmItemName, EDataType.NVarChar, 255, info.ItemName),
                GetParameter(ParmItemValue, EDataType.NVarChar, 255, info.ItemValue),
                GetParameter(ParmParentId, EDataType.Integer, info.ParentID),
                GetParameter(ParmTaxis, EDataType.Integer, info.Taxis)
            };

            using (var conn = GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        id = ExecuteNonQueryAndReturnId(trans, sqlString, parms);
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                }
            }

            return(id);

            //RelatedFieldManager.ClearCache();
        }