예제 #1
0
 public FrmBatchCodeMaker(string longservername)
 {
     InitializeComponent();
     dbset = DbConfig.GetSetting(longservername);
     dbobj = DBOMaker.CreateDbObj(dbset.DbType);
     dbobj.DbConnectStr  = dbset.ConnectStr;
     this.lblServer.Text = dbset.Server;
 }
예제 #2
0
        private void CreatDbObj(string servername)
        {
            var dbset = DbConfig.GetSetting(servername);

            //todo:这儿要尽量做到通用。
            dbObject = DBOMaker.CreateDbObj(dbset.DbType);
            dbObject.DbConnectStr = dbset.ConnectStr;
        }
예제 #3
0
        private void btnConnTest_Click(object sender, System.EventArgs e)
        {
            try
            {
                string server = this.comboBoxServer.Text.Trim();
                string user   = this.txtUser.Text.Trim();
                string pass   = this.txtPass.Text.Trim();
                if ((user == "") || (server == ""))
                {
                    MessageBox.Show(this, "服务器或用户名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                constr = GetSelVerified() == "Windows"
                                ? "Integrated Security=SSPI;Data Source=" + server + ";Initial Catalog=master"
                                : (pass == ""
                                    ? "user id=" + user + ";initial catalog=master;data source=" + server
                                    : "user id=" + user + ";password="******";initial catalog=master;data source=" + server);

                string strtype = GetSelVer();

                #region 判断版本 GetSelVer()
                try
                {
                    string ver = GetSQLVer(constr);
                    if ((ver == "8") && (strtype == "SQL2005"))
                    {
                        DialogResult dr = MessageBox.Show(this, "该数据库服务器版本并非SQLServer 2005,是否进行重新选择?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        if (dr == DialogResult.OK)
                        {
                            //comboBoxServerVer.SelectedIndex = 1;
                            return;
                        }
                    }
                    if ((ver == "9") && (strtype == "SQL2000"))
                    {
                        DialogResult dr = MessageBox.Show(this, "该数据库服务器版本并非SQLServer 2000,是否进行重新选择?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                        if (dr == DialogResult.OK)
                        {
                            //comboBoxServerVer.SelectedIndex = 0;
                            return;
                        }
                    }
                }
                catch
                {
                }
                #endregion

                try
                {
                    this.Text = "正在连接服务器,请稍候...";

                    IDbObject dbobj;
                    dbobj = DBOMaker.CreateDbObj(strtype);

                    dbobj.DbConnectStr = constr;
                    var dblist = dbobj.GetDBList();

                    this.cmbDBlist.Enabled = true;
                    this.cmbDBlist.Items.Clear();
                    this.cmbDBlist.Items.Add("全部库");
                    if (dblist != null)
                    {
                        if (dblist.Count > 0)
                        {
                            foreach (string dbName in dblist)
                            {
                                this.cmbDBlist.Items.Add(dbName);
                            }
                        }
                    }
                    this.cmbDBlist.SelectedIndex = 0;
                    this.Text = "连接服务器成功!";
                }
                catch (System.Exception ex)
                {
                    LogHelper.WriteException(ex);
                    this.Text = "连接服务器或获取数据信息失败!";
                    string strinfo = "连接服务器或获取数据信息失败!\r\n";
                    strinfo += "请检查服务器地址或用户名密码是否正确!\r\n";
                    strinfo += "如果连接失败,服务器名可以用 “(local)”或是“.” 或者“机器名” 试一下!\r\n";
                    strinfo += "如果需要查看帮助文件以帮助您解决问题,请点“确定”,否则点“取消”";
                    DialogResult drs = MessageBox.Show(this, strinfo, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    if (drs == DialogResult.OK)
                    {
                        try
                        {
                            Process proc = new Process();
                            Process.Start("IExplore.exe", "http://www.cnblogs.com/huyong/");
                        }
                        catch
                        {
                            MessageBox.Show("请访问:http://www.cnblogs.com/huyong/", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    return;
                }
            }
            catch (System.Exception ex)
            {
                //LogInfo.WriteLog(System.Reflection.MethodBase.GetCurrentMethod(), ex);
                LogHelper.WriteException(ex);
                MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #4
0
        public void GenerateDataGridView()
        {
            if (this.CurrentDbViewForm == null)
            {
                MessageBox.Show("无可用对象!");
            }

            dgvDefine.AutoGenerateColumns = false;

            #region 手动生成列(已注释)

            /*
             * DataGridViewTextBoxColumn colAttribute = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "ColumnName";
             * colAttribute.HeaderText = "属性名称";
             * colAttribute.Name = "colAttribute";
             *
             * DataGridViewComboBoxColumn colType = new System.Windows.Forms.DataGridViewComboBoxColumn();
             * colAttribute.DataPropertyName = "TypeName";
             * colAttribute.HeaderText = "类型";
             * colAttribute.Name = "colType";
             *
             * DataGridViewTextBoxColumn colTitle = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "ColDescription";
             * colAttribute.HeaderText = "标题";
             * colAttribute.Name = "colTitle";
             *
             * DataGridViewTextBoxColumn colDTColumnName = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "ColumnName";
             * colAttribute.HeaderText = "列名";
             * colAttribute.Name = "colDTColumnName";
             *
             * DataGridViewComboBoxColumn colDTDataType = new System.Windows.Forms.DataGridViewComboBoxColumn();
             * colAttribute.DataPropertyName = "";
             * colAttribute.HeaderText = "数据类型";
             * colAttribute.Name = "colDTDataType";
             *
             * DataGridViewTextBoxColumn colDTDataLength = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "Length";
             * colAttribute.HeaderText = "长度";
             * colAttribute.Name = "colDTDataLength";
             *
             * DataGridViewTextBoxColumn colDTDataPreci = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "Preci";
             * colAttribute.HeaderText = "小数";
             * colAttribute.Name = "colDTDataPreci";
             *
             * DataGridViewCheckBoxColumn colDTDataNull = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             * colAttribute.DataPropertyName = "IsNull";
             * colAttribute.HeaderText = "非空";
             * colDTDataNull.Width = 45;
             * colAttribute.Name = "colDTDataNull";
             *
             * DataGridViewCheckBoxColumn colDTDataPrimaryKey = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             * colAttribute.DataPropertyName = "IsPK";
             * colAttribute.HeaderText = "主键";
             * colDTDataNull.Width = 45;
             * colAttribute.Name = "colDTDataPrimaryKey";
             *
             * DataGridViewCheckBoxColumn colDTDataIdentity = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             * colAttribute.DataPropertyName = "IsIdentity";
             * colAttribute.HeaderText = "自增";
             * colDTDataNull.Width = 45;
             * colAttribute.Name = "colDTDataIdentity";
             *
             * DataGridViewTextBoxColumn colDTDataDefaultValue = new System.Windows.Forms.DataGridViewTextBoxColumn();
             * colAttribute.DataPropertyName = "DefaultVal";
             * colAttribute.HeaderText = "默认值";
             * colAttribute.Name = "colDTDataDefaultValue";
             *
             * this.dgvDefine.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[]
             * {
             *  colAttribute, colType, colTitle, colDTColumnName, colDTDataType, colDTDataLength,
             *  colDTDataPreci, colDTDataNull, colDTDataPrimaryKey, colDTDataIdentity, colDTDataDefaultValue
             * });
             */
            #endregion

            var selectedNode = this.CurrentDbViewForm.treeView1.SelectedNode;
            if (selectedNode == null)
            {
                return;
            }
            this.ServerName = selectedNode.Parent.Parent.Parent.Text;
            this.DBName     = selectedNode.Parent.Parent.Text;
            this.TableName  = selectedNode.Text;

            txtName.Text      = this.TableName;
            txtTableName.Text = this.TableName;
            dbSet             = DbConfig.GetSetting(this.ServerName);

            var listDataTypeRefer = GetDataTypeRefer();
            colType.ValueMember      = "To";
            colType.DisplayMember    = "To";
            colType.DataPropertyName = "To";
            colType.DataSource       = listDataTypeRefer;

            colDTDataType.ValueMember      = "From";
            colDTDataType.DisplayMember    = "From";
            colDTDataType.DataPropertyName = "From";
            colDTDataType.DataSource       = listDataTypeRefer;
            //todo:这儿要尽量做到通用。
            idbObj = DBOMaker.CreateDbObj(dbSet.DbType);
            idbObj.DbConnectStr = dbSet.ConnectStr;
            var colList = idbObj.GetColumnInfoList(this.DBName, this.TableName);
            dgvDefine.DataSource = colList;
        }