예제 #1
0
        private void dbStartBTN_Click(object sender, EventArgs e)
        {
            #region TNS配置

            String FileName = oraCli.Text + @"\network\admin\tnsnames.ora";
            if (!Directory.Exists(oraCli.Text) && !File.Exists(FileName))
            {
                MessageBox.Show(this, "Oracle客户端不存在!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            StringBuilder sb = new StringBuilder();
            if (AutoCBX.Checked == false)
            {
                try
                {
                    sb.Append(dbtns.Text + "=\r\n");
                    sb.Append("  (DESCRIPTION=\r\n");
                    sb.Append("    (ADDRESS=\r\n");
                    sb.Append("      (PROTOCOL=TCP)\r\n");
                    sb.Append("      (HOST=" + dbhost.Text + ")\r\n");
                    sb.Append("      (PORT=1521)\r\n");
                    sb.Append("    )\r\n");
                    sb.Append("    (CONNECT_DATA=\r\n");
                    sb.Append("      (SERVER=dedicated)\r\n");
                    sb.Append("      (SERVICE_NAME=" + dbtns.Text + ")\r\n");
                    sb.Append("    )\r\n");
                    sb.Append("  )");
                }
                catch (Exception)
                {
                    MessageBox.Show(this, "网站TNS连接配置失败,请手动修改文件【tnsnames.ora】", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                File.WriteAllText(FileName, sb.ToString());
            }
            #endregion

            #region SQLRun.bat制作
            String fileName  = sqlPath.Text + @"\SQLRun.bat";
            String sqlplus   = "sqlplus.exe";
            String oracleTNS = dbuser.Text + "/" + dbpass.Text + "@" + dbtns.Text;
            sb = new StringBuilder();
            sb.Append("PATH=" + oraCli.Text + "\\bin\r\n");
            for (int i = 0; i < FileView.Items.Count; i++)
            {
                if (FileView.GetItemChecked(i))
                {
                    sb.Append(sqlplus + " " + oracleTNS + " @" + SQLFiles[i].FullName + "\r\n");
                }
            }

            sb.Append("pause\r\n");
            sb.Append("EXIT\r\n");

            File.WriteAllText(fileName, sb.ToString());
            DoDosCMD(fileName);
            Process.Start(sqlPath.Text);
            #endregion
        }