Example #1
0
 internal bool isNewServer(DBConfig _DBConfig, TreeNode _ServerFather)
 {
     foreach (TreeNode _tnServer in _ServerFather.Nodes)
     {
         if (_DBConfig.ServerName == _tnServer.Text)
         {
             return(false);
         }
     }
     return(true);
 }
Example #2
0
 internal bool isNewDataBase(DBConfig _DBConfig, TreeNode _DataBaseFather)
 {
     foreach (TreeNode _tnDataBase in _DataBaseFather.Nodes)
     {
         if (_tnDataBase.Text == _DBConfig.DataBase)
         {
             return(false);
         }
     }
     return(true);
 }
Example #3
0
        /// <summary>
        /// 确定按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            _DBConfig     = new DBConfig();
            _conString    = new StringBuilder();
            _DataBaseList = new List <string>();

            if (cboServerName.Text == "Local(本机)")
            {
                _DBConfig.ServerName = "Local(本机)";
                _conString.Append("Data Source=.;");
            }
            else
            {
                _DBConfig.ServerName = "Local\\SQLExpress(本机\\SQLExpress)";
                _conString.Append("server=").Append(cboServerName.Text).Append(";");  //这里做了修改,可以自己添加登录实例名称
                //_conString.Append("Data Source=.\\SQLExpress;");
            }

            //身份认证类型
            if (cboValidataType.Text == "Windows   身份认证")
            {
                _DBConfig.ValidataType = "Windows   身份认证";
                _conString.Append("Initial Catalog=master;");
                _conString.Append("Integrated Security=SSPI;");
            }
            else
            {
                _DBConfig.ValidataType = "SQL Server身份认证";
                //_conString.Append("Initial Catalog=master;");
                _conString.Append("database=master;");
                _conString.Append("User ID=" + txtLoginName.Text + ";Password="******";");
                string str = _conString.ToString();
            }

            _DataBaseList = SQLServerDBHelper.GetDataBase(_conString.ToString());

            if (_DataBaseList.Count > 0)
            {
                //_DataBaseList.Add("全部数据库");
                //cboDataBase.DataSource = _DataBaseList;
                //cboDataBase.Enabled = true;
                //cboDataBase.SelectedIndex = 0;
            }
            else
            {
                //cboDataBase.Enabled = false;
                //cboDataBase.Text = "";
                //cboDataBase.DataSource = null;
            }
            //直接把所有库查出来
            //if (cboDataBase.Text.Trim() != "")
            //{
            ////全部或多个库
            //if (cboDataBase.Text.Trim() == "全部数据库")
            //{
            foreach (string _strItem in _DataBaseList)
            {
                DBConfig _NewDBConfig = new DBConfig();

                //if (_strItem == "全部数据库") continue;
                string conString = _conString.ToString();
                //直接replace master,需要改进
                conString = conString.Replace("master", _strItem);
                _NewDBConfig.ConString    = conString;
                _NewDBConfig.DataBase     = _strItem;
                _NewDBConfig.ServerName   = _DBConfig.ServerName;
                _NewDBConfig.ServerType   = _DBConfig.ServerType;
                _NewDBConfig.UserName     = _DBConfig.UserName;
                _NewDBConfig.UserPwd      = _DBConfig.UserPwd;
                _NewDBConfig.ValidataType = _DBConfig.ValidataType;

                if (!DBSettings.Exist(_NewDBConfig))
                {
                    DBSettings.AddConfigLiat(_NewDBConfig);
                }
            }
            //}
            //else
            //{
            //    DBConfig _NewDBConfig = new DBConfig();
            //    //直接replace master,需要改进
            //    _NewDBConfig.ConString = _conString.ToString().Replace("master", cboDataBase.Text.Trim());
            //    _NewDBConfig.DataBase = cboDataBase.Text.Trim();
            //    _NewDBConfig.ServerName = _DBConfig.ServerName;
            //    _NewDBConfig.ServerType = _DBConfig.ServerType;
            //    _NewDBConfig.UserName = _DBConfig.UserName;
            //    _NewDBConfig.UserPwd = _DBConfig.UserPwd;
            //    _NewDBConfig.ValidataType = _DBConfig.ValidataType;

            //    if (!DBSettings.Exist(_NewDBConfig))
            //        DBSettings.AddConfigLiat(_NewDBConfig);
            //}
            ////如果回传
            //if (isPostBack)
            //{
            //    this.Hide();
            //    _MainForm.LoadData();
            //}
            //else
            //{
            //    this.Hide();
            //    _MainForm = new MainForm(this);
            //    _MainForm.Show();
            //}
            //    SelectForms sf = new SelectForms();
            //    sf.Show();
            //}
            //else
            //{

            //}
            //else
            //{
            //    MessageHelper.WarningMessageShow("请先测试连接,稍后重试!");
            //}

            this.DialogResult = DialogResult.Cancel;
            if (IsPostBack)
            {
                this.Close();
            }
            else
            {
                var gen = new frmGenerator();
                //传递事件到外层
                gen.Generate += (list, dict, p) => Generate(list, dict, p);
                gen.Show();
                this.Hide();
            }
        }
Example #4
0
        /// <summary>
        /// 读取数据库
        /// </summary>
        /// <param name="_DBConfig"></param>
        /// <returns></returns>
        public TreeNode LoadDataBase(DBConfig _DBConfig)
        {
            TreeNode tn = new TreeNode();

            tn.Text       = _DBConfig.DataBase;
            tn.ImageIndex = 1;
            tn.Tag        = "DataBase";
            //tn.ContextMenuStrip = cmsForDataBase;

            TreeNode tnDataTables = new TreeNode();

            tnDataTables.Text       = "数据表";
            tnDataTables.ImageIndex = 2;
            tnDataTables.Tag        = "DataTables";

            DataTable dtTables = new DataTable();

            dtTables = SQLServerDBHelper.GetTables(_DBConfig.ConString, "U");
            for (int i = 0; i < dtTables.Rows.Count; i++)
            {
                DataRow  tableRow = dtTables.Rows[i];
                TreeNode tnTable  = new TreeNode();
                tnTable.Text       = tableRow[0].ToString();
                tnTable.ImageIndex = 3;
                tnTable.Tag        = "Table|" + _DBConfig.ConString;
                //tnTable.ContextMenuStrip = cmsForTable;
                tnDataTables.Nodes.Add(tnTable);
            }

            TreeNode tnDataView = new TreeNode("视图");

            //tnDataView.Nodes[0].show
            tnDataView.ImageIndex = 2;
            tnDataView.Tag        = "DataViews";
            //tnDataView.

            DataTable dtViews = new DataTable();

            dtViews = SQLServerDBHelper.GetTables(_DBConfig.ConString, "V");
            for (int j = 0; j < dtViews.Rows.Count; j++)
            {
                DataRow  viewRow = dtViews.Rows[j];
                TreeNode tnView  = new TreeNode();
                tnView.Text       = viewRow[0].ToString();
                tnView.ImageIndex = 4;
                tnView.Tag        = "View";
                //tnView.ContextMenuStrip = cmsForView;
                tnDataView.Nodes.Add(tnView);
                //HideCheckBox(tnView);
            }

            TreeNode tnDataProc = new TreeNode("存储过程");

            tnDataProc.ImageIndex = 2;
            tnDataProc.Tag        = "DataProcs";

            DataTable dtProcs = new DataTable();

            dtProcs = SQLServerDBHelper.GetTables(_DBConfig.ConString, "P");
            for (int k = 0; k < dtProcs.Rows.Count; k++)
            {
                DataRow  procRow = dtProcs.Rows[k];
                TreeNode tnProc  = new TreeNode();
                tnProc.Text       = procRow[0].ToString();
                tnProc.ImageIndex = 5;
                tnProc.Tag        = "Proc";
                //tnProc.ContextMenuStrip = cmsForProc;
                tnDataProc.Nodes.Add(tnProc);
                //HideCheckBox(tnProc);
            }

            tn.Nodes.Add(tnDataTables);
            tn.Nodes.Add(tnDataView);
            tn.Nodes.Add(tnDataProc);
            return(tn);
        }