public static ModelDeleteStatus Delete(int modelID) { ContModelInfo cacheModelByID = ContModel.GetCacheModelByID(modelID); ModelDeleteStatus result; if (cacheModelByID == null) { result = ModelDeleteStatus.ModelNotExists; } else { int num = ContModel.IsModelRefing(modelID); if (num > 0) { result = (ModelDeleteStatus)num; } else if (BizBase.dbo.DeleteModel <ContModelInfo>(cacheModelByID)) { ContField.DeleteByModelID(modelID); BizBase.dbo.ExecSQL(" DROP TABLE " + cacheModelByID.TableName); CacheUtils.Del("JsonLeeCMS_CacheForGetContModel"); result = ModelDeleteStatus.Success; } else { CacheUtils.Del("JsonLeeCMS_CacheForGetContModel"); result = ModelDeleteStatus.Error; } } return(result); }
public static FieldAddState Add(ContFieldInfo field) { ContModelInfo cacheModelByID = ContModel.GetCacheModelByID(field.ModelID); FieldAddState result; if (cacheModelByID == null) { result = FieldAddState.ModelNotExists; } else { int value = BizBase.dbo.GetValue <int>(string.Concat(new object[] { "SELECT COUNT(*) FROM cms_ContField WHERE ModelID=", field.ModelID, " AND FieldName='", field.FieldName, "'" })); if (value > 0) { result = FieldAddState.FieldNameExists; } else { if (BizBase.dbo.InsertModel <ContFieldInfo>(field) > 0) { try { string text = field.DataType; if (string.Compare(text, "nvarchar", true) == 0) { object obj = text; text = string.Concat(new object[] { obj, "(", field.DataLength, ")" }); } TableManager.AddTableColumn(cacheModelByID.TableName, field.FieldName, text, true, field.DefaultValue); } catch { result = FieldAddState.CreateColumnError; return(result); } } CacheUtils.Del("JsonLeeCMS_CacheForGetContModel"); result = FieldAddState.Success; } } return(result); }
public static bool Update(ContFieldInfo field) { ContModelInfo cacheModelByID = ContModel.GetCacheModelByID(field.ModelID); ContFieldInfo dataById = ContField.GetDataById(field.AutoID); bool result; if (BizBase.dbo.UpdateModel <ContFieldInfo>(field)) { if (!dataById.IsSystem) { try { string text = field.DataType; if (string.Compare(text, "nvarchar", true) == 0) { object obj = text; text = string.Concat(new object[] { obj, "(", field.DataLength, ")" }); } TableManager.AlterTableColumn(cacheModelByID.TableName, dataById.FieldName, field.FieldName, text, true, field.DefaultValue); } catch (Exception ex) { throw ex; } } CacheUtils.Del("JsonLeeCMS_CacheForGetContModel"); result = true; } else { result = false; } return(result); }
public static bool CopyContent(int intContID) { ContentInfo dataById = Content.GetDataById(intContID); bool result; if (dataById != null) { ContModelInfo cacheModelByID = ContModel.GetCacheModelByID(dataById.ModelID); string strSQL = string.Concat(new object[] { "INSERT INTO cms_Content ( NodeID, NodeName, ModelID, TableName, Title, SubTitle, Summary, Author, Editor, Source, SourceUrl, Content, Attachment, TagKey, ContentImage, SeoKey, SeoDescription, Lang, Inputer, Sort, Status, AutoTimeStamp ) SELECT NodeID, NodeName, ModelID, TableName, '复制:'+Title, SubTitle, Summary, Author, Editor, Source, SourceUrl, Content, Attachment, TagKey, ContentImage, SeoKey, SeoDescription, Lang, '", Account.GetLoginAccount().AccountName, "', (SELECT MAX(Sort)+1 FROM cms_Content) AS CurrSort, 0, getdate() FROM cms_Content WHERE AutoID=", intContID, ";if @@rowcount>0 select @@IDENTITY" }); object @object = BizBase.dbo.GetObject(strSQL); int num = (@object == null) ? 0 : Convert.ToInt32(@object); if (num > 0) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(" INSERT INTO " + dataById.TableName + " ( "); IList <ContFieldInfo> customFieldListByModelID = ContField.GetCustomFieldListByModelID(cacheModelByID.AutoID); for (int i = 0; i < customFieldListByModelID.Count; i++) { if (customFieldListByModelID[i].FieldName != "AutoID") { if (i == customFieldListByModelID.Count - 1) { stringBuilder.Append(customFieldListByModelID[i].FieldName); } else { stringBuilder.Append(customFieldListByModelID[i].FieldName + ","); } } } stringBuilder.Append(" ) "); stringBuilder.Append(" SELECT "); for (int i = 0; i < customFieldListByModelID.Count; i++) { if (customFieldListByModelID[i].FieldName != "AutoID") { if (i == customFieldListByModelID.Count - 1) { if (customFieldListByModelID[i].FieldName.Equals("ContID")) { stringBuilder.Append(num.ToString()); } else { stringBuilder.Append(customFieldListByModelID[i].FieldName); } } else if (customFieldListByModelID[i].FieldName.Equals("ContID")) { stringBuilder.Append(num.ToString() + ","); } else { stringBuilder.Append(customFieldListByModelID[i].FieldName + ","); } } } stringBuilder.Append(string.Concat(new object[] { " FROM ", dataById.TableName, " WHERE ContID=", dataById.AutoID })); result = BizBase.dbo.ExecSQL(stringBuilder.ToString()); return(result); } } result = false; return(result); }
public static bool UpdateContent(ContentInfo content, Dictionary <string, ContFieldInfo> dicField) { bool result; if (content == null) { result = false; } else { ContModelInfo cacheModelByID = ContModel.GetCacheModelByID(content.ModelID); if (cacheModelByID == null) { result = false; } else { content.Title = Content.GetStringFromDic("Title", dicField); if (string.IsNullOrEmpty(content.Title)) { content.Title = "默认的标题"; } content.SubTitle = Content.GetStringFromDic("SubTitle", dicField); content.Summary = Content.GetStringFromDic("Summary", dicField); content.Author = Content.GetStringFromDic("Author", dicField); content.Editor = Content.GetStringFromDic("Editor", dicField); content.Source = Content.GetStringFromDic("Source", dicField); content.SourceUrl = Content.GetStringFromDic("SourceUrl", dicField); content.Content = Content.GetStringFromDic("Content", dicField); content.TagKey = Content.GetStringFromDic("TagKey", dicField); content.ContentImage = Content.GetStringFromDic("ContentImage", dicField); content.Attachment = Content.GetStringFromDic("Attachment", dicField); content.RelateContent = Content.GetStringFromDic("RelateContent", dicField); content.SeoKey = Content.GetStringFromDic("SeoKey", dicField); content.SeoDescription = Content.GetStringFromDic("SeoDescription", dicField); content.IsTop = Content.GetBoolFromDic("IsTop", dicField, false); content.IsRecommend = Content.GetBoolFromDic("IsRecommend", dicField, false); content.IsNew = Content.GetBoolFromDic("IsNew", dicField, false); content.TemplateFile = Content.GetStringFromDic("TemplateFile", dicField); content.Hit = Content.GetIntFromDic("Hit", dicField, 0); content.Sort = Content.GetIntFromDic("Sort", dicField, 999); content.AutoTimeStamp = Content.GetDateTimeFromDic("AutoTimeStamp", dicField, new DateTime(1900, 1, 1)); Content.Update(content); IList <ContFieldInfo> customFieldListByModelID = ContField.GetCustomFieldListByModelID(content.ModelID); foreach (ContFieldInfo current in customFieldListByModelID) { if (current.FieldName == "ContID") { current.Value = content.AutoID.ToString(); } else { current.Value = Content.GetStringFromDic(current.FieldName, dicField); } } if (Content.ExistsCustomTableData(cacheModelByID.TableName, content.AutoID)) { Content.UpdateCustomContent(content.AutoID, content.TableName, customFieldListByModelID); } else { Content.AddCustomContent(cacheModelByID, customFieldListByModelID); } result = true; } } return(result); }
public static int Add(ContentInfo content, Dictionary <string, ContFieldInfo> dicField) { NodeInfo cacheNodeById = Node.GetCacheNodeById(content.NodeID); int result; if (cacheNodeById == null) { result = 0; } else { ContModelInfo cacheModelByID = ContModel.GetCacheModelByID(cacheNodeById.ModelID); if (cacheModelByID == null) { result = 0; } else { content.NodeName = cacheNodeById.NodeName; content.ModelID = cacheModelByID.AutoID; content.TableName = cacheModelByID.TableName; content.Title = Content.GetStringFromDic("Title", dicField); if (string.IsNullOrEmpty(content.Title)) { content.Title = "默认的标题"; } content.SubTitle = Content.GetStringFromDic("SubTitle", dicField); content.Summary = Content.GetStringFromDic("Summary", dicField); content.Author = Content.GetStringFromDic("Author", dicField); content.Editor = Content.GetStringFromDic("Editor", dicField); content.Source = Content.GetStringFromDic("Source", dicField); content.SourceUrl = Content.GetStringFromDic("SourceUrl", dicField); content.Content = Content.GetStringFromDic("Content", dicField); content.TagKey = Content.GetStringFromDic("TagKey", dicField); content.ContentImage = Content.GetStringFromDic("ContentImage", dicField); content.Attachment = Content.GetStringFromDic("Attachment", dicField); content.RelateContent = Content.GetStringFromDic("RelateContent", dicField); content.SeoKey = Content.GetStringFromDic("SeoKey", dicField); content.SeoDescription = Content.GetStringFromDic("SeoDescription", dicField); content.IsTop = Content.GetBoolFromDic("IsTop", dicField, false); content.IsRecommend = Content.GetBoolFromDic("IsRecommend", dicField, false); content.IsNew = Content.GetBoolFromDic("IsNew", dicField, false); content.TemplateFile = Content.GetStringFromDic("TemplateFile", dicField); content.Hit = Content.GetIntFromDic("Hit", dicField, 0); content.Sort = Content.GetIntFromDic("Sort", dicField, 999); content.Inputer = Account.GetLoginAccount().AccountName; content.Lang = JObject.cultureLang; if (dicField.ContainsKey("AutoTimeStamp")) { content.AutoTimeStamp = Content.GetDateTimeFromDic("AutoTimeStamp", dicField, DateTime.Now); } else { content.AutoTimeStamp = DateTime.Now; } int num = Content.Add(content); IList <ContFieldInfo> customFieldListByModelID = ContField.GetCustomFieldListByModelID(cacheModelByID.AutoID); foreach (ContFieldInfo current in customFieldListByModelID) { if (current.FieldName == "ContID") { current.Value = num.ToString(); } else { current.Value = Content.GetStringFromDic(current.FieldName, dicField); } } Content.AddCustomContent(cacheModelByID, customFieldListByModelID); result = num; } } return(result); }