/tool/WinISQL/WinISQL/Form1.cs

https://github.com/ALTIBASE/altibase · C# · 261 lines · 208 code · 41 blank · 12 comment · 17 complexity · 3439566f403a2c0be2ec6144db026135 MD5 · raw file

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Data;
  9. using Altibase.Data.AltibaseClient;
  10. namespace WindowsApplication1
  11. {
  12. public partial class Form1 : Form
  13. {
  14. Hashtable mainTabControlHT = new Hashtable();
  15. int mainTabPageID;
  16. // String del = "Altibase.Data.AltibaseClient.AltibaseException:Altibase ADO.NET ERROR: ";
  17. // String del = "Altibase.Data.AltibaseClient.AltibaseException:";
  18. // String split = "\r\n";
  19. public Form1()
  20. {
  21. InitializeComponent();
  22. mainTabPageID = 1;
  23. }
  24. // Connect
  25. private void toolStripButton1_Click(object sender, EventArgs e)
  26. {
  27. ConnNode c_node = new ConnNode();
  28. String mainTabPageName = c_node.AddConn(tabControl1, mainTabPageID++, textBox1.Text);
  29. mainTabControlHT.Add(mainTabPageName, c_node);
  30. EditorNode e_node = (EditorNode)c_node.subTabControlHT[c_node.sub_tabctl.SelectedTab.Name];
  31. e_node.s_editor.conn.Open();
  32. }
  33. // Add SqlEditor
  34. private void toolStripButton2_Click(object sender, EventArgs e)
  35. {
  36. EditorNode e_node = new EditorNode();
  37. ConnNode t_node = (ConnNode)mainTabControlHT[tabControl1.SelectedTab.Name];
  38. String subTabPageName = e_node.AddSqlEditor(t_node.sub_tabctl, t_node.subTabPageID++);
  39. t_node.subTabControlHT.Add(subTabPageName, e_node);
  40. textBox2.Text = subTabPageName;
  41. e_node.s_editor.conn.Open();
  42. }
  43. private void toolStripButton4_Click(object sender, EventArgs e)
  44. {
  45. ConnNode t_node = (ConnNode)mainTabControlHT[tabControl1.SelectedTab.Name];
  46. EditorNode e_node = (EditorNode)t_node.subTabControlHT[t_node.sub_tabctl.SelectedTab.Name];
  47. String query = e_node.s_editor.syntaxRichTextBox1.Text.Trim().ToLower();
  48. if (query.StartsWith("select"))
  49. {
  50. select();
  51. }
  52. else
  53. {
  54. nonSelect();
  55. }
  56. incSeq();
  57. }
  58. private void select()
  59. {
  60. ConnNode t_node = (ConnNode)mainTabControlHT[tabControl1.SelectedTab.Name];
  61. EditorNode e_node = (EditorNode)t_node.subTabControlHT[t_node.sub_tabctl.SelectedTab.Name];
  62. AltibaseConnection a_conn = e_node.s_editor.conn;
  63. DataSet a_dataset = e_node.s_editor.dataSet1;
  64. DataGridView a_dataGV = e_node.s_editor.dataGridView1;
  65. //AltibaseDataAdapter a_dataAdapter = e_node.s_editor.dataAdapter1;
  66. //AltibaseCommand a_cmd = e_node.s_editor.cmd;
  67. String query = e_node.s_editor.syntaxRichTextBox1.Text;
  68. AltibaseDataAdapter da = new AltibaseDataAdapter(a_conn.CreateCommand());
  69. da.SelectCommand = new AltibaseCommand(query, a_conn);
  70. a_dataset.Clear();
  71. try
  72. {
  73. int result = da.Fill(a_dataset);
  74. a_dataGV.DataSource = a_dataset.Tables[0];
  75. setMsg("select", result);
  76. setHistory();
  77. }
  78. catch (Exception ex)
  79. {
  80. setErrMsg(ex);
  81. }
  82. }
  83. private void nonSelect()
  84. {
  85. ConnNode t_node = (ConnNode)mainTabControlHT[tabControl1.SelectedTab.Name];
  86. EditorNode e_node = (EditorNode)t_node.subTabControlHT[t_node.sub_tabctl.SelectedTab.Name];
  87. AltibaseConnection a_conn = e_node.s_editor.conn;
  88. DataSet a_dataset = e_node.s_editor.dataSet1;
  89. String query = e_node.s_editor.syntaxRichTextBox1.Text;
  90. AltibaseCommand cmd = new AltibaseCommand(query, a_conn);
  91. String split = " ";
  92. a_dataset.Clear();
  93. try
  94. {
  95. int result = cmd.ExecuteNonQuery();
  96. string[] query_split = query.Split(split.ToCharArray());
  97. foreach (string s in query_split)
  98. {
  99. if (s.Trim() != "")
  100. {
  101. setMsg((String)s, result);
  102. break;
  103. }
  104. }
  105. setHistory();
  106. }
  107. catch (Exception ex)
  108. {
  109. setErrMsg(ex);
  110. }
  111. }
  112. private void setErrMsg(Exception ex)
  113. {
  114. ConnNode t_node = (ConnNode)mainTabControlHT[tabControl1.SelectedTab.Name];
  115. EditorNode e_node = (EditorNode)t_node.subTabControlHT[t_node.sub_tabctl.SelectedTab.Name];
  116. String del = "Altibase.Data.AltibaseClient.AltibaseException:";
  117. String split = "\r\n";
  118. int i = 1;
  119. // String msg = ex.ToString();
  120. String msg = ex.ToString().TrimStart(del.ToCharArray()).Trim();
  121. string[] msg_split = msg.Split(split.ToCharArray());
  122. foreach (string s in msg_split)
  123. {
  124. if (s.Trim() != "" && s.Trim().StartsWith("at") == false)
  125. {
  126. if (i == 1)
  127. {
  128. e_node.s_editor.listBox1.Items.Add(e_node.seq + ": " + s);
  129. }
  130. else
  131. {
  132. e_node.s_editor.listBox1.Items.Add(" " + s);
  133. }
  134. i++;
  135. }
  136. }
  137. toolStripStatusLabel2.Text = "Command execute fail.";
  138. }
  139. private void setMsg(String s, int cnt)
  140. {
  141. ConnNode t_node = (ConnNode)mainTabControlHT[tabControl1.SelectedTab.Name];
  142. EditorNode e_node = (EditorNode)t_node.subTabControlHT[t_node.sub_tabctl.SelectedTab.Name];
  143. String tmp = "";
  144. switch (s)
  145. {
  146. case "alter" :
  147. case "create" :
  148. case "drop" :
  149. case "grant" :
  150. case "revoke" :
  151. case "rename" :
  152. case "truncate" :
  153. case "commit" :
  154. case "rollback" :
  155. case "savepoint" :
  156. e_node.s_editor.listBox1.Items.Add(e_node.seq + ": " + s.Replace(s.Substring(0,1), s.Substring(0,1).ToUpper()) + " success.");
  157. toolStripStatusLabel2.Text = s.Replace(s.Substring(0,1), s.Substring(0,1).ToUpper()) + " success.";
  158. break;
  159. case "select" :
  160. tmp = "selected.";
  161. break;
  162. case "insert" :
  163. tmp = "inserted.";
  164. break;
  165. case "update" :
  166. tmp = "updated.";
  167. break;
  168. case "delete" :
  169. tmp = "deleted.";
  170. break;
  171. case "move" :
  172. tmp = "moved.";
  173. break;
  174. /* case "ENQUEUE" :
  175. break;
  176. case "DEQUEUE" :
  177. break;
  178. */ default :
  179. e_node.s_editor.listBox1.Items.Add(e_node.seq + ": " + " Command execute success.");
  180. toolStripStatusLabel2.Text = "Command execute success.";
  181. tmp = " ";
  182. break;
  183. }
  184. if (tmp != "")
  185. {
  186. if (cnt == 0)
  187. {
  188. e_node.s_editor.listBox1.Items.Add(e_node.seq + ": No rows " + tmp);
  189. toolStripStatusLabel2.Text = "No rows " + tmp;
  190. }
  191. else if (cnt == 1)
  192. {
  193. e_node.s_editor.listBox1.Items.Add(e_node.seq + ": 1 row " + tmp);
  194. toolStripStatusLabel2.Text = "1 row " + tmp;
  195. }
  196. else
  197. {
  198. e_node.s_editor.listBox1.Items.Add(e_node.seq + ": " + cnt + " rows " + tmp);
  199. toolStripStatusLabel2.Text = cnt + " rows " + tmp;
  200. }
  201. }
  202. }
  203. private void setHistory()
  204. {
  205. ConnNode t_node = (ConnNode)mainTabControlHT[tabControl1.SelectedTab.Name];
  206. EditorNode e_node = (EditorNode)t_node.subTabControlHT[t_node.sub_tabctl.SelectedTab.Name];
  207. String query = e_node.s_editor.syntaxRichTextBox1.Text.Replace("\r\n", " ");
  208. e_node.s_editor.listBox3.Items.Add(e_node.seq + ": " + query);
  209. }
  210. private void incSeq()
  211. {
  212. ConnNode t_node = (ConnNode)mainTabControlHT[tabControl1.SelectedTab.Name];
  213. EditorNode e_node = (EditorNode)t_node.subTabControlHT[t_node.sub_tabctl.SelectedTab.Name];
  214. e_node.seq++;
  215. }
  216. private void connectToolStripMenuItem_Click(object sender, EventArgs e)
  217. {
  218. }
  219. }
  220. }