Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        //初始化数据按钮
        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;
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Iniclass.WriteString("config", "IsConfig", "True", FilePath);                           //如果不存在,先写配置文件
                //普通三层的配置文件
                Iniclass.WriteString("Codes", "namespace_Model", textBox2.Text, FilePath);
                Iniclass.WriteString("Codes", "ModelClassEmbellish", textBox8.Text, FilePath);
                Iniclass.WriteString("Codes", "namespace_DAL", textBox6.Text, FilePath);
                Iniclass.WriteString("Codes", "DALClassEmbellish", textBox9.Text, FilePath);
                Iniclass.WriteString("Codes", "namespace_BLL", textBox3.Text, FilePath);
                Iniclass.WriteString("Codes", "BLLClassEmbellish", textBox10.Text, FilePath);
                //登录部分的配置文件
                if (radioButton1.Checked)
                {
                    LoginType = "windows";
                }
                else if (radioButton2.Checked)
                {
                    LoginType = "sqlserver";
                }

                Iniclass.WriteString("SQL", "LoginType", LoginType, FilePath);      //将数据库登录方式写入配置文件
                Iniclass.WriteString("SQL", "ServerName", textBox1.Text, FilePath); //windows登录 服务器名称
                Iniclass.WriteString("SQL", "SqlAccount", textBox4.Text, FilePath); //sqlserver登录 账号
                Iniclass.WriteString("SQL", "SqlPwd", textBox5.Text, FilePath);     //sqlserver登录 密码



                MessageBox.Show("配置成功!");
                //this.Owner.Show();  //显示主窗体
                this.Dispose();     //关闭子窗体
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        //获取数据库信息
        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("第一次运行程序请先配置 请检查登录方式及登录信息!");
                }
            }
        }