Answered by:
mvc automated counter using entity framework

Question
-
User-1162256410 posted
good day. i am making an automated counter using entity framework. the format goes like this
_______________________________________________________________________
||STARTING SERIES || ENDING SERIES || CURRENT SERIES || STATUS ||
||001 || 100 || 001 || FALSE ||
_______________________________________________________________________
when the page load and status is true, a modal pop up should open so that you could enter a new entry. the starting series is the beginning of the transaction and ending series is the final transaction digit. the current series will be the number that will be printed to a form or receipt and this will be triggered using a button.
for short, when a user clicks a button, the current series will increment, print a receipt and save to the database. the form will reload with the new incremented value. and when the current series is greater than the ending series, the status will change to true then a modal pop up will show to begin a new transaction.
i was able to able to do the modal pop up but not the incrementing value. Thanks in advance
Best Regards,Aeon
Monday, October 23, 2017 3:25 AM
Answers
-
User-1162256410 posted
i was able to make it work already. all i used was a simple javascript command and some sql connection in the controller. thanks for the reply anyways.
my code goes like this:
this is the action series
public ActionResult Series() { List<eSeriess> series = db2.eSeriesses.Where(x => x.status == "False").ToList(); ViewBag.Series = series; return View(); }
the view
@foreach (var item in ViewBag.series) { <input type="text" value="@item.id" id="myNumber" name="myNumber" readonly class="hidden" /> <input type="text" value="@item.s_end" id="myNumber2" name="myNumber2" readonly class="hidden" /> <input type="text" value="@item.s_current" id="myNumber3" name="myNumber3" readonly class="hidden" /> <input type="text" value="@item.status" id="status" name="status" readonly class="hidden" /> } @using (Html.BeginForm("Save", "Series", FormMethod.Post)) { <div class="container"> <div class="form-group"> <center> <input type="text" id="item1" name="item1" class="hidden" /> <input type="text" id="item2" name="item2" class="hidden" /> <input type="text" id="item4" name="item4" class="form-control" readonly/> <input type="text" id="item3" name="item3" class="hidden" /> <br /> <input type="text" id="serial1" name="serial1" class="hidden" /> <input type="text" id="status2" name="status2" class="hidden" /> <button type="submit" class="btn btn-info">Print</button> </center> </div> </div> }
now in this code, the for loop gets the viewbag series wherein the value returns a value where it is false, a javascript code gets those value and populates the method below so when a user clicks the button, it will increment.
the javascript
<script> $(window).on('load', function () { var s_end = document.getElementById("myNumber2").value; var s_current = document.getElementById("myNumber3").value; var s_status1 = document.getElementById("status").value; var s_end1 = s_end.substring(3); var s_current1 = s_current.substring(3); var s_serial = s_end.slice(0, 3); var s_id1 = parseInt(document.getElementById("myNumber").value); var s_end2 = parseInt(s_end1, 10); var s_end3= s_end1.length; var s_current2 = parseInt(s_current1, 10); var x = parseInt(s_current1, 10) + 1; var x1 = x.toString(); String.prototype.pad = function pad(str, max) { str = str.toString(); return str.length < max ? pad("0" + str, max) : str; }; document.getElementById("serial1").value = s_serial; document.getElementById("item1").value = s_id1; document.getElementById("item2").value = s_end1; document.getElementById("item3").value = x1.pad(x1, s_end3); document.getElementById("item4").value = s_current2; document.getElementById("status2").value = s_status1; if ((s_current2 > s_end2) && (s_current2 != s_end2)) { $('#myModal').modal({ backdrop: 'static', keyboard: false }); $('#myModal').modal('show'); $('#m_item1').val(s_id1); } if (!s_current2 || !s_end2) { $('#myModal').modal({ backdrop: 'static', keyboard: false }); $('#myModal').modal('show'); $('#m_item1').val(s_id1); } }); </script> }
in this javascript the code runs the getting of value and populating to the method. also, when the value of the end series is less than the current method or even both are null, the modal will show.
i know my coding is a little bit messy but im working on it. thanks again sir for your reply.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, November 3, 2017 12:32 AM
All replies
-
User1771544211 posted
Hi C.Aeon,
i was able to able to do the modal pop up but not the incrementing value. Thanks in advanceCould you please share your code here? Then we can check what's wrong with your side and check how to fix it.
In my opinion, I will use the ajax to submit the form data and return the incremented value to the client. Then in the ajax success method, assign the incremented value to the field.
Best Regards,
Jean
Tuesday, October 24, 2017 5:28 AM -
User-1162256410 posted
i was able to make it work already. all i used was a simple javascript command and some sql connection in the controller. thanks for the reply anyways.
my code goes like this:
this is the action series
public ActionResult Series() { List<eSeriess> series = db2.eSeriesses.Where(x => x.status == "False").ToList(); ViewBag.Series = series; return View(); }
the view
@foreach (var item in ViewBag.series) { <input type="text" value="@item.id" id="myNumber" name="myNumber" readonly class="hidden" /> <input type="text" value="@item.s_end" id="myNumber2" name="myNumber2" readonly class="hidden" /> <input type="text" value="@item.s_current" id="myNumber3" name="myNumber3" readonly class="hidden" /> <input type="text" value="@item.status" id="status" name="status" readonly class="hidden" /> } @using (Html.BeginForm("Save", "Series", FormMethod.Post)) { <div class="container"> <div class="form-group"> <center> <input type="text" id="item1" name="item1" class="hidden" /> <input type="text" id="item2" name="item2" class="hidden" /> <input type="text" id="item4" name="item4" class="form-control" readonly/> <input type="text" id="item3" name="item3" class="hidden" /> <br /> <input type="text" id="serial1" name="serial1" class="hidden" /> <input type="text" id="status2" name="status2" class="hidden" /> <button type="submit" class="btn btn-info">Print</button> </center> </div> </div> }
now in this code, the for loop gets the viewbag series wherein the value returns a value where it is false, a javascript code gets those value and populates the method below so when a user clicks the button, it will increment.
the javascript
<script> $(window).on('load', function () { var s_end = document.getElementById("myNumber2").value; var s_current = document.getElementById("myNumber3").value; var s_status1 = document.getElementById("status").value; var s_end1 = s_end.substring(3); var s_current1 = s_current.substring(3); var s_serial = s_end.slice(0, 3); var s_id1 = parseInt(document.getElementById("myNumber").value); var s_end2 = parseInt(s_end1, 10); var s_end3= s_end1.length; var s_current2 = parseInt(s_current1, 10); var x = parseInt(s_current1, 10) + 1; var x1 = x.toString(); String.prototype.pad = function pad(str, max) { str = str.toString(); return str.length < max ? pad("0" + str, max) : str; }; document.getElementById("serial1").value = s_serial; document.getElementById("item1").value = s_id1; document.getElementById("item2").value = s_end1; document.getElementById("item3").value = x1.pad(x1, s_end3); document.getElementById("item4").value = s_current2; document.getElementById("status2").value = s_status1; if ((s_current2 > s_end2) && (s_current2 != s_end2)) { $('#myModal').modal({ backdrop: 'static', keyboard: false }); $('#myModal').modal('show'); $('#m_item1').val(s_id1); } if (!s_current2 || !s_end2) { $('#myModal').modal({ backdrop: 'static', keyboard: false }); $('#myModal').modal('show'); $('#m_item1').val(s_id1); } }); </script> }
in this javascript the code runs the getting of value and populating to the method. also, when the value of the end series is less than the current method or even both are null, the modal will show.
i know my coding is a little bit messy but im working on it. thanks again sir for your reply.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, November 3, 2017 12:32 AM