我有些疑惑,我想澄清。
我们的网站上有两个功能,我们希望为客户处理处方药。
一项功能允许潜在的新客户将其处方药从当前提供的药房转移到我们的药房。
另一项功能允许当前客户重新填写他们当前的处方。
处方必须从之前的提供者转移,或者必须在重新填写之前存在。
为了实现处方转移部分,我有两个表,一个叫做Customer(包含客户个人信息以及当前提供的药房名称和电话号码),另一个叫Prescriptions。该表包含处方信息。 customerId在此表上作为customer表的外键。
以下代码将记录插入客户表和处方表中,以便客户将处方从一个药房转移到我们的药房。
我也知道我需要检查是否客户试图转移prescriptiosn已经存在于我们的桌子上。我还没有这样做,但会。
我怀疑如何处理此任务的补充部分。
非常感谢任何想法。
以下是插入转让处方的代码。
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim s As String
Dim sql As String
Dim connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;data source=" & Server.MapPath("App_Data\GCP.accdb")
Try
SetRowData()
Dim table As DataTable = TryCast(ViewState("CurrentTable"), DataTable)
If table IsNot Nothing Then
s = "INSERT INTO Customer(FirstName, LastName, MiddleInitial, DOB, Email_Address, Phone, Address, City, State, ZipCode, PharmacyName, PharmacyPhone) Values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
sql = "Select Max(custId) From Customer"
'Response.Write(s)
'Response.End()
Dim con As New OleDbConnection(connStr)
Dim cmd1 As New OleDbCommand(s, con)
cmd1.Parameters.AddWithValue("", txtfName.Text)
cmd1.Parameters.AddWithValue("", txtMI.Text)
cmd1.Parameters.AddWithValue("", txtLName.Text)
cmd1.Parameters.AddWithValue("", txtDOB.Text)
cmd1.Parameters.AddWithValue("", txtemail.Text)
cmd1.Parameters.AddWithValue("", txtphone.Text)
cmd1.Parameters.AddWithValue("", txtAddress.Text)
cmd1.Parameters.AddWithValue("", txtcity.Text)
cmd1.Parameters.AddWithValue("", txtstate.Text)
cmd1.Parameters.AddWithValue("", txtzip.Text)
cmd1.Parameters.AddWithValue("", txtpharmacyName.Text)
cmd1.Parameters.AddWithValue("", txtPharmacyPhone.Text)
con.Open()
cmd1.ExecuteNonQuery()
cmd1.CommandText = sql
ID = cmd1.ExecuteScalar()
For Each row As DataRow In table.Rows
Dim txPrescription As String = TryCast(row.ItemArray(1), String)
If txPrescription IsNot Nothing Then
Try
s = "INSERT INTO Prescriptions(Prescription, custId) VALUES "
s += "('" & txPrescription & "', " & ID & ")"
'Response.Write(s)
'Response.End()
'Dim connStr As String = ConfigurationManager.ConnectionStrings("allstringconstrng").ConnectionString
Dim conn As New OleDbConnection(connStr)
Dim cmd As New OleDbCommand(s, conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
'Display some feedback to the user to let them know it was processed
lblResult.ForeColor = System.Drawing.Color.Green
lblResult.Text = "Your Prescriptions Transfer Request has been sent. Prescription requests are normally processed within 24 hours!"
'Clear the form
txPrescription = ""
txtfName.Text = ""
txtMI.Text = ""
txtLName.Text = ""
txtDOB.Text = ""
txtemail.Text = ""
txtphone.Text = ""
txtAddress.Text = ""
txtcity.Text = ""
txtstate.Text = ""
txtzip.Text = ""
Catch
'If the message failed at some point, let the user know
lblResult.ForeColor = System.Drawing.Color.Red
lblResult.Text = "Your record failed to save, please try again."
End Try
End If
Next
End If
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub