123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Data;
- using SysBaseLibs;
- namespace SysDataLibs
- {
- public class rsDDColumn
- {
- // private
- private string _ColumnId = "";
- private string _ColumnName = "";
- private int _Width = 0;
- //private int _ColumnLength = 0;
- private rsDataType _DataType = null;
- private bool _IsAuto = false;
- private bool _IsPrimaryKey = false;
- private bool _isNull = true;
- private DataRow _DataRow=null;
- private string _ColumnDesc = "";
- private string _DefValue = "";
- private bool _IsVisable = false;
- private int _Sequence = -1;
- private string _RelationColumn = "";
- private Dictionary<string,object> _SaveObject = null;
- private string _DisplayValue = "";
- private string _IsSelect = "Y";
- private string _Format = "";
-
- private DBConnSql _DBConn = null;
- public rsDDColumn(DataRow poRow)
- {
- _DataRow = poRow;
- if (_DataRow != null)
- {
- _ColumnId = _DataRow["ColumnId"].ToString().Trim();
- _DataType = new rsDataType(_DataRow["DataType"].ToString());
- _DataType.ColLength = Utils.ValI(_DataRow["CharNum"].ToString());
- _DataType.ColPrecision = Utils.ValI(_DataRow["ColPrecision"].ToString());
- _DataType.ColDecimal = Utils.ValI(_DataRow["ColDecimal"].ToString());
-
- _IsAuto = UtilStr.StrToBool(_DataRow["AutoGen"].ToString());
- _IsPrimaryKey = UtilStr.StrToBool(_DataRow["PrimaryKey"].ToString());
- _isNull = UtilStr.StrToBool(_DataRow["AllowNull"].ToString());
- _ColumnDesc = _DataRow["ColDesc"].ToString();
- if (_DataRow["DefValue"] != null)
- _DefValue = _DataRow["DefValue"].ToString();
-
- if (_DefValue.Trim().Length == 0)
- _DefValue = _DataType.DBEmptyValue;
- if (_DataRow["width"] != null)
- _Width = Utils.ValI(_DataRow["width"].ToString());
-
- if (_DataRow["IsVisable"] != null)
- _IsVisable = UtilStr.StrToBool(_DataRow["IsVisable"].ToString());
- if (_DataRow["Sequence"] != null)
- _Sequence = Utils.ValI(_DataRow["Sequence"].ToString());
- if (_DataRow["ColumnName"] != null)
- _ColumnName = _DataRow["ColumnName"].ToString().Trim();
- if (_DataRow["RelationColumns"] != null)
- _RelationColumn = _DataRow["RelationColumns"].ToString().Trim();
- if (_DataRow["DisplayValue"] != null)
- _DisplayValue = _DataRow["DisplayValue"].ToString().Trim();
- if (_DataRow["IsSelect"] != null)
- _IsSelect = _DataRow["IsSelect"].ToString().Trim();
- if (_DataRow["Format"] != null)
- _Format = _DataRow["Format"].ToString().Trim();
- }
- }
- public rsDDColumn(string pcColumnId, string pcColumnName, int piWidth,
- int piColumnLength, string pcDataType, bool pbIsAuto, bool pbIsPrimaryKey,bool pbisNull)
- {
- _ColumnId = pcColumnId;
- _ColumnName = pcColumnName;
- _Width = piWidth;
- _DataType.ColLength = piColumnLength;
- _DataType = new rsDataType(pcDataType);
- _IsAuto = pbIsAuto;
- _IsPrimaryKey = pbIsPrimaryKey;
- _isNull = pbisNull;
-
- }
- /// <summary>
- /// 字段名称
- /// </summary>
- public string ColumnName
- {
- get {
- return _ColumnName;
- }
- set { _ColumnName = value; }
- }
- /// <summary>
- /// 字段编号
- /// </summary>
- public string ColumnId
- {
- get
- {
- return _ColumnId;
- }
- }
- /// <summary>
- /// 字段显示宽度
- /// </summary>
- public int Width
- {
- get { return _Width; }
- set { _Width = value; }
- }
- /// <summary>
- /// 字段长度
- /// </summary>
- public int ColumnLength
- {
- get { return _DataType.ColLength; }
- }
- /// <summary>
- /// 字段类型
- /// </summary>
- public rsDataType DataType
- {
- get { return _DataType; }
- }
- /// <summary>
- /// 是否自动增长
- /// </summary>
- public bool IsAuto
- {
- get { return _IsAuto; }
- }
- /// <summary>
- /// 是否是主键
- /// </summary>
- public bool IsPrimaryKey
- {
- get { return _IsPrimaryKey; }
- }
- /// <summary>
- /// 是否可见
- /// </summary>
- public bool IsVisable
- {
- get { return _IsVisable; }
- set { _IsVisable = value; }
- }
- /// <summary>
- /// 是否是数字
- /// </summary>
- public bool IsNum
- {
- get
- {
- return _DataType.IsNumeric;
- }
- }
- /// <summary>
- /// 字段排序
- /// </summary>
- public int Sequence
- {
- get { return _Sequence; }
- }
- /// <summary>
- /// 关联的字段
- /// </summary>
- public string RelationColunm
- {
- get { return _RelationColumn; }
- }
- /// <summary>
- /// 显示的字段 如[[1,男],[0,女]]
- /// </summary>
- public string DisplayValue
- {
- get { return _DisplayValue; }
- set { _DisplayValue = value; }
- }
- /// <summary>
- /// 进行自动拼装sql 语句的时候,该字段是否参与
- /// </summary>
- public string IsSelect
- {
- get { return _IsSelect; }
- set { _IsSelect = value; }
- }
- /// <summary>
- /// 字段数据格式化,主要针对 日期 和 数值
- /// </summary>
- public string Format
- {
- get { return _Format; }
- set { _Format = value; }
- }
- public void putValue(string pcKey, object poValue)
- {
- if (_SaveObject == null)
- _SaveObject = new Dictionary<string, object>();
- if (_SaveObject.ContainsKey(pcKey))
- _SaveObject[pcKey] = poValue;
- else
- _SaveObject.Add(pcKey, poValue);
- }
- public string GetValue(string pcKey)
- {
- string lcRetVal = "";
- object loObj = GetValueObj(pcKey);
- if (loObj != null)
- lcRetVal = loObj.ToString();
- return lcRetVal;
- }
- public object GetValueObj(string pcKey)
- {
- object loRetVal = null;
- if (_SaveObject != null && _SaveObject.ContainsKey(pcKey))
- {
- loRetVal = _SaveObject[pcKey];
- }
- return loRetVal;
- }
- private rsQuery _RelationTable = null;
- private string _RelationTableId = "";
- private string _RelationColumnId = "";
- private string GetTableId
- {
- get
- {
- if (_RelationTableId == "")
- {
- if (_RelationColumn != null && _RelationColumn.Trim().Length > 0)
- {
- _RelationTableId = DALibs.GetTableId(_RelationColumn);
- }
- }
- return _RelationTableId;
- }
- }
- private string GetColumnId
- {
- get
- {
- if (_RelationColumnId == "")
- if (_RelationColumn != null && _RelationColumn.Trim().Length > 0)
- {
- _RelationColumnId = DALibs.GetColumnId(_RelationColumn);
- }
- return _RelationColumnId;
- }
- }
- /// <summary>
- ///
- /// </summary>
- private Dictionary<string, string> _DisplayValues = null;
- /// <summary>
- /// 获取字段的显示值 比如在表 DisplayValue 定义 [1:男],[2:女] 则 传递 1 返回 男
- /// </summary>
- /// <param name="pcValue"></param>
- /// <returns></returns>
- public string GetDisplayValue(string pcValue)
- {
- string lcRetVal = pcValue;
- if (_DisplayValues == null)
- {
- if (_DisplayValue.Trim().Length > 0)
- {
- Array loArr = UtilStr.StrToArray(_DisplayValue);
- if (loArr != null && loArr.Length > 0)
- {
- _DisplayValues = new Dictionary<string, string>();
- foreach (string lcStr in loArr)
- {
- Array loArr2 = UtilStr.StrToArrayEx(lcStr, ":");
- if (loArr2 != null && loArr2.Length == 2)
- {
- string lcKey = UtilStr.UAndT(loArr2.GetValue(0).ToString().Trim());
- if (!_DisplayValues.ContainsKey(lcKey))
- _DisplayValues.Add(loArr2.GetValue(0).ToString(), loArr2.GetValue(1).ToString());
- else
- _DisplayValues[lcKey] = loArr2.GetValue(1).ToString();
- }
- }
- }
- }
- }
- if (_DisplayValues != null)
- {
- if (_DisplayValues.ContainsKey(UtilStr.UAndT(pcValue)))
- lcRetVal = _DisplayValues[UtilStr.UAndT(pcValue)].ToString().Trim();
- }
- return lcRetVal;
- }
- /// <summary>
- /// 想关联字段赋值 比如 该字段 是MarketID 在User表中,要获取相应的MarketName 则 RelationClumn 为 Markets.MarketName
- /// </summary>
- /// <param name="poDbConn"></param>
- public void SetDbConn(DBConnSql poDbConn)
- {
- if (GetTableId.Trim().Length > 0)
- {
- _DBConn = poDbConn;
- string lcSql = " select " + this.ColumnId + "," + GetColumnId + " from " + GetTableId;
- _RelationTable = _DBConn.OpenQuery(lcSql);
- }
- }
- /// <summary>
- /// 获取关联或真实显示的信息 优先显示 DisplayValue 再显示 RelationValue
- /// </summary>
- /// <param name="pcValue"></param>
- /// <returns></returns>
- public string DispalyValueTranslate(string pcValue)
- {
- string lcRetVal = pcValue;
- string lcValue = "";
- lcValue = GetDisplayValue(pcValue);
- if (string.IsNullOrEmpty(lcValue))
- {
- lcValue = GetRelationValue(pcValue);
- if (lcValue != pcValue)
- {
- lcRetVal = lcValue;
- }
- }
- else
- {
- if (lcValue != pcValue)
- {
- lcRetVal = lcValue;
- }
- }
- return lcRetVal;
- }
- /// <summary>
- /// 获取RelationValue
- /// </summary>
- /// <param name="pcStr"></param>
- /// <returns></returns>
- public string GetRelationValue(string pcStr)
- {
- string lcRetVal = pcStr;
- if (pcStr.Trim().Length > 0)
- {
- if (_RelationTable != null && _RelationTable.IsOpened)
- {
- if (_RelationTable.GoToRecordByFieldsAndValues(this.ColumnId, pcStr))
- lcRetVal = _RelationTable.GetString(GetColumnId);
- }
- }
- return lcRetVal;
- }
- /// <summary>
- /// 判断与当前的字段是否匹配
- /// </summary>
- /// <param name="pcColumnId"></param>
- /// <returns></returns>
- public bool MatchColumnId(string pcColumnId)
- {
- pcColumnId = UtilStr.UAndT(pcColumnId);
- return UtilStr.UAndT(this.ColumnId) == pcColumnId;
- }
- /// <summary>
- /// 获取 字段的对象
- /// </summary>
- /// <param name="poColumns"></param>
- /// <param name="pcColumnId"></param>
- /// <returns></returns>
- public static rsDDColumn GetColumnById(List<rsDDColumn> poColumns, string pcColumnId)
- {
- rsDDColumn loRetVal = null;
- if (poColumns != null && pcColumnId != null)
- {
- pcColumnId=UtilStr.UAndT(pcColumnId);
- foreach (rsDDColumn loCol in poColumns)
- {
- if (UtilStr.UAndT(loCol.ColumnId) == pcColumnId)
- {
- loRetVal = loCol;
- break;
- }
- }
- }
- return loRetVal;
- }
- }
- }
|