Browse Source

Additional checks on batch insertion

Neal Wilson 7 years ago
parent
commit
a81302d1fb
1 changed files with 15 additions and 2 deletions
  1. 15
    2
      config/Windows/newbatch.xml

+ 15
- 2
config/Windows/newbatch.xml View File

501
             var approval = findChildObject(this, 'approval');
501
             var approval = findChildObject(this, 'approval');
502
             approval.checked = true;
502
             approval.checked = true;
503
             var target = findChildObject(this, 'target');
503
             var target = findChildObject(this, 'target');
504
+            var greenCheck = function() {
505
+                var itemArray = table.columnArray(0, 32).split("\\s*,\\s*");
506
+                var weightArray = table.columnArray(1, 0).split("\\s*,\\s*");
507
+                return (itemArray.length == weightArray.length) && (itemArray.length > 0);
508
+            }
504
             var checkSubmitEnable = function () {
509
             var checkSubmitEnable = function () {
505
                 if(roasted.currentIndex > 0) {
510
                 if(roasted.currentIndex > 0) {
506
                     if(timefield.text.length > 0) {
511
                     if(timefield.text.length > 0) {
507
                         if(duration.text.length > 0) {
512
                         if(duration.text.length > 0) {
508
                             if(batch.tempData.length > 0) {
513
                             if(batch.tempData.length > 0) {
509
                                 if(green.text.length > 0) {
514
                                 if(green.text.length > 0) {
510
-                                    return true;
515
+                                    if(greenCheck()) {
516
+                                        return true;
517
+                                    }
511
                                 }
518
                                 }
512
                             }
519
                             }
513
                         }
520
                         }
576
                 q2 = q2 + selectedRoasterID;
583
                 q2 = q2 + selectedRoasterID;
577
                 q2 = q2 + ", :duration, :approval, NULL, NULL, NULL, NULL, '{";
584
                 q2 = q2 + ", :duration, :approval, NULL, NULL, NULL, NULL, '{";
578
                 q2 = q2 + fileno;
585
                 q2 = q2 + fileno;
579
-                q2 = q2 + "}')";
586
+                q2 = q2 + "}') RETURNING time";
580
                 query2 = new QSqlQuery();
587
                 query2 = new QSqlQuery();
581
                 query2.prepare(q2);
588
                 query2.prepare(q2);
582
                 query2.bind(":time", timefield.text);
589
                 query2.bind(":time", timefield.text);
584
                 query2.bind(":duration", duration.text);
591
                 query2.bind(":duration", duration.text);
585
                 query2.bind(":approval", approval.checked);
592
                 query2.bind(":approval", approval.checked);
586
                 query2.exec();
593
                 query2.exec();
594
+                if(!query2.next()) {
595
+                    displayError(TTR("batchWindow", "Failed to save batch to database. Please check inputs and connection and try again."));
596
+                    query2 = query2.invalidate();
597
+                    query = query.invalidate();
598
+                    return;
599
+                }
587
                 query2 = query2.invalidate();
600
                 query2 = query2.invalidate();
588
                 if(target.checked) {
601
                 if(target.checked) {
589
                     var q3 = "INSERT INTO item_files (time, item, files) VALUES(:time, :item, '{";
602
                     var q3 = "INSERT INTO item_files (time, item, files) VALUES(:time, :item, '{";

Loading…
Cancel
Save