Guest User

Untitled

a guest
Jun 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11.  
  12.  
  13. namespace DBMS_Project
  14. {
  15. public partial class Form1 : Form
  16. {
  17. string sqlCommand;
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. this.Size = new Size(1000, 600);
  22. tabPage1.Text = "Doctor";
  23. tabPage2.Text = "Division";
  24. tabPage3.Text = "Patient";
  25. tabPage4.Text = "Reservation";
  26. tabPage5.Text = "Shift Arrangement";
  27. tabPage6.Text = "Raw SQL Query";
  28. }
  29.  
  30. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  31. {
  32.  
  33. }
  34.  
  35. private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  36. {
  37.  
  38. }
  39.  
  40. private void rdoFname_Lname_Shi_CheckedChanged(object sender, EventArgs e)
  41. {
  42.  
  43. }
  44.  
  45. private void btnQuery_Click(object sender, EventArgs e)
  46. {
  47. // SQL connection
  48. SqlConnection cn = new SqlConnection();
  49. cn.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;" +
  50. "AttachDbFilename=|DataDirectory|Dental_Center.mdf;" +
  51. "Integrated Security=True";
  52.  
  53.  
  54. if (tabControl1.SelectedTab == tabPage1) // "Doctor" table query
  55. {
  56. if (rdoDid_Doc.Checked == false && rdoDivNo_Doc.Checked == false && rdoFname_Lname_Doc.Checked == false)
  57. {
  58. MessageBox.Show("Please select a query type!!");
  59. }
  60. else
  61. {
  62. DataSet ds = new DataSet();
  63.  
  64. if (rdoDid_Doc.Checked == true) // query with Did
  65. {
  66. sqlCommand = "SELECT * FROM Doctor WHERE DoctorID = " + txtQuery.Text;
  67. }
  68. else if (rdoDivNo_Doc.Checked == true) //query with DivNo
  69. {
  70. sqlCommand = "SELECT * FROM Doctor WHERE DivisionNo = " + txtQuery.Text;
  71. }
  72. else if (rdoFname_Lname_Doc.Checked == true) // query with fname_lname
  73. {
  74. // split text into fname and lname
  75. string[] splitStr = txtQuery.Text.Split();
  76. string fName = splitStr[0];
  77. string lName = splitStr[1];
  78.  
  79. sqlCommand = "SELECT * FROM Doctor WHERE FName = " + "\'" + fName + "\'" + " AND LName = " + "\'" + lName + "\'";
  80. }
  81.  
  82. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  83. da.Fill(ds);
  84. dataGridView1.DataSource = ds.Tables[0];
  85. }
  86.  
  87. }
  88. else if (tabControl1.SelectedTab == tabPage2) // "Division" table query
  89. {
  90. DataSet ds = new DataSet();
  91. if (rdoDivNo_Div.Checked == false && rdoDivName_Div.Checked == false)
  92. {
  93. MessageBox.Show("Please select a query type!!");
  94. }
  95. else
  96. {
  97. if(rdoDivNo_Div.Checked == true) // query with DivNo
  98. {
  99. sqlCommand = "SELECT * FROM Division WHERE Division_no = " + txtQuery.Text;
  100. }
  101. else if(rdoDivName_Div.Checked == true)
  102. {
  103. sqlCommand = "SELECT * FROM Division WHERE DivisionName = " + "\'" + txtQuery.Text +"\'";
  104. }
  105.  
  106. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  107. da.Fill(ds);
  108. dataGridView1.DataSource = ds.Tables[0];
  109. }
  110. }
  111. else if(tabControl1.SelectedTab == tabPage3) // "Patient" table query
  112. {
  113. DataSet ds = new DataSet();
  114.  
  115. if (rdo_Pid_Pat.Checked == false && rdoDoc_inCharge_Pat.Checked == false && rdoDivNo_Pat.Checked == false && rdoFname_Lname_Pat.Checked == false && rdoPhonenum_Pat.Checked == false)
  116. {
  117. MessageBox.Show("Please select a query type!!");
  118. }
  119. else
  120. {
  121. if(rdo_Pid_Pat.Checked == true) // query with Pid
  122. {
  123. sqlCommand = "SELECT * FROM Patient WHERE PatientID = " + txtQuery.Text;
  124. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  125. da.Fill(ds);
  126. dataGridView1.DataSource = ds.Tables[0];
  127. }
  128. else if(rdoDoc_inCharge_Pat.Checked == true) // query with doc_in_charge fname lname
  129. {
  130. // split text into fname and lname
  131. string[] splitStr = txtQuery.Text.Split();
  132. string fName = splitStr[0];
  133. string lName = splitStr[1];
  134.  
  135. sqlCommand = "SELECT Patient.PatientID, Patient.FName, Patient.LName FROM Patient, Doctor WHERE Doctor.FName = " + "\'" + fName + "\'" + "AND Doctor.LName = " + "\'" + lName + "\'" +
  136. "AND Patient.Doctor_In_Charge_ID = Doctor.DoctorID";
  137. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  138. da.Fill(ds);
  139. dataGridView1.DataSource = ds.Tables[0];
  140.  
  141. }
  142. else if(rdoDivNo_Pat.Checked == true) // query with DivName
  143. {
  144. sqlCommand = "SELECT Patient.PatientID, Patient.FName, Patient.LName FROM Patient, Doctor, Division WHERE Doctor.DivisionNo = Division.Division_no AND Division.DivisionName = " + "\'" + txtQuery.Text + "\'" +
  145. " AND Doctor.DoctorID = Patient.Doctor_In_Charge_ID";
  146. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  147. da.Fill(ds);
  148. dataGridView1.DataSource = ds.Tables[0];
  149. }
  150. else if(rdoFname_Lname_Pat.Checked == true) // query with fname lname
  151. {
  152. // split text into fname and lname
  153. string[] splitStr = txtQuery.Text.Split();
  154. string fName = splitStr[0];
  155. string lName = splitStr[1];
  156.  
  157. sqlCommand = "SELECT * FROM Patient WHERE FName = " + "\'" + fName + "\'" + "AND LName = " + "\'" + lName + "\'";
  158. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  159. da.Fill(ds);
  160. dataGridView1.DataSource = ds.Tables[0];
  161. }
  162. else if(rdoPhonenum_Pat.Checked == true) //query with phonenum
  163. {
  164. sqlCommand = "SELECT * FROM Patient WHERE PhoneNum = " + "\'" + txtQuery.Text + "\'";
  165. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  166. da.Fill(ds);
  167. dataGridView1.DataSource = ds.Tables[0];
  168. }
  169. }
  170.  
  171. }
  172. else if (tabControl1.SelectedTab == tabPage4) // "Reservation" Table query
  173. {
  174. DataSet ds = new DataSet();
  175. if(rdoFname_Lname_Res.Checked == false && rdoPhonenum_Res.Checked == false)
  176. {
  177. MessageBox.Show("Please select a query type!!");
  178. }
  179. else
  180. {
  181. if(rdoFname_Lname_Res.Checked == true) // query with fname lname
  182. {
  183. // split text into fname and lname
  184. string[] splitStr = txtQuery.Text.Split();
  185. string fName = splitStr[0];
  186. string lName = splitStr[1];
  187.  
  188. sqlCommand = "SELECT Patient.FName, Patient.LName, Reservation.DateTime FROM Patient, Reservation WHERE Patient.PatientID = Reservation.PatientID AND Patient.FName = " + "\'" + fName + "\'" + "AND Patient.LName = " + "\'" + lName + "\'";
  189. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  190. da.Fill(ds);
  191. dataGridView1.DataSource = ds.Tables[0];
  192. }
  193. else if(rdoPhonenum_Res.Checked == true)
  194. {
  195. sqlCommand = "SELECT Patient.FName, Patient.LName, Reservation.DateTime FROM Patient, Reservation WHERE Patient.PatientID = Reservation.PatientID AND Patient.PhoneNum = " + "\'" + txtQuery.Text +"\'";
  196. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  197. da.Fill(ds);
  198. dataGridView1.DataSource = ds.Tables[0];
  199. }
  200. }
  201. }
  202. else if(tabControl1.SelectedTab == tabPage5) // "Shift Arrange" Table query
  203. {
  204. DataSet ds = new DataSet();
  205. if(rdoFname_Lname_Shi.Checked == false && rdoDid_Shi.Checked == false && rdoSession_Shi.Checked == false)
  206. {
  207. MessageBox.Show("Please select a query type!!");
  208. }
  209. else
  210. {
  211. if(rdoFname_Lname_Shi.Checked == true) // query with fname lname
  212. {
  213. // split text into fname and lname
  214. string[] splitStr = txtQuery.Text.Split();
  215. string fName = splitStr[0];
  216. string lName = splitStr[1];
  217.  
  218. sqlCommand = "SELECT Shift_Arrange.Session, Shift_Arrange.Date FROM Doctor, Shift_Arrange WHERE Doctor.DoctorID = Shift_Arrange.DoctorID AND Doctor.FName = " + "\'" + fName + "\'" + "AND Doctor.LName = " + "\'" + lName + "\'";
  219. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  220. da.Fill(ds);
  221. dataGridView1.DataSource = ds.Tables[0];
  222. }
  223. else if(rdoDid_Shi.Checked == true) // query with doctor ID
  224. {
  225. sqlCommand = "SELECT Doctor.FName, Doctor.LName, Shift_Arrange.Session, Shift_Arrange.Date FROM Shift_Arrange, Doctor WHERE Doctor.DoctorID = " + txtQuery.Text + " AND Doctor.DoctorID = Shift_Arrange.DoctorID";
  226. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  227. da.Fill(ds);
  228. dataGridView1.DataSource = ds.Tables[0];
  229. }
  230. else if(rdoSession_Shi.Checked == true) // query with sessionDate
  231. {
  232. sqlCommand = "SELECT Doctor.FName, Doctor.LName, Shift_Arrange.Session, Shift_Arrange.Date FROM Shift_Arrange, Doctor WHERE Date = " + "\'" + txtQuery.Text + "\'" + " AND Doctor.DoctorID = Shift_Arrange.DoctorID";
  233. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  234. da.Fill(ds);
  235. dataGridView1.DataSource = ds.Tables[0];
  236. }
  237. }
  238.  
  239. }
  240. else if(tabControl1.SelectedTab == tabPage6) // SQL raw query
  241. {
  242. DataSet ds = new DataSet();
  243. sqlCommand = txtRawSQL.Text;
  244. SqlDataAdapter da = new SqlDataAdapter(sqlCommand, cn);
  245. da.Fill(ds);
  246. dataGridView1.DataSource = ds.Tables[0];
  247. }
  248.  
  249. }
  250. }
  251. }
Add Comment
Please, Sign In to add comment