13693261870
2022-10-20 93b9a4bd47bfec774894928392d52a61fca07c38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using JavaCode.cs;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace JavaCode
{
    public partial class FrmMyBatisPlus : Form
    {
        #region 成员变量+构造函数
        string baseDir = AppDomain.CurrentDomain.BaseDirectory;
 
        private PostgreHelper _dbHelper;
 
        private List<TabInfo> _list;
 
        public FrmMyBatisPlus()
        {
            InitializeComponent();
        }
 
        private void FrmMyBatisPlus_Load(object sender, EventArgs e)
        {
            _dbHelper = new PostgreHelper(DbEnum.langfang);
        }
        #endregion
 
        // 135502,69701  29257,20582
        private void btnReadTab_Click(object sender, EventArgs e)
        {
            try
            {
                string tabName = this.txtTabPre.Text.Trim();
                string tabFilter = string.IsNullOrEmpty(tabName) ? "" : string.Format("and c.relname like '{0}%'", tabName);
 
                string sql = string.Format("select c.relname as \"tab\", cast(obj_description(c.oid) as varchar) as \"desc\", a.attnum as \"num\", a.attname as \"col\",concat_ws('', t.typname, SUBSTRING(format_type(a.atttypid, a.atttypmod) from '(.*)')) as \"type\", d.description as \"bak\" from pg_attribute a left join pg_description d on d.objoid = a.attrelid and d.objsubid = a.attnum left join pg_class c on a.attrelid = c.oid left join pg_type t on a.atttypid = t.oid where a.attnum >= 0 and reltype>0 and relnamespace in ({0}) {1} order by c.relname desc, a.attnum asc", this.txtNS.Text.Trim(), tabFilter);
 
                DataTable dt = _dbHelper.GetDataTable(sql, null);
                _list = ModelHandler.FillModel<TabInfo>(dt);
                if (_list == null || _list.Count == 0)
                {
                    MessageBox.Show("没有查询到数据!");
                    return;
                }
 
                List<string> tabList = new List<string>();
                foreach (TabInfo ti in _list)
                {
                    if (!tabList.Contains(ti.tab))
                    {
                        tabList.Add(ti.tab);
                    }
                }
                this.tabList.DataSource = tabList;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 
        private void btnAll_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.tabList.Items.Count; i++)
            {
                this.tabList.SetSelected(i, true);
            }
        }
 
        private void btnAnti_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.tabList.Items.Count; i++)
            {
                bool flag = this.tabList.GetSelected(i);
                this.tabList.SetSelected(i, !flag);
            }
        }
 
        private void btnNone_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.tabList.Items.Count; i++)
            {
                this.tabList.SetSelected(i, false);
            }
        }
 
        private void tabList_SelectedIndexChanged(object sender, EventArgs e)
        {
            string tab = this.tabList.SelectedItem as string;
            List<TabInfo> tabs = (from p in _list where p.tab == tab orderby p.num select p).ToList<TabInfo>();
 
            this.dgvTab.DataSource = new BindingList<TabInfo>(tabs);
            if (tabs != null && tabs.Count > 1)
            {
                this.dgvTab.Rows[1].Selected = true;
                this.dgvTab.CurrentCell = this.dgvTab.Rows[1].Cells[0];
            }
        }
 
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            //
        }
 
        private String QueryPrimaryKey(string tab)
        {
            string sql = string.Format("select pg_attribute.attname as colname from pg_constraint inner join pg_class on pg_constraint.conrelid = pg_class.oid inner join pg_attribute on pg_attribute.attrelid = pg_class.oid and pg_attribute.attnum = pg_constraint.conkey[1] inner join pg_type on pg_type.oid = pg_attribute.atttypid where pg_class.relname = '{0}' and pg_constraint.contype='p'", tab);
 
            object obj = _dbHelper.GetScalar(sql, null);
 
            return obj == null ? null : obj.ToString();
        }
    }
}