Introduction
XDBDesigner is a WYSWYG designer which can design database structure , just lick PowerDesigner , and it can load PDM file which created by PowerDesigner . It can save design result to a XML file and load design from a XML file . It is a appliction of XDesignerLib .
Using the code
XDBDesigner is a application of XDesignerLib , XDesignerLib is a middle ware which use to create WYSWYG designer easy and fast . XDesignerLib already bring a set of design DOOM , people can extend design DOM to create own designer . For example , in XDBDesigner , it create a tablefield element by the following C# code :
public class DesignDBFieldElement : XDesignerDom.DesignLabelElement
{
public static System.Drawing.SolidBrush BackBrush =
new System.Drawing.SolidBrush( System.Drawing.Color.FromArgb( 0xff,0xA9,0xD2,0xFE)) ;
public override bool RefreshView(DesignPaintEventArgs e)
{
if( myOwnerDocument.RuntimeScaleRate < 0.1 )
return true;
int index = myOwnerDocument.GetImageIndex( this );
if( index >= 0 )
this.Icon = myOwnerDocument.ImageList[ index ] ;
if( this.LinkHightlight )
e.FillDrawRects( System.Drawing.SystemBrushes.Highlight , e.ViewBounds );
else if( this.IsCurrent )
e.FillDrawRects( System.Drawing.SystemBrushes.Info , e.ViewBounds );
base.CustomDraw( e );
return true;
}
public override System.Drawing.Color TextColor
{
get
{
if( this.LinkHightlight )
return System.Drawing.SystemColors.HighlightText ;
else
{
if( "new".Equals( Tag ))
return System.Drawing.Color.Blue ;
else if( "delete".Equals ( Tag ))
return System.Drawing.Color.Red ;
else
return System.Drawing.SystemColors.WindowText ;
}
}
set
{
base.TextColor = value;
}
}
public override bool LoadProperties(XDesignerProperty.IPropertyPackage Loader)
{
if( Loader.HasModified("customproperties"))
this.CustomProperties.ParseString( Loader.GetString("customproperties"));
if( Loader.HasModified("convertlist"))
this.ConvertList.ParseString( Loader.GetString("convertlist"));
if( Loader.HasModified("falsevalue"))
this.FalseValue = Loader.GetString("falsevalue");
if( Loader.HasModified("truevalue"))
this.TrueValue = Loader.GetString("truevalue");
if( Loader.HasModified("isboolean"))
this.IsBoolean = Loader.GetBoolean("isboolean" , false);
if( Loader.HasModified("defaultvalue"))
this.DefaultValue = Loader.GetString("defaultvalue") ;
if( Loader.HasModified("hasdefaultvalue"))
this.HasDefaultValue = Loader.GetBoolean("hasdefaultvalue" , false );
if( Loader.HasModified("fformat"))
this.FFormat = Loader.GetString("fformat");
if( Loader.HasModified("nullable"))
this.Nullable = Loader.GetBoolean("nullable" , true );
if( Loader.HasModified("indexed"))
this.Indexed = Loader.GetBoolean("indexed" , false );
if( Loader.HasModified("key"))
this.PrimaryKey = Loader.GetBoolean("key" , false );
if( Loader.HasModified("fwidth")) this.FWidth = Loader.GetString("fwidth" ) ;
if( Loader.HasModified("ftype")) this.FType = Loader.GetString("ftype");
if( Loader.HasModified("remark")) this.Remark = Loader.GetString("remark");
if( Loader.HasModified("desc")) this.Desc = Loader.GetString("desc");
if( Loader.HasModified("fname") ) this.FName = Loader.GetString("fname");
if( Loader.FromUI )
{
if( (( DesignDBTableElement ) myParent).RefreshPreferredWidth())
{
myParent.Resize();
myParent.Invalidate();
}
if( this.PrimaryKey )
( ( DesignDBTableElement ) myParent ).KeyField = this.FName ;
myOwnerDocument.RaiseChangeElement( this );
}
return true;
}
public override bool SaveProperties(XDesignerProperty.IPropertyPackage Saver)
{
Saver.SetString("convertlist", ConvertList.ToString());
Saver.SetString("customproperties" , this.CustomProperties.ToString());
Saver.SetString("falsevalue" , this.FalseValue );
Saver.SetString("truevalue" , this.TrueValue );
Saver.SetBoolean("isboolean" , this.IsBoolean , false );
Saver.SetString("defaultvalue" , this.DefaultValue );
Saver.SetBoolean("hasdefaultvalue" , this.HasDefaultValue , false );
Saver.SetString("fformat" , this.FFormat );
Saver.SetBoolean("indexed" , this.Indexed , false );
Saver.SetBoolean("key" ,this.PrimaryKey , false );
Saver.SetBoolean("nullable" , this.Nullable , true);
Saver.SetString("fwidth" , this.FWidth );
Saver.SetString("ftype" , this.FType );
Saver.SetString("remark" , this.Remark );
Saver.SetString("desc" , this.Desc );
Saver.SetString("fname" , this.FName );
if( myOwnerDocument.ForXSLTFlag )
{
Saver.SetString("isstring" , IsStringField() ? "1" : "0");
Saver.SetString("isinteger" , IsIntegerField() ? "1" : "0");
Saver.SetString("isfloat" , IsFloatField() ? "1" : "0" );
Saver.SetString("isbyte" , this.IsByteField() ? "1" : "0");
int index = myParent.Items.IndexOf( this );
Saver.SetString("fixindex" ,
index > 9 ? index.ToString() : index.ToString() + " " );
}
if( Saver is PropertyListItemCollection )
{
PropertyListItemCollection items = ( PropertyListItemCollection ) Saver ;
PropertyStringItem item = ( PropertyStringItem ) items["fformat"];
item.ListItems = new string[] {"String",
"Integer",
"Decimal",
"Double",
"DateTime",
"Base64",
"YYYYMMDDHHMMSS",
"YYYYMMDDHHMM",
"YYYYMMDDHH",
"YYYYMMDD",
"HHMMSS"};
item = ( PropertyStringItem ) items["ftype"];
item.ListItems = new string[]{ "image",
"text",
"uniqueidentifier",
"tinyint",
"smallint",
"int",
"smalldatetime",
"real",
"money",
"datetime",
"float",
"sql_variant",
"ntext",
"bit",
"decimal",
"numeric",
"smallmoney",
"bigint",
"varbinary",
"varchar",
"binary",
"char",
"timestamp",
"nvarchar",
"nchar",
"sysname"};
}
return true;
}
public object Tag = null;
public override string TagName
{
get{ return "field";}
}
public DesignDBFieldElement()
{
base.bolMultiline = false;
this.intAlign = System.Drawing.StringAlignment.Near ;
}
public string FName
{
get{ return strID ;}
set{ strID = value;}
}
private string strDesc ;
public string Desc
{
get{ return strDesc ;}
set{ strDesc = value;}
}
private string strRemark ;
public string Remark
{
get{ return strRemark ;}
set{ strRemark = value;}
}
private string strFType ;
public string FType
{
get{ return strFType ;}
set{ strFType = value;}
}
private string strFWidth ;
public string FWidth
{
get{ return strFWidth;}
set{ strFWidth = value;}
}
private string strFFormat ;
public string FFormat
{
get{ return strFFormat ;}
set{ strFFormat = value;}
}
private bool bolNullable = true;
public bool Nullable
{
get{ return bolNullable ;}
set{ bolNullable = value;}
}
private bool bolPrimaryKey = false;
public bool PrimaryKey
{
get{ return bolPrimaryKey ;}
set{ bolPrimaryKey = value;}
}
private bool bolIndexed = false;
public bool Indexed
{
get{ return bolIndexed ;}
set{ bolIndexed = value;}
}
private bool bolHasDefaultValue = false;
public bool HasDefaultValue
{
get{ return bolHasDefaultValue ;}
set{ bolHasDefaultValue = value;}
}
private string strDefaultValue ;
public string DefaultValue
{
get{ return strDefaultValue;}
set{ strDefaultValue = value;}
}
private bool bolIsBoolean = false;
public bool IsBoolean
{
get{ return bolIsBoolean ;}
set{ bolIsBoolean = value;}
}
private string strTrueValue = null;
public string TrueValue
{
get{ return strTrueValue ;}
set{ strTrueValue = value;}
}
private string strFalseValue = null;
public string FalseValue
{
get{ return strFalseValue ;}
set{ strFalseValue = value;}
}
public XDesignerCommon.StringValueItemCollection ConvertList =
new XDesignerCommon.StringValueItemCollection();
public XDesignerCommon.StringValueItemCollection CustomProperties =
new XDesignerCommon.StringValueItemCollection();
public string ConvertListString
{
get{ return ConvertList.ToString(); }
set{ ConvertList.ParseString( value );}
}
}
Points of Interest
Every one know it is very hard to develop a WYSWYG designer , but using XDesignerLib middle ware , you can create your own WYSWYG designer fast and easy . What are you waiting for ? Try it at once .
Learn more information about XDBDesigner , please visit http://www.xdesigner.cn/xdbdesigner/default-eng.htm .
Learn more information about XDesignerLib , please visit http://www.xdesigner.cn/xdesignerlib/default-eng.htm .
Lear more information about author , please visit http://www.xdesigner.cn/default-eng.htm or mail to yyf9989@hotmail.com .