c# - ASP.NET malfunction when signing up to an event -
we 2 students trying develop website asp.net functions. have come issue:
we have booking page logged in user can sign events, have made separate tabel handling sign ups.
in table have member_id session, , event id.
we continue check member_id , event_id in database make sure same member cant sign same event twice.
protected void page_load(object sender, eventargs e) { if (session["medlems_id"] == null) response.redirect("medlemslogin.aspx"); if (!ispostback) { if (session["redirectedmessage"] != null) { lblmessage.text = session["redirectedmessage"].tostring(); session["redirectedmessage"] = null; } } } protected void gridview1_rowcommand(object sender, gridviewcommandeventargs e) { // få fat hold_id fra den valgte kolonne og gem det variablen varhold_id var varhold_id = gridview1.rows[convert.toint32(e.commandargument)].cells[6].text; //db connection string connstr = @"provider=microsoft.ace.oledb.12.0;data source=|datadirectory|\drt.mdb;jet oledb:database password=password"; oledbconnection myconn = new oledbconnection(connstr); myconn.open(); oledbcommand cmd = new oledbcommand(strcmd, myconn); cmd.commandtext = "select * booking hold_id = @hold_idpar"; cmd.parameters.addwithvalue("hold_idpar", varhold_id); oledbdatareader objreader = cmd.executereader(); if (objreader.read()) { var antalpladser = convert.toint32(objreader["pladser"]); var antaltilmeldte = convert.toint32(objreader["tilmeldte"]); var holdnavn = convert.tostring(objreader["hold"]); var medlems_idva = session["medlems_id"]; if (antalpladser > 0) { oledbcommand dbcmd = new oledbcommand(strcmd, myconn); dbcmd.commandtext = "select hold_id tilmelding hold_id = @hold_idpar , medlems_id = @medlems_idpar"; dbcmd.parameters.addwithvalue("medlems_idpar", medlems_idva); dbcmd.parameters.addwithvalue("hold_idpar", varhold_id); oledbdatareader valreader = dbcmd.executereader(); if (valreader.read()) { lblmessage.text= "du er allerede tilmeldt"; } else { oledbcommand cmd3 = new oledbcommand(strcmd, myconn); cmd3.commandtext = "update booking set tilmeldte = tilmeldte+1, pladser = pladser-1 hold_id = @hold_idpar"; cmd3.parameters.addwithvalue("hold_idpar", varhold_id); cmd3.executenonquery(); oledbcommand cmd2 = new oledbcommand(strcmd, myconn); cmd2.commandtext = "insert tilmelding (medlems_id, hold_id) values (@medlems_idpar, @hold_idpar)"; cmd2.parameters.addwithvalue("medlems_idpar", medlems_idva); cmd2.parameters.addwithvalue("hold_idpar", varhold_id); cmd2.executenonquery(); session["redirectedmessage"] = "du er tilmeldt holdet" + holdnavn; response.redirect("kalender.aspx"); } //response.redirect("kalender.aspx"); } else { lblmessage.text = "der er ikke flere pladser"; } } objreader.close(); myconn.close(); } private object int32(object p) { throw new notimplementedexception(); } public string strcmd { get; set; }
our problem that, members can keep signing events. if event id , member id same, works correctly reason.
here translation database since used danish words naming db.
hold_id=event_id medlems_id=member_id
hope can us, since our hair becoming quite gray.
before insert can use below query:
select event_table.event_id event_table inner join member_table on event_table.event_id=member_table.event_id
and not sign member if event_id selected above query matches event id in session. (suppose table containing events 'event_table' , table containing member sign 'member_table')
Comments
Post a Comment