/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Everest.Library.Data.Rule;
using Everest.Library.ExtensionMethod;
using System.Collections.Specialized;
namespace Everest.CmsServices.Models{
public class DetailColumn
{
public Guid UUID { get; set; }
public int ColumnId { get; set; }
public string ColumnName { get; set; }
public string Label { get; set; }
public string DataType { get; set; }
public bool? AllowNull { get; set; }
public int? Length { get; set; }
public int? Order { get; set; }
public bool? Queryable { get; set; }
public bool? Modifiable { get; set; }
public string ControlType { get; set; }
public string ValidatorGroup { get; set; }
public UniqueName ValidatorGroupUniqueName
{
private get
{
return null;
}
set
{
this.ValidatorGroup = value.ToString();
}
}
public int? RefrenceSchemaId { get; set; }
public int? RefrenceNameColumnId { get; set; }
public string Items { get; set; }
public string DefaultValue { get; set; }
public int IntSortOrder { get; set; }
public string SortOrder
{
get
{
return ((SortOrder)IntSortOrder).ToString();
}
}
public bool? Indexable { get; set; }
public bool? VisibleInList { get; set; }
public Guid OriginalUUID { get; set; }
public string VType { get; set; }
public string Tpl { get; set; }
public string Tooltip { get; set; }
}
public partial class Cms_Column : IRuleEntity
{
public Cms_Column()
{
this.UUID = Guid.NewGuid();
this.OriginalUUID = this.UUID;
this.SortOrder = -1;
}
public Cms_Column(string columnName, string label, ColumnDataType dataType, ControlType controlType)
: this()
{
this.ColumnName = columnName;
this.Label = label;
this.DataType = dataType.ToString();
this.ControlType = controlType.ToString();
}
public static Cms_Column CreateCms_Column(IEverestCmsDataContext dataContext, NameValueCollection dic)
{
//bool isBlank = true;
//foreach (var value in dic.)
//{
// if (StringExtensions.IsNullOrEmptyTrim(value))
// {
// isBlank = true;
// }
// else
// {
// isBlank = false;
// break;
// }
//}
//if (isBlank)
//{
// return null;
//}
Cms_Column column = new Cms_Column();
//set the OriginalUUID is used when update the schema,determine if is the column is added or deleted.
column.OriginalUUID = column.UUID;
if (!StringExtensions.IsNullOrEmptyTrim(dic["OriginalUUID"]))
{
column.OriginalUUID = new Guid(dic["OriginalUUID"]);
}
column.ColumnName = dic["ColumnName"];
column.Label = dic["Label"];
column.DataType = dic["DataType"];
//Length????
if (!StringExtensions.IsNullOrEmptyTrim(dic["Length"]))
{
column.Length = int.Parse(dic["Length"]);
}
column.ControlType = dic["ControlType"];
if (column.ControlType.ToLower() == "file")
{
column.DataType = ColumnDataType.String.ToString();
}
column.Items = dic["Items"];
column.DefaultValue = dic["DefaultValue"];
if (!StringExtensions.IsNullOrEmptyTrim(dic["VisibleInList"]))
{
column.VisibleInList = bool.Parse(dic["VisibleInList"]);
}
if (!StringExtensions.IsNullOrEmptyTrim(dic["Queryable"]))
{
column.Queryable = bool.Parse(dic["Queryable"]);
}
if (!StringExtensions.IsNullOrEmptyTrim(dic["Indexable"]))
{
column.Indexable = bool.Parse(dic["Indexable"]);
}
if (!StringExtensions.IsNullOrEmptyTrim(dic["AllowNull"]))
{
column.AllowNull = bool.Parse(dic["AllowNull"]);
}
if (!StringExtensions.IsNullOrEmptyTrim(dic["Modifiable"]))
{
column.Modifiable = bool.Parse(dic["Modifiable"]);
}
if (!StringExtensions.IsNullOrEmptyTrim(dic["ValidatorGroup"]))
{
UniqueName uniqueName = new UniqueName(dic["ValidatorGroup"]);
column.Cms_ValidatorGroup = dataContext.QueryValidatorGroup(uniqueName.ApplicationName, uniqueName.ItemName).FirstOrDefault();
}
if (!StringExtensions.IsNullOrEmptyTrim(dic["SortOrder"]))
{
column.SortOrder = (int)(SortOrder)Enum.Parse(typeof(SortOrder), (dic["SortOrder"]));
}
else
{
column.SortOrder = (int)System.Data.SqlClient.SortOrder.Unspecified;
}
if (!StringExtensions.IsNullOrEmptyTrim(dic["VType"]))
{
column.VType = dic["VType"].ToString();
}
if (!StringExtensions.IsNullOrEmptyTrim(dic["Tpl"]))
{
column.Tpl = dic["Tpl"].ToString();
}
if (!StringExtensions.IsNullOrEmptyTrim(dic["Tooltip"]))
{
column.Tooltip = dic["Tooltip"].ToString();
}
return column;
}
#region IRuleEntity Members
public IEnumerable<RuleViolation> GetRuleViolations()
{
List<RuleViolation> violations = new List<RuleViolation>();
//if (StringExtensions.IsNullOrEmptyTrim(column.ColumnName))
//{
// resultData.AddError("FormSchemaName", string.Format(Resources.Coluns, i + 1, "ColumnName"));
//}
//if (StringExtensions.IsNullOrEmptyTrim(column.DataType))
//{
// resultData.AddError("FormSchemaName", string.Format(Resources.Coluns, i + 1, "DataType"));
//}
//if (StringExtensions.IsNullOrEmptyTrim(column.ControlType))
//{
// resultData.AddError("FormSchemaName", string.Format(Resources.Coluns, i + 1, "ControlType"));
//}
return violations;
}
#endregion
}
}
|