-
Notifications
You must be signed in to change notification settings - Fork 18
/
Form1.vb
5607 lines (5072 loc) · 237 KB
/
Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports System.IO
Imports System.Management
Imports System.Drawing.Drawing2D
Imports System.Drawing.imaging
Imports System.Drawing.printing
Imports System.Threading
Imports System.Globalization
Imports System.Runtime.InteropServices
Imports System.Net
Imports System.Xml
Imports System.Web.Script.Serialization
Public Class Form1
'v. 8.0: Major release
' Includes checking GitHub for new version and linking to GitHub wiki for documentation. Removed references to BC license and server.
'
'v. 7.0: Major release
' Includes option to use Alma's RESTful API URL to retrieve an item's XML file, as
' well as the deprecated Java SOAP APIs. The RESTful XML file is converted into
' the SOAP XML format so that SpineOMatic can process the file without major
' modification to the software.
'
'v. 6.12: Minor trial release
' Allows the ! (render as bar code) formatting code to be used in custom Pocket Labels.
' Will be distributed to one user who wanted the feature, and included in subsequent
' releases if it is acceptable.
'
'v. 6.11: Minor release
' Clarified and changed LC/LC child lit./NLM and Dewey parsing behavior:
' Tweak and Test panel for the LC... parser: "Decimal" break description was changed to
' "Class Decimal". Fixed a bug in "Break before decimal" that was causing a break
' after the decimal rather than before. An option was added to allow break both before
' or after the decimal.
' An option was added to the Dewey parser to allow breaking on the cutter decimal
' string after a specific number of characters following the decimal.
'
'v. 6.1: Minor release
' Fixed bug in "*" format code ("Suppress field display");
' Added check for unbalanced quotation marks in "Quoted text" format code.
'
'v. 6.0: Major release features:
' Holdings processor now lets user select no holdings, textual holdings parsed by SpineOMatic,
' or Ex Libris' Parsed Holdings fields. If Parsed Holdings are specified but do not exist,
' SpineOMatic will parse the textual holdings. The display will indicated which call number
' parser was used, and also which holdings parser was used.
' Asterisk (*) formatting code ("suppress" field display) suppresses display if the XML field
' is blank, or if the field is equal to any of three user-defined values.
' Tweak and Test SuDoc parser allows breaking on "Other" characters, with option
' to remove characters. (Behavior is consistent with LC, Dewey and Other parsers.)
' Dewey parser provides an option to print long numeric class numbers in groups of characters.
' New print option to send label text to a custom DOS batch file ("viados.bat"), which can
' print to legacy printers attached via LPT or COM ports, etc.
' Margins and line spacing can be entered in inches or centimeters.
' A decimal point or a comma can represent decimal fractions.
' Allows negative top margin and left margin settings.
' To insert XML field names into text boxes that allow it, items can be selected from
' a list of all XML fields (rather than typing the names).
'
'v. 5.21: Minor release to handle unencoded ampersands in the item's XML record.
' Added the tilde (~) character to stand for space characters in the Tweak and Test
' Other Break text strings.
' Changed the "Hide cutter decimal" routine from removing all decimals to removing only
' the first character, if it is a decimal.
'
'v. 5.2: Minor release to fix a bug in the multi-label print to Desktop routine, which failed to
' change the print button from "Stop" to "Send to Desktop Printer".
'
'v. 5.1: Minor release to fix the Holdings parser, which was causing spaces between elements
' to be removed.
' A "Break on spaces" checkbox was added to the Holdings parser's Tweak and Test panel;
' Made improvements to the management of default settings for Spine, Custom, Custom/Flag slips
' and Pocket Labels
' A "copy to clipboard" feature was added to send Report text and CurrentXML/settings.som
' text to the Windows clipboard.
'
'v. 5.0: Major release to add Pocket Label printing;
' Repairs errors due to unencoded angle bracket characters appearing in the data of
' returned XML files.
' Does not check the arc.bc.edu:8080 server at startup, but only when Check for
' Updates is clicked. (Due to occasional arc crashes that prevent SpineOMatic from
' starting.)
' Allows any call_number_type to be handled by any of SpineOMatic's parsing routines.
' Blank <call_number_type> can be converted to any specified type (0 - 8).
' Added option to the LC Tweak and Test panel to suppress the decimal that normally
' precedes the cutter.
' Added a Holdings parser to the Tweak and Test panels.
' Call number formats (Spine, Custom & Custom w/Flag Slips and Pocket Labels) each
' have their own separate set of margin settings and other defaults.
' Added formatting characters "^" to suppress newline after field, "*" to
' suppresse display of a field if it is blank or zero, and "+" to look up <location_name>
' in the Label Prefixes table and use the label text (that allows line breaks via semicolons).
' Increased maximum number of label copies from 5 to 99.
' Added a "cancel print" option for Desktop printing, and added a warning for Batch
' and FTP printing if more than 5 label copies are requested.
' Added keyboard shortcut CTRL p to trigger a manual print without having to use
' the mouse.
' Added a License Agreement that requires the user to either accept terms or cancel
' installation on first use of software, change of version, or relocation to a different PC.
'
'v. 4.32: Minor release to fix wrapping (if wrapping was turned on for one field, it
' stayed on for other fields that did not specify wrapping). Added a formatting
' code to add a text prefix to custom label fields, as well as to Spine fields
' "Include holdings" and "Include other value". Double quotes around text cause
' text to be prefixed to the printed value. Eg: "copy: "<copy_id>
' Redid the fix (originally in v. 4.3) that was supposed to prevent loss of Custom
' fields upon saving.
'
'v. 4.31: Minor release to fix a bug that prevented "Include holdings" from working.
' This is the first release to use two digits after the decimal of the release number.
'
'v. 4.3: Fixed a bug causing multi-cuttered LC call numbers to hide the decimal when
' breaking on cutter. Fixed bug that caused Custom fields to be lost when
' user saved settings while Flag Slips checkbox was checked.
' Replaced code written to parse the Ex Libris XML file with VB.NET's XML parser.
' Also alerted user if errors were detected in
' user-specified XML fields, i.e., not found, extraneous characters, etc.
' Checkbox added to either display error alert only, or to pop up a detailed message.
' Added ability for user to add formatting characters to Custom fields:
' (%=parse call#, #=parse holdings, !=render as barcode, ~=add space) before entry.
' Also allowed space (~) to be added before "Other" field in Spine label section.
' Added multi-label print capability, allowing label to be printed from 1 to 5 times.
'
'v. 4.2: Fixed a bug to allow SpineOMatic to recognize international date settings.
' Added Tweak and Test panel to allow user to modify the behaviors of
' SpineOMatic's parsing routines.
' Added a Dewey Decimal and an "Other" parser.
' Moved the Test Parsing section from Java Setup to
' the Tweak and Test Parsing panel. Removed the portrait/landscape distinction
' when SpineOMatic parsed SuDoc numbers. User can now set up parsing for one or
' the other.
' Added better checking for Java URL problems and credential issues.
' If the customer's PC cannot connect to BC servers due to blocking by their
' proxy server, a message tells them to whitelist the BC servers.
'
'v. 4.1: Changes to wording and layout of Print Flag Slips checkbox and Label Printing
' Web Service Credentials.
'
'v. 4.0: Removed need to provide a folder to receive Alma XML file. The installation
' directory will be used by default;
' Imported graphic background for the About box that contains the BC seal graphic;
' Java app class file and alma-sdk files are now automatically downloaded if needed,
' without manual intervention;
' Added separate margin/orientation/maximum settings for Flag Slips. Toggling the
' "print flag slips" checkbox calls up Flag Slip settings or returns to standard settings;
' The Java application is now run as a process from within vb rather than as an
' external .bat file. Java installation is verified, and problems locating or
' accessing java are reported to the user.
' A list of servers can be specified from which to obtain updates (i.e., the updatePath.
' If the default server fails, each server in the list is tried in turn to try to find
' a working server. If none can be found, a "fail" message is displayed.
'=======================================================================================
'v. 3.3: Added SuDoc parsing for portrait and landscape modes; Changes to error checking
' and AboveCall#Text behavior;
'
'v. 3.2: Added ability to put an additional field (e.g., <copy_id>) at end of spine label;
' Ensured label text in OutputBox does not end with unnecessary cr/lf;
' Fixed bug in Above Call# Text that produced incorrect matching.
' Limited User ID to 8 alpha characters.
'
'v. 3.1: Added Station name and User ID; Reports; Test Parsing; better LC/LC Children's lit/NLM
' call number parsing.
'
'v. 3.0: Cosmetic changes to admin panels; added "About" box with download/view
' of associated documentation. Added access to Alma Label Printing Web Service
' via desktop java app; Added option to use Ex Libris parsed call numbers.
'=======================================================================================
'v. 2.6: for "Custom" labels, text not enclosed in angle brackets (<...>) will print as-is on the label
' Bug fix: manual print button now checks line lengths against max. chars/line;
'v. 2.5: adds textbox for url to Alma Label Printing Web Service
'v. 2.4: adds barcode font dialog selection for use in flag slips;
'v. 2.3: dlgSettings.UseEXDialog = True to enable print dialog selection in Windows 7
'v. 2.2: corrects spacing & punctuation errors in incoming call numbers (for TML);
'v. ...:
Dim somVersion As String = "8.1.3"
Dim javaClassName As String = "almalabelu2" 'the java class name
Dim javaSDKName As String = "alma-sdk.1.0.jar" 'the Ex Libris SDK for web services
Dim javaTest As String = "javatest" 'java class that reports presence and version of java
Dim mypath As String = "" 'path of startup directory will be used as mypath
Dim servers As String = "arc.bc.edu:8080|libstaff.bc.edu:8080|mlib.bc.edu:8080"
Dim lcxml As String = ""
Dim issuexml As String = ""
Dim locxml As String = ""
Dim libxml As String = ""
Dim otherxml As String = ""
Dim titlexml As String = ""
Dim libraryxml As String = ""
Dim pixelsPerInchX As Integer = 0
Dim pixelsPerInchY As Integer = 0
Dim changeCount As Integer = 0
Dim xmlReturned As String = ""
Dim settings As String = ""
Dim winFrom As Integer = 0
Dim winTo As Integer = 0
Dim wline As Array = Nothing
Dim wlinesToPrint As Integer = 0
Dim origText As String = ""
Dim editText As String = ""
Dim maxLines As Integer = 0
Dim LABELS As Array
Dim nxt As Integer = 0
Dim horizPos As Integer = 0
Dim fontname As String = ""
Dim fontsize As Single = 0.0
Dim fWeight As System.Drawing.FontStyle
Dim bcWeight As System.Drawing.FontStyle
Dim topMargin As Single = 0.0
Dim leftMargin As Single = 0.0
Dim lineSpacing As Single = 0.0
Dim labelRows As Integer
Dim labelCols As Integer
Dim labelWidth As Single
Dim labelHeight As Single
Dim gapWidth As Single
Dim gapHeight As Single
Dim original_settings As String = ""
Dim closing_settings As String = ""
Dim saveTab As TabPage
Dim lastxml As String = ""
Dim ignoreChange As Boolean = True
Dim ALTfile As String = ""
Dim madeALTchanges As Boolean = False
Dim statrec As String
Dim lastbc As String = ""
Dim cntype As String
Dim almaReturnCode As String = ""
Dim almaLibrary As String = ""
Dim almaLocation As String = ""
Dim usermessage As String = ""
Dim settingsfound As Boolean = True
Dim settingsLoaded As Boolean = False
Dim settingsOpen As Boolean = False
Dim logView As Boolean = False
Dim flagSlipDefaults As String = ""
Dim firstPage As Boolean = True
Dim otherList As String = ""
Dim xmlerr As String = ""
Dim indenting As Boolean = False
Dim wrapping As Boolean = False
Dim totalLines As Integer = 0
Dim labelCount As Integer = 0
Dim needTypeCheck As Boolean = False 'alerts if call number parsers have been changed
Dim xdoc As New System.Xml.XmlDocument
Dim warranty_accepted As Boolean = True
Dim spin As Integer = 1
Dim stopPrinting As Boolean = False
Dim spineDefaultLoaded As Boolean = False
Dim customNonFlagDefaultLoaded As Boolean = False
Dim customFlagDefaultLoaded As Boolean = False
Dim pocketDefaultLoaded As Boolean = False
Dim WithEvents client As New WebClient
Dim licenseDeclined As Boolean = True
Dim pcname As String = ""
Dim spineVerticalLine As Boolean
Dim nonFlagVerticalLine As Boolean
Dim flagVerticalLine As Boolean
Dim pocketVerticalLine As Boolean
Dim usingDewey As Boolean = False
Dim xtb As TextBox
Dim xtbOrigColor As Color
Private Const LB_SETTABSTOPS As Int32 = &HCB
<DllImport("user32.dll")>
Private Shared Function SendMessage(
ByVal hWnd As IntPtr,
ByVal wMsg As Int32,
ByVal wParam As IntPtr,
ByVal lParam As IntPtr) _
As Int32
'DLL import is used to set margins in the Reports ("StatsOut") textbox
End Function
Private Sub SetTabs()
'{0, 65, 110, 165, 240, 255} (original settings)
Dim ListBoxTabs() As Integer = {0, 60, 110, 180, 240, 255}
Dim result As Integer
Dim ptr As IntPtr
Dim pinnedArray As GCHandle
pinnedArray = GCHandle.Alloc(ListBoxTabs, GCHandleType.Pinned)
ptr = pinnedArray.AddrOfPinnedObject()
'Send LB_SETTABSTOPS message to TextBox.
result = SendMessage(Me.statsOut.Handle, LB_SETTABSTOPS,
New IntPtr(ListBoxTabs.Length), ptr)
pinnedArray.Free()
'Refresh the TextBox control.
Me.statsOut.Refresh()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If licenseDeclined Then Exit Sub
Dim resp As String = ""
writeStat("S") 'write "S" (scanned, not printed) to statrec, and write to stat file.
If madeALTchanges = True Then
Dim box = MessageBox.Show("Changes to your local label text file have not been saved." & vbCrLf & "Do you want to save them now?", "Save Settings", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If box = box.Yes Then
btn_saveALT.PerformClick()
MsgBox("Changes to your local label text file have been saved.", MsgBoxStyle.Information, "Settings Saved")
madeALTchanges = False
End If
End If
saveSettings("tostring") 'put current settings into the closing_settings string
closing_settings = closing_settings.Replace(vbLf, "")
original_settings = original_settings.Replace(vbLf, "")
If original_settings <> closing_settings Then
'Clipboard.SetText("orig:" & vbCrLf & original_settings & vbCrLf & "new:" & vbCrLf & closing_settings)
Dim box = MessageBox.Show("Your settings have changed, but have not been saved." & vbCrLf &
"Do you want to save them now?" & vbCrLf & vbCrLf &
"(Click CANCEL to continue working.)", "Save Settings", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
If box = box.Yes Then
saveSettings("todisk")
MsgBox("Your settings have been saved.", MsgBoxStyle.Information, "Settings Saved")
Else
If box = box.cancel Then
e.Cancel = True
End If
End If
End If
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
If Asc(e.KeyChar) = 1 Then 'keychar 1 = "CTRL a"
e.Handled = True
If settingsOpen = False Then
openSettings()
Else
'Me.CloseSettings_Click(Nothing, Nothing)
CloseSettings()
End If
End If
If Asc(e.KeyChar) = 16 Then 'CTRL p
e.Handled = True
ManualPrint.PerformClick()
End If
End Sub
Private Sub NumericKeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles inMaxLines.KeyPress, inLineSpacing.KeyPress, TextBox23.KeyPress, TextBox22.KeyPress, TextBox21.KeyPress, TextBox20.KeyPress, TextBox19.KeyPress, inMaxChars.KeyPress, inLabelWidth.KeyPress, inLabelRows.KeyPress, inLabelHeight.KeyPress, inLabelCols.KeyPress, inGapWidth.KeyPress, inGapHeight.KeyPress, inFontSize.KeyPress, inBCFontSize.KeyPress, inStartCol.KeyPress, inStartRow.KeyPress, wrapWidth.KeyPress, plMin4.KeyPress, plMin3.KeyPress, plMin2.KeyPress, plMin1.KeyPress, plMax4.KeyPress, plMax3.KeyPress, plMax2.KeyPress, plMax1.KeyPress, plDistance.KeyPress, plLeftMargin.KeyPress, convertBlankTo.KeyPress, dosBlankLines.KeyPress, dosPlTabNum.KeyPress, dosPlColNum.KeyPress, appendAscii.KeyPress 'Handles TextBox.KeyPress
Dim tb As TextBox = sender
Dim dc As String = ""
If decimalDOT.Checked Then dc = "." Else dc = ","
If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar) Or (e.KeyChar = dc And tb.Text.IndexOf(dc) < 0)) Then
e.Handled = True
Beep()
Exit Sub
End If
End Sub
Private Sub NegativeKeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles inTopMargin.KeyPress, inLeftMargin.KeyPress
Dim tb As TextBox = sender
Dim dc As String = ""
If decimalDOT.Checked Then dc = "." Else dc = ","
If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar) Or (e.KeyChar = dc And tb.Text.IndexOf(dc) < 0) Or e.KeyChar = "-") Then
e.Handled = True
Beep()
End If
End Sub
Private Sub NumericLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles inMaxLines.Leave, inTopMargin.Leave, inLineSpacing.Leave, inLeftMargin.Leave, TextBox23.Leave, TextBox22.Leave, TextBox21.Leave, TextBox20.Leave, TextBox19.Leave, inMaxChars.Leave, inLabelWidth.Leave, inLabelRows.Leave, inLabelHeight.Leave, inLabelCols.Leave, inGapWidth.Leave, inGapHeight.Leave, inFontSize.Leave, inBCFontSize.Leave, inStartCol.Leave, inStartRow.Leave, wrapWidth.Leave, plMin4.Leave, plMin3.Leave, plMin2.Leave, plMin1.Leave, plMax4.Leave, plMax3.Leave, plMax2.Leave, plMax1.Leave, plDistance.Leave, plLeftMargin.Leave, convertBlankTo.Leave, dosBlankLines.Leave, dosPlTabNum.Leave, dosPlColNum.Leave, appendAscii.Leave, deweydigitsperline.Leave, deweyDigitsToBreak.Leave 'Handles TextBox.KeyPress
Dim tb As TextBox = sender
If tb.Text.Length = 0 Then
tb.Text = "0"
End If
End Sub
Private Sub limitValues(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles deweydigitsperline.KeyPress, deweyDigitsToBreak.KeyPress
Dim tb As TextBox = sender
If Not "234567".Contains(e.KeyChar) Then
e.Handled = True
Beep()
Else
'deweydigitsperline.Text = e.KeyChar
sender.Text = e.KeyChar
e.Handled = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
settingsfound = True
Dim disclaimerInfo As String = ""
Dim currentLicense As String = ""
pcname = System.Net.Dns.GetHostName()
Me.KeyPreview = True
Me.Show()
mypath = System.AppDomain.CurrentDomain.BaseDirectory()
Me.Text = "SpineOMatic " & somVersion
CloseSettings() 'close the settings panels
Application.DoEvents()
continueFormLoad()
End Sub
Private Sub continueFormLoad()
licenseDeclined = False
GetSettingsFile()
'CloseSettings() Let the "GetSettingsFile" routine determine if settings exist or not.
'If no settings file exists, panels should remain open
Application.DoEvents()
settingsLoaded = True
original_settings = RichTextBox1.Text
XMLPath.Text = mypath 'path is now always set to the installation directory, "mypath"
Try
FileSystemWatcher1.Path = XMLPath.Text
FileSystemWatcher2.Path = XMLPath.Text
Catch
MsgBox("Directory to watch for incoming XML files is not valid." & vbCrLf &
"Path = " & XMLPath.Text, MsgBoxStyle.Exclamation, "Invalid Path")
FileSystemWatcher1.Path = ""
End Try
batchPreview.Text = GetBatch(batchNumber.Value)
If batchPreview.Lines.Length > 0 Then
'batchEntries.Text = batchPreview.Lines.Length - 1
batchEntries.Text = countBatch()
Else
batchEntries.Text = "0"
End If
btnMonitor.Enabled = False
createBatFiles()
downloadAboveLcFile()
Application.DoEvents()
loadLabelText()
lblStation.Text = station.Text
usermessage = "Please enter your User ID in the 'User:' box above." & vbCrLf & vbCrLf &
"The ID must be 8 characters or less." & vbCrLf & vbCrLf &
"When done, press the ENTER key."
If chkRequireUser.Checked Then
usrname.Enabled = True
OutputBox.Text = usermessage
usrname.BackColor = Color.Yellow
usrname.Focus()
Else
usrname.Text = "[none]"
usrname.Enabled = False
InputBox.Select()
InputBox.Focus()
End If
Dim date1 As Date = Date.Now
Dim dtNow As Date = Date.Now
Dim dtFirstOfMonth As Date = dtNow.AddDays(-dtNow.Day + 1)
fromScan.Format = DateTimePickerFormat.Short
fromScan.CustomFormat = "MM/dd/yyyy"
toScan.Format = DateTimePickerFormat.Short
toScan.CustomFormat = "MM/dd/yyyy"
'toScan.Value = DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.CurrentCulture)
'toScan.Value = date1.Month & "/" & date1.Day & "/" & date1.Year
fromScan.Value = dtFirstOfMonth
toScan.Value = date1.Date.ToString
SetTabs() 'change tab settings of the Reports textbox.
TabControl1.SelectedIndex = 1
TabControl1.SelectedIndex = 0
lbl_setclipboard.ForeColor = Color.MediumBlue
InputBox.Focus()
End Sub
Private Function countBatch() As String
Dim ln As Integer = -1
Dim pos As Integer = 1
Do
pos = InStr(pos + 1, batchPreview.Text, "===============", CompareMethod.Text)
ln = ln + 1
Loop While pos <> 0
Return CType(ln + 1, String)
End Function
Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created
'Watches a selected directory for the arrival of an Ex Libris' Alma item XML file
'and generates a spine label when one arrives.
'
'If the file is being written into the directory by another application (i.e., a
'Java program that retrieves the Alma file and writes in into the specified
'directory), the FileSystemWatcher may fire before the file is completely written.
'This routine waits until the file can be successfully read. It tries up to 20
'times, waiting 100ms between tries.
Dim fileFound As Boolean = False
Dim loopcnt As Integer
loopcnt = 20
Do While loopcnt > 0
Try
Dim tr As TextReader = New StreamReader(e.FullPath)
xmlReturned = tr.ReadToEnd()
tr.Close()
fileFound = True
Exit Do
Catch ex As Exception
loopcnt = loopcnt - 1
Thread.Sleep(100)
End Try
Loop
If fileFound Then
InputBox.Text = e.Name.Replace(".xml", "")
lastxml = e.FullPath
'If xmlReturned.Contains("<bib_data link") Then
' xmlReturned = convertRESTfulXML()
'End If
getBarcodeFile()
If AutoPrintBox.Checked Then
ManualPrint.PerformClick()
End If
Else
MsgBox("The complete Alma XML file did not arrive: " & e.FullPath, MsgBoxStyle.Exclamation, "File Incomplete")
End If
End Sub
Private Function convertRESTfulXML() As String
'Converts RESTful XML files into depricated SOAP format so that existing SpineOMatic code can
'be used with the new XML format.
Dim doc As New XmlDocument
Dim t As String = ""
Dim cn As String = ""
Dim ct As String = ""
Dim n As String = ""
Dim titl As String = ""
Dim cntype As String = ""
Dim e As Integer
Dim mynode As XmlNode
Dim anode As XmlNode
Dim nl As XmlNodeList
Dim pcn As String = "" 'parsed call number
Dim pild As String = "" 'parsed issue level description
Dim i As Integer = 0
'The RESTful XML text is loaded into an XML document
doc.LoadXml(xmlReturned)
Dim elemList As XmlNodeList = doc.GetElementsByTagName("item_data") 'most user fields are under
'<item_data>...</item_data>
'Put all RESTful <item_data> fields into string "t"
For e = 0 To elemList.Count - 1
t = elemList(e).InnerXml & vbCrLf
Next e
'RESTful parsed_call_number and parsed_issue_level_description fields need to be modified
'in the final text. Here is where we remove these fields from the text string "t":
If t.Contains("<parsed_call_number") Then
t = t.Substring(0, t.IndexOf("<parsed_call_number>")) & t.Substring(t.IndexOf("</parsed_call_number>") + 21)
End If
If t.Contains("<parsed_issue_level_description>") Then
t = t.Substring(0, t.IndexOf("<parsed_issue_level_description>")) & t.Substring(t.IndexOf("</parsed_issue_level_description>") + 32)
End If
'These routines step through each element of the <parsed_call_number> and <parsed_issue_level_desctiption>
'fields in the XML document, and a sequence number is added to the XML field names.
'Ex: <call_no>BX</call_no> is changed to <call_no_1>BX</call_no_1>, etc...
i = 1
pcn = ""
For Each mynode In doc.SelectNodes("/item/item_data/parsed_call_number/*")
If IsNothing(mynode) Then Exit For
pcn = pcn & "<call_no_" & i & ">" & mynode.InnerXml & "</call_no_" & i & ">" & vbCrLf
i = i + 1
Next
pcn = "<parsed_call_number>" & vbCrLf & pcn & vbCrLf & "</parsed_call_number>"
i = 1
pild = ""
For Each mynode In doc.SelectNodes("/item/item_data/parsed_issue_level_description/*")
If IsNothing(mynode) Then Exit For
pild = pild & "<issue_level_description_" & i & ">" & mynode.InnerXml & "</issue_level_description_" & i & ">" & vbCrLf
i = i + 1
Next
pild = "<parsed_issue_level_description>" & vbCrLf & pild & vbCrLf & "</parsed_issue_level_description>"
'the new fields are stored in variables 'pcn' (parsed call number) and 'pild' (parsed issue level description)
'fields, and these modified fields are added back to string "t" later in the process.
'<call_number> is not in the <item_data> section, so it's put in variable 'cn' and added to string 't' later
nl = doc.GetElementsByTagName("call_number")
cn = nl(0).OuterXml
'<call_number_type> is not in <item_data> either, so it is extracted in 'ct', and later added to string 't'
nl = doc.GetElementsByTagName("call_number_type")
ct = "<call_number_type>" & nl(0).InnerXml & "</call_number_type>"
'<title> is not in <item_data>, so it is extracted to 'nl' and added back to string 't' later.
nl = doc.GetElementsByTagName("title")
titl = nl(0).OuterXml
'<library desc="O'Neill">ONL</library>' is changed into two fields:
'1) <library_code>ONL</library_code>
'2) <library_name>O'Neill</library_name>
'liname and licode are added to string 't'
Dim lid As XmlNodeList = doc.GetElementsByTagName("library")
Dim licode As String = "<library_code>" & lid(0).InnerXml & "</library_code>"
anode = doc.SelectSingleNode("//library")
Dim liname As String = "<library_name>" & anode.Attributes(0).Value & "</library_name>"
'<location desc="Offsite Collection (RM150 GOVD)">RM150_GOVD</location> is changed into:
'1) <location_name>Offsite Collection (RM150 GOVD)</location_name>
'2) <location_code>RM150_GOVD</location_code>
'lod and locode are added to string 't'
Dim lod As XmlNodeList = doc.GetElementsByTagName("location")
Dim locode As String = "<location_code>" & lod(0).InnerXml & "</location_code>"
anode = doc.SelectSingleNode("//location")
Dim loname As String = "<location_name>" & anode.Attributes(0).Value & "</location_name>"
'all the new XML elements that were relocated or created are added back to string 't', and
'string 't' is inserted into an 'XmlShell' invisible text box, replacing the text "**XMLBODY**"
'that identifies the spot where the new XML is to be interted.
xmlReturned = xmlShell.Text.Replace("**XMLBODY**", cn & vbCrLf & ct & vbCrLf & titl & vbCrLf & licode & vbCrLf & liname & vbCrLf & loname & locode & vbCrLf & pcn & vbCrLf & pild & vbCrLf & t)
'the new RESTful "<description>" field names are changed to <issue_level_description>, to
'mimic the SOAP naming convention
xmlReturned = xmlReturned.Replace("<description>", "<issue_level_description>")
xmlReturned = xmlReturned.Replace("</description>", "</issue_level_description>")
Return xmlReturned
End Function
Private Sub ManualPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ManualPrint.Click
'manual print
If ManualPrint.Text = "Stop Printing" Then
stopPrinting = True
SetPrintButtonText()
Exit Sub
End If
Dim dayTime As String = ""
Dim logentry As String = ""
Dim barcodenum As String = ""
Dim lencheck As Integer = 0
Dim chkline As Array = Nothing
Dim maxlines As Integer = CType(inMaxLines.Text, Integer)
Dim linesOK As Boolean = True
Dim maxchars As Integer = CType(inMaxChars.Text, Integer)
Dim repeat As Integer = 0
Dim i As Integer = 0
Dim batchText As String = ""
Dim labelin As String
plDistance.BackColor = Color.White
If chkUsePocketLabels.Checked Then
If btnSL4.Checked Or btnSL6.Checked Or (btnPlCustom.Checked And PLcount.Value = 2) Then
If CType(plDistance.Text, Single) = 0.0 Then
plDistance.BackColor = Color.Pink
MsgBox("When printing two pocket labels, you must specify a vertical distance" & vbCrLf &
"between the top lines of the two labels.", MsgBoxStyle.Exclamation, "No Distance Specified")
plDistance.Focus()
Exit Sub
End If
End If
End If
If Trim(OutputBox.Text) = "" Then
Beep()
InputBox.Focus()
Exit Sub
End If
editText = OutputBox.Text
barcodenum = InputBox.Text
If (editText <> origText) And barcodenum <> "" And logEdits.Checked Then
dayTime = DateTime.Now.ToString("ddd MMM d, yyyy HH:mm", CultureInfo.InvariantCulture)
logentry = dayTime & vbTab & barcodenum & vbTab & origText.Replace(vbCrLf, "|") & vbTab & editText.Replace(vbCrLf, "|")
writeFile(mypath & "changelog.txt", logentry, True)
editText = ""
origText = ""
End If
If OutputBox.Text.Contains("** ERROR **") Then
Beep()
MsgBox("Could not find this barcode number in Alma.", MsgBoxStyle.Exclamation, "Barcode Number Error")
Exit Sub
End If
If OutputBox.Text.Contains("Java: **") Then
Beep()
MsgBox("Could not contact Alma.", MsgBoxStyle.Exclamation, "Connection Error")
End If
lencheck = checkLineLength()
chkline = Split(OutputBox.Text, vbCrLf)
If lencheck <> 99 Then
'chkline = Split(OutputBox.Text, vbCrLf)
MsgBox("Line #" & lencheck & ":" & vbCrLf & chkline(lencheck - 1) &
vbCrLf & " contains more than " & maxchars & " characters.")
Exit Sub
End If
If chkline.Length > maxlines Then
Beep()
MsgBox("Lable contains more than " & maxlines & " lines.", MsgBoxStyle.Exclamation, "Too Many Lines")
Exit Sub
End If
If lblXMLWarn.Visible = True Then
Beep()
MsgBox("An XML <field> used in your settings is incorrect.", MsgBoxStyle.Exclamation, "XML Reference Error")
Exit Sub
End If
'********************
' Use DOS Batch File
'********************
If useDOSBatch.Checked Then
Dim txtout As String = ""
Dim extraLines As Integer = CType(dosBlankLines.Text, Integer)
Dim addcr As String = ""
Dim tabpos As Integer = 0
Dim k As Integer = 0
Dim extraSpaces As Integer = CType(dosPlColNum.Text, Integer)
Dim tabcount As Integer = CType(dosPlTabNum.Text, Integer)
Dim addsp As String = ""
Dim taray As Array
Dim mg As String = ""
If chkUsePocketLabels.Checked Then
taray = packagePocket().Split(vbCrLf)
txtout = ""
For k = 0 To taray.Length - 1
tabpos = taray(k).replace(vbLf, "").IndexOf(vbTab)
If dosPlUseCol.Checked Then
addsp = New String(" ", extraSpaces - tabpos)
txtout = txtout & taray(k).Replace(vbTab, addsp) & vbCrLf
Else
If tabcount > 1 Then
addsp = New String(vbTab, tabcount)
Else
addsp = vbTab
End If
txtout = txtout & taray(k).replace(vbTab, addsp) & vbCrLf
End If
Next
txtout = txtout & terminator(taray.Length)
Else
txtout = txtout & OutputBox.Text & terminator(OutputBox.Lines.Length)
End If
viaDOS(txtout)
Exit Sub
End If
If UseDesktop.Checked Then
getPrintParams()
PrintDocument2.PrinterSettings.PrinterName = inPrinterName.Text
PrintDocument2.PrintController = New System.Drawing.Printing.StandardPrintController
If chkUsePocketLabels.Checked Then
labelin = packagePocket()
labelin = labelin.Replace(vbCrLf, "|")
Else
labelin = OutputBox.Text.Replace(vbCrLf, "|")
End If
'For desktop printing, only one label will be in the "LABELS" array,
'but the print routine always uses the LABELS array to get its input,
'for single label printing and for multi-label batch printing.
LABELS = labelin.Split(vbCrLf)
repeat = CType(LabelRepeat.Value, Integer)
If repeat > 1 And ManualPrint.Text <> "Stop Printing" Then
ManualPrint.Text = "Stop Printing"
printProgress.Visible = True
Application.DoEvents()
End If
For i = 1 To repeat
Application.DoEvents()
If stopPrinting Then
SetPrintButtonText()
stopPrinting = False
printProgress.Visible = False
Exit For
End If
Try
printProgress.Text = "Printing " & i & " of" & repeat
Application.DoEvents()
PrintDocument2.Print()
Catch ex As Exception
MsgBox("Printer settings are not correct." & vbCrLf &
"Make sure a valid printer has been selected, and try again." &
vbCrLf & ex.ToString, MsgBoxStyle.Exclamation, "Printer Selection Error")
Exit For
End Try
Next i
'********************
SetPrintButtonText()
'********************
printProgress.Visible = False
nxt = 0
writeStat("P") 'add P to end of statrec and write to statfile.
OutputBox.Text = ""
plOutput.Text = ""
TempLabelBox.Text = ""
InputBox.Text = ""
InputBox.Focus()
Else
repeat = CType(LabelRepeat.Value, Integer)
If repeat > 5 AndAlso MessageBox.Show(repeat & " labels will be printed.", "Confirm Multipl Label Request", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) = Windows.Forms.DialogResult.Cancel Then Exit Sub
If UseLaser.Checked Then 'SAVE TO BATCH
If chkUsePocketLabels.Checked Then
batchText = packagePocket()
Else
batchText = OutputBox.Text
End If
repeat = LabelRepeat.Value
For i = 1 To repeat
sendToBatch2(batchText)
Next i
writeStat("B") 'add B to end of statrec and write to statfile
OutputBox.Text = ""
plOutput.Text = ""
TempLabelBox.Text = ""
InputBox.Text = ""
InputBox.Focus()
Else
ftpPrint()
End If
End If
End Sub
Private Function terminator(ByVal actualLen As Integer) As String
Dim trm As String = ""
Dim desiredLen As Integer = CType(dosBlankLines.Text, Integer)
If desiredLen > actualLen Then
If dosAddLines.Checked Then
trm = New String("^", desiredLen - actualLen).Replace("^", vbCrLf)
Else
trm = Chr(CType(appendAscii.Text, Integer))
End If
Else
trm = ""
End If
Return trm
End Function
Private Sub SetPrintButtonText()
ManualPrint.ForeColor = Color.Black
If UseFTP.Checked Then ManualPrint.Text = "Send to FTP Printer"
If UseLaser.Checked Then ManualPrint.Text = "Add to batch #" & batchNumber.Value.ToString
If UseDesktop.Checked Then ManualPrint.Text = "Send to desktop printer"
'If useDOSBatch.Checked Then ManualPrint.Text = "Run viados.bat"
End Sub
Private Function packagePocket() As String
'combines spine label in OutputBox with pocket label in plOutput.
'A tab character separates lines of spine text from a line of pocket label text.
Dim k As Integer = 0
Dim sp As String = ""
Dim s As Integer = 0
Dim p As Integer = 0
Dim stext As String = ""
Dim ptext As String = ""
Do
If s <= OutputBox.Lines.Length - 1 Then stext = OutputBox.Lines(s) : s = s + 1 Else stext = ""
If p <= plOutput.Lines.Length - 1 Then ptext = plOutput.Lines(p) : p = p + 1 Else ptext = ""
If stext = "" And ptext = "" Then Exit Do
sp = sp & stext & vbTab & ptext & vbCrLf
k = k + 1 : If k > 20 Then Return "*** Error preparing pocket labels for printing ***"
Loop
sp = sp.Substring(0, sp.Length - 2) 'remove final crlf
Return sp
End Function
Private Sub btnPrintBatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintBatch.Click
Dim labelsIn As String
Dim wrk As String
labelsIn = GetBatch(batchNumber.Value)
'modified------------------------------
'LABELS = labelsIn.Split(vbCrLf)
'--------------------------------------
wrk = labelsIn.Replace(vbCrLf & "===============" & vbCrLf, "^")
wrk = wrk.Replace(vbCrLf, "|")
wrk = wrk.Replace("^", vbCrLf)
'MsgBox("wrk:" & wrk)
LABELS = wrk.Split(vbCrLf)
If LABELS.Length = 0 Then
MsgBox("There are no labels in batch number " & batchNumber.Value)
Exit Sub
End If
nxt = 0
getPrintParams()
firstPage = True
PrintDocument2.PrinterSettings.PrinterName = inPrinterName.Text
PrintPreviewDialog1.Document = PrintDocument2
Try
PrintPreviewDialog1.ShowDialog()
Catch
MsgBox("The specified printer: " & vbCrLf & vbCrLf & inPrinterName.Text & vbCrLf & vbCrLf & "does not exist." _
& vbCrLf & "Please select a different printer.", MsgBoxStyle.Exclamation, "Printer not found")
End Try
End Sub
Private Sub getPrintParams()
Dim cf As Single = 0.0
If unitINCH.Checked Then
cf = 100
Else
cf = 39.3701
End If
horizPos = 0
fontname = inFontName.Text
fontsize = CType(inFontSize.Text, Single)
fWeight = FontStyle.Regular
If inFontWeight.Checked Then fWeight = FontStyle.Bold
maxLines = CType(inMaxLines.Text, Integer)
topMargin = CType(inTopMargin.Text, Single) * cf '100
leftMargin = CType(inLeftMargin.Text, Single) * cf '100
lineSpacing = CType(inLineSpacing.Text, Single) * cf '100
If UseLaser.Checked Then 'for batch printing, set params for multi-row & multi-column sheets
labelRows = CType(inLabelRows.Text, Integer)
labelCols = CType(inLabelCols.Text, Integer)
labelWidth = CType(inLabelWidth.Text, Single) * cf '100
labelHeight = CType(inLabelHeight.Text, Single) * cf '100
gapWidth = CType(inGapWidth.Text, Single) * cf '100
gapHeight = CType(inGapHeight.Text, Single) * cf '100
Else ' for single-label desktop printing, rows & columns are always "1", with no gaps.
labelRows = 1
labelCols = 1
labelWidth = 0
labelHeight = 0
gapWidth = 0
gapHeight = 0
End If
End Sub
Private Sub sendToBatch(ByVal labelout As String)
'add a spine label or book flag to the end of the selected label batch
labelout = labelout.Replace(vbCrLf, "|")
'labelout = vbCrLf + "----------" & vbCrLf & labelout
labelout = Mid$(labelout, 1, labelout.Length) 'remove final "|"
writeFile(mypath & "labelbatch" & batchNumber.Value & ".txt", labelout, True)
batchPreview.Text = batchPreview.Text + labelout
batchEntries.Text = batchEntries.Text + 1
End Sub
Private Sub sendToBatch2(ByVal labelout As String)
'NEW METHOD
'add a spine label or book flag to the end of the selected label batch
If CType(batchEntries.Text, Integer) > 0 Then
labelout = vbCrLf & "===============" & vbCrLf & labelout
End If
writeFile(mypath & "labelbatch" & batchNumber.Value & ".txt", labelout, True)
batchPreview.Text = batchPreview.Text + labelout
batchEntries.Text = batchEntries.Text + 1
End Sub
Private Sub PrintDocument2_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument2.PrintPage
Dim x As Single = 0.0
Dim y As Single = 0.0
Dim ypos As Single = 0.0
Dim z As Integer = 0
Dim t As Integer = 0
Dim down As Integer = 0
Dim across As Integer = 0
Dim i As Integer = 0
Dim pFont = New Font(fontname, fontsize, fWeight)
If inBCFontWeight.Checked Then
bcWeight = FontStyle.Bold
Else
bcWeight = FontStyle.Regular
End If
Dim bFont = New Font(inBCFontName.Text, CType(inBCFontSize.Text, Single), bcWeight)
'Dim testlbl As String = "QA|76.73|.J38|H674|2006"
Dim line As Array '= testlbl.Split("|")
Dim test As String = ""
Dim extraSpace As Integer = 0
Dim bcwidth As Single = 0.0
Dim cntrOffset As Integer = 0
Dim nextLabel As String = ""
Dim startRow As Integer = CType(inStartRow.Text, Integer)
Dim startcol As Integer = CType(inStartCol.Text, Integer)
Dim PlySave As Integer 'save starting point of call# label to use if a pocket label
Dim PLx As Integer
Dim PLy As Integer 'will subsequently be printed.
Dim leftPocket As Integer = 0 'left margin of pocket label
Dim plk As Integer = 0
Dim plparams As Array
Dim theseArePocketLabels As Boolean = False
Dim cf As Single = 0.0
If unitINCH.Checked Then
cf = 100
Else
cf = 39.3701
End If
If chkUsePocketLabels.Checked Then
plparams = PocketParams() 'called to get the labelCount (1 or 2) currently in effect
End If
If startRow > labelRows Then
MsgBox("Starting row number is greater than the maximum rows.", MsgBoxStyle.Exclamation, "Starting Row Number Too Large")
Exit Sub
End If
If startcol > labelCols Then
MsgBox("Starting column number is greater than the maximum columns.", MsgBoxStyle.Exclamation, "Starting Column Number Too Large")
Exit Sub
End If
' values preceded by ! will display a barcode first, followed by the actual value on the next line
' values preceded by ~ will have extra vertical spacing
If Not firstPage Then
startRow = 1
startcol = 1
End If