string LoginType = ""; //数据库的登录方式 分为window登录和sqlserver登录两种 private void Config_Load(object sender, EventArgs e) { textBox2.Text = Iniclass.GetString("Codes", "namespace_Model", "Model", FilePath); textBox8.Text = Iniclass.GetString("Codes", "ModelClassEmbellish", "", FilePath); textBox6.Text = Iniclass.GetString("Codes", "namespace_DAL", "DAL", FilePath); textBox9.Text = Iniclass.GetString("Codes", "DALClassEmbellish", "", FilePath); textBox3.Text = Iniclass.GetString("Codes", "namespace_BLL", "BLL", FilePath); textBox10.Text = Iniclass.GetString("Codes", "BLLClassEmbellish", "", FilePath); textBox1.Text = Iniclass.GetString("SQL", "ServerName", "", FilePath); textBox4.Text = Iniclass.GetString("SQL", "SqlAccount", "", FilePath); textBox5.Text = Iniclass.GetString("SQL", "SqlPwd", "", FilePath); LoginType = Iniclass.GetString("SQL", "LoginType", "", FilePath);//先获取登录方式 然后根据登录方式判断哪个应该被选中 if (LoginType == "windows") { radioButton1.Checked = true; } else if (LoginType == "sqlserver") { radioButton2.Checked = true; } else { radioButton1.Checked = false; radioButton2.Checked = false; } }
private void MainForm_Load(object sender, EventArgs e) { try { dir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); label_Author.Text += Info.Author; label_Version.Text += Info.VersionNum; string IsConfig = Iniclass.GetString("config", "IsConfig", "", FilePath); //检测是否存在配置文件,如果存在继续执行,如果不存在,先配置配置文件; if (!IsConfig.Equals("True")) { MessageBox.Show("请先点击配置按钮来配置必要的参数!"); //跳转到配置Form来执行配置 Config con = new Config(); con.Owner = this; //this.Hide(); con.ShowDialog();//打开配置窗进行配置文件的写入 } textBox3.Text = Iniclass.GetString("Codes", "namespace_Model", "Model", FilePath); textBox8.Text = Iniclass.GetString("Codes", "ModelClassEmbellish", "", FilePath); textBox2.Text = Iniclass.GetString("Codes", "namespace_DAL", "DAL", FilePath); textBox9.Text = Iniclass.GetString("Codes", "DALClassEmbellish", "", FilePath); textBox6.Text = Iniclass.GetString("Codes", "namespace_BLL", "BLL", FilePath); textBox10.Text = Iniclass.GetString("Codes", "BLLClassEmbellish", "", FilePath); LoginType = Iniclass.GetString("SQL", "LoginType", "", FilePath);//先获取登录方式 然后根据登录方式判断哪个应该被选中 if (LoginType == "windows") { label1.Text = "(windows登录)Data Source="; textBox1.Text = Iniclass.GetString("SQL", "ServerName", "", FilePath); } else if (LoginType == "sqlserver") { label1.Text = "(Sql登录) Data Source="; textBox1.Text = Iniclass.GetString("SQL", "ServerName", "", FilePath); } else { label1.Text = "请先进行配置数据库登录"; textBox1.Text = "先进行配置--ERROR!!!"; } } catch (Exception) { throw; } }
//初始化数据按钮 private void button10_Click(object sender, EventArgs e) { textBox3.Text = Iniclass.GetString("Codes", "namespace_Model", "Model", FilePath); textBox8.Text = Iniclass.GetString("Codes", "ModelClassEmbellish", "", FilePath); textBox2.Text = Iniclass.GetString("Codes", "namespace_DAL", "DAL", FilePath); textBox9.Text = Iniclass.GetString("Codes", "DALClassEmbellish", "", FilePath); textBox6.Text = Iniclass.GetString("Codes", "namespace_BLL", "BLL", FilePath); textBox10.Text = Iniclass.GetString("Codes", "BLLClassEmbellish", "", FilePath); LoginType = Iniclass.GetString("SQL", "LoginType", "", FilePath);//先获取登录方式 然后根据登录方式判断哪个应该被选中 if (LoginType == "windows") { label1.Text = "(windows登录)Data Source="; textBox1.Text = Iniclass.GetString("SQL", "ServerName", "", FilePath); } else if (LoginType == "sqlserver") { label1.Text = "(Sql登录) Data Source="; textBox1.Text = Iniclass.GetString("SQL", "ServerName", "", FilePath); } else { label1.Text = "请先进行配置数据库登录"; textBox1.Text = "先进行配置--ERROR!!!"; } textBox5.Text = "Class1"; textBox4.Text = "Class1"; textBox7.Text = "Class1"; checkBox1.Checked = true; checkBox2.Checked = true; checkBox3.Checked = true; checkBox4.Checked = true; checkBox5.Checked = true; checkBox6.Checked = true; checkBox7.Checked = true; checkBox8.Checked = true; checkBox9.Checked = true; checkBox10.Checked = true; }
//获取数据库信息 private void button2_Click(object sender, EventArgs e) { try { string sql = "select name from sys.databases where database_id > 4";//查询sqlserver中的非系统库 string ConnectionStr = ""; if (LoginType.Equals("windows")) { ConnectionStr = "Data Source=" + textBox1.Text.Trim() + ";Initial Catalog=master;Integrated Security=True"; } else if (LoginType.Equals("sqlserver")) { //从配置文件获取到数据库登录的信息 string userId = Iniclass.GetString("SQL", "SqlAccount", "--", FilePath); string Pwd = Iniclass.GetString("SQL", "SqlPwd", "--", FilePath); //将数据库登录信息填充到链接字符串中以实现sqlserver方式登录 ConnectionStr = "Data Source=" + textBox1.Text.Trim() + ";Initial Catalog=master;User Id=" + userId + ";Password="******";"; } DataSet ds = SqlHelper.ExecuteDataSet(ConnectionStr, sql); DataTable dataTable = ds.Tables[0]; TreeNode grand = new TreeNode(textBox1.Text.Trim());//添加节点服务器地址 grand.ImageIndex = 1; treeView1.Nodes[0].Nodes.Add(grand); foreach (DataRow row in dataTable.Rows) { TreeNode root = new TreeNode(row["name"].ToString());//创建节点 root.Name = row["name"].ToString(); root.ImageIndex = 2; grand.Nodes.Add(root); TreeNode biao = new TreeNode("表"); biao.Name = "表"; biao.ImageIndex = 3; root.Nodes.Add(biao); //获取表名 string sqltable = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'"; DataSet ds2 = SqlHelper.ExecuteDataSet("Data Source=" + textBox1.Text.Trim() + ";Initial Catalog=" + row["name"] + ";Integrated Security=True", sqltable); DataTable dt2 = ds2.Tables[0]; foreach (DataRow row2 in dt2.Rows) { TreeNode biaovalue = new TreeNode(row2[0].ToString()); biaovalue.Name = row2[0].ToString(); biaovalue.ImageIndex = 4; biao.Nodes.Add(biaovalue); } } } catch (Exception) { //throw; if (LoginType.Equals("windows")) { MessageBox.Show("windows身份登录 获取数据库信息失败,请重试!"); } else if (LoginType.Equals("sqlserver")) { MessageBox.Show("sqlserver身份登录 获取数据库信息失败,请重试!"); } else { MessageBox.Show("第一次运行程序请先配置 请检查登录方式及登录信息!"); } } }