c# - Logic to prevent insertion if there are no available slots -



c# - Logic to prevent insertion if there are no available slots -

i'm developing application in asp.net c# , i'm trying figure out best way implement logic statement stop scheme allowing reservation taken if trailer canoes , kayaks full. issue trailer hold canoes , kayaks, there's lot of different combinations.

there 5 "rows" on trailer count upwards vertically, , 2 "columns" dissect 5 rows in middle. draw diagram show looks like, , boats can go where. "c" stand canoe , "k" stand kayak. trailer looks this:

class="lang-none prettyprint-override">c only|c } ______|______ } boat trailer 1c\2k|1c\2k } ______|______ } 1c\2k|1c\2k } ______|______ } 1c\2k|1c\2k } ______|______ } c only| c } ______|______ }

so question is, what's best alternative far coding , logic concerned not take more "reservations" when trailer full? application .aspx form insert command sql server taking client information.

public enum boattype : int { kayak = 1, canoe = 2 } public class boatreservation { public int reservationid { get; set; } public boattype reservationboattype { get; set; } } public class boattrailer { public list<boatreservation> canoeslots = new list<boatreservation>(); public list<boatreservation> regularslots = new list<boatreservation>(); public boattrailer() { } public bool addboat(boatreservation b) { bool boatadded = false; switch (b.reservationboattype) { case boattype.canoe: if (canoeslots.count() < 4) { canoeslots.add(b); boatadded = true; } else { var reg = regularslots.sum(x => convert.toint16(x.reservationboattype)); if (reg <= 10) { regularslots.add(b); boatadded = true; } } break; case boattype.kayak: { var reg = regularslots.sum(x => convert.toint16(x.reservationboattype)); if (reg <= 11) { regularslots.add(b); boatadded = true; } } break; } homecoming boatadded; } public void removeboat(boatreservation b) { switch (b.reservationboattype) { case boattype.kayak: if (regularslots.contains(b)) { regularslots.remove(b); } break; case boattype.canoe: if (regularslots.contains(b)) { regularslots.remove(b); } else { if (canoeslots.contains(b)) { canoeslots.remove(b); if (regularslots.where(fb => fb.reservationboattype == boattype.canoe).count() > 0) { //move reservation regular canoe opening boatreservation mv = regularslots.findlast(fb => fb.reservationboattype == boattype.canoe); regularslots.remove(mv); canoeslots.add(mv); } } } break; } } public string availableslots() { string output = string.empty; int availablecanoecnt = (4 - canoeslots.count()) + ((12 - regularslots.count()) / 2); int availablekayakcnt = (12 - regularslots.count()); output = string.format("canoe slots left: {0} kayak slots left {1} ", availablecanoecnt, availablekayakcnt); homecoming output; } }

quick class handles reservations (both adding , deleting) of canoes/kayaks fit trailer.

c# asp.net sql

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -