Example #1
0
        private void RefreshServer()
        {
            this.button_RefreshServer.Enabled = false;
            this.comboBox_Server.Enabled      = false;
            this.comboBox_Server.Items.Clear();
            this.comboBox_Server.Text = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBConnectCtrl_RetrievingDataSources");
            System.Windows.Forms.Application.DoEvents();

            Cursor.Current = Cursors.WaitCursor;

            System.Data.DataTable dataTable = sqlAS.EnumSqlservers();

            DisplayData(dataTable);
            if (this.comboBox_Server.Items.Count > 0)
            {
                comboBox_Server.SelectedIndex = 0;
            }
            else
            {
                comboBox_Server.Text = "";
            }

            this.button_RefreshServer.Enabled = true;
            this.comboBox_Server.Enabled      = true;

            Cursor.Current = Cursors.Default;
        }
Example #2
0
        private bool IsAuthorized()
        {
            if (CurrentPrjInfo.CurrentEnvironment == MESEnvironment.MESReportDesigner ||
                CurrentPrjInfo.CurrentEnvironment == MESEnvironment.MESDesigner ||
                CurrentPrjInfo.CurrentEnvironment == MESEnvironment.MESDeveloper ||
                CurrentPrjInfo.CurrentEnvironment == MESEnvironment.MESClient
                )
            {
                return(true);
            }
            else if (CurrentPrjInfo.CurrentEnvironment == MESEnvironment.None)
            {
                if (_dogExpert.IsFieldRunning())
                {
                    return(true);
                }
            }

            if (_dogExpert.IsMESReportEnabled())
            {
                return(true);
            }
            else
            {
                if (_bAuthorized)
                {
                    return(true);
                }
                ToolBarVisible = false;
                Form f = this.FindForm();
                f.Text += GetStringFromPublicResourceClass.GetStringFromPublicResource("MESReportIsNotAuthorized");
                return(false);
            }
        }
Example #3
0
        private void SelectedForm_Load(object sender, EventArgs e)
        {
            switch (_doctype)
            {
            case byte.MaxValue:
                this.Text = GetStringFromPublicResourceClass.GetStringFromPublicResource("MESPleaseSelectView");
                break;

            case 1:
                this.Text = GetStringFromPublicResourceClass.GetStringFromPublicResource("MESPleaseSelectReport");
                break;

            case 2:
                this.Text = GetStringFromPublicResourceClass.GetStringFromPublicResource("MESPleaseSelectForm");
                break;
            }

            CurrentPrjInfo.GetFormTreeView(_doctype, ref this.treeView1);
            if (null != Identity)
            {
                TreeNode node = FindNodeOnPath(this.treeView1.Nodes, Identity.FullPath);
                if (null != node)
                {
                    this.treeView1.SelectedNode = node;
                    node.EnsureVisible();
                }
            }
        }
Example #4
0
        private void button_ConnectTest_Click(object sender, EventArgs e)
        {
            string myServerName = comboBox_Server.Text.Trim();
            string myDBName     = comboBox_DB.Text.Trim();
            string userId       = textBox_UserName.Text.Trim();
            string passWord     = textBox_Password.Text.Trim();
            int    ConnectType  = comboBox_Protocol.SelectedIndex + 1;
            string portID       = textBox_PortID.Text;
            string strConnect   = "";

            if (ConnectType == 1)
            {
                strConnect = "Pooling = 'false';Server=" + myServerName +
                             ";Initial Catalog=" + myDBName +
                             ";User Id=" + userId +
                             ";Password="******";";
            }
            else if (ConnectType == 2)//Pooling = 'false';
            {
                strConnect = "Server=tcp:" + myServerName + "," + portID +
                             ";Initial Catalog=" + myDBName +
                             ";User Id=" + userId +
                             ";Password="******";";
            }
            //strConnect = "Server=TCP:" + myServerName + "," + portID +
            //    ";Initial Catalog=" + myDBName +
            //    ";User Id=" + userId +
            //    ";Password="******";";
            SqlConnection conn = null;

            try
            {
                conn = new SqlConnection(strConnect);
                conn.Open();
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
            if (conn.State == ConnectionState.Open)
            {
                string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBConnectCtrl_DBConTestSucceed");
                string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Succeed");
                MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                conn.Close();
            }
            else
            {
                string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBConnectCtrl_DBConTestFail");
                string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Fail");
                MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #5
0
        private void RefreshDB()
        {
            string myServerName = comboBox_Server.Text.Trim();
            string userId       = textBox_UserName.Text.Trim();
            string passWord     = textBox_Password.Text.Trim();

            if (myServerName.CompareTo("") == 0)
            {
                string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBConnectCtrl_DBServerNameIsNull");
                string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            this.button_RefreshDB.Enabled = false;
            this.comboBox_DB.Enabled      = false;
            this.comboBox_DB.Items.Clear();
            this.comboBox_DB.Text = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBConnectCtrl_RetrievingDataSources");
            System.Windows.Forms.Application.DoEvents();

            Cursor.Current = Cursors.WaitCursor;

            if (!sqlAS.ConnectSMOServer(myServerName, userId, passWord))
            {
                comboBox_DB.Text = "";
                this.button_RefreshDB.Enabled = true;
                this.comboBox_DB.Enabled      = true;

                Cursor.Current = Cursors.Default;
                return;
            }

            List <string> databases = sqlAS.GetServerDatabases();

            comboBox_DB.Items.Clear();

            if (null != databases)
            {
                foreach (string dbName in databases)
                {
                    comboBox_DB.Items.Add(dbName);
                }
            }
            if (this.comboBox_DB.Items.Count > 0)
            {
                comboBox_DB.SelectedIndex = 0;
            }
            else
            {
                comboBox_DB.Text = "";
            }

            this.button_RefreshDB.Enabled = true;
            this.comboBox_DB.Enabled      = true;

            Cursor.Current = Cursors.Default;
        }
Example #6
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(sourceName))
            {
                string strformat = string.Format(GetStringFromPublicResourceClass.GetStringFromPublicResource("NewDBSourceForm_DBSourceCantNull"));
                MessageBox.Show(strformat, GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (IsDBSourceNameExisted(sourceName))
            {
                string strformat = string.Format(GetStringFromPublicResourceClass.GetStringFromPublicResource("NewDBSourceForm_DBSourceExisted"), sourceName);
                MessageBox.Show(strformat, GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }
Example #7
0
        private void button_ConnectAccessTest_Click(object sender, EventArgs e)
        {
            string strMsAccessPath = textBox_MSAccessPath.Text.Trim();

            strMsAccessPath = ProjectPathClass.ParseStringWithMacro(strMsAccessPath);
            if (string.IsNullOrEmpty(strMsAccessPath))
            {
                string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBAccessPathNULL");
                string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string userId   = textBox_MSAccessUID.Text.Trim();
            string passWord = textBox_MSAccessPass.Text.Trim();

            try
            {
                OleDbConnectionStringBuilder connectStringBuilder = new OleDbConnectionStringBuilder();
                connectStringBuilder.DataSource = strMsAccessPath;
                connectStringBuilder.Provider   = "Microsoft.Jet.OLEDB.4.0";
                OleDbConnection _OleDbConn = new OleDbConnection(connectStringBuilder.ConnectionString);
                _OleDbConn.Open();

                if (_OleDbConn == null)
                {
                    string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                    MessageBox.Show(_RefDBConnection.GetLastError(), strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                if (_OleDbConn.State == ConnectionState.Open)
                {
                    string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBConnectCtrl_DBConTestSucceed");
                    string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Succeed");
                    MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    _OleDbConn.Close();
                }
            }
            catch (System.Data.OleDb.OleDbException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #8
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            int iret = ConnectDB();

            if (iret == 2)
            {
                // 连接成功关闭ParentForm
                this.Close();
                this.DialogResult = DialogResult.OK;
            }
            else if (iret == 0)
            {
                string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBConnectCtrl_DBConTestFail");
                string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Fail");
                MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //else if(iret == 0)
            //{
            //    string strText = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBConnectCtrl_UserLoginFail");
            //    string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Fail");
            //    MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
        }
Example #9
0
        private void Btn_OleDBTest_Click(object sender, EventArgs e)
        {
            string strOleConnectString = comboBox_ConnectString.Text.Trim();

            if (string.IsNullOrEmpty(strOleConnectString))
            {
                string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSOleDBConnectStringNull");
                string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                OleDbConnection _OleDbConn = new OleDbConnection(strOleConnectString);
                _OleDbConn.Open();

                if (_OleDbConn == null)
                {
                    string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                    MessageBox.Show(_RefDBConnection.GetLastError(), strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (_OleDbConn.State == ConnectionState.Open)
                {
                    string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBConnectCtrl_DBConTestSucceed");
                    string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Succeed");
                    MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    _OleDbConn.Close();
                }
            }
            catch (System.Data.OleDb.OleDbException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #10
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>
        /// 0 -- 数据库连接失败
        /// 1 -- 用户登录失败
        /// 2 -- 连接成功
        /// </returns>
        private int ConnectDB()
        {
            this.button_OK.Enabled = false;
            bConnected             = false;
            if (_SelectDBType == RefDBType.MSSqlServer)
            {
                string myServerName = comboBox_Server.Text.Trim();
                if (string.IsNullOrEmpty(myServerName))
                {
                    string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBServerNULL");
                    string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                    MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.button_OK.Enabled = true;
                    return(0);
                }
                string myDBName = comboBox_DB.Text.Trim();
                if (string.IsNullOrEmpty(myDBName))
                {
                    string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBDBNameNULL");
                    string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                    MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.button_OK.Enabled = true;
                    return(0);
                }
                string userId = textBox_UserName.Text.Trim();
                if (string.IsNullOrEmpty(userId))
                {
                    string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBUserIDNULL");
                    string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                    MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.button_OK.Enabled = true;
                    return(0);
                }
                string passWord = textBox_Password.Text.Trim();

                ConnectType iProtocolType = (ConnectType)(comboBox_Protocol.SelectedIndex + 1);

                string portID = textBox_PortID.Text.Trim();
                //string strConnect = "Data Source=" + myServerName +
                //        ";Initial Catalog=" + myDBName +
                //        ";User Id=" + userId +
                //        ";Password="******";";
                try
                {
                    _RefDBConnection               = new PMSRefDBConnection();
                    _RefDBConnection.RefDBType     = RefDBType.MSSqlServer;
                    _RefDBConnection.StrServerName = myServerName;
                    _RefDBConnection.StrDBName     = myDBName;
                    _RefDBConnection.StrUserID     = userId;
                    _RefDBConnection.StrPassWord   = passWord;
                    _RefDBConnection.EConnectType  = iProtocolType;
                    _RefDBConnection.StrPortID     = portID;
                    _conn = _RefDBConnection.GetSqlConnection();

                    //sqlStructure = new SqlStructure(myServerName, myDBName, userId, passWord, iProtocolType, portID);

                    //_conn = SqlStructure.GetSqlConncetion();
                    if (_conn == null)
                    {
                        bConnected             = false;
                        this.button_OK.Enabled = true;
                        return(0);
                    }
                    //if (!SqlStructure.ConnectSMOServer())
                    //{
                    //    bConnected = false;
                    //    this.button_OK.Enabled = true;
                    //    return 0;
                    //}

                    //SqlStructure.PMSCenterDataContext = new PMSCenterDataContext(_conn);
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    MessageBox.Show(ex.ToString());
                    bConnected             = false;
                    this.button_OK.Enabled = true;
                    return(0);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    bConnected             = false;
                    this.button_OK.Enabled = true;
                    return(0);
                }

                if (_conn.State == ConnectionState.Open)
                {
                    // 连接数据库成功
                    SaveSettings();
                    bConnected    = true;
                    strServerName = myServerName;
                    strDBName     = myDBName;
                    strUserID     = userId;
                    strPassWord   = passWord;

                    // 连接成功关闭
                    this.Close();
                    this.DialogResult = DialogResult.OK;
                    return(2);
                }
                else
                {
                    bConnected = false;
                    return(0);
                }
            }
            else if (_SelectDBType == RefDBType.Oracle)
            {
                string myServerName = comboBox_OracleServer.Text.Trim();
                if (string.IsNullOrEmpty(myServerName))
                {
                    string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBServerNULL");
                    string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                    MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.button_OK.Enabled = true;
                    return(0);
                }
                string userId = textBox_OracleUserID.Text.Trim();
                if (string.IsNullOrEmpty(userId))
                {
                    string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBUserIDNULL");
                    string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                    MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.button_OK.Enabled = true;
                    return(0);
                }
                string passWord          = textBox_OracleUserPass.Text.Trim();
                string OracleConnectAs   = comboBox_ConnectAs.Text.Trim();
                string OracleConnectMode = comboBox_ConnectMode.Text.Trim();
                string OracleHome        = comboBox_OracleHome.Text.Trim();
                string OracleSID         = string.Empty;
                string OraclePortID      = string.Empty;
                string OracleOwner       = textBox_Owner.Text.Trim();
                bool   OracleDirect      = checkBox_Direct.Checked;
                if (OracleDirect)
                {
                    OracleSID = comboBox_SID.Text.Trim();
                    if (string.IsNullOrEmpty(OracleSID))
                    {
                        string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBOracleSIDNULL");
                        string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                        MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        this.button_OK.Enabled = true;
                        return(0);
                    }
                    OraclePortID = textBox_OracleProtID.Text.Trim();
                    if (string.IsNullOrEmpty(OraclePortID))
                    {
                        string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBOraclePortIDNULL");
                        string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                        MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        this.button_OK.Enabled = true;
                        return(0);
                    }
                }

                try
                {
                    _RefDBConnection                = new PMSRefDBConnection();
                    _RefDBConnection.RefDBType      = RefDBType.Oracle;
                    _RefDBConnection.StrServerName  = myServerName;
                    _RefDBConnection.StrDBName      = OracleSID;
                    _RefDBConnection.StrUserID      = userId;
                    _RefDBConnection.StrPassWord    = passWord;
                    _RefDBConnection.BDirect        = OracleDirect;
                    _RefDBConnection.StrConnectAs   = OracleConnectAs;
                    _RefDBConnection.StrConnectMode = OracleConnectMode;
                    _RefDBConnection.StrPortID      = OraclePortID;
                    _RefDBConnection.Owner          = OracleOwner;
                    _conn = _RefDBConnection.GetOracleConnection();

                    if (_conn == null)
                    {
                        bConnected             = false;
                        this.button_OK.Enabled = true;
                        return(0);
                    }
                }
                catch (Oracle.DataAccess.Client.OracleException ex)
                {
                    MessageBox.Show(ex.ToString());
                    bConnected             = false;
                    this.button_OK.Enabled = true;
                    return(0);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    bConnected             = false;
                    this.button_OK.Enabled = true;
                    return(0);
                }

                if (_conn.State == ConnectionState.Open)
                {
                    // 连接数据库成功
                    SaveSettings();
                    bConnected    = true;
                    strServerName = myServerName;
                    strDBName     = OracleSID;
                    strUserID     = userId;
                    strPassWord   = passWord;

                    // 连接成功关闭
                    this.Close();
                    this.DialogResult = DialogResult.OK;
                    return(2);
                }
                else
                {
                    bConnected = false;
                    return(0);
                }
            }
            else if (_SelectDBType == RefDBType.MSAccess)
            {
                strMsAccessPath = textBox_MSAccessPath.Text.Trim();
                if (string.IsNullOrEmpty(strMsAccessPath))
                {
                    string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBAccessPathNULL");
                    string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                    MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.button_OK.Enabled = true;
                    return(0);
                }

                string userId   = textBox_MSAccessUID.Text.Trim();
                string passWord = textBox_MSAccessPass.Text.Trim();

                try
                {
                    _RefDBConnection           = new PMSRefDBConnection();
                    _RefDBConnection.RefDBType = RefDBType.MSAccess;
                    _RefDBConnection.StrDBPath = strMsAccessPath;
                    _OleDbConn = _RefDBConnection.GetOleConnection();
                    // 利用 OleDbConnectionStringBuilder 对象来构建
                    // 连接字符串。
                    //acsStructure = new AccessStructure(strMsAccessPath, userId, passWord);
                    //if (AccessStructure.ConnectDB())
                    //    _OleDbConn = AccessStructure.OleDbConn;
                    if (_OleDbConn == null)
                    {
                        string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                        MessageBox.Show(_RefDBConnection.GetLastError(), strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        bConnected             = false;
                        this.button_OK.Enabled = true;
                        return(0);
                    }
                }
                catch (System.Data.OleDb.OleDbException ex)
                {
                    MessageBox.Show(ex.ToString());
                    bConnected             = false;
                    this.button_OK.Enabled = true;
                    return(0);
                }

                if (_OleDbConn.State == ConnectionState.Open)
                {
                    // 连接数据库成功
                    SaveSettings();
                    bConnected = true;

                    return(2);
                }
                else
                {
                    bConnected = false;
                    return(0);
                }
            }
            else if (_SelectDBType == RefDBType.OleDB)
            {
                ConnectionString = comboBox_ConnectString.Text.Trim();
                if (string.IsNullOrEmpty(ConnectionString))
                {
                    bConnected = false;
                    return(0);
                }

                try
                {
                    _RefDBConnection               = new PMSRefDBConnection();
                    _RefDBConnection.RefDBType     = RefDBType.OleDB;
                    _RefDBConnection.ConnectString = ConnectionString;
                    _OleDbConn = _RefDBConnection.GetOleConnection();

                    if (_OleDbConn == null)
                    {
                        string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                        MessageBox.Show(_RefDBConnection.GetLastError(), strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        bConnected             = false;
                        this.button_OK.Enabled = true;
                        return(0);
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    bConnected             = false;
                    this.button_OK.Enabled = true;
                    return(0);
                }

                if (_OleDbConn.State == ConnectionState.Open)
                {
                    // 连接数据库成功
                    SaveSettings();
                    bConnected = true;
                    return(2);
                }
                else
                {
                    bConnected = false;
                    return(0);
                }
            }

            return(0);
        }
Example #11
0
        private void button_ConnectOracleTest_Click(object sender, EventArgs e)
        {
            string OracleServerName  = comboBox_OracleServer.Text.Trim();
            string OracleUserId      = textBox_OracleUserID.Text.Trim();
            string OraclePassWord    = textBox_OracleUserPass.Text.Trim();
            string OracleConnectAs   = comboBox_ConnectAs.Text.Trim();
            string OracleConnectMode = comboBox_ConnectMode.Text.Trim();
            string OracleHome        = comboBox_OracleHome.Text.Trim();
            string OracleSID         = comboBox_SID.Text.Trim();
            string OraclePortID      = textBox_OracleProtID.Text.Trim();
            bool   OracleDirect      = checkBox_Direct.Checked;
            string strConnect        = "";

            if (OracleDirect == false)
            {
                strConnect =   //Pooling = False;
                             "User Id=" + OracleUserId +
                             ";Password="******";Data Source=" + OracleServerName +
                             ";";
                if (OracleConnectAs != "Normal" && OracleConnectAs != "")
                {
                    strConnect += "DBA Privilege=" + OracleConnectAs +
                                  ";";
                }
            }
            else
            {
                strConnect = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + OracleServerName +
                             ")(PORT=" + OraclePortID +
                             ")))(CONNECT_DATA=(SERVER=" + OracleConnectMode +
                             ")(SERVICE_NAME=" + OracleSID +
                             ")));User Id=" + OracleUserId +
                             ";Password="******";";
            }

            OracleConnection conn = null;

            try
            {
                conn = new OracleConnection(strConnect);
                conn.Open();
            }
            catch (Oracle.DataAccess.Client.OracleException ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }

            if (conn.State == ConnectionState.Open)
            {
                string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBConnectCtrl_DBConTestSucceed");
                string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Succeed");
                MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                conn.Close();
            }
            else
            {
                string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBConnectCtrl_DBConTestFail");
                string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Fail");
                MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #12
0
        private int ConnectSqlServer(string myServerName
                                     , string myDBName
                                     , string userId
                                     , string passWord)
        {
            if (string.IsNullOrEmpty(myServerName))
            {
                string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBServerNULL");
                string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(0);
            }

            if (string.IsNullOrEmpty(myDBName))
            {
                string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBDBNameNULL");
                string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(0);
            }

            if (string.IsNullOrEmpty(userId))
            {
                string strText    = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMSDBUserIDNULL");
                string strCaption = GetStringFromPublicResourceClass.GetStringFromPublicResource("PMS_Warnning");
                MessageBox.Show(strText, strCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(0);
            }

            ConnectType iProtocolType = (ConnectType)(1);

            string portID = "1433";

            //string strConnect = "Data Source=" + myServerName +
            //        ";Initial Catalog=" + myDBName +
            //        ";User Id=" + userId +
            //        ";Password="******";";

            try
            {
                //SqlStructure sqlStructure = new SqlStructure(myServerName, myDBName, userId, passWord, iProtocolType, portID);
                SqlStructure.InitSqlStructure(myServerName, myDBName, userId, passWord, iProtocolType, portID);

                SqlConnection _conn = SqlStructure.GetSqlConncetion();
                if (_conn == null)
                {
                    return(0);
                }
                if (!SqlStructure.ConnectSMOServer())
                {
                    return(0);
                }
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                MessageBox.Show(ex.ToString());
                return(0);
            }

            return(1);
        }