douxu0550 2017-02-21 14:08
浏览 6
已采纳

什么是我最好的实时处理和更新方法?

I am trying to create a webpage to call from a MYSQL database, present the information retrieved and then handle in a couple of ways.

Upon entering a unique number, I bring up the relevant details, example here being;

Order Number    |    Item


----------
1234                 B111
1234                 C333
1234                 D999

After this, I want to input (more specifically, scan Barcodes) each of the "Items" manually, confirming they have been manually checked.

Once complete, and all 3 items have been matched correctly, I want to submit the page and append 2 fields into the database (this part is no problem). But I don't want this to be possible until each of the items has been checked off, so no committal to the DB will be made until it is confirmed correct. Also, if something is scanned is not in this range, an alert will be shown.

Is anyone able to point me in the right direction on the best way to do this? I am not after a complete solution, just a general direction to the best approach to do this.

  • 写回答

1条回答 默认 最新

  • dongzhan0624 2017-02-21 16:11
    关注

    If I understand correctly, you are trying to do the following, in different steps:

    • Step 1 Look up and open an order.
    • Step 2a Scan a product
    • Step 2b Haveit looked up and shown
    • Step 2c Show if the action has worked out and show feedback
    • Step 2d See if there are more products
      • If yes, go back to Step 2a
      • If no, go to Step 3
    • Step 3 Submit data and have it processed in the backend

    And what you are asking is a good way to handle the whole of step 2

    I can come up with 2 ways:

    Server sided

    Make some extra tables to hold a 'session'. Your session here is those 3 steps in all.

    ScanSessionHeader ScanSessionLine

    for example

    When you scan the order, you make a header record with a change DateTime and make it hold an open state.

    As long as the record is in this 'open' state. You show this on your webpage and you can keep showing the next scan field.

    When you submit a product line to the backend you, save the product barcode in the ScanSessionLine and it's validation state.

    And you can show this information on the webpage.

    When the whole thing needs to be submitted, you 'close' the header so it can not longer be used to add more lines too.

    And if all lines are validated properly you process them all in one go.

    You can do the same by storing everything in SESSION variables, but the whole scan session will get lost when the server gets restarted.

    This can be prevented by showing any open scan sessions when none are actively bound to this session. (by holding a ScanSessionHeader.ID in the session) so you can continue after a server restart (or Apache restart).

    Client side with asynchronous server calls

    After the order gets retrieved, you open a form with the field for the product barcode.

    You can do this from the server side, but I would start this with JavaScript from the start.

    As soon as something is entered in the field, you do an AJAX call: https://www.w3schools.com/xml/ajax_intro.asp

    This loads a webpages in the background, with parameters and after you use this call to validate the barcode, you can set the state of the product line.

    With every product scanned you can show a new product line, so you can add more.

    And as long as all lines get validated as correct, you keep showing the submit button for the whole form.

    However, all data gets lost as soon as the pages gets reloaded. For example Javascript error prevents you from completing the form further so the user reloads.

    What path you choose depend on your use case:

    If you want a safe solution with ways to save the state of the scanning, go with the first one and save in the database. Just make sure to implement a way to throw away old/stall scan sessions.

    If you need more speed and don't want to wait for full page reloads and want it all to look more fancy and snappy. Go with asynchronous server calls and do all your magic with JavaScript.

    You can still save the whole session in a database, but it will take a bit more code to be able to restore a session to the webpage the user is viewing.

    Or if you want a really quick and dirty solution. Pass all data needed for the validations into the webpage and let Javascript handle everything.

    Write down some requirements and I could advise what path could work for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler