using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using YTSoft.DBUtility;
namespace YTSoft.BaseCallCenter.DAL
{
///
/// 数据访问类:T_Form_EntityAttribute
///
public partial class T_Form_EntityAttribute
{
public T_Form_EntityAttribute()
{ }
#region Method
///
/// 是否存在该记录
///
public bool Exists(int F_AttributeId)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from T_Form_EntityAttribute");
strSql.Append(" where F_AttributeId=@F_AttributeId");
SqlParameter[] parameters = {
new SqlParameter("@F_AttributeId", SqlDbType.Int,4)
};
parameters[0].Value = F_AttributeId;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
///
/// 增加一条数据
///
public int Add(YTSoft.BaseCallCenter.Model.T_Form_EntityAttribute model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into T_Form_EntityAttribute(");
strSql.Append("F_TypeId,F_DBTypeName,F_Name,F_DBFieldlName,F_Length,F_IsNullable,F_EntityId,F_DBTableName,F_DefaultValue,F_ColumnNumber,F_ValidForUpdateAPI,F_ValidForReadAPI,F_ValidForCreateAPI,F_VisibleToPlatform,F_IsPKAttribute,F_IsCustomField,F_DisplayMask,F_IsSortAttribute,F_PrecisionValue,F_IsIdentity,F_VersionNumber,F_AppDefaultValue,F_Locked,F_MaxLength,F_MinValue,F_MaxValue,F_LookupKey,F_LookupStyle,F_IsLookup,F_Des)");
strSql.Append(" values (");
strSql.Append("@F_TypeId,@F_DBTypeName,@F_Name,@F_DBFieldlName,@F_Length,@F_IsNullable,@F_EntityId,@F_DBTableName,@F_DefaultValue,@F_ColumnNumber,@F_ValidForUpdateAPI,@F_ValidForReadAPI,@F_ValidForCreateAPI,@F_VisibleToPlatform,@F_IsPKAttribute,@F_IsCustomField,@F_DisplayMask,@F_IsSortAttribute,@F_PrecisionValue,@F_IsIdentity,@F_VersionNumber,@F_AppDefaultValue,@F_Locked,@F_MaxLength,@F_MinValue,@F_MaxValue,@F_LookupKey,@F_LookupStyle,@F_IsLookup,@F_Des)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@F_TypeId", SqlDbType.Int,4),
new SqlParameter("@F_DBTypeName", SqlDbType.NVarChar,50),
new SqlParameter("@F_Name", SqlDbType.NVarChar,50),
new SqlParameter("@F_DBFieldlName", SqlDbType.NVarChar,50),
new SqlParameter("@F_Length", SqlDbType.Int,4),
new SqlParameter("@F_IsNullable", SqlDbType.Bit,1),
new SqlParameter("@F_EntityId", SqlDbType.Int,4),
new SqlParameter("@F_DBTableName", SqlDbType.NVarChar,50),
new SqlParameter("@F_DefaultValue", SqlDbType.NVarChar,50),
new SqlParameter("@F_ColumnNumber", SqlDbType.Int,4),
new SqlParameter("@F_ValidForUpdateAPI", SqlDbType.Bit,1),
new SqlParameter("@F_ValidForReadAPI", SqlDbType.Bit,1),
new SqlParameter("@F_ValidForCreateAPI", SqlDbType.Bit,1),
new SqlParameter("@F_VisibleToPlatform", SqlDbType.Bit,1),
new SqlParameter("@F_IsPKAttribute", SqlDbType.Bit,1),
new SqlParameter("@F_IsCustomField", SqlDbType.Bit,1),
new SqlParameter("@F_DisplayMask", SqlDbType.Int,4),
new SqlParameter("@F_IsSortAttribute", SqlDbType.Bit,1),
new SqlParameter("@F_PrecisionValue", SqlDbType.Int,4),
new SqlParameter("@F_IsIdentity", SqlDbType.Bit,1),
new SqlParameter("@F_VersionNumber", SqlDbType.Timestamp,8),
new SqlParameter("@F_AppDefaultValue", SqlDbType.Int,4),
new SqlParameter("@F_Locked", SqlDbType.Bit,1),
new SqlParameter("@F_MaxLength", SqlDbType.Int,4),
new SqlParameter("@F_MinValue", SqlDbType.Float,8),
new SqlParameter("@F_MaxValue", SqlDbType.Float,8),
new SqlParameter("@F_LookupKey", SqlDbType.NVarChar,50),
new SqlParameter("@F_LookupStyle", SqlDbType.NVarChar,50),
new SqlParameter("@F_IsLookup", SqlDbType.Bit,1),
new SqlParameter("@F_Des", SqlDbType.NVarChar,500)};
parameters[0].Value = model.F_TypeId;
parameters[1].Value = model.F_DBTypeName;
parameters[2].Value = model.F_Name;
parameters[3].Value = model.F_DBFieldlName;
parameters[4].Value = model.F_Length;
parameters[5].Value = model.F_IsNullable;
parameters[6].Value = model.F_EntityId;
parameters[7].Value = model.F_DBTableName;
parameters[8].Value = model.F_DefaultValue;
parameters[9].Value = model.F_ColumnNumber;
parameters[10].Value = model.F_ValidForUpdateAPI;
parameters[11].Value = model.F_ValidForReadAPI;
parameters[12].Value = model.F_ValidForCreateAPI;
parameters[13].Value = model.F_VisibleToPlatform;
parameters[14].Value = model.F_IsPKAttribute;
parameters[15].Value = model.F_IsCustomField;
parameters[16].Value = model.F_DisplayMask;
parameters[17].Value = model.F_IsSortAttribute;
parameters[18].Value = model.F_PrecisionValue;
parameters[19].Value = model.F_IsIdentity;
parameters[20].Value = null;
parameters[21].Value = model.F_AppDefaultValue;
parameters[22].Value = model.F_Locked;
parameters[23].Value = model.F_MaxLength;
parameters[24].Value = model.F_MinValue;
parameters[25].Value = model.F_MaxValue;
parameters[26].Value = model.F_LookupKey;
parameters[27].Value = model.F_LookupStyle;
parameters[28].Value = model.F_IsLookup;
parameters[29].Value = model.F_Des;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
///
/// 更新一条数据
///
public bool Update(YTSoft.BaseCallCenter.Model.T_Form_EntityAttribute model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update T_Form_EntityAttribute set ");
strSql.Append("F_TypeId=@F_TypeId,");
strSql.Append("F_DBTypeName=@F_DBTypeName,");
strSql.Append("F_Name=@F_Name,");
strSql.Append("F_DBFieldlName=@F_DBFieldlName,");
strSql.Append("F_Length=@F_Length,");
strSql.Append("F_IsNullable=@F_IsNullable,");
strSql.Append("F_EntityId=@F_EntityId,");
strSql.Append("F_DBTableName=@F_DBTableName,");
strSql.Append("F_DefaultValue=@F_DefaultValue,");
strSql.Append("F_ColumnNumber=@F_ColumnNumber,");
strSql.Append("F_ValidForUpdateAPI=@F_ValidForUpdateAPI,");
strSql.Append("F_ValidForReadAPI=@F_ValidForReadAPI,");
strSql.Append("F_ValidForCreateAPI=@F_ValidForCreateAPI,");
strSql.Append("F_VisibleToPlatform=@F_VisibleToPlatform,");
strSql.Append("F_IsPKAttribute=@F_IsPKAttribute,");
strSql.Append("F_IsCustomField=@F_IsCustomField,");
strSql.Append("F_DisplayMask=@F_DisplayMask,");
strSql.Append("F_IsSortAttribute=@F_IsSortAttribute,");
strSql.Append("F_PrecisionValue=@F_PrecisionValue,");
strSql.Append("F_IsIdentity=@F_IsIdentity,");
strSql.Append("F_AppDefaultValue=@F_AppDefaultValue,");
strSql.Append("F_Locked=@F_Locked,");
strSql.Append("F_MaxLength=@F_MaxLength,");
strSql.Append("F_MinValue=@F_MinValue,");
strSql.Append("F_MaxValue=@F_MaxValue,");
strSql.Append("F_LookupKey=@F_LookupKey,");
strSql.Append("F_LookupStyle=@F_LookupStyle,");
strSql.Append("F_IsLookup=@F_IsLookup,");
strSql.Append("F_Des=@F_Des");
strSql.Append(" where F_AttributeId=@F_AttributeId");
SqlParameter[] parameters = {
new SqlParameter("@F_TypeId", SqlDbType.Int,4),
new SqlParameter("@F_DBTypeName", SqlDbType.NVarChar,50),
new SqlParameter("@F_Name", SqlDbType.NVarChar,50),
new SqlParameter("@F_DBFieldlName", SqlDbType.NVarChar,50),
new SqlParameter("@F_Length", SqlDbType.Int,4),
new SqlParameter("@F_IsNullable", SqlDbType.Bit,1),
new SqlParameter("@F_EntityId", SqlDbType.Int,4),
new SqlParameter("@F_DBTableName", SqlDbType.NVarChar,50),
new SqlParameter("@F_DefaultValue", SqlDbType.NVarChar,50),
new SqlParameter("@F_ColumnNumber", SqlDbType.Int,4),
new SqlParameter("@F_ValidForUpdateAPI", SqlDbType.Bit,1),
new SqlParameter("@F_ValidForReadAPI", SqlDbType.Bit,1),
new SqlParameter("@F_ValidForCreateAPI", SqlDbType.Bit,1),
new SqlParameter("@F_VisibleToPlatform", SqlDbType.Bit,1),
new SqlParameter("@F_IsPKAttribute", SqlDbType.Bit,1),
new SqlParameter("@F_IsCustomField", SqlDbType.Bit,1),
new SqlParameter("@F_DisplayMask", SqlDbType.Int,4),
new SqlParameter("@F_IsSortAttribute", SqlDbType.Bit,1),
new SqlParameter("@F_PrecisionValue", SqlDbType.Int,4),
new SqlParameter("@F_IsIdentity", SqlDbType.Bit,1),
new SqlParameter("@F_AppDefaultValue", SqlDbType.Int,4),
new SqlParameter("@F_Locked", SqlDbType.Bit,1),
new SqlParameter("@F_MaxLength", SqlDbType.Int,4),
new SqlParameter("@F_MinValue", SqlDbType.Float,8),
new SqlParameter("@F_MaxValue", SqlDbType.Float,8),
new SqlParameter("@F_LookupKey", SqlDbType.NVarChar,50),
new SqlParameter("@F_LookupStyle", SqlDbType.NVarChar,50),
new SqlParameter("@F_IsLookup", SqlDbType.Bit,1),
new SqlParameter("@F_Des", SqlDbType.NVarChar,500),
new SqlParameter("@F_AttributeId", SqlDbType.Int,4)};
parameters[0].Value = model.F_TypeId;
parameters[1].Value = model.F_DBTypeName;
parameters[2].Value = model.F_Name;
parameters[3].Value = model.F_DBFieldlName;
parameters[4].Value = model.F_Length;
parameters[5].Value = model.F_IsNullable;
parameters[6].Value = model.F_EntityId;
parameters[7].Value = model.F_DBTableName;
parameters[8].Value = model.F_DefaultValue;
parameters[9].Value = model.F_ColumnNumber;
parameters[10].Value = model.F_ValidForUpdateAPI;
parameters[11].Value = model.F_ValidForReadAPI;
parameters[12].Value = model.F_ValidForCreateAPI;
parameters[13].Value = model.F_VisibleToPlatform;
parameters[14].Value = model.F_IsPKAttribute;
parameters[15].Value = model.F_IsCustomField;
parameters[16].Value = model.F_DisplayMask;
parameters[17].Value = model.F_IsSortAttribute;
parameters[18].Value = model.F_PrecisionValue;
parameters[19].Value = model.F_IsIdentity;
parameters[20].Value = model.F_AppDefaultValue;
parameters[21].Value = model.F_Locked;
parameters[22].Value = model.F_MaxLength;
parameters[23].Value = model.F_MinValue;
parameters[24].Value = model.F_MaxValue;
parameters[25].Value = model.F_LookupKey;
parameters[26].Value = model.F_LookupStyle;
parameters[27].Value = model.F_IsLookup;
parameters[28].Value = model.F_Des;
parameters[29].Value = model.F_AttributeId;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 删除一条数据
///
public bool Delete(int F_AttributeId)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from T_Form_EntityAttribute ");
strSql.Append(" where F_AttributeId=@F_AttributeId");
SqlParameter[] parameters = {
new SqlParameter("@F_AttributeId", SqlDbType.Int,4)
};
parameters[0].Value = F_AttributeId;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 批量删除数据
///
public bool DeleteList(string F_AttributeIdlist)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from T_Form_EntityAttribute ");
strSql.Append(" where F_AttributeId in (" + F_AttributeIdlist + ") ");
int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 得到一个对象实体
///
public YTSoft.BaseCallCenter.Model.T_Form_EntityAttribute GetModel(int F_AttributeId)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 F_AttributeId,F_TypeId,F_DBTypeName,F_Name,F_DBFieldlName,F_Length,F_IsNullable,F_EntityId,F_DBTableName,F_DefaultValue,F_ColumnNumber,F_ValidForUpdateAPI,F_ValidForReadAPI,F_ValidForCreateAPI,F_VisibleToPlatform,F_IsPKAttribute,F_IsCustomField,F_DisplayMask,F_IsSortAttribute,F_PrecisionValue,F_IsIdentity,F_VersionNumber,F_AppDefaultValue,F_Locked,F_MaxLength,F_MinValue,F_MaxValue,F_LookupKey,F_LookupStyle,F_IsLookup,F_Des from T_Form_EntityAttribute ");
strSql.Append(" where F_AttributeId=@F_AttributeId");
SqlParameter[] parameters = {
new SqlParameter("@F_AttributeId", SqlDbType.Int,4)
};
parameters[0].Value = F_AttributeId;
YTSoft.BaseCallCenter.Model.T_Form_EntityAttribute model = new YTSoft.BaseCallCenter.Model.T_Form_EntityAttribute();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["F_AttributeId"] != null && ds.Tables[0].Rows[0]["F_AttributeId"].ToString() != "")
{
model.F_AttributeId = int.Parse(ds.Tables[0].Rows[0]["F_AttributeId"].ToString());
}
if (ds.Tables[0].Rows[0]["F_TypeId"] != null && ds.Tables[0].Rows[0]["F_TypeId"].ToString() != "")
{
model.F_TypeId = int.Parse(ds.Tables[0].Rows[0]["F_TypeId"].ToString());
}
if (ds.Tables[0].Rows[0]["F_DBTypeName"] != null && ds.Tables[0].Rows[0]["F_DBTypeName"].ToString() != "")
{
model.F_DBTypeName = ds.Tables[0].Rows[0]["F_DBTypeName"].ToString();
}
if (ds.Tables[0].Rows[0]["F_Name"] != null && ds.Tables[0].Rows[0]["F_Name"].ToString() != "")
{
model.F_Name = ds.Tables[0].Rows[0]["F_Name"].ToString();
}
if (ds.Tables[0].Rows[0]["F_DBFieldlName"] != null && ds.Tables[0].Rows[0]["F_DBFieldlName"].ToString() != "")
{
model.F_DBFieldlName = ds.Tables[0].Rows[0]["F_DBFieldlName"].ToString();
}
if (ds.Tables[0].Rows[0]["F_Length"] != null && ds.Tables[0].Rows[0]["F_Length"].ToString() != "")
{
model.F_Length = int.Parse(ds.Tables[0].Rows[0]["F_Length"].ToString());
}
if (ds.Tables[0].Rows[0]["F_IsNullable"] != null && ds.Tables[0].Rows[0]["F_IsNullable"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["F_IsNullable"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_IsNullable"].ToString().ToLower() == "true"))
{
model.F_IsNullable = true;
}
else
{
model.F_IsNullable = false;
}
}
if (ds.Tables[0].Rows[0]["F_EntityId"] != null && ds.Tables[0].Rows[0]["F_EntityId"].ToString() != "")
{
model.F_EntityId = int.Parse(ds.Tables[0].Rows[0]["F_EntityId"].ToString());
}
if (ds.Tables[0].Rows[0]["F_DBTableName"] != null && ds.Tables[0].Rows[0]["F_DBTableName"].ToString() != "")
{
model.F_DBTableName = ds.Tables[0].Rows[0]["F_DBTableName"].ToString();
}
if (ds.Tables[0].Rows[0]["F_DefaultValue"] != null && ds.Tables[0].Rows[0]["F_DefaultValue"].ToString() != "")
{
model.F_DefaultValue = ds.Tables[0].Rows[0]["F_DefaultValue"].ToString();
}
if (ds.Tables[0].Rows[0]["F_ColumnNumber"] != null && ds.Tables[0].Rows[0]["F_ColumnNumber"].ToString() != "")
{
model.F_ColumnNumber = int.Parse(ds.Tables[0].Rows[0]["F_ColumnNumber"].ToString());
}
if (ds.Tables[0].Rows[0]["F_ValidForUpdateAPI"] != null && ds.Tables[0].Rows[0]["F_ValidForUpdateAPI"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["F_ValidForUpdateAPI"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_ValidForUpdateAPI"].ToString().ToLower() == "true"))
{
model.F_ValidForUpdateAPI = true;
}
else
{
model.F_ValidForUpdateAPI = false;
}
}
if (ds.Tables[0].Rows[0]["F_ValidForReadAPI"] != null && ds.Tables[0].Rows[0]["F_ValidForReadAPI"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["F_ValidForReadAPI"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_ValidForReadAPI"].ToString().ToLower() == "true"))
{
model.F_ValidForReadAPI = true;
}
else
{
model.F_ValidForReadAPI = false;
}
}
if (ds.Tables[0].Rows[0]["F_ValidForCreateAPI"] != null && ds.Tables[0].Rows[0]["F_ValidForCreateAPI"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["F_ValidForCreateAPI"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_ValidForCreateAPI"].ToString().ToLower() == "true"))
{
model.F_ValidForCreateAPI = true;
}
else
{
model.F_ValidForCreateAPI = false;
}
}
if (ds.Tables[0].Rows[0]["F_VisibleToPlatform"] != null && ds.Tables[0].Rows[0]["F_VisibleToPlatform"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["F_VisibleToPlatform"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_VisibleToPlatform"].ToString().ToLower() == "true"))
{
model.F_VisibleToPlatform = true;
}
else
{
model.F_VisibleToPlatform = false;
}
}
if (ds.Tables[0].Rows[0]["F_IsPKAttribute"] != null && ds.Tables[0].Rows[0]["F_IsPKAttribute"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["F_IsPKAttribute"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_IsPKAttribute"].ToString().ToLower() == "true"))
{
model.F_IsPKAttribute = true;
}
else
{
model.F_IsPKAttribute = false;
}
}
if (ds.Tables[0].Rows[0]["F_IsCustomField"] != null && ds.Tables[0].Rows[0]["F_IsCustomField"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["F_IsCustomField"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_IsCustomField"].ToString().ToLower() == "true"))
{
model.F_IsCustomField = true;
}
else
{
model.F_IsCustomField = false;
}
}
if (ds.Tables[0].Rows[0]["F_DisplayMask"] != null && ds.Tables[0].Rows[0]["F_DisplayMask"].ToString() != "")
{
model.F_DisplayMask = int.Parse(ds.Tables[0].Rows[0]["F_DisplayMask"].ToString());
}
if (ds.Tables[0].Rows[0]["F_IsSortAttribute"] != null && ds.Tables[0].Rows[0]["F_IsSortAttribute"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["F_IsSortAttribute"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_IsSortAttribute"].ToString().ToLower() == "true"))
{
model.F_IsSortAttribute = true;
}
else
{
model.F_IsSortAttribute = false;
}
}
if (ds.Tables[0].Rows[0]["F_PrecisionValue"] != null && ds.Tables[0].Rows[0]["F_PrecisionValue"].ToString() != "")
{
model.F_PrecisionValue = int.Parse(ds.Tables[0].Rows[0]["F_PrecisionValue"].ToString());
}
if (ds.Tables[0].Rows[0]["F_IsIdentity"] != null && ds.Tables[0].Rows[0]["F_IsIdentity"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["F_IsIdentity"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_IsIdentity"].ToString().ToLower() == "true"))
{
model.F_IsIdentity = true;
}
else
{
model.F_IsIdentity = false;
}
}
if (ds.Tables[0].Rows[0]["F_AppDefaultValue"] != null && ds.Tables[0].Rows[0]["F_AppDefaultValue"].ToString() != "")
{
model.F_AppDefaultValue = int.Parse(ds.Tables[0].Rows[0]["F_AppDefaultValue"].ToString());
}
if (ds.Tables[0].Rows[0]["F_Locked"] != null && ds.Tables[0].Rows[0]["F_Locked"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["F_Locked"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_Locked"].ToString().ToLower() == "true"))
{
model.F_Locked = true;
}
else
{
model.F_Locked = false;
}
}
if (ds.Tables[0].Rows[0]["F_MaxLength"] != null && ds.Tables[0].Rows[0]["F_MaxLength"].ToString() != "")
{
model.F_MaxLength = int.Parse(ds.Tables[0].Rows[0]["F_MaxLength"].ToString());
}
if (ds.Tables[0].Rows[0]["F_MinValue"] != null && ds.Tables[0].Rows[0]["F_MinValue"].ToString() != "")
{
model.F_MinValue = decimal.Parse(ds.Tables[0].Rows[0]["F_MinValue"].ToString());
}
if (ds.Tables[0].Rows[0]["F_MaxValue"] != null && ds.Tables[0].Rows[0]["F_MaxValue"].ToString() != "")
{
model.F_MaxValue = decimal.Parse(ds.Tables[0].Rows[0]["F_MaxValue"].ToString());
}
if (ds.Tables[0].Rows[0]["F_LookupKey"] != null && ds.Tables[0].Rows[0]["F_LookupKey"].ToString() != "")
{
model.F_LookupKey = ds.Tables[0].Rows[0]["F_LookupKey"].ToString();
}
if (ds.Tables[0].Rows[0]["F_LookupStyle"] != null && ds.Tables[0].Rows[0]["F_LookupStyle"].ToString() != "")
{
model.F_LookupStyle = ds.Tables[0].Rows[0]["F_LookupStyle"].ToString();
}
if (ds.Tables[0].Rows[0]["F_IsLookup"] != null && ds.Tables[0].Rows[0]["F_IsLookup"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["F_IsLookup"].ToString() == "1") || (ds.Tables[0].Rows[0]["F_IsLookup"].ToString().ToLower() == "true"))
{
model.F_IsLookup = true;
}
else
{
model.F_IsLookup = false;
}
}
if (ds.Tables[0].Rows[0]["F_Des"] != null && ds.Tables[0].Rows[0]["F_Des"].ToString() != "")
{
model.F_Des = ds.Tables[0].Rows[0]["F_Des"].ToString();
}
return model;
}
else
{
return null;
}
}
///
/// 获得数据列表
///
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select F_AttributeId,F_TypeId,F_DBTypeName,F_Name,F_DBFieldlName,F_Length,F_IsNullable,F_EntityId,F_DBTableName,F_DefaultValue,F_ColumnNumber,F_ValidForUpdateAPI,F_ValidForReadAPI,F_ValidForCreateAPI,F_VisibleToPlatform,F_IsPKAttribute,F_IsCustomField,F_DisplayMask,F_IsSortAttribute,F_PrecisionValue,F_IsIdentity,F_VersionNumber,F_AppDefaultValue,F_Locked,F_MaxLength,F_MinValue,F_MaxValue,F_LookupKey,F_LookupStyle,F_IsLookup,F_Des ");
strSql.Append(" FROM T_Form_EntityAttribute ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return DbHelperSQL.Query(strSql.ToString());
}
///
/// 获得前几行数据
///
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append(" F_AttributeId,F_TypeId,F_DBTypeName,F_Name,F_DBFieldlName,F_Length,F_IsNullable,F_EntityId,F_DBTableName,F_DefaultValue,F_ColumnNumber,F_ValidForUpdateAPI,F_ValidForReadAPI,F_ValidForCreateAPI,F_VisibleToPlatform,F_IsPKAttribute,F_IsCustomField,F_DisplayMask,F_IsSortAttribute,F_PrecisionValue,F_IsIdentity,F_VersionNumber,F_AppDefaultValue,F_Locked,F_MaxLength,F_MinValue,F_MaxValue,F_LookupKey,F_LookupStyle,F_IsLookup,F_Des ");
strSql.Append(" FROM T_Form_EntityAttribute ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
///
/// 获取记录总数
///
public int GetRecordCount(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) FROM T_Form_EntityAttribute ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
object obj = DbHelperSQL.GetSingle(strSql.ToString());
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
///
/// 分页获取数据列表
///
public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT * FROM ( ");
strSql.Append(" SELECT ROW_NUMBER() OVER (");
if (!string.IsNullOrEmpty(orderby.Trim()))
{
strSql.Append("order by T." + orderby);
}
else
{
strSql.Append("order by T.F_AttributeId desc");
}
strSql.Append(")AS Row, T.* from T_Form_EntityAttribute T ");
if (!string.IsNullOrEmpty(strWhere.Trim()))
{
strSql.Append(" WHERE " + strWhere);
}
strSql.Append(" ) TT");
strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
return DbHelperSQL.Query(strSql.ToString());
}
/*
///
/// 分页获取数据列表
///
public DataSet GetList(int PageSize,int PageIndex,string strWhere)
{
SqlParameter[] parameters = {
new SqlParameter("@tblName", SqlDbType.VarChar, 255),
new SqlParameter("@fldName", SqlDbType.VarChar, 255),
new SqlParameter("@PageSize", SqlDbType.Int),
new SqlParameter("@PageIndex", SqlDbType.Int),
new SqlParameter("@IsReCount", SqlDbType.Bit),
new SqlParameter("@OrderType", SqlDbType.Bit),
new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
};
parameters[0].Value = "T_Form_EntityAttribute";
parameters[1].Value = "F_AttributeId";
parameters[2].Value = PageSize;
parameters[3].Value = PageIndex;
parameters[4].Value = 0;
parameters[5].Value = 0;
parameters[6].Value = strWhere;
return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
}*/
#endregion Method
///
/// 增加一条数据
///
public int AddTran(Model.T_Form_EntityAttribute model)
{
try
{
int res = -1;
StringBuilder strSql = new StringBuilder();
StringBuilder strFildSql = new StringBuilder();
using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
{
if (conn.State.ToString() != "Open")
conn.Open();
///设置隔离级别,启动数据库事务
SqlTransaction trans = conn.BeginTransaction(IsolationLevel.ReadCommitted);
SqlCommand cmd = new SqlCommand();
try
{
strSql.Append("Declare @err int;declare @res int; declare @count int;declare @F_AttributeId int; set @F_AttributeId=0; set @err=0;set @res=0;set @count=0;");
//判断实体中是否存在此属性名称和数据字段名称
strSql.Append("select @count=count(F_Name) from T_Form_EntityAttribute where F_EntityId=" + model.F_EntityId.ToString() + " and F_Name='" + model.F_Name.Trim() + "' ");
strSql.Append("if @count>0");
strSql.Append("begin set @res=-3 end else begin ");
strSql.Append("set @count=0;select @count=count(F_DBFieldlName) from T_Form_EntityAttribute where F_EntityId=" + model.F_EntityId.ToString() + " and F_DBFieldlName='" + model.F_DBFieldlName.Trim() + "' ");
strSql.Append("if @count>0");
strSql.Append("begin set @res=-2 end else begin ");
#region 属性信息
strSql.Append("insert into T_Form_EntityAttribute(");
strSql.Append("F_TypeId,F_DBTypeName,F_Name,F_DBFieldlName,F_Length,F_IsNullable,F_EntityId,F_DBTableName,F_DefaultValue,F_ColumnNumber,F_ValidForUpdateAPI,F_ValidForReadAPI,F_ValidForCreateAPI,F_VisibleToPlatform,F_IsPKAttribute,F_IsCustomField,F_DisplayMask,F_IsSortAttribute,F_PrecisionValue,F_IsIdentity,F_AppDefaultValue,F_Locked,F_MaxLength,F_MinValue,F_MaxValue,F_LookupKey,F_LookupStyle,F_IsLookup,F_Des)");
strSql.Append(" values (");
strSql.Append("@F_TypeId,@F_DBTypeName,@F_Name,@F_DBFieldlName,@F_Length,@F_IsNullable,@F_EntityId,@F_DBTableName,@F_DefaultValue,@F_ColumnNumber,@F_ValidForUpdateAPI,@F_ValidForReadAPI,@F_ValidForCreateAPI,@F_VisibleToPlatform,@F_IsPKAttribute,@F_IsCustomField,@F_DisplayMask,@F_IsSortAttribute,@F_PrecisionValue,@F_IsIdentity,@F_AppDefaultValue,@F_Locked,@F_MaxLength,@F_MinValue,@F_MaxValue,@F_LookupKey,@F_LookupStyle,@F_IsLookup,@F_Des)");
strSql.Append(";select @F_AttributeId=@@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@F_TypeId", SqlDbType.Int,4),
new SqlParameter("@F_DBTypeName", SqlDbType.NVarChar,50),
new SqlParameter("@F_Name", SqlDbType.NVarChar,50),
new SqlParameter("@F_DBFieldlName", SqlDbType.NVarChar,50),
new SqlParameter("@F_Length", SqlDbType.Int,4),
new SqlParameter("@F_IsNullable", SqlDbType.Bit,1),
new SqlParameter("@F_EntityId", SqlDbType.Int,4),
new SqlParameter("@F_DBTableName", SqlDbType.NVarChar,50),
new SqlParameter("@F_DefaultValue", SqlDbType.NVarChar,50),
new SqlParameter("@F_ColumnNumber", SqlDbType.Int,4),
new SqlParameter("@F_ValidForUpdateAPI", SqlDbType.Bit,1),
new SqlParameter("@F_ValidForReadAPI", SqlDbType.Bit,1),
new SqlParameter("@F_ValidForCreateAPI", SqlDbType.Bit,1),
new SqlParameter("@F_VisibleToPlatform", SqlDbType.Bit,1),
new SqlParameter("@F_IsPKAttribute", SqlDbType.Bit,1),
new SqlParameter("@F_IsCustomField", SqlDbType.Bit,1),
new SqlParameter("@F_DisplayMask", SqlDbType.Int,4),
new SqlParameter("@F_IsSortAttribute", SqlDbType.Bit,1),
new SqlParameter("@F_PrecisionValue", SqlDbType.Int,4),
new SqlParameter("@F_IsIdentity", SqlDbType.Bit,1),
new SqlParameter("@F_AppDefaultValue", SqlDbType.Int,4),
new SqlParameter("@F_Locked", SqlDbType.Bit,1),
new SqlParameter("@F_MaxLength", SqlDbType.Int,4),
new SqlParameter("@F_MinValue", SqlDbType.Float,8),
new SqlParameter("@F_MaxValue", SqlDbType.Float,8),
new SqlParameter("@F_LookupKey", SqlDbType.NVarChar,50),
new SqlParameter("@F_LookupStyle", SqlDbType.NVarChar,50),
new SqlParameter("@F_IsLookup", SqlDbType.Bit,1),
new SqlParameter("@F_Des", SqlDbType.NVarChar,500)};
parameters[0].Value = model.F_TypeId;
parameters[1].Value = model.F_DBTypeName;
parameters[2].Value = model.F_Name;
parameters[3].Value = model.F_DBFieldlName;
parameters[4].Value = model.F_Length;
parameters[5].Value = model.F_IsNullable;
parameters[6].Value = model.F_EntityId;
parameters[7].Value = model.F_DBTableName;
parameters[8].Value = model.F_DefaultValue;
parameters[9].Value = model.F_ColumnNumber;
parameters[10].Value = model.F_ValidForUpdateAPI;
parameters[11].Value = model.F_ValidForReadAPI;
parameters[12].Value = model.F_ValidForCreateAPI;
parameters[13].Value = model.F_VisibleToPlatform;
parameters[14].Value = model.F_IsPKAttribute;
parameters[15].Value = model.F_IsCustomField;
parameters[16].Value = model.F_DisplayMask;
parameters[17].Value = model.F_IsSortAttribute;
parameters[18].Value = model.F_PrecisionValue;
parameters[19].Value = model.F_IsIdentity;
parameters[20].Value = model.F_AppDefaultValue;
parameters[21].Value = model.F_Locked;
parameters[22].Value = model.F_MaxLength;
parameters[23].Value = model.F_MinValue;
parameters[24].Value = model.F_MaxValue;
parameters[25].Value = model.F_LookupKey;
parameters[26].Value = model.F_LookupStyle;
parameters[27].Value = model.F_IsLookup;
parameters[28].Value = model.F_Des;
strSql.Append(" SELECT @err=@err+@@ERROR; ");
string isnull = " NULL ";
string ispkey = "";
string defaultvalue = "";
string isautoadd = "";
string fieldtype = model.F_DBTypeName;
if (model.F_Length != null)
{
fieldtype = fieldtype + "(" + model.F_Length.ToString() + ")";
}
if (model.F_IsNullable)
{
isnull = " NULL ";
}
else
{
isnull = " NOT NULL ";
}
if (model.F_IsPKAttribute)
{
ispkey = " primary key ";
}
else
{
ispkey = "";
}
if (model.F_IsIdentity)
{
isautoadd = " identity(1,1) ";
}
else
{
isautoadd = "";
}
if (!string.IsNullOrEmpty(model.F_DefaultValue))
{
defaultvalue = " default(" + model.F_DefaultValue.Trim() + ") ";
}
strFildSql.Append("[" + model.F_DBFieldlName + "] " + fieldtype + isnull + ispkey + isautoadd + defaultvalue + " ");
//遍历绑定参数
foreach (SqlParameter parm in parameters)
{
if ((parm.Direction == ParameterDirection.InputOutput || parm.Direction == ParameterDirection.Input) &&
(parm.Value == null))
{
parm.Value = DBNull.Value;
}
cmd.Parameters.Add(parm);
}
#endregion
#region 创建表
strSql.Append("ALTER TABLE [dbo].[" + model.F_DBTableName + "] ADD ");
strSql.Append(strFildSql.ToString());
strSql.Append("");
strSql.Append(" SELECT @err=@err+@@ERROR; ");
#endregion
#region 执行命令
cmd.CommandType = CommandType.Text;
cmd.Connection = trans.Connection;
cmd.Transaction = trans;
strSql.Append(" end end ");
cmd.CommandText = strSql.Append("SELECT @err,@res").ToString();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
rdr.Read();
// 如果错误的数量不为零, 抛出异常终止操作
if (rdr.GetInt32(0) != 0)
{
//throw new ApplicationException("数据插入错误 —— 回滚原因");
trans.Rollback();
res = -1;
}
else
{
res = rdr.GetInt32(1);
}
}
///提交事务
trans.Commit();
cmd.Parameters.Clear();
#endregion
}
catch
{
res = -1;
///事务回滚
trans.Rollback();
//throw new ApplicationException(e.Message);
}
finally
{
strSql = null;
conn.Close();
conn.Dispose();
}
}
return res;
}
catch
{
return -1;
}
}
}
}