Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 13.24 KB | None | 0 0
  1. Imports MySql.Data.Types
  2. Imports MySql.Data.MySqlClient
  3. Public Class Form4
  4.  
  5.     Dim ie, pr As New DataSet()
  6.     Dim intCurrentIndex As Integer = 0
  7.     Dim issCurrentIndex As Integer = 0
  8.     Dim iss, pre As New MySqlDataAdapter()
  9.     Dim conn As New MySqlConnection("server=localhost" & ";user id=" & login.txtUsername.Text & "; password=" & login.txtPassword.Text & "; port=3306; database=test; pooling=false")
  10.  
  11.     Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12.         IssueSQL()
  13.         PrescriberSQL()
  14.     End Sub
  15.  
  16.     Private Sub PrescriberField()
  17.         txtprename.Text = pr.Tables(0).Rows(intCurrentIndex).Item("Name").ToString()
  18.         txtLocation.Text = pr.Tables(0).Rows(intCurrentIndex).Item("Location").ToString()
  19.         txtPhone.Text = pr.Tables(0).Rows(intCurrentIndex).Item("Telephone").ToString()
  20.         txtpreid.Text = pr.Tables(0).Rows(intCurrentIndex).Item("Prescriber_ID").ToString()
  21.     End Sub
  22.  
  23.     Private Sub IssueField()
  24.         txtIn_Stock.Text = ie.Tables(0).Rows(issCurrentIndex).Item("In_Stock").ToString()
  25.         txtamountgiven.Text = ie.Tables(0).Rows(issCurrentIndex).Item("Amount_Given").ToString()
  26.         txtExpiry.Text = ie.Tables(0).Rows(issCurrentIndex).Item("Expiry").ToString()
  27.         TxtWarning.Text = ie.Tables(0).Rows(issCurrentIndex).Item("Warning").ToString()
  28.         txtdrug.Text = ie.Tables(0).Rows(issCurrentIndex).Item("Drug").ToString()
  29.         txtdose.Text = ie.Tables(0).Rows(issCurrentIndex).Item("Dose").ToString()
  30.         txtIssueId.Text = ie.Tables(0).Rows(issCurrentIndex).Item("MedicationID").ToString()
  31.  
  32.     End Sub
  33.  
  34.     Public Sub PrescriberSQL()
  35.         pre.SelectCommand = New MySqlCommand("SELECT * FROM Prescriber")
  36.         pre.SelectCommand.Connection = conn
  37.  
  38.  
  39.         pre.UpdateCommand = New MySqlCommand("Update Prescriber SET Name =?Name, Location =?Location, Telephone =?Telephone WHERE Prescriber_ID = ?Prescriber_ID")
  40.         pre.UpdateCommand.Connection = conn
  41.         pre.UpdateCommand.Parameters.Add("?Name", MySqlDbType.VarChar, 50, "Name")
  42.         pre.UpdateCommand.Parameters.Add("?Location", MySqlDbType.VarChar, 70, "Location")
  43.         pre.UpdateCommand.Parameters.Add("?Telephone", MySqlDbType.VarChar, 70, "Telephone")
  44.         pre.UpdateCommand.Parameters.Add("?Prescriber_ID", MySqlDbType.Int16, 5, "Prescriber_ID")
  45.  
  46.         pre.InsertCommand = New MySqlCommand("INSERT INTO Prescriber(Prescriber_ID, Name , Location, Telephone) VALUES(?Prescriber_ID,?Name ,?Location, ?Telephone)")
  47.         pre.InsertCommand.Connection = conn
  48.         pre.InsertCommand.Parameters.Add("?Name", MySqlDbType.VarChar, 50, "Name")
  49.         pre.InsertCommand.Parameters.Add("?Location", MySqlDbType.VarChar, 70, "Location")
  50.         pre.InsertCommand.Parameters.Add("?Telephone", MySqlDbType.VarChar, 70, "Telephone")
  51.         pre.InsertCommand.Parameters.Add("?Prescriber_ID", MySqlDbType.Int16, 5, "Prescriber_ID")
  52.  
  53.  
  54.         pre.DeleteCommand = New MySqlCommand("DELETE FROM Prescriber WHERE Prescriber_ID = ?Prescriber_ID")
  55.         pre.DeleteCommand.Connection = conn
  56.         pre.DeleteCommand.Parameters.Add("?Prescriber_ID", MySqlDbType.Int16, 5, "Prescriber_ID")
  57.  
  58.         pre.Fill(pr)
  59.  
  60.         If pr.Tables(0).Rows.Count > 0 Then 'Check to see if the table is empty
  61.             PrescriberField()
  62.         End If
  63.     End Sub
  64.  
  65.     Public Sub IssueSQL()
  66.         iss.SelectCommand = New MySqlCommand("SELECT * FROM Medication")
  67.         iss.SelectCommand.Connection = conn
  68.  
  69.  
  70.         iss.UpdateCommand = New MySqlCommand("Update Medication SET In_Stock =?In_Stock, Amount_Given =?Amount_Given, Expiry =?Expiry, Warning =?Warning, Drug =?Drug, Dose =?Dose   WHERE MedicationID = ?MedicationID")
  71.         iss.UpdateCommand.Connection = conn
  72.         iss.UpdateCommand.Parameters.Add("?In_Stock", MySqlDbType.VarChar, 40, "In_Stock")
  73.         iss.UpdateCommand.Parameters.Add("?Amount_Given", MySqlDbType.VarChar, 40, "Amount_Given")
  74.         iss.UpdateCommand.Parameters.Add("?Expiry", MySqlDbType.VarChar, 70, "Expiry")
  75.         iss.UpdateCommand.Parameters.Add("?Warning", MySqlDbType.VarChar, 70, "Warning")
  76.         iss.UpdateCommand.Parameters.Add("?Drug", MySqlDbType.VarChar, 70, "Drug")
  77.         iss.UpdateCommand.Parameters.Add("?Dose", MySqlDbType.VarChar, 70, "Dose")
  78.         iss.UpdateCommand.Parameters.Add("?MedicationID", MySqlDbType.Int16, 5, "MedicationID")
  79.  
  80.  
  81.  
  82.         iss.InsertCommand = New MySqlCommand("INSERT INTO Medication(MedicationID, Amount_Given, Expiry, Warning, Drug , Dose) VALUES(?MedicationID,?Amount_Given, ?Expiry, Warning, ?Drug ,?Dose)")
  83.         iss.InsertCommand.Connection = conn
  84.         iss.InsertCommand.Parameters.Add("?In_Stock", MySqlDbType.VarChar, 50, "In_Stock")
  85.         iss.InsertCommand.Parameters.Add("?Amount_Given", MySqlDbType.VarChar, 70, "Amount_Given")
  86.         iss.InsertCommand.Parameters.Add("?Expiry", MySqlDbType.VarChar, 70, "Expiry")
  87.         iss.InsertCommand.Parameters.Add("?Warning", MySqlDbType.VarChar, 70, "Warning")
  88.         iss.InsertCommand.Parameters.Add("?Drug", MySqlDbType.VarChar, 70, "Drug")
  89.         iss.InsertCommand.Parameters.Add("?Dose", MySqlDbType.VarChar, 70, "Dose")
  90.         iss.InsertCommand.Parameters.Add("?MedicationID", MySqlDbType.Int16, 5, "MedicationID")
  91.  
  92.  
  93.         iss.DeleteCommand = New MySqlCommand("DELETE FROM Medication WHERE MedicationID = ?MedicationID")
  94.         iss.DeleteCommand.Connection = conn
  95.         iss.DeleteCommand.Parameters.Add("?MedicationID", MySqlDbType.Int16, 5, "MedicationID")
  96.  
  97.         iss.Fill(ie)
  98.  
  99.         If ie.Tables(0).Rows.Count > 0 Then 'Check to see if the table is empty
  100.             IssueField()
  101.         End If
  102.     End Sub
  103.  
  104.  
  105.     Private Sub IssueUpdate()
  106.         Dim dr As DataRow
  107.         dr = ie.Tables(0).Rows(issCurrentIndex) 'This gets a reference to the row currently being edited
  108.         dr.BeginEdit()
  109.         dr("Drug") = txtDrug.Text
  110.         dr("Dose") = txtDose.Text
  111.         dr("Issue_ID") = txtissueid.Text
  112.         dr.EndEdit()
  113.         iss.Update(ie)  'Ask the pattaapatpter to call the UppatteCommand and uppatte the pattabase
  114.         ie.AcceptChanges() 'Commits the change to the pattaset.
  115.     End Sub
  116.  
  117.     Private Sub IssueDelete()
  118.         Dim button As DialogResult
  119.  
  120.         button = MessageBox.Show _
  121.         ("Are you sure you want to delete this patient?", _
  122.         "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
  123.  
  124.         If button = Windows.Forms.DialogResult.Yes Then
  125.             Try
  126.                 Dim dr As DataRow
  127.                 dr = ie.Tables(0).Rows(issCurrentIndex)
  128.                 dr.Delete() 'Delete the row
  129.                 iss.Update(ie)
  130.             Catch ex As Exception
  131.                 MsgBox(ex.Message)
  132.             Finally
  133.                 ie.AcceptChanges()
  134.                 IssueField()
  135.             End Try
  136.         Else
  137.             'Do Nothing
  138.         End If
  139.  
  140.     End Sub
  141.     Private Sub IssueAdd()
  142.         Dim dr As DataRow
  143.         dr = ie.Tables(0).NewRow()  'Gets a reference to a new row.
  144.         dr("Drug") = txtDrug.Text
  145.         dr("Dose") = txtDose.Text
  146.         dr("MedicationID") = txtIssueId.Text
  147.         ie.Tables(0).Rows.Add(dr)
  148.         iss.Update(ie)
  149.         ie.AcceptChanges()
  150.     End Sub
  151.  
  152.  
  153.     Private Sub PrescriberUpdate()
  154.         Dim dr As DataRow
  155.         dr = pr.Tables(0).Rows(intCurrentIndex) 'This gets a reference to the row currently being edited
  156.         dr.BeginEdit()
  157.         dr("Name") = txtprename.Text
  158.         dr("Location") = txtLocation.Text
  159.         dr("Telephone") = txtPhone.Text
  160.         dr("Prescriber_ID") = txtpreid.Text
  161.         dr.EndEdit()
  162.         pre.Update(pr)  'Ask the pattaapatpter to call the UppatteCommand and uppatte the pattabase
  163.         pr.AcceptChanges() 'Commits the change to the pattaset.
  164.     End Sub
  165.  
  166.     Private Sub PrescriberDelete()
  167.         Dim button As DialogResult
  168.  
  169.         button = MessageBox.Show _
  170.         ("Are you sure you want to delete this patient?", _
  171.         "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
  172.  
  173.         If button = Windows.Forms.DialogResult.Yes Then
  174.             Try
  175.                 Dim dr As DataRow
  176.                 dr = pr.Tables(0).Rows(intCurrentIndex)
  177.                 dr.Delete() 'Delete the row
  178.                 pre.Update(pr)
  179.             Catch ex As Exception
  180.                 MsgBox(ex.Message)
  181.             Finally
  182.                 pr.AcceptChanges()
  183.                 PrescriberField()
  184.             End Try
  185.         Else
  186.             'Do Nothing
  187.         End If
  188.  
  189.     End Sub
  190.     Private Sub PrescriberAdd()
  191.         Dim dr As DataRow
  192.         dr = pr.Tables(0).NewRow()  'Gets a reference to a new row.
  193.         dr("Name") = txtprename.Text
  194.         dr("Location") = txtLocation.Text
  195.         dr("Telephone") = txtPhone.Text
  196.         dr("Prescriber_ID") = txtpreid.Text
  197.         pr.Tables(0).Rows.Add(dr)
  198.         pre.Update(pr)
  199.         pr.AcceptChanges()
  200.     End Sub
  201.  
  202.     Private Sub PrescriberSearch()
  203.             pre.SelectCommand = New MySqlCommand("SELECT * FROM Prescriber WHERE Name = ?Name")
  204.         pre.SelectCommand.Connection = conn
  205.         pre.SelectCommand.Parameters.Add("?Name", MySqlDbType.VarChar, 50, "Name")
  206.         pre.SelectCommand.Parameters.Add("?Location", MySqlDbType.VarChar, 70, "Location")
  207.         pre.SelectCommand.Parameters.Add("?Telephone", MySqlDbType.VarChar, 70, "Telephone")
  208.         pre.SelectCommand.Parameters.Add("?Prescriber_ID", MySqlDbType.Int16, 5, "Prescriber_ID")
  209.  
  210.     pre.Fill(pr)
  211.     End Sub
  212.  
  213.     Private Sub btnissfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnissfirst.Click
  214.         issCurrentIndex = 0
  215.         IssueField()
  216.     End Sub
  217.  
  218.     Private Sub btnissprevious_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnissprevious.Click
  219.         If issCurrentIndex > 0 Then
  220.             issCurrentIndex = issCurrentIndex - 1
  221.             IssueField()
  222.         Else
  223.             MessageBox.Show("You're already at the first record.")
  224.         End If
  225.     End Sub
  226.  
  227.     Private Sub btnissLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnisslast.Click
  228.         issCurrentIndex = ie.Tables(0).Rows.Count - 1
  229.         IssueField()
  230.     End Sub
  231.  
  232.     Private Sub btnissnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnissnext.Click
  233.         If issCurrentIndex < ie.Tables(0).Rows.Count - 1 Then
  234.             issCurrentIndex = issCurrentIndex + 1
  235.             IssueField()
  236.         Else
  237.             MessageBox.Show("You're already at the last record.")
  238.         End If
  239.     End Sub
  240.  
  241.     Private Sub btnissadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnissadd.Click
  242.         IssueAdd()
  243.     End Sub
  244.  
  245.     Private Sub btnissupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnissupdate.Click
  246.         IssueUpdate()
  247.         IssueField()
  248.     End Sub
  249.  
  250.     Private Sub btnissdelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnissdelete.Click
  251.         IssueDelete()
  252.     End Sub
  253.  
  254.     Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
  255.         'Since 0 is the first row
  256.         intCurrentIndex = 0
  257.         PrescriberField()
  258.  
  259.     End Sub
  260.  
  261.     Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
  262.  
  263.         If intCurrentIndex > 0 Then  'We move back only if we're not at the first row.
  264.             intCurrentIndex = intCurrentIndex - 1  'Subtract one from the current index.
  265.             PrescriberField()
  266.  
  267.         Else
  268.             MessageBox.Show("You're already at the first record.")
  269.         End If
  270.  
  271.     End Sub
  272.  
  273.     Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
  274.         If intCurrentIndex < pr.Tables(0).Rows.Count - 1 Then 'pa.Tables(0).Rows.Count - 1 is the index for the last row
  275.             intCurrentIndex = intCurrentIndex + 1  'Add one to the current index.
  276.             PrescriberField()
  277.  
  278.         Else
  279.             MessageBox.Show("You're already at the last record.")
  280.         End If
  281.     End Sub
  282.  
  283.     Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
  284.         intCurrentIndex = pr.Tables(0).Rows.Count - 1 'pa.Tables(0).Rows.Count - 1 is the index for the last row
  285.         PrescriberField()
  286.  
  287.     End Sub
  288.  
  289.  
  290.     Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
  291.         PrescriberUpdate()
  292.         PrescriberField()
  293.  
  294.     End Sub
  295.  
  296.     Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
  297.         PrescriberAdd()
  298.  
  299.     End Sub
  300.  
  301.     Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
  302.         PrescriberDelete()
  303.  
  304.     End Sub
  305.  
  306.     Private Sub txtRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRefresh.Click
  307.         PrescriberField()
  308.         IssueField()
  309.     End Sub
  310.  
  311.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  312.     PrescriberSearch
  313.     End Sub
  314. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement