Beispiel #1
0
 private void btnConnectTest_Click(object sender, EventArgs e)
 {
     try
     {
         con = new SqlConnection(DBUtils.GetConnetionString(this.ipBox.Text.Trim(),
                                                            this.userBox.Text.Trim(),
                                                            this.pwdBox.Text.Trim()));
         con.Open();
         string sql = @"Select   name   from   master..sysdatabases where   name   not   in('master','model','msdb','tempdb','northwind','pubs')";
         var    dt  = DBUtils.execSql(con, sql);
         if (dt != null && dt.Rows.Count > 0)
         {
             if (!this.dbList.Enabled)
             {
                 this.dbList.Enabled = true;
             }
             this.dbList.DataSource = null;
             this.dbList.Items.Clear();
             this.dbList.DataSource = dt.AsEnumerable().Select(r => r["name"].ToString()).ToList();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("数据源配置出错,请检查\r\n" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Beispiel #2
0
        private void loadColumns()
        {
            /*if (totalCount == 0)
             * {
             *  MessageBox.Show("请先设置脚本!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             *
             *  return;
             * }*/

            #region try to set connettion
            try
            {
                if (con != null)
                {
                    con.Close();
                }
                con = new SqlConnection(DBUtils.GetConnetionString(config.DataSource.Ip, config.DataSource.User, config.DataSource.Pwd, config.Script.Db));
                con.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("该脚本已不可用,请重新自定义或联系逐浪官方\r\n" + ex.Message,
                                "提示",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            #endregion

            #region check connection and query columns
            if (con.State != ConnectionState.Open)
            {
                MessageBox.Show("连接未打开!\r\n请重新测试脚本 或 重新加载", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //从数据库获取列名
            string    sql = "select top 0 * from (" + config.Script.Sql + ") as temp";
            DataTable dt;
            try
            {
                dt = DBUtils.execSql(con, sql);
            }
            catch (Exception ex)
            {
                MessageBox.Show("您的脚本语句有语法错误,具体如下\r\n" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            #endregion

            #region try to parse the data from server then bind to DataGridView
            this.dataFormatTable.Rows.Clear();
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                DataGridViewRow          r             = new DataGridViewRow();
                DataGridViewCheckBoxCell stateCheckBox = new DataGridViewCheckBoxCell();
                stateCheckBox.Value = true;
                DataGridViewComboBoxCell typeComboList = new DataGridViewComboBoxCell();
                typeComboList.Items.Add("普通文本");
                typeComboList.Items.Add("日期");
                typeComboList.Items.Add("日期和时间");
                typeComboList.Items.Add("真假");
                typeComboList.Items.Add("整型");
                typeComboList.Items.Add("浮点型");
                typeComboList.Items.Add("超链接");
                typeComboList.Items.Add("其他");
                typeComboList.Items.Add("小数型");
                DBType dBType = (DBType)Enum.Parse(typeof(DBType), (dt.Columns[i].DataType).ToString().Split('.')[1]);
                typeComboList.Value = ((ComboName)((int)dBType)).ToString();
                DataGridViewTextBoxCell nameBox = new DataGridViewTextBoxCell();
                nameBox.Value = dt.Columns[i].ColumnName;
                DataGridViewTextBoxCell widthBox = new DataGridViewTextBoxCell();
                widthBox.Value = 10;
                DataGridViewTextBoxCell hideColumnName = new DataGridViewTextBoxCell();
                hideColumnName.Value = dt.Columns[i].ColumnName;
                r.Cells.Add(stateCheckBox);
                r.Cells.Add(nameBox);
                r.Cells.Add(typeComboList);
                r.Cells.Add(widthBox);
                r.Cells.Add(hideColumnName);
                this.dataFormatTable.Rows.Add(r);
            }
            #endregion

            #region step control
            this.tabPage2.Parent = this.stepControl;
            this.tabPage1.Parent = null;
            this.tabPage3.Parent = null;



            #endregion
        }