0

So i work in a production set up, and i have an aspx page, what i need the page to do is ....

When a (unit is packed) increment my label to the next number (So at the start of the shift, the label displays 0, and increments by one when a operation is executed)

I also need to set this label to reset after 8 hours... so there is 3 shift patterns 6am-2pm ---- 2pm - 10pm -- 10pm - 6pm....

So this time must always be in use even if the web page is closed and opened again...

I hope this makes sense...

1 Answers1

0

Let's see if I undestood it right, first you want to have a label that changes depending on someone clicking a button, and second you want to refresh the page if at three hours(06:00, 14:00, 22:00).

There's a problem at least for me, you need to save the current label value somewhere between all the people that is working with the label system.

In my solution, you need a database to save it.

At the Page_Load of the aspx file, I would call a function that returns the current label value, something like this:

public static string label = 0;

protected void Page_Load(object sender, EventArgs e)
{
    label = getValueLabel();
}

The function getValueLabel should go to the database and return the current label.

Now for the label resetting at some hours, I would do something with the task manager, and then set it on the webserver where the project is hosted.

It could be a simple console application, that goes to the database and updates the current label value.

You set this application to run at 06:00, 14:00 and 22:00, and this will clean the label value.

And last part for the webpage to reset at certain hours, you can use Javascript to do it.

Here's the solution from @Nick in this question.

function refreshAt(hours, minutes, seconds) {
    var now = new Date();
    var then = new Date();

    if(now.getHours() > hours ||
       (now.getHours() == hours && now.getMinutes() > minutes) ||
        now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
        then.setDate(now.getDate() + 1);
    }
    then.setHours(hours);
    then.setMinutes(minutes);
    then.setSeconds(seconds);

    var timeout = (then.getTime() - now.getTime());
    setTimeout(function() { window.location.reload(true); }, timeout);
}

When loaded the page just call the function three times.

refreshAt(06,0,0);
refreshAt(14,0,0);
refreshAt(22,0,0);

Hopefully I gave you some ideas so you can do it, it's kinda difficult if I cant see code or your project tree.

  • Thanks, yes this has helped with the timer, but the label will update once a backend operation has been performed, so the operation will fire this to the database and then the label must refresh with the incremented number... So basically once postback label needs to ++ –  Apr 13 '18 at 11:54
  • Once you do the backend operation (which will call a function that will increment the label) the page will postback and will update itself since the `getValueLabel` is inside the Page_Load. There might be a problem when someone has incremented the label while an user is still doing the operation with the old label. I would say that you should use the label value strictly from the database. – Emiliano Montesdeoca Apr 13 '18 at 12:01
  • Hi sorry, i am new to all this coding lark, so are you saying i need to create numbers in a database to increment the value of the label... sorry i am very very new to coding :) –  Apr 13 '18 at 14:08
  • It's fine I am here to help you, so what I am saying is that everytime you increment the label, you have to do it in the database and then you also load it in the aspx from the database. Because you are loading the label value from the database you just have to increment the value in the database. You only need to have a table with a field called (for example) currentLabel with a type of integer. Everytime an user fires the function you go to that table and then ++ the currentLabel. So with this structure, all user using the label system will load the latest when loading the page. – Emiliano Montesdeoca Apr 13 '18 at 14:24
  • Ok thank you very much i understand this, what is the coding when it is writen in c# ?? :) –  Apr 16 '18 at 07:44
  • I can't give you an specific piece of code, since I dont know how you have done all your code until now, but I recomend you to use EntityFramework to connect to the database to update the label value, here is the documentation: https://msdn.microsoft.com/en-us/library/aa937723(v=vs.113).aspx – Emiliano Montesdeoca Apr 16 '18 at 11:07