Ejemplo n.º 1
0
        private void NonQuerySql(string sql)
        {
            dtResult = null;

            try
            {
                using (PDBConnection conn = new PDBConnection(GlobalVar.ConnStr))
                {
                    conn.Open();
                    PDBCommand cmd = conn.CreateCommand();
                    cmd.ExecuteNonQuery(sql);

                    this.richTxtMsg.Text      = "SQL:\n" + sql + "\n执行成功";
                    this.richTxtMsg.ForeColor = Color.Green;
                }
            }
            catch (Exception ex)
            {
                this.richTxtMsg.Text      = "执行SQL:\n" + sql + "\n发生错误:" + ex.Message;
                this.richTxtMsg.ForeColor = Color.Red;
            }

            this.tabControlResult.SelectedTab = this.tabPageMsg;
            BindResult();
        }
Ejemplo n.º 2
0
 private void QuerySql(string sql)
 {
     dtResult = null;
     try
     {
         Stopwatch sw = new Stopwatch();
         sw.Start();
         using (PDBConnection conn = new PDBConnection(GlobalVar.ConnStr))
         {
             conn.Open();
             PDBCommand cmd = conn.CreateCommand();
             dtResult = cmd.ExecuteQuery(sql);
             sw.Stop();
             this.tabControlResult.SelectedTab = this.tabPageData;
             this.richTxtMsg.Text      = "SQL:\n" + sql + "\n执行成功\n执行耗时:" + sw.ElapsedMilliseconds + "ms";
             this.richTxtMsg.ForeColor = Color.Green;
         }
     }
     catch (Exception ex)
     {
         this.richTxtMsg.Text              = "SQL:\n" + sql + "\n发生错误:" + ex.Message;
         this.richTxtMsg.ForeColor         = Color.Red;
         this.tabControlResult.SelectedTab = this.tabPageMsg;
     }
     BindResult();
 }
Ejemplo n.º 3
0
        private void InsertSql(string sql)
        {
            dtResult = null;
            try
            {
                using (PDBConnection conn = new PDBConnection(GlobalVar.ConnStr))
                {
                    conn.Open();
                    PDBCommand   cmd    = conn.CreateCommand();
                    PDBErrorCode retVal = cmd.ExecuteInsert(sql);
                    if (retVal != PDBErrorCode.PdbE_OK)
                    {
                        this.richTxtMsg.Text      = "SQL:\n" + sql + "\n发生错误:\n";
                        this.richTxtMsg.Text     += PDBErrorMsg.GetErrorMsg(retVal);
                        this.richTxtMsg.ForeColor = Color.Red;
                    }
                    else
                    {
                        this.richTxtMsg.Text      = "SQL:\n" + sql + "\n执行成功!";
                        this.richTxtMsg.ForeColor = Color.Green;
                    }
                }
            }
            catch (Exception ex)
            {
                this.richTxtMsg.Text      = "执行SQL:\n" + sql + "\n发生错误:" + ex.Message;
                this.richTxtMsg.ForeColor = Color.Red;
            }

            this.tabControlResult.SelectedTab = this.tabPageMsg;
            BindResult();
        }
Ejemplo n.º 4
0
        private void BindTableList(TreeNode sysTabRoot, TreeNode dataTabRoot)
        {
            try
            {
                using (PDBConnection conn = new PDBConnection(GlobalVar.ConnStr))
                {
                    conn.Open();
                    PDBCommand cmd = conn.CreateCommand();

                    DataTable dtTable = cmd.ExecuteQuery("select * from sys_table");
                    foreach (DataRow dr in dtTable.Rows)
                    {
                        string    tabName  = dr["tabname"].ToString();
                        DataTable colTable = cmd.ExecuteQuery(string.Format("select * from sys_column where tabname='{0}'", tabName));

                        if (tabName.StartsWith("sys_"))
                        {
                            BindTableInfo(sysTabRoot, tabName, colTable);
                        }
                        else
                        {
                            BindTableInfo(dataTabRoot, tabName, colTable);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowError(ex.Message);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Open database with connectstring
        /// </summary>
        public void Open()
        {
            if (conn != null && conn.IsValid() == true)
            {
                ;
            }

            conn = new PDBConnection(ConnectString);
            conn.Open();
        }
Ejemplo n.º 6
0
        private bool LoginPDB()
        {
            if (this.txbServer.Text.Trim().Length == 0)
            {
                MsgBox.ShowError("服务器地址不能为空!");
                return(false);
            }

            if (this.txbPort.Text.Trim().Length == 0)
            {
                MsgBox.ShowError("端口不能为空!");
                return(false);
            }

            if (this.txbUser.Text.Trim().Length == 0)
            {
                MsgBox.ShowError("用户名不能为空!");
                return(false);
            }

            if (this.txbPwd.Text.Trim().Length == 0)
            {
                MsgBox.ShowError("密码不能为空!");
                return(false);
            }

            string connStr = string.Format("server={0};port={1};username={2};password={3}",
                                           this.txbServer.Text.Trim(), this.txbPort.Text.Trim(),
                                           this.txbUser.Text.Trim(), this.txbPwd.Text.Trim());

            try
            {
                using (PDBConnection conn = new PDBConnection(connStr))
                {
                    conn.Open();
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowError(ex.Message);
                return(false);
            }

            GlobalVar.Server      = this.txbServer.Text.Trim();
            GlobalVar.Port        = int.Parse(this.txbPort.Text.Trim());
            GlobalVar.User        = this.txbUser.Text.Trim();
            GlobalVar.Pwd         = this.txbPwd.Text.Trim();
            GlobalVar.ConnStr     = connStr;
            GlobalVar.IsConnected = true;

            return(true);
        }
Ejemplo n.º 7
0
        private bool updatePwd()
        {
            if (this.txbPwd.Text.Trim().Length < 6 || this.txbPwd1.Text.Trim().Length < 6)
            {
                MsgBox.ShowError("密码不能小于6位!");
                return(false);
            }

            if (!this.txbPwd.Text.Trim().Equals(this.txbPwd1.Text.Trim()))
            {
                MsgBox.ShowError("两次输入密码不相等,请重新输入!");

                this.txbPwd.Text  = "";
                this.txbPwd1.Text = "";
                this.txbPwd.Focus();
                return(false);
            }
            else if (this.txbPwd.Text.Trim().Equals("pinusdb"))
            {
                MsgBox.ShowError("不能设置为与初始密码相同!");
                return(false);
            }
            else
            {
                try
                {
                    string sql = "set password for sa=password('" + this.txbPwd.Text.Trim() + "')";
                    using (PDBConnection conn = new PDBConnection(GlobalVar.ConnStr))
                    {
                        conn.Open();
                        PDBCommand cmd = conn.CreateCommand();
                        cmd.ExecuteNonQuery(sql);

                        GlobalVar.Pwd = this.txbPwd.Text.Trim();
                        string connStr = string.Format("server={0};port={1};username={2};password={3}",
                                                       GlobalVar.Server, GlobalVar.Port, GlobalVar.User, GlobalVar.Pwd);
                        GlobalVar.ConnStr = connStr;
                        this.DialogResult = DialogResult.OK;
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    MsgBox.ShowError(ex.Message);
                    return(false);
                }
            }
        }
Ejemplo n.º 8
0
        private void SysMessageForm_Load(object sender, EventArgs e)
        {
            try
            {
                string majorVer = "";
                string minorVer = "";
                string buildVer = "";
                string dbSql    = "select name,value from sys_config";
                using (PDBConnection conn = new PDBConnection(GlobalVar.ConnStr))
                {
                    conn.Open();
                    PDBCommand cmd      = conn.CreateCommand();
                    DataTable  dtResult = cmd.ExecuteQuery(dbSql);
                    foreach (DataRow dr in dtResult.Rows)
                    {
                        string nameStr = dr["name"].ToString().ToLower();
                        string valStr  = dr["value"].ToString();

                        switch (nameStr)
                        {
                        case "majorversion":
                            majorVer = valStr;
                            break;

                        case "minorversion":
                            minorVer = valStr;
                            break;

                        case "buildversion":
                            buildVer = valStr;
                            break;

                        case "devcnt":
                            lblLicDevCnt.Text = valStr;
                            break;
                        }
                    }

                    lblDBVer.Text = majorVer + "." + minorVer + "." + buildVer;
                }
            }catch (Exception)
            {
                MsgBox.ShowError("读取系统配置失败");
                return;
            }
        }
Ejemplo n.º 9
0
        private void AboutForm_Load(object sender, EventArgs e)
        {
            String    sql      = "select name,value from sys_config";
            DataTable dtResult = null;

            try
            {
                using (PDBConnection conn = new PDBConnection(GlobalVar.ConnStr))
                {
                    conn.Open();
                    PDBCommand cmd = conn.CreateCommand();
                    dtResult = cmd.ExecuteQuery(sql);
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowError("读取系统配置表出错");
                return;
            }

            string majorVer = "";
            string minorVer = "";
            string buildVer = "";

            foreach (DataRow dr in dtResult.Rows)
            {
                if (dr["name"].ToString().Equals("majorVersion"))
                {
                    majorVer = dr["value"].ToString();
                }
                else if (dr["name"].ToString().Equals("minorVersion"))
                {
                    minorVer = dr["value"].ToString();
                }
                else if (dr["name"].ToString().Equals("buildVersion"))
                {
                    buildVer = dr["value"].ToString();
                }
            }

            this.lblDBVersion.Text = majorVer + "." + minorVer + "." + buildVer;
        }
Ejemplo n.º 10
0
        private bool CreateTable(string sql)
        {
            try
            {
                using (PDBConnection conn = new PDBConnection(GlobalVar.ConnStr))
                {
                    conn.Open();
                    PDBCommand cmd = conn.CreateCommand();
                    cmd.ExecuteNonQuery(sql);
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowError(ex.Message);
                return(false);
            }
            initEvent();
            MsgBox.ShowInfo("创建表成功");

            return(true);
        }
Ejemplo n.º 11
0
        public PDBConnection GetConnection()
        {
            do
            {
                lock (this)
                {
                    while (connList_.Count > 0)
                    {
                        int           idx     = connList_.Count - 1;
                        PDBConnection tmpConn = connList_[idx];
                        connList_.RemoveAt(idx);

                        if (tmpConn.IsValid())
                        {
                            return(tmpConn);
                        }
                        else
                        {
                            tmpConn.Dispose();
                            Interlocked.Decrement(ref curConnCnt_);
                            connEvent_.Set();
                        }
                    }

                    if (curConnCnt_ < maxConnCnt_)
                    {
                        PDBConnection conn = new PDBConnection(connStr_);
                        conn.Open();
                        Interlocked.Increment(ref curConnCnt_);
                        return(conn);
                    }
                    else
                    {
                        connEvent_.Reset();
                    }
                }

                connEvent_.WaitOne();
            } while (true);
        }
Ejemplo n.º 12
0
 private void detachTable()
 {
     if (tvNav.SelectedNode != null)
     {
         //根节点没有父节点会报错
         if (tvNav.SelectedNode.Level == 0 || tvNav.SelectedNode.Parent.Text != "数据表")
         {
             MsgBox.ShowError("请选择要分离的数据表!");
             return;
         }
         string       tableName = tvNav.SelectedNode.Text;
         DialogResult dr        = MsgBox.ShowQuestion("您确定要分离数据表【" + tableName + "】吗?");
         if (dr == DialogResult.OK)
         {
             string sql = "detach table " + tableName;
             try
             {
                 using (PDBConnection conn = new PDBConnection(GlobalVar.ConnStr))
                 {
                     conn.Open();
                     PDBCommand cmd = conn.CreateCommand();
                     cmd.ExecuteNonQuery(sql);
                 }
             }
             catch (Exception ex)
             {
                 MsgBox.ShowError(ex.Message);
                 return;
             }
             InitTreeNav();
             MsgBox.ShowInfo("分离表成功");
         }
     }
     else
     {
         MsgBox.ShowError("请选择要分离的数据表!");
     }
 }