Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi, no one has given me a solution to this problem
I want that if a student buys a meal with his ID card, it will not be repeated with his university card and vice versa because the university card and the ID card are different.

...........................

Hello everyone, This site sells meals to students. The student is required to present his university card or ID card to purchase the meal. I want the student not to buy the meal repeatedly because he has the university card and the ID card and the two numbers are different. I want it to search by name. If the name is present in the database at meal time, it will not be repeated if it is with the university number or the ID number

What I have tried:

VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim aid = Trim(txtUserName.Text)
        Dim Connection As New SqlConnection()
        If Trim(txtUserName.Text) = "111" Then
            Dim adapter As New SqlDataAdapter("SELECT Aid, sname, location from student where ltrim(rtrim(aid))='" & Trim(txtUserName.Text) & "'", Connection)

            Dim ds As New DataSet()
            adapter.Fill(ds, "head")
            Label6.Text = ds.Tables("head").Rows(0).Item("sname") & "(" & ds.Tables("head").Rows(0).Item("Aid") & ")"
            Label9.Text = ds.Tables("head").Rows(0).Item("location")
            Label10.Text = "STATUS : " & Label9.Text
            stype = ds.Tables("head").Rows(0).Item("location")
            Textbox5.Text = ds.Tables("head").Rows(0).Item("location")
            Label10.BackColor = Drawing.Color.White
            Label10.ForeColor = Drawing.Color.Green
            Label5.Visible = True
            Label6.Visible = True
            Label7.Visible = True
            Label8.Visible = True
            Label9.Visible = True
            Label10.Visible = True
            Label14.Visible = True
            Label15.Visible = True
            Label16.Visible = True

            'Textbox4.Visible = True
            'Textbox10.Visible = True
            Textbox11.Visible = True
            'Textbox12.Visible = True
            BindCheck()

        Else
            'BindCheck()

            ServicePointManager.ServerCertificateValidationCallback = AddressOf RemoteCertificateValidate
            Dim StudentOutputData As New BarCodeApps.ServiceReference1.Student2Data
            Dim StudentInputData As New BarCodeApps.ServiceReference1.UserInput
            Dim StudentSSOClient As New BarCodeApps.ServiceReference1.StudentsServiceClient

            'StudentInputData.StudentId = aid
            StudentInputData.NationalId = aid

            StudentInputData.ConsumerApplication = "BarCodeApps"
            'StudentOutputData = StudentSSOClient.GetStudent2Info(StudentInputData)

            If StudentOutputData.IsDataFound = False Then
                StudentInputData.StudentId = aid
                StudentInputData.NationalId = Nothing
                'StudentOutputData = StudentSSOClient.GetStudent2Info(StudentInputData)
            End If

            Fname = StudentOutputData.FIRST_NAME_ENG
            MNAME = StudentOutputData.MIDDLE_NAME_ENG
            lNAME = StudentOutputData.LAST_NAME_ENG
            Label6.Text = Fname & " " & MNAME & " " & lNAME & "(" & StudentOutputData.STUDENT_ID & ")"
            Textbox9.Text = Fname & " " & MNAME & " " & lNAME
            '                                   Label7.Text = StudentOutputData.STUDENT_ID


            Label9.Text = StudentOutputData.DEPARTMENT_NAME & " " & StudentOutputData.DEPARTMENT_NAME_ENG
            Label10.Text = "STATUS : " & StudentOutputData.STATUS_DESC
            scode = StudentOutputData.STATUS_CODE
            Label13.Text = StudentOutputData.DEPARTMENT_NAME
            Label11.Text = StudentOutputData.STATUS_DESC
            Label12.Text = StudentOutputData.STATUS_CODE
            stype = "KSU Student"
            Textbox5.Text = "KSU Student"
            Textbox6.Text = StudentOutputData.STATUS_CODE



            ' Else
            '  GoTo Line313
            '  End If
            If CStr(Textbox6.Text) = "" Then
                Textbox6.Text = 99
            End If
            lblOutput.Visible = True
            Label5.Visible = True
            Label6.Visible = True
            'Label7.Visible = True
            Label8.Visible = True
            Label9.Visible = True
            Label10.Visible = True
            'Label14.Visible = True
            'Label15.Visible = True
            'Label16.Visible = True
            'Textbox4.Visible = True
            'Textbox10.Visible = True
            'Textbox11.Visible = True
            'Textbox12.Visible = True
            If scode = "1" Then
                'If scode = "1" Or scode = "7" Then
                BindBlockStudent()
                Label10.BackColor = Drawing.Color.White
                Label10.ForeColor = Drawing.Color.Green
                image2.Visible = True
                Label10.Text = "STATUS : " & StudentOutputData.STATUS_DESC
                Textbox8.Text = "Normal"
                ' ElseIf CStr(Textbox6.Text) <> "1" And CStr(Textbox6.Text) <> "7" And CStr(Textbox6.Text) <> "99" Then
            ElseIf CStr(Textbox6.Text) <> "1" And CStr(Textbox6.Text) <> "99" Then
                Label10.ForeColor = Drawing.Color.Red
                Label10.BackColor = Drawing.Color.Yellow
                Label10.Text = "STATUS : " & StudentOutputData.STATUS_DESC
            ElseIf CStr(Textbox6.Text) = "99" Then

                Label10.Text = "STATUS : " & "Student Not Registered in KSU List..!"
Line313:
                Dim cmdAddType As SqlCommand = New SqlCommand("chkID", conn)
                cmdAddType.CommandType = CommandType.StoredProcedure
                cmdAddType.Parameters.Add(New SqlParameter("@IDNO", SqlDbType.NVarChar, 255))
                'cmdAddType.Parameters.Add(New SqlParameter("@sname", SqlDbType.NVarChar, 255))
                Dim OParm As SqlParameter = cmdAddType.Parameters.Add("@OReturn", SqlDbType.Int)
                OParm.Direction = ParameterDirection.Output
                cmdAddType.Parameters("@IDNO").Value = Trim(txtUserName.Text)
                'cmdAddType.Parameters("@sname").Value = Trim(txtUserName.Text)
                conn.Open()
                cmdAddType.ExecuteNonQuery()
                conn.Close()
                Dim OReturn As String = cmdAddType.Parameters("@OReturn").Value.ToString
                If CStr(OReturn) = "1" Then
                    Dim adapter As New SqlDataAdapter("SELECT Aid, sname,building, location,mealtype from student where ltrim(rtrim(aid))='" & Trim(txtUserName.Text) & "' and starttime <getdate() and="" endtime=""> GETDATE()", Connection)
                    'and   (CONVERT(varchar, STARTTIME, 113) < CONVERT(varchar, GETDATE(), 113)) AND (CONVERT(varchar, ENDTIME, 113) > CONVERT(varchar, GETDATE(),113))
                    Dim ds As New DataSet()
                    adapter.Fill(ds, "head")
                    If ds.Tables("head").Rows.Count <> 0 Then
                        Label6.Text = ds.Tables("head").Rows(0).Item("sname") & "(" & ds.Tables("head").Rows(0).Item("Aid") & ")"
                        Textbox9.Text = ds.Tables("head").Rows(0).Item("sname")
                        Label9.Text = ds.Tables("head").Rows(0).Item("building")
                        Label10.Text = "STATUS : " & Label9.Text
                        'stype = "NON-KSU Student"
                        'Textbox5.Text = "NON-KSU Student"
                        stype = ds.Tables("head").Rows(0).Item("location")
                        Textbox5.Text = ds.Tables("head").Rows(0).Item("location")
                        Textbox8.Text = ds.Tables("head").Rows(0).Item("mealtype")
                        Textbox6.Text = 2
                        BindBlockStudent()
                        Label10.BackColor = Drawing.Color.White
                        Label10.ForeColor = Drawing.Color.Green
                        image2.Visible = True
                    Else
                        Label10.Text = "STATUS : " & "Student Meal Time Expired/Not Available..!"
                        Label10.BackColor = Drawing.Color.Yellow
                        Label10.ForeColor = Drawing.Color.Red
                    End If
                ElseIf CStr(OReturn) = "3" Then
                    Dim adapter As New SqlDataAdapter("SELECT Aid, sname,building, location,mealtype from student where ltrim(rtrim(aid))='" & Trim(txtUserName.Text) & "' and mobile is not null", conn)
                    'and   (CONVERT(varchar, STARTTIME, 113) < CONVERT(varchar, GETDATE(), 113)) AND (CONVERT(varchar, ENDTIME, 113) > CONVERT(varchar, GETDATE(),113))
                    Dim ds As New DataSet()
                    adapter.Fill(ds, "head")
                    If ds.Tables("head").Rows.Count <> 0 Then
                        Label6.Text = ds.Tables("head").Rows(0).Item("sname") & "(" & ds.Tables("head").Rows(0).Item("Aid") & ")"
                        Textbox9.Text = ds.Tables("head").Rows(0).Item("sname")
                        Label9.Text = ds.Tables("head").Rows(0).Item("building")
                        Label10.Text = "STATUS : " & Label9.Text
                        stype = "KSU Student"
                        Textbox5.Text = "KSU Student"
                        Textbox8.Text = ds.Tables("head").Rows(0).Item("mealtype")
                        Textbox6.Text = 2
                        BindBlockStudent()
                        Label10.BackColor = Drawing.Color.White
                        Label10.ForeColor = Drawing.Color.Green
                        image2.Visible = True
                    End If
                Else
                    Label10.Text = "STATUS : " & "Student Not Registered in KSU & Non KSU List..!" & "*" & StudentOutputData.STATUS_DESC & "*" & StudentOutputData.STATUS_CODE

                    Label10.BackColor = Drawing.Color.Yellow
                    Label10.ForeColor = Drawing.Color.Red
                    'Response.Write("")
                    'Response.Write("window.open('AddStudent.aspx?prompt0=" & Trim(txtUserName.Text) & "','AddStudent','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=820,height=620')" & vbCrLf)
                    'Response.Write("")
                    'Response.Write("")
                    'Response.Write("alert('Student Status is Inactive... ')")
                    'Response.Write("")
                End If

            End If
        End If
    End Sub

sql..........................................
SQL
USE [Barcode]
GO
/****** Object:  StoredProcedure [dbo].[chkID]    Script Date: 2023/11/01 07:47:24 ص ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
/* 
    Project : KSU Barcode Project
    author: Mujib 
    purpose: Check Badge Number
*/
ALTER PROCEDURE [dbo].[chkID]
	@IDNO nvarchar(50),
	@OReturn int output

as
if exists(select aID from STUDENT where (AID=@IDNO) and mobile is null)
	select @OReturn =1
	
/*else if exists(select aID from STUDENT where (AID=@IDNO) and mobile =0)
	select @OReturn =1*/

else if exists(select aID from STUDENT where (AID=@IDNO) and mobile is not null)
	select @OReturn =3	
	else
	select @OReturn =2
Posted
Updated 1-Nov-23 22:18pm
v5
Comments
CHill60 1-Nov-23 4:27am    
You've stated what you want but haven't said what the problem is
yossef2023 1-Nov-23 4:31am    
The problem is that the student has two cards, the university card and the ID card, and the numbers are different. I want if he buys with the university number, he does not buy the ID card, and vice versa. The university number, the ID number, and the name are found in the database.
CHill60 1-Nov-23 7:55am    
Well firstly if you search by name, what are you going to do if two students have the same name (very common). But you still have not stated what it is you want from US.
If you want to get the record where either the ID card or the University Card has been presented then use an OR clause in your WHERE clause in your SQL statement
e.g.
WHERE @IDNO = idcard OR @IDNO = unicard
[no name] 1-Nov-23 5:24am    
Let them use both, but only bill the first one "registered". Unless it's some meaningless policy issue , you have all the information you need to say who used what when ... if anyone asked.
Richard Deeming 2-Nov-23 5:03am    
"Bumping" your question to the top of the list to complain that nobody has done your work for you and handed you a solution yet is extremely rude, and a great way to ensure that nobody will try to help you.

Rather than complaining, how about you try answering the questions that CHill60 asked you yesterday?

1 solution

Design your database such that you have a Student table and within that table you store their University Card Number and their ID Number (I would possibly have had an intersection table but I'm keeping this simple)

Have another table that records who has bought a meal. That table should contain the ID number used, a value equating to the Primary key of the Student table (i.e. a Foreign key back to the Student table), and presumably some details about the meal purchased.

To search whether or not a student has already had a meal search for something like
SQL
SELECT StudentPK 
FROM Student S
INNER JOIN MealsBought M ON S.IDNO = M.CardNo OR S.UniNO = M.CardNo;
Or if you want to do it by passing the card used for the meal then use
SQL
SELECT * -- list the actual columns
FROM Student S
WHERE S.IDNO = @IDNO OR S.UniNo = @IDNO;
(As I said in my comment yesterday)

Some other advice:
- Don't use default names for controls. Get into the habit of giving them meaningful names the minute you place them on your canvas/form/page. Who knows what Button1 is meant to be??
- Only post relevant code in your questions and learn to use the code helper in the question editor. Nobody wants to scroll through a lot of meaningless text
- Always, always include some sample data and your expected results. For database questions including the table schemas is usually useful - but only the relevant ones.

Finally, take note of the comment from Richard - we do this as volunteers in our spare time, some of us do not take kindly to impatient students. Put the effort in and we will try our best, but it's your homework, not ours.
 
Share this answer
 
Comments
Maciej Los 4-Nov-23 13:56pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900