using HotelPms.Share.Util;
using System.Data.Common;
namespace HotelPms.Share.Data.Script;
public class Field
{
///
/// 項目名(列名)
///
public string Name { get; set; } = string.Empty;
///
/// 説明
///
public string Description { get; set; } = string.Empty;
///
/// 型
/// 例:NVARCHAR(50)
///
public string DataType { get; set; } = string.Empty;
///
/// プライマリーキーかどうか
///
public bool IsPrimaryKey { get; set; } = false;
///
/// 自動増加型かどうか
///
public bool IsIdentity { get; set; } = false;
///
/// 変更チェック
/// ※プライマリーキー変更は手動でしましょう
///
///
/// 0.なし 1.Description 2.DataType 12.両方変更あり
public int CompareTo(Field item)
{
bool type1 = (item.Description.CompareTo(Description) != 0);
bool type2 = (item.DataType.Replace("[", string.Empty).Replace("]", string.Empty).ToUpper().CompareTo(DataType.Replace("[", string.Empty).Replace("]", string.Empty).ToUpper()) != 0);
if (type1 && !type2) { return 1; }
else if (!type1 && type2) { return 2; }
else if (type1 && type2) { return 12; }
else { return 0; }
}
public Field() { }
public Field(DbDataReader reader)
{
Name = CConvert.ToString(reader["Name"]);
Description = CConvert.ToString(reader["Description"]);
DataType = CConvert.ToString(reader["DataType"]);
IsPrimaryKey = CConvert.ToInt(reader["IsPrimaryKey"]) == 1;
}
}