private void button2_Click(object sender, EventArgs e) { this.Model = new DatabaseSetting { Database = this.DatabaseTxt.Text, Password = PasswordTxt.Text, Port = porttxt.Text, Server = Servertxt.Text, UserName = UserTxt.Text }; var constr = string.Format("Server={0};database={1};UID={2};password={3};Port={4};CharSet=utf8;Persist Security Info=True", Model.Server, Model.Database, Model.UserName, Model.Password, Model.Port); using (var db = new ContextTest(constr)) { try { db.Open(); MessageBox.Show("Connection Is Ok"); db.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public string CreatePhpModel() { using (var ctx = new ContextTest(ConnectionString)) { var cmd = ctx.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = string.Format(@"SELECT TABLE_SCHEMA, DATA_TYPE, COLUMN_TYPE, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS where `columns`.`TABLE_Schema`='{0}' group by table_name", "dbstokobat"); IDataReader dr = cmd.ExecuteReader(); var s = dr.GetSchemaTable(); List <MySchemaInfor> list = this.GetTable(dr); var ns = ""; if (!string.IsNullOrEmpty(namespacess.Text)) { ns = namespacess.Text; } else { ns = SettingDatabase.Database; } List <string> listprivate = new List <string>(); foreach (var itemtable in list) { sb.Append(string.Format("<?php\n \n namespace {0} \n", ns)); sb.Append("{ \n"); sb.Append(string.Format(" class {0}", itemtable.TableName)); sb.Append(" \n {\n"); cmd.CommandText = string.Format("Select * From {0}.{1} limit 1", itemtable.Database, itemtable.TableName); dr = cmd.ExecuteReader(); List <ColumnInfo> ReaderSchema = MappingCommon.ReadColumnInfo(dr.GetSchemaTable()); foreach (var item in ReaderSchema) { sb.Append(string.Format(" ${0};\n ", item.ColumnName)); //var p = string.Format(" private {0} _{1};\n ", this.DataTypeConvert(item.DataType), item.ColumnName.ToLower()); //listprivate.Add(p); } dr.Close(); sb.Append(" }\n"); sb.Append("}\n\n\n ?>"); if (aClass1File.Checked) { sbview.Append(sb.ToString()); CreateFile(sb, Isb, itemtable, "php"); sb.Clear(); } } } if (aClass1File.Checked) { return(sbview.ToString()); } else { return(sb.ToString()); } }
//metode public string CreatePoco() { using (var db = new ContextTest(ConnectionString)) { try { var cmd = db.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = this.commandText; IDataReader dr = cmd.ExecuteReader(); var s = dr.GetSchemaTable(); List <MySchemaInfor> list = this.GetTable(dr); dr.Close(); var ns = ""; if (!string.IsNullOrEmpty(namespacess.Text)) { ns = namespacess.Text; } else { ns = SettingDatabase.Database; } // sb.Append(Header.Text); List <string> listprivate = new List <string>(); foreach (var itemtable in list) { Isb.Append("using System;\r"); sb.Append(string.Format("\n \n namespace {0} \n", ns)); sb.Append("{ \n"); Isb.Append(string.Format("\n \n namespace {0} \n", ns)); Isb.Append("{ \n\r"); if (OcphDal.Checked) { sb.Append(string.Format(" [TableName({0}{1}{2})] \n", '"', itemtable.TableName, '"')); } if (Inpc.Checked) { sb.Append(string.Format(" public class {0} :BaseNotify, I{0}", itemtable.TableName)); } else { sb.Append(string.Format(" public class {0} :I{0}", itemtable.TableName)); } Isb.Append(string.Format(" public interface I{0}", itemtable.TableName)); sb.Append(" \n {\n"); Isb.Append(" \n {\n"); cmd.CommandText = string.Format("Select * From {0}.{1} limit 1", itemtable.Database, itemtable.TableName); dr = cmd.ExecuteReader(); List <ColumnInfo> ReaderSchema = MappingCommon.ReadColumnInfo(dr.GetSchemaTable()); foreach (var item in ReaderSchema) { if (OcphDal.Checked && item.IsKey) { sb.Append(string.Format(" [PrimaryKey({0}{1}{2})] \n", '"', item.ColumnName, '"')); } if (OcphDal.Checked) { sb.Append(string.Format(" [DbColumn({0}{1}{2})] \n", '"', item.ColumnName, '"')); } Isb.Append(string.Format(" {0} {1} ", DataTypeConvert.CSharp(item.DataType), item.ColumnName)); Isb.Append("{ get; set;} \n\n"); if (Modern.Checked) { sb.Append(string.Format(" public {0} {1} ", DataTypeConvert.CSharp(item.DataType), item.ColumnName)); sb.Append("{ get; set;} \n\n"); } else { sb.Append(string.Format(" public {0} {1} ", DataTypeConvert.CSharp(item.DataType), item.ColumnName)); sb.Append("\n { \n get{return "); sb.Append(string.Format("_{0};", item.ColumnName.ToLower())); sb.Append("} \n set{ \n"); if (!Inpc.Checked) { sb.Append(string.Format(" _{0}=value;", item.ColumnName.ToLower())); } else { sb.Append(string.Format("\n SetProperty(ref _{0}, value);", item.ColumnName.ToLower())); } sb.Append("\n }\n } \n\n"); var p = string.Format(" private {0} _{1};\n ", DataTypeConvert.CSharp(item.DataType), item.ColumnName.ToLower()); listprivate.Add(p); } } if (Clasic.Checked) { foreach (var i in listprivate) { sb.Append(i); } listprivate.Clear(); } dr.Close(); sb.Append(" }\n"); sb.Append("}\n\n\n"); Isb.Append(" }\n"); Isb.Append("}\n\n\n"); if (aClass1File.Checked) { if (OcphDal.Checked) { sb.Insert(0, "using Ocph.DAL;"); } sb.Insert(0, Header.Text); sbview.Append(sb.ToString()); CreateFile(sb, Isb, itemtable, "cs"); sb.Clear(); Isb.Clear(); } } } catch (Exception ex) { throw; } } if (aClass1File.Checked) { return(sbview.ToString()); } else { return(sb.ToString()); } }