using System;
using System.Xml;
using System.Xml.Serialization;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.Serialization;
using Tdo;
using Tdo.Common;
using Tdo.Common.Entities;
using Tdo.Common.Entities.Tables;
using Tdo.Common.Entities.Views;
using Tdo.Common.Helper;
using Tdo.Common.TdoSqlExpressionDom;
using Tdo.Common.TdoTypes;
namespace Tdo.Common.TdoTypes{
/// <summary>
/// TdoBinary class. Allows to keep SqlBinary (byte[], image, binary) actualValue type
/// </summary>
[CLSCompliant(true)]
[Serializable()]
public sealed class TdoBinary : TdoTypeBase<SqlBinary>, ITdoColumn
{
#region Constructors
/// <summary>
/// Default constructor for TdoBinary Class.
/// </summary>
public TdoBinary()
{
this.actualValue = SqlBinary.Null;
}
/// <summary>
/// Constructor for TdoBinary Class.
/// </summary>
/// <param name="value">Column constant value</param>
/// <param name="columnAlias">Alias column.</param>
public TdoBinary(SqlBinary value, string columnAlias)
{
this.Caption = this.ColumnName = columnAlias;
this.actualValue = TdoBinary.ClonedValue(value);
this.IsConstant = true;
}
/// <summary>
/// Constructor for TdoBinary class
/// </summary>
/// <param name="allowDBNull">Boolean that indicates wether the field can be NULL</param>
/// <param name="autoIncrement">Boolean that indicates if the field is IDENTITY (auto-increase)</param>
/// <param name="autoIncrementSeed">Long that indicates how much is increasing the IDENTITY field</param>
/// <param name="autoIncrementStep">Long that indicates the start actualValue of the IDENTITY field </param>
/// <param name="caption">String that indicates the heading/columnAlias of the field</param>
/// <param name="columnName">String that indicates the name of the column (field)</param>
/// <param name="maxLength">Integer that indicates the maximum length of the field (-1,field without limit)</param>
/// <param name="readOnly">Boolean that indicates if the field is only reading</param>
/// <param name="unique">Boolean that indicates if a unique constraint exists on that field</param>
/// <param name="tdoEntity">TdoEntity referenced to the class that contains the field</param>
public TdoBinary(bool allowDBNull, bool autoIncrement, long autoIncrementSeed,
long autoIncrementStep, string caption, string columnName,
int maxLength, bool readOnly,
bool unique, ITdoEntity tdoEntity)
:
base(allowDBNull, autoIncrement, autoIncrementSeed,
autoIncrementStep, caption, columnName,maxLength,
readOnly, unique, tdoEntity)
{
this.actualValue = SqlBinary.Null;
}
#endregion Constructors
#region Properties
/// <summary>
/// Get or Set Value property of Object type
/// </summary>
[XmlIgnore]
public override object ObjectValue
{
get
{
return this.actualValue;
}
set
{
if (value != null && value != DBNull.Value)
this.actualValue = new SqlBinary((byte[])value);
else
this.actualValue = SqlBinary.Null;
this.pModified = !this.ReadOnly;
}
}
/// <summary>
/// System.Data.SqlDbType of ITdoColumn
/// </summary>
[XmlAttribute()]
public override SqlDbType SqlDbType
{
get
{
return System.Data.SqlDbType.Binary;
}
}
/// <summary>
/// Gets or sets if column is a constant expression.
/// </summary>
/// <remarks>
/// True for Value, false for Column.
/// </remarks>
/// <exception cref="System.InvalidOperationException">thrown when IsConstant property is set to true for blob fields.</exception>
[XmlIgnore()]
public new bool IsConstant
{
get
{
return this.pIsConstant;
}
set
{
if (value)
throw new InvalidOperationException("Blob types cannot be constant values.");
base.IsConstant = value;
}
}
#endregion Properties
#region Methods
/// <summary>
/// Comparison operator Equals
/// </summary>
/// <param name="obj">Object to compare</param>
public override bool Equals(object obj)
{
return base.Equals(obj);
}
/// <summary>
/// Returns Hash code
/// </summary>
public override int GetHashCode()
{
return base.GetHashCode();
}
internal override SqlBinary ClonedValue(bool actualValue)
{
return (actualValue ? TdoBinary.ClonedValue(this.actualValue) : TdoBinary.ClonedValue(this.oldValue));
}
/// <summary>
/// Return a copy of SqlBinary structure
/// </summary>
/// <param name="toClone">SqlBinary to copy</param>
/// <returns>SqlBinary structure copied</returns>
public static SqlBinary ClonedValue(SqlBinary toClone)
{
SqlBinary res;
if (toClone.IsNull)
{
res = SqlBinary.Null;
}
else
{
res = new SqlBinary(toClone.Value);
}
return res;
}
/// <summary>
/// Creates a copy of this TdoBinary object.
/// </summary>
/// <returns></returns>
public override ITdoType<SqlBinary> Clone()
{
TdoBinary clone = new TdoBinary(this.pAllowDBNull, this.pAutoIncrement, this.pAutoIncrementSeed, this.pAutoIncrementStep, this.pCaption, this.pColumnName, this.pMaxLength, this.pReadOnly, this.pUnique, this.pTdoEntity);
clone.Value = this.ClonedValue();
return clone;
}
/// <summary>
/// Returns the string representation of the content of the field
/// </summary>
/// <returns>string</returns>
public override string ToString()
{
//TODO: Ridefinire per alcuni tipi ... tipo Binary
return this.Value.ToString();
}
#endregion Methods
#region Operators
/// <summary>
/// Comparison operator is not (null)
/// </summary>
/// <param name="left">Parameter on the left of the operator</param>
/// <param name="right">Parameter on the right of the operator</param>
/// <returns>Returns an expression like TdoSqlExpression useful to convert the where clause to string</returns>
public static TdoSqlExpression operator !=(TdoBinary left, DBNull right)
{
return new TdoSqlExpression((ITdoColumn)left, SqlOperator.NotEqual, right);
}
/// <summary>
/// Comparison operator is (null)
/// </summary>
/// <param name="left">Parameter on the left of the operator</param>
/// <param name="right">Parameter on the right of the operator</param>
/// <returns>Returns an expression like TdoSqlExpression useful to convert the where clause to string</returns>
public static TdoSqlExpression operator ==(TdoBinary left, DBNull right)
{
return new TdoSqlExpression((ITdoColumn)left, SqlOperator.Equal, right);
}
/// <summary>
/// Comparison operator Like
/// </summary>
/// <param name="left">Parameter on the left of the operator</param>
/// <param name="right">Parameter on the right of the operator</param>
/// <returns>Returns an expression like TdoSqlExpression useful to convert the where clause to string</returns>
public static TdoSqlExpression operator %(TdoBinary left, byte[] right)
{
return new TdoSqlExpression((ITdoColumn)left, SqlOperator.Like, right);
}
/// <summary>
/// Comparison operator Not Like
/// </summary>
/// <param name="left">Parameter on the left of the operator</param>
/// <param name="right">Parameter on the right of the operator</param>
/// <returns>Returns an expression like TdoSqlExpression useful to convert the where clause to string</returns>
public static TdoSqlExpression operator -(TdoBinary left, byte[] right)
{
return new TdoSqlExpression((ITdoColumn)left, SqlOperator.NotLike, right);
}
/// <summary>
/// Comparison operator Like
/// </summary>
/// <param name="left">Parameter on the left of the operator</param>
/// <param name="right">Parameter on the right of the operator</param>
/// <returns>Returns an expression like TdoSqlExpression useful to convert the where clause to string</returns>
public static TdoSqlExpression operator ==(TdoBinary left, byte[] right)
{
return new TdoSqlExpression((ITdoColumn)left, SqlOperator.Equal, right);
}
/// <summary>
/// Comparison operator Not Like
/// </summary>
/// <param name="left">Parameter on the left of the operator</param>
/// <param name="right">Parameter on the right of the operator</param>
/// <returns>Returns an expression like TdoSqlExpression useful to convert the where clause to string</returns>
public static TdoSqlExpression operator !=(TdoBinary left, byte[] right)
{
return new TdoSqlExpression((ITdoColumn)left, SqlOperator.NotEqual, right);
}
#endregion Operators
}
}
|