using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using DataLibrary;
using System.Data;
using System.Diagnostics;
using System.Security;
using System.Net.Mail;
using System.Text;
using CoreSavingLibrary;
namespace Saving.Applications.admin
{
public partial class w_sheet_dbms : PageWebSheet, WebSheet
{
public void WebSheetLoadBegin()
{
if (!IsPostBack)
{
String datasource = state.SsConnectionString;// "Data Source=rac/gcoop;Persist Security Info=True;User ID=ifsct;Password=ifsct;Unicode=True;";
datasource = (Request["d"] != null) ? Request["d"] : datasource;
if (this.TbConnectionString.Text == null || TbConnectionString.Text.Trim() == "")
{
TbConnectionString.Text = datasource;
}
if (TbConnectionStringSrc.Text == null || TbConnectionStringSrc.Text.Trim() == "")
{
TbConnectionStringSrc.Text = datasource;
}
LbServerMessage.Text = "";
GridView1.DataSource = null;
GridView1.DataBind();
GridView1.DataSource = null;
GridView1.DataBind();
try
{
WebUtil.Query("create or replace view v_current_login as select USERNAME,application,CREATE_TIME,LAST_TRY from ssotoken order by LAST_TRY desc ");
}
catch { }
}
else
{
}
}
public void InitJsPostBack()
{
}
public void CheckJsPostBack(string eventArg)
{
switch (eventArg)
{
case "jsSearch":
break;
}
}
public string ExecuteCmd(string Arguments, string user, string password, string domain)
{
return ExecuteCommand("cmd", Arguments, user, password, domain);
}
public string ExecuteCommand(string command, string Arguments, string user, string password, string domain)
{
string output = null;
Process p = new Process();
ProcessStartInfo s = new ProcessStartInfo();
if (domain != null || domain != "") s.Domain = domain;
if (user != null || user != "") s.UserName = user;
if (password != null || password != "")
{
s.Password = new SecureString();
char[] passwords = password.ToCharArray();
for (int i = 0; i < password.Length; i++)
{
s.Password.AppendChar(passwords[i]);
}
}
s.FileName = command;
s.UseShellExecute = false;
s.RedirectStandardOutput = true;
s.RedirectStandardError = true;
s.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
if (Arguments != null && Arguments != "") s.Arguments = "/C \"" + Arguments+"\"";
p.StartInfo = s;
p.EnableRaisingEvents = true;
try
{
p.Start();
while (!p.HasExited)
{
System.Threading.Thread.Sleep(1000);
}
//check to see what the exit code was
if (p.ExitCode != 0)
{
output = "Exitcode: " + p.ExitCode + " - Err1: " + p.StandardError + " - Executor: " + System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
}
else
{
output = "Command Result: " + p.StandardOutput.ReadToEnd();
}
}
catch (Exception ex)
{ output += ex.Message; }
return output;
}
public void SaveWebSheet()
{
}
public void WebSheetLoadEnd()
{
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
LbOutput.Text = "";
string connectionString = TbConnectionString.Text;
Sta ta = new Sta(connectionString);
ta.Transection();
try
{
string sql = TbSQL.Text.Trim();
if (sql.ToLower().IndexOf("select") >= 0)
{
DataTable dt = ta.QueryDataTable(sql);
if (dt != null)
{
GridView1.DataSource = dt;
GridView1.DataBind();
LbServerMessage.Text = DateTime.Now+" ข้อมูล = " + dt.Rows.Count + " row";
LbServerMessage.ForeColor = Color.Green;
}
else
{
LbServerMessage.Text = DateTime.Now + " ไม่พบข้อมูล";
LbServerMessage.ForeColor = Color.Red;
}
}
else
{
ta.Exe(sql);
LbServerMessage.Text = DateTime.Now + " ทำรายการสำเร็จ";
LbServerMessage.ForeColor = Color.Green;
}
ta.Commit();
ta.Close();
/*
this.TbKillSQL.Text = @"
"+"begin"+@"
for i in (" + this.TbSQL.Text.Trim() + @") LOOP
execute immediate i.SQLD||' ';
end loop;
end;
/
";
*/
}
catch (Exception ex)
{
try
{
ta.RollBack();
}
catch { }
ta.Close();
LbServerMessage.Text = ex.Message;
LbServerMessage.ForeColor = Color.Red;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
LbOutput.Text = "";
string connectionString = TbConnectionString.Text;
Sta ta = new Sta(connectionString);
ta.Transection();
try
{
string sql = TbSQL.Text.Trim();
ta.Exe(sql);
ta.Commit();
ta.Close();
LbServerMessage.Text = DateTime.Now + " ทำงานเสร็จ";
LbServerMessage.ForeColor = Color.Green;
}
catch (Exception ex)
{
try
{
ta.RollBack();
}
catch { }
ta.Close();
LbServerMessage.Text = ex.Message;
LbServerMessage.ForeColor = Color.Red;
}
}
protected void Button3_Click(object sender, EventArgs e)
{
LbOutput.Text = "";
string connectionString = TbConnectionString.Text;
Sta ta = new Sta(connectionString);
ta.Transection();
try
{
string sql = TbSQL.Text.Trim();
ta.ExePlSql(sql);
ta.Commit();
ta.Close();
LbServerMessage.Text = DateTime.Now + " ทำงานเสร็จ";
LbServerMessage.ForeColor = Color.Green;
}
catch (Exception ex)
{
try
{
ta.RollBack();
}
catch { }
ta.Close();
LbServerMessage.Text = ex.Message;
LbServerMessage.ForeColor = Color.Red;
}
}
protected void Button4_Click(object sender, EventArgs e)
{
LbOutput.Text = "";
string cmd = TbSQL.Text.Trim();
LbServerMessage.Text =this.ExecuteCmd(cmd, "", "", "");
LbServerMessage.ForeColor = Color.Green;
}
public void RestartIreportBuilder()
{
try
{
Process[] process = System.Diagnostics.Process.GetProcessesByName("javaw");
for (int i = 0; i < process.Length; i++)
{
process[i].Kill();
}
//System.Diagnostics.Process.Start("C:\\GCOOP_ALL\\FSCT\\GCOOP\\run_ireport_builder.bat");
}
catch {
}
this.ExecuteCmd("taskkill /F /IM javaw.exe", "", "", "");
System.Diagnostics.Process.Start("C:\\GCOOP_ALL\\FSCT\\GCOOP\\run_ireport_builder.bat");
/*
string args = "";
string str2 = "C:\\GCOOP_ALL\\FSCT\\0.ResetIreportBuilder.bat";
ProcessStartInfo startinfo = new ProcessStartInfo(str2, args);
startinfo.CreateNoWindow = true;
startinfo.UseShellExecute = false;
startinfo.WorkingDirectory = "C:\\GCOOP_ALL\\FSCT";
// *** Redirect the output ***
startinfo.RedirectStandardError = true;
startinfo.RedirectStandardOutput = true;
Process process;
process = Process.Start(startinfo);
process.WaitForExit();
//string stdinput = process.StandardOutput.ReadToEnd();
//string stdoutput = process.StandardError.ReadToEnd();
int ecode = process.ExitCode;
LbServerMessage.ForeColor = Color.Green;
//LbServerMessage.Text = (string)ecode+"";
//+":
" + stdoutput;
*/
}
protected void Button45_Click(object sender, EventArgs e)
{
LbOutput.Text = "";
RestartIreportBuilder();
}
private void createDataDic()
{
string v_flag = Request["v"];
LbOutput.Text = "";
string connectionString = TbConnectionString.Text;
Sta ta = new Sta(connectionString);
Sta ta_ = new Sta(connectionString);
string output = "
| "+i+"."+table_name+" | ||||
| Table Name | Table Column Name | Description | Data Type | |
| " + (j == 1 ? (table_name.ToLower() + "") : "") + ""; output += (j == 2 ? ((v_flag != null ? dt_.GetString(9) : (""))) : ""); output += (j == 2 ? ((v_flag != null ? dt_.GetString(10) : ( ""))) : ""); output += " | "; output += "" + dt_.GetString(0).ToLower() + (dt_.GetString(6) != "" ? ("(" + dt_.GetString(6) + ")") : "") + (dt_.GetString(7) != "" ? ("(" + dt_.GetString(7) + ")") : "") + " | "; output += "" + (v_flag != null ? dt_.GetString(8) : ("")) + " | "; output += "" + dt_.GetString(1) + ""; if (dt_.GetString(1) != "DATE") { if (dt_.GetString(1) == "NUMBER") { if (dt_.GetString(3) != "" && dt_.GetString(4) != "") { output += "(" + (dt_.GetString(3) + ((dt_.GetString(4) != "0" && dt_.GetString(4) != "") ? ("," + dt_.GetString(4)) : "")) + ")"; } else { output += "(" + dt_.GetString(2) + ")"; } } else { output += "(" + dt_.GetString(2) + ")"; } } output += " | "; //output+=""+ dt_.GetString(5)+" | "; //select constraint_name,constraint_type from all_constraints where constraint_type in ('P','U','R') and table_name='
| constraint | ||||
| " + k + "." + dt_.GetString(0) + " | " + dt_.GetString(1) + " | |||