Click here to Skip to main content
13,050,896 members (62,803 online)
Click here to Skip to main content
Add your own
alternative version

Stats

51.1K views
538 downloads
23 bookmarked
Posted 14 Aug 2006

Use C# write a designer like PowerDesigner

, 14 Aug 2006
Rate this:
Please Sign up or sign in to vote.
How to develop a database structure designer use C#

Sample Image - xdbdesigner.png

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 ;
    }
    ///<summary>
    /// 字段名称
    ///</summary>            
    public string FName
    {
        get{ return strID ;}
        set{ strID = value;}
    }

    private string strDesc ;
    ///<summary>
    /// 字段说明
    ///</summary>            
    public string Desc
    {
        get{ return strDesc ;}
        set{ strDesc = value;}
    }

    private string strRemark ;
    ///<summary>
    /// 字段详细说明
    ///</summary>            
    public string Remark
    {
        get{ return strRemark ;}
        set{ strRemark = value;}
    }

    private string strFType ;
    ///<summary>
    /// 字段类型
    ///</summary>            
    public string FType
    {
        get{ return strFType ;}
        set{ strFType = value;}
    }

    private string strFWidth ;
    ///<summary>
    /// 字段长度
    ///</summary>            
    public string FWidth
    {
        get{ return strFWidth;}
        set{ strFWidth = value;}
    }

    private string strFFormat ;
    ///<summary>
    /// 字段内容格式
    ///</summary>            
    public string FFormat
    {
        get{ return strFFormat ;}
        set{ strFFormat = value;}
    }

    private bool bolNullable = true;
    ///<summary>
    /// 是否为空
    ///</summary>            
    public bool  Nullable
    {
        get{ return bolNullable ;}
        set{ bolNullable = value;}
    }

    private bool bolPrimaryKey = false;
    ///<summary>
    /// 是否为主键
    ///</summary>            
    public bool  PrimaryKey
    {
        get{ return bolPrimaryKey ;}
        set{ bolPrimaryKey = value;}
    }

    private bool bolIndexed = false;
    ///<summary>
    /// 是否索引
    ///</summary>            
    public bool  Indexed
    {
        get{ return bolIndexed ;}
        set{ bolIndexed = value;}
    }

    private bool bolHasDefaultValue = false;
    ///<summary>
    /// 是否有默认值
    ///</summary>            
    public bool  HasDefaultValue
    {
        get{ return bolHasDefaultValue ;}
        set{ bolHasDefaultValue = value;}
    }

    private string strDefaultValue ;
    ///<summary>
    /// 默认值
    ///</summary>            
    public string DefaultValue
    {
        get{ return strDefaultValue;}
        set{ strDefaultValue = value;}
    }

    private bool bolIsBoolean = false;
    ///<summary>
    /// 是否是布尔类型的字段
    ///</summary>            
    public bool  IsBoolean
    {
        get{ return bolIsBoolean ;}
        set{ bolIsBoolean = value;}
    }

    private string strTrueValue = null;
    ///<summary>
    /// 表示真的数值
    ///</summary>            
    public string TrueValue
    {
        get{ return strTrueValue ;}
        set{ strTrueValue = value;}
    }

    private string strFalseValue = null;
    ///<summary>
    /// 表示假的数值
    ///</summary>            
    public string FalseValue
    {
        get{ return strFalseValue ;}
        set{ strFalseValue = value;}
    }

    /// <summary>
    /// 转换列表
    /// </summary>
    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 );}
    }
}//public class DesignDBFieldElement : XDesigner.DesignLabel 

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 . 

<!------------------------------- That's it! --------------------------->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 .

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

yuan yong fu
Web Developer duchang soft
China China
yuan yong fu of duchang soft , come from CHINA , 2008 Microsoft MVP,Use GDI+,XML/XSLT, site:http://www.cnblogs.com/xdesigner/

You may also be interested in...

Pro
Pro

Comments and Discussions

 
General兄弟,牛,赞一个! Pin
abmer29-Jan-09 0:01
memberabmer29-Jan-09 0:01 
GeneralNice WYSIWYG Pin
Shyam Bharath20-May-07 5:58
memberShyam Bharath20-May-07 5:58 
GeneralI'm waiting for something.. Pin
Laubi15-Aug-06 0:20
memberLaubi15-Aug-06 0:20 
GeneralRe: I'm waiting for something.. Pin
T-luv15-Aug-06 7:30
memberT-luv15-Aug-06 7:30 
QuestionHow many others think software should be in English? Pin
T-luv15-Aug-06 7:35
memberT-luv15-Aug-06 7:35 
AnswerRe: How many others think software should be in English? Pin
Dario Solera15-Aug-06 12:01
memberDario Solera15-Aug-06 12:01 
GeneralRe: How many others think software should be in English? Pin
bkerr20-Aug-06 14:38
memberbkerr20-Aug-06 14:38 
GeneralRe: How many others think software should be in English? Pin
Dario Solera20-Aug-06 21:53
memberDario Solera20-Aug-06 21:53 
GeneralRe: How many others think software should be in English? Pin
T-luv21-Aug-06 2:32
memberT-luv21-Aug-06 2:32 
AnswerRe: How many others think software should be in English? Pin
dadeval25-Aug-06 1:26
memberdadeval25-Aug-06 1:26 
AnswerRe: How many others think software should be in English? Pin
Marcus Deecke1-Oct-06 22:49
memberMarcus Deecke1-Oct-06 22:49 
GeneralRe: How many others think software should be in English? Pin
Alan Gold12-Sep-07 7:56
memberAlan Gold12-Sep-07 7:56 
AnswerRe: How many others think software should be in English? Pin
Marcus Deecke14-Sep-07 0:48
memberMarcus Deecke14-Sep-07 0:48 
GeneralRe: How many others think software should be in English? Pin
T-luv23-Feb-08 14:40
memberT-luv23-Feb-08 14:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 15 Aug 2006
Article Copyright 2006 by yuan yong fu
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid