| | |
| | | using System.ComponentModel; |
| | | using System.Data; |
| | | using System.Diagnostics; |
| | | using System.Drawing; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace JavaCode |
| | |
| | | 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 \"tab\", cast(obj_description(c.oid) as varchar) \"desc\", a.attnum \"num\", a.attname \"col\", t.typname \"type\", d.description \"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} and position('pg.dropped' in a.attname) = 0 order by c.relname desc, a.attnum asc", this.txtNS.Text.Trim(), tabFilter); |
| | | string sql = string.Format("select c.relname \"tab\", cast(obj_description(c.oid) as varchar) \"desc\", a.attnum \"num\", a.attname \"col\", t.typname \"type\", d.description \"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} and position('pg.dropped' in a.attname) = 0 order by c.relname desc, a.attnum asc", this.txtTabNS.Text.Trim(), tabFilter); |
| | | |
| | | DataTable dt = _dbHelper.GetDataTable(sql, null); |
| | | _list = ModelHandler.FillModel<TabInfo>(dt); |
| | |
| | | MessageBox.Show(ex.Message); |
| | | } |
| | | } |
| | | |
| | | private void btnGeneAll_Click(object sender, EventArgs e) |
| | | { |
| | | try |
| | | { |
| | | string mapperPath = Path.Combine(baseDir, "BsGenerate\\Mapper"); |
| | | string entityPath = Path.Combine(baseDir, "BsGenerate\\Entity"); |
| | | |
| | | List<string> names = GetTabList(); |
| | | foreach (string name in names) |
| | | { |
| | | List<TabInfo> tabs = GetTabInfo(name); |
| | | GenerateMapper(mapperPath, name, tabs); |
| | | GenerateEntity(entityPath, name, tabs); |
| | | } |
| | | |
| | | string path = Path.Combine(baseDir, "BsGenerate"); |
| | | OpenFolder(path); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MessageBox.Show(ex.Message); |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region 生成 Mapper |
| | |
| | | { |
| | | if (!Directory.Exists(path)) Directory.CreateDirectory(path); |
| | | |
| | | string tabName = this.txtTabNS.Text.Trim() + name; |
| | | string tabName = this.txtTabPrefix.Text.Trim() + name; |
| | | //string shortName = NameConvert(name, true); |
| | | string shortName = GetEntityName(name, true); |
| | | |
| | |
| | | string entityNS = this.txtEntityNS.Text.Trim(); |
| | | string entityName = shortName + "Entity"; |
| | | |
| | | string ns = this.txtNS.Text.Trim(); |
| | | string bak = string.IsNullOrWhiteSpace(tabs[0].desc) ? shortName : tabs[0].desc.Replace("表", ""); |
| | | |
| | | //if (this.HasGeom(tabs)) return; |
| | |
| | | .Replace("{mapperName}", mapperName) |
| | | .Replace("{entityNS}", entityNS) |
| | | .Replace("{entityName}", entityName) |
| | | .Replace("{ns}", ns) |
| | | .Replace("{bak}", bak); |
| | | |
| | | string fileName = shortName + "Mapper.java"; |
| | |
| | | { |
| | | if (!Directory.Exists(path)) Directory.CreateDirectory(path); |
| | | |
| | | string tabName = this.txtTabNS.Text.Trim() + name; |
| | | string tabName = this.txtTabPrefix.Text.Trim() + name; |
| | | //string shortName = NameConvert(name, true); |
| | | string shortName = GetEntityName(name, true); |
| | | |
| | | string entityNS = this.txtEntityNS.Text.Trim(); |
| | | string entityName = shortName + "Entity"; |
| | | |
| | | string ns = this.txtNS.Text.Trim(); |
| | | string bak = string.IsNullOrWhiteSpace(tabs[0].desc) ? shortName : tabs[0].desc.Replace("表", ""); |
| | | long uid = (long)Math.Floor((new Random()).NextDouble() * 1000000000000000000D); |
| | | |
| | |
| | | .Replace("{entityName}", entityName) |
| | | .Replace("{bak}", bak) |
| | | .Replace("{tabName}", tabName) |
| | | .Replace("{ns}", ns) |
| | | .Replace("{uid}", uid.ToString()); |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region 生成所有 |
| | | private void btnGeneAll_Click(object sender, EventArgs e) |
| | | { |
| | | try |
| | | { |
| | | string mapperPath = Path.Combine(baseDir, "BsGenerate\\Mapper"); |
| | | string entityPath = Path.Combine(baseDir, "BsGenerate\\Entity"); |
| | | |
| | | List<string> names = GetTabList(); |
| | | foreach (string name in names) |
| | | { |
| | | List<TabInfo> tabs = GetTabInfo(name); |
| | | GenerateMapper(mapperPath, name, tabs); |
| | | GenerateEntity(entityPath, name, tabs); |
| | | } |
| | | |
| | | string path = Path.Combine(baseDir, "BsGenerate"); |
| | | OpenFolder(path); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MessageBox.Show(ex.Message); |
| | | } |
| | | } |
| | | |
| | | private void txtTabPrefix_TextChanged(object sender, EventArgs e) |
| | | { |
| | | txtChanged(sender, e); |
| | | } |
| | | |
| | | private void txtNS_TextChanged(object sender, EventArgs e) |
| | | { |
| | | txtChanged(sender, e); |
| | | } |
| | | |
| | | private void txtChanged(object sender, EventArgs e) |
| | | { |
| | | string pre = txtTabPrefix.Text.Replace(".", "").Trim(); |
| | | string ns = txtNS.Text.Trim(); |
| | | txtMapperNS.Text = "com.lf.server.mapper.bd".Replace("lf", ns).Replace("bd", pre); |
| | | txtEntityNS.Text = "com.lf.server.entity.bd".Replace("lf", ns).Replace("bd", pre); |
| | | } |
| | | #endregion |
| | | |
| | | #region 公共方法 |
| | | private List<string> GetTabList() |
| | | { |