예제 #1
0
파일: FormMain.cs 프로젝트: m12k/Files
    private void buttonConnect_Click(object sender, EventArgs e)
    {
        try
        {
            if (buttonConnect.Text == "Connect")
            {

                var result = ((comboBoxProject.Items[comboBoxProject.SelectedIndex]) as GetUserProjectsResult);
                string connectionString = "";

                //Start of: check connection
                if (result.Provider == "OLEDB")
                {
                    connectionString = Global.GetConnectionString(result.File, result.UserID, result.Password, result.HasOtherDetails.Value, result.MDW);
                    classCheckConnection = new ClassCheckConnection(connectionString, Global.DataProvider.OLEDB);
                }
                else if (result.Provider == "SQL")
                {
                    connectionString = Global.GetConnectionString(result.Datasource, result.DatabaseName, result.UserID, result.Password);
                    classCheckConnection = new ClassCheckConnection(connectionString, Global.DataProvider.SQL);
                }

                if (!classCheckConnection.CheckConnection())
                {
                    Global.ShowMessage("Connection Failed.\n\nPlease check.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                //End of: check connection

                treeProject.Nodes["NodeHeader"].Nodes["NodeName"].Text = "Name: " + result.Name;
                treeProject.Nodes["NodeHeader"].Nodes["NodeDescription"].Text = "Description: " + result.Desc;


                if (result.Provider == "OLEDB")
                {
                    foreach (TreeNode n in treeProject.Nodes["NodeHeader"].Nodes)
                    {
                        if (n.Name == "NodeDatasource" || n.Name == "NodeDatabaseName")
                            n.Remove();
                    }

                    treeProject.Nodes["NodeHeader"].Nodes.Add("NodeDatabase", "Database: " + result.File);

                    Global.ProjectDataProvider = Global.DataProvider.OLEDB;
                }
                else if (result.Provider == "SQL")
                {
                    foreach (TreeNode n in treeProject.Nodes["NodeHeader"].Nodes)
                    {
                        if (n.Name == "NodeDatabase")
                            n.Remove();
                    }

                    treeProject.Nodes["NodeHeader"].Nodes.Add("NodeDatasource", "Datasource: " + result.Datasource);
                    treeProject.Nodes["NodeHeader"].Nodes.Add("NodeDatabaseName", "Database Name: " + result.DatabaseName);

                    Global.ProjectDataProvider = Global.DataProvider.SQL;
                }


                Global.ProjectConnectionString = connectionString;
            }
            
            treeProject.CollapseAll();                               
            SetConnectionStatus();
            SetMenuStatus();
        }
        catch (Exception)
        {
            throw;
        }
    }
예제 #2
0
파일: FormProject.cs 프로젝트: m12k/Files
        private void buttonTestConnection_Click(object sender, EventArgs e)
        {
            try
            {
                if (radioButtonMSAccess.Checked)
                {
                    if (textBoxFileMDB.Text == "") { Global.ShowMessage("Please select mdb file", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; }

                    classCheckConnection = new ClassCheckConnection(Global.GetConnectionString(textBoxFileMDB.Text, textBoxAccessUserID.Text, textBoxAccessPassword.Text, checkBoxOtherDetails.Checked, textBoxFileMDW.Text), Global.DataProvider.OLEDB);
                }
                else
                {
                    string msg = "";

                    if (textBoxSQLDatasource.Text == "")
                        msg += "Datasource\n";
                    if (textBoxSQLDatabaseName.Text == "")
                        msg += "Database Name\n";

                    if (msg.Length > 0)
                    {
                        Global.ShowMessage("Please fill in required fields.\n\n" + msg, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }

                    classCheckConnection = new ClassCheckConnection(Global.GetConnectionString(textBoxSQLDatasource.Text, textBoxSQLDatabaseName.Text, textBoxSQLUserId.Text, textBoxSQLPassword.Text), Global.DataProvider.SQL);
                }
                
                if (classCheckConnection.CheckConnection())
                    Global.ShowMessage("Connection Succesful!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                else
                    Global.ShowMessage("Connection Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            }
            catch (Exception)
            {
                throw;
            }
        }