Ejemplo n.º 1
0
        private void RefreshDB()
        {
            treeView1.Nodes.Clear();
            treeView1.BeginUpdate();
            var dbNode = treeView1.Nodes.Add("数据库");
            try
            {
                using(var fw = this.BeginRun("正在获取表内容..."))
                {
                    var tableNode = dbNode.Nodes.Add("表");
                    tableNode.Tag = ObjectType.Table;
                    Db.Engine.Execute("SELECT a.Name,b.Value FROM sysobjects a LEFT JOIN  sys.extended_properties b ON a.ID=b.Major_ID AND b.Minor_ID=0 WHERE a.XType='U' AND a.Name <>'sysdiagrams' ORDER BY a.Name").ToReader(reader =>
                    {
                        while(reader.Read())
                        {
                            ObjectInfo info = new ObjectInfo()
                            {
                                Type = ObjectType.Table,
                                Name = reader.GetString(0),
                                Comments = Convert.ToString(reader.GetValue(1))
                            };
                            tableNode.Nodes.Add(info.ToString()).Tag = info;
                        }
                    });

                    fw.Text = "正在获取视图内容...";
                    var viewNode = dbNode.Nodes.Add("视图");
                    viewNode.Tag = ObjectType.View;
                    Db.Engine.Execute("SELECT a.Name FROM sysobjects a WHERE a.XType='V' ORDER BY a.Name").ToReader(reader =>
                    {
                        while(reader.Read())
                        {
                            ObjectInfo info = new ObjectInfo()
                            {
                                Type = ObjectType.View,
                                Name = reader.GetString(0),
                            };
                            info.ClassName = info.Name;
                            if(info.ClassName.StartsWith("v_", StringComparison.CurrentCultureIgnoreCase))
                            {
                                info.ClassName = info.ClassName.Remove(0, 2);
                            }
                            viewNode.Nodes.Add(info.ToString()).Tag = info;
                        }
                    }); ;

                }
            }
            finally
            {
                treeView1.EndUpdate();
                dbNode.Expand();
            }
        }
Ejemplo n.º 2
0
        public Result WriteCode(string folder,ObjectInfo info, string code)
        {
            try
            {

                File.WriteAllText(Path.Combine(folder, info.Name + ".cs"), code);
                return Result.Successfully;
            }
            catch (Exception ex)
            {
                return ex;
            }
            
        }
Ejemplo n.º 3
0
        public string GenerateCode(ObjectInfo objectInfo, SettingInfo setting, string owner)
        {
            if(string.IsNullOrEmpty(PropertyType)) this.PropertyType = this.ParseDbType();

            var comments = this.Comments;
            if(!string.IsNullOrEmpty(comments))
            {
                if(!comments.StartsWith("设置或获取一个值,表示")) comments = ("设置或获取一个值,表示") + comments;
                if(comments.Last() != '。') comments += "。";
            }
            return @"        /// <summary>
        /// " + comments + @"
        /// </summary>
" + this.InnerGenerateCode(objectInfo, setting);
        }
Ejemplo n.º 4
0
 private string InnerGenerateCode(ObjectInfo objectInfo, SettingInfo setting)
 {
     var attrs = this.GenerateAttributes();
     var f = (attrs.Length > 0 ? ("        " + attrs + "\r\n") : string.Empty) + Format1;
     return string.Format(f, this.PropertyType, this.PropertyName);
 }
Ejemplo n.º 5
0
 private void DisplayObjectInfo(ObjectInfo info)
 {
     var code = info.GenerateCode(Db.Engine, Shared.Setting);
     new FormEditor(info.ToString(), code).ShowDialog();
 }
Ejemplo n.º 6
0
        private void lbl_Run_Click(object sender, EventArgs e)
        {
            var sql = textEditorControl1.SelectedText;
            if(string.IsNullOrEmpty(sql)) sql = textEditorControl1.Text;

            if(string.IsNullOrEmpty(sql))
            {
                this.ShowLabel("空的查询语句。");
                return;
            }
            var r = this.InputBox("请输入实体的名称:", "类名");
            string className = null;
            if(!r.ShowDialog()
                || string.IsNullOrEmpty(className = r.GetText(0))) return;

            ObjectInfo info = new ObjectInfo() { Name = className };
            var code = info.GenerateCode(Db.Engine, Shared.Setting, sql);
            new FormEditor("自定义 SQL 语句", code).ShowDialog();
        }
Ejemplo n.º 7
0
        private void DisplayObjectInfo(ObjectInfo info)
        {
            var code = info.GenerateCode(Db.Engine, Shared.Setting);

            new FormEditor(info.ToString(), code).ShowDialog();
        }