-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
7417 lines (6846 loc) · 299 KB
/
Form1.cs
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Globalization;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using System.Xml;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
namespace SpineLabeler
{
public partial class Form1
{
// v. 9.0: Major release
// Change langage from VB.NET to C#.NET
// 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. ...:
private string somVersion = "9.0.0";
private string javaClassName = "almalabelu2"; // the java class name
private string javaSDKName = "alma-sdk.1.0.jar"; // the Ex Libris SDK for web services
private string javaTest = "javatest"; // java class that reports presence and version of java
private string mypath = ""; // path of startup directory will be used as mypath
private string servers = "arc.bc.edu:8080|libstaff.bc.edu:8080|mlib.bc.edu:8080";
private string lcxml = "";
private string issuexml = "";
private string locxml = "";
private string libxml = "";
private string otherxml = "";
private string titlexml = "";
private string libraryxml = "";
private int pixelsPerInchX = 0;
private int pixelsPerInchY = 0;
private int changeCount = 0;
private string xmlReturned = "";
private string settings = "";
private int winFrom = 0;
private int winTo = 0;
private Array wline = null;
private int wlinesToPrint = 0;
private string origText = "";
private string editText = "";
private int maxLines = 0;
private Array LABELS;
private int nxt = 0;
private int horizPos = 0;
private string fontname = "";
private float fontsize = 0.0f;
private FontStyle fWeight;
private FontStyle bcWeight;
private float topMargin = 0.0f;
private float leftMargin = 0.0f;
private float lineSpacing = 0.0f;
private int labelRows;
private int labelCols;
private float labelWidth;
private float labelHeight;
private float gapWidth;
private float gapHeight;
private string original_settings = "";
private string closing_settings = "";
private TabPage saveTab;
private string lastxml = "";
private bool ignoreChange = true;
private string ALTfile = "";
private bool madeALTchanges = false;
private string statrec;
private string lastbc = "";
private string cntype;
private string almaReturnCode = "";
private string almaLibrary = "";
private string almaLocation = "";
private string usermessage = "";
private bool settingsfound = true;
private bool settingsLoaded = false;
private bool settingsOpen = false;
private bool logView = false;
private string flagSlipDefaults = "";
private bool firstPage = true;
private string otherList = "";
private string xmlerr = "";
private bool indenting = false;
private bool wrapping = false;
private int totalLines = 0;
private int labelCount = 0;
private bool needTypeCheck = false; // alerts if call number parsers have been changed
private XmlDocument xdoc = new XmlDocument();
private bool warranty_accepted = true;
private int spin = 1;
private bool stopPrinting = false;
private bool spineDefaultLoaded = false;
private bool customNonFlagDefaultLoaded = false;
private bool customFlagDefaultLoaded = false;
private bool pocketDefaultLoaded = false;
private WebClient client;
private bool licenseDeclined = true;
private string pcname = "";
private bool spineVerticalLine;
private bool nonFlagVerticalLine;
private bool flagVerticalLine;
private bool pocketVerticalLine;
private bool usingDewey = false;
private TextBox xtb;
private Color xtbOrigColor;
private const int LB_SETTABSTOPS = 0xCB;
private ArrayList zplBatchAL = new ArrayList();
public Form1()
{
client = new WebClient();
InitializeComponent();
String pkInstalledPrinters;
for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)
{
pkInstalledPrinters = PrinterSettings.InstalledPrinters[i];
zebraPrinterBox.Items.Add(pkInstalledPrinters);
}
}
[DllImport("user32.dll")]
// DLL import is used to set margins in the Reports ("StatsOut") textbox
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
private void SetTabs()
{
// {0, 65, 110, 165, 240, 255} (original settings)
int[] ListBoxTabs = new int[] { 0, 60, 110, 180, 240, 255 };
int result;
IntPtr ptr;
GCHandle pinnedArray;
pinnedArray = GCHandle.Alloc(ListBoxTabs, GCHandleType.Pinned);
ptr = pinnedArray.AddrOfPinnedObject();
// Send LB_SETTABSTOPS message to TextBox.
result = SendMessage(statsOut.Handle, LB_SETTABSTOPS, new IntPtr(ListBoxTabs.Length), ptr);
pinnedArray.Free();
// Refresh the TextBox control.
statsOut.Refresh();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (licenseDeclined)
return;
string resp = "";
writeStat("S"); // write "S" (scanned, not printed) to statrec, and write to stat file.
if (madeALTchanges == true)
{
DialogResult box = MessageBox.Show("Changes to your local label text file have not been saved." + Constants.vbCrLf + "Do you want to save them now?", "Save Settings", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (box == DialogResult.Yes)
{
btn_saveALT.PerformClick();
Interaction.MsgBox("Changes to your local label text file have been saved.", MsgBoxStyle.Information, "Settings Saved");
madeALTchanges = false;
}
}
saveSettings("tostring"); // put current settings into the closing_settings string
closing_settings = closing_settings.Replace(Constants.vbLf, "");
original_settings = original_settings.Replace(Constants.vbLf, "");
if ((original_settings ?? "") != (closing_settings ?? ""))
{
// Clipboard.SetText("orig:" & vbCrLf & original_settings & vbCrLf & "new:" & vbCrLf & closing_settings)
DialogResult box = MessageBox.Show("Your settings have changed, but have not been saved." + Constants.vbCrLf + "Do you want to save them now?" + Constants.vbCrLf + Constants.vbCrLf + "(Click CANCEL to continue working.)", "Save Settings", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (box == DialogResult.Yes)
{
saveSettings("todisk");
Interaction.MsgBox("Your settings have been saved.", MsgBoxStyle.Information, "Settings Saved");
}
else if (box == DialogResult.Cancel)
{
e.Cancel = true;
}
}
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Strings.Asc(e.KeyChar) == 1) // keychar 1 = "CTRL a"
{
e.Handled = true;
if (settingsOpen == false)
{
openSettings();
}
else
{
// Me.CloseSettings_Click(Nothing, Nothing)
CloseSettings();
}
}
if (Strings.Asc(e.KeyChar) == 16) // CTRL p
{
e.Handled = true;
ManualPrint.PerformClick();
}
}
private void NumericKeyPress(object sender, KeyPressEventArgs e) // Handles TextBox.KeyPress
{
TextBox tb = (TextBox)sender;
string dc = "";
if (decimalDOT.Checked)
dc = ".";
else
dc = ",";
if (!(char.IsDigit(e.KeyChar) | char.IsControl(e.KeyChar) | Conversions.ToString(e.KeyChar) == dc & tb.Text.IndexOf(dc) < 0))
{
e.Handled = true;
Interaction.Beep();
return;
}
}
private void NegativeKeyPress(object sender, KeyPressEventArgs e)
{
TextBox tb = (TextBox)sender;
string dc = "";
if (decimalDOT.Checked)
dc = ".";
else
dc = ",";
if (!(char.IsDigit(e.KeyChar) | char.IsControl(e.KeyChar) | Conversions.ToString(e.KeyChar) == dc & tb.Text.IndexOf(dc) < 0 | Conversions.ToString(e.KeyChar) == "-"))
{
e.Handled = true;
Interaction.Beep();
}
}
private void NumericLeave(object sender, EventArgs e) // Handles TextBox.KeyPress
{
TextBox tb = (TextBox)sender;
if (tb.Text.Length == 0)
{
tb.Text = "0";
}
}
private void limitValues(object sender, KeyPressEventArgs e)
{
TextBox tb = (TextBox)sender;
if (!"234567".Contains(Conversions.ToString(e.KeyChar)))
{
e.Handled = true;
Interaction.Beep();
}
else
{
// deweydigitsperline.Text = e.KeyChar
((dynamic)sender).Text = e.KeyChar;
e.Handled = true;
}
}
private void Form1_Load(object sender, EventArgs e)
{
settingsfound = true;
string disclaimerInfo = "";
string currentLicense = "";
pcname = Dns.GetHostName();
KeyPreview = true;
Show();
mypath = AppDomain.CurrentDomain.BaseDirectory;
Text = "SpineOMatic " + somVersion;
CloseSettings(); // close the settings panels
Application.DoEvents();
continueFormLoad();
}
private void 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
{
Interaction.MsgBox("Directory to watch for incoming XML files is not valid." + Constants.vbCrLf + "Path = " + XMLPath.Text, MsgBoxStyle.Exclamation, "Invalid Path");
FileSystemWatcher1.Path = "";
}
batchPreview.Text = GetBatch((int)Math.Round(batchNumber.Value));
if (batchPreview.Lines.Length > 0)
{
// batchEntries.Text = batchPreview.Lines.Length - 1
batchEntries.Text = countBatch();
}
else
{
batchEntries.Text = "0";
}
btnMonitor.Enabled = false;
createBatFiles();
downloadAboveLcFile();
Application.DoEvents();
loadLabelText();
lblStation.Text = station.Text;
usermessage = "Please enter your User ID in the 'User:' box above." + Constants.vbCrLf + Constants.vbCrLf + "The ID must be 8 characters or less." + Constants.vbCrLf + Constants.vbCrLf + "When done, press the ENTER key.";
if (chkRequireUser.Checked)
{
usrname.Enabled = true;
OutputBox.Text = usermessage;
usrname.BackColor = Color.Yellow;
usrname.Focus();
}
else
{
usrname.Text = "[none]";
usrname.Enabled = false;
InputBox.Select();
InputBox.Focus();
}
var date1 = DateTime.Now;
var dtNow = DateTime.Now;
var dtFirstOfMonth = 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 = Conversions.ToDate(date1.Date.ToString());
SetTabs(); // change tab settings of the Reports textbox.
TabControl1.SelectedIndex = 1;
TabControl1.SelectedIndex = 0;
lbl_setclipboard.ForeColor = Color.MediumBlue;
InputBox.Focus();
}
private string countBatch()
{
int ln = -1;
int pos = 1;
do
{
pos = Strings.InStr(pos + 1, batchPreview.Text, "===============", CompareMethod.Text);
ln = ln + 1;
}
while (pos != 0);
return (ln + 1).ToString();
}
private void FileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
{
// 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.
bool fileFound = false;
int loopcnt;
loopcnt = 20;
while (loopcnt > 0)
{
try
{
TextReader tr = new StreamReader(e.FullPath);
xmlReturned = tr.ReadToEnd();
tr.Close();
fileFound = true;
break;
}
catch (Exception ex)
{
loopcnt = loopcnt - 1;
Thread.Sleep(100);
}
}
if (fileFound)
{
InputBox.Text = e.Name.Replace(".xml", "");
lastxml = e.FullPath;
// If xmlReturned.Contains("<bib_data link") Then
// xmlReturned = convertRESTfulXML()
// End If
getBarcodeFile();
if (AutoPrintBox.Checked)
{
ManualPrint.PerformClick();
}
}
else
{
Interaction.MsgBox("The complete Alma XML file did not arrive: " + e.FullPath, MsgBoxStyle.Exclamation, "File Incomplete");
}
}
private string convertRESTfulXML()
{
// Converts RESTful XML files into depricated SOAP format so that existing SpineOMatic code can
// be used with the new XML format.
var doc = new XmlDocument();
string t = "";
string cn = "";
string ct = "";
string n = "";
string titl = "";
string cntype = "";
int e;
XmlNode mynode;
XmlNode anode;
XmlNodeList nl;
string pcn = ""; // parsed call number
string pild = ""; // parsed issue level description
int i = 0;
// The RESTful XML text is loaded into an XML document
doc.LoadXml(xmlReturned);
var elemList = doc.GetElementsByTagName("item_data"); // most user fields are under
// <item_data>...</item_data>
// Put all RESTful <item_data> fields into string "t"
var loopTo = elemList.Count - 1;
for (e = 0; e <= loopTo; e++)
t = elemList[e].InnerXml + Constants.vbCrLf;
// 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"))
{
t = t.Substring(0, t.IndexOf("<parsed_call_number>")) + t.Substring(t.IndexOf("</parsed_call_number>") + 21);
}
if (t.Contains("<parsed_issue_level_description>"))
{
t = t.Substring(0, t.IndexOf("<parsed_issue_level_description>")) + t.Substring(t.IndexOf("</parsed_issue_level_description>") + 32);
}
// 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 = "";
foreach (XmlNode currentMynode in doc.SelectNodes("/item/item_data/parsed_call_number/*"))
{
mynode = currentMynode;
if (mynode == null)
break;
pcn = pcn + "<call_no_" + i + ">" + mynode.InnerXml + "</call_no_" + i + ">" + Constants.vbCrLf;
i = i + 1;
}
pcn = "<parsed_call_number>" + Constants.vbCrLf + pcn + Constants.vbCrLf + "</parsed_call_number>";
i = 1;
pild = "";
foreach (XmlNode currentMynode1 in doc.SelectNodes("/item/item_data/parsed_issue_level_description/*"))
{
mynode = currentMynode1;
if (mynode == null)
break;
pild = pild + "<issue_level_description_" + i + ">" + mynode.InnerXml + "</issue_level_description_" + i + ">" + Constants.vbCrLf;
i = i + 1;
}
pild = "<parsed_issue_level_description>" + Constants.vbCrLf + pild + Constants.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'
var lid = doc.GetElementsByTagName("library");
string licode = "<library_code>" + lid[0].InnerXml + "</library_code>";
anode = doc.SelectSingleNode("//library");
string liname = "<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'
var lod = doc.GetElementsByTagName("location");
string locode = "<location_code>" + lod[0].InnerXml + "</location_code>";
anode = doc.SelectSingleNode("//location");
string loname = "<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 + Constants.vbCrLf + ct + Constants.vbCrLf + titl + Constants.vbCrLf + licode + Constants.vbCrLf + liname + Constants.vbCrLf + loname + locode + Constants.vbCrLf + pcn + Constants.vbCrLf + pild + Constants.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;
}
private void ManualPrint_Click(object sender, EventArgs e)
{
// manual print
if (ManualPrint.Text == "Stop Printing")
{
stopPrinting = true;
SetPrintButtonText();
return;
}
string dayTime = "";
string logentry = "";
string barcodenum = "";
int lencheck = 0;
Array chkline = null;
int maxlines = Conversions.ToInteger(inMaxLines.Text);
bool linesOK = true;
int maxchars = Conversions.ToInteger(inMaxChars.Text);
int repeat = 0;
int i = 0;
string batchText = "";
string labelin;
plDistance.BackColor = Color.White;
if (chkUsePocketLabels.Checked)
{
if (btnSL4.Checked | btnSL6.Checked | btnPlCustom.Checked & PLcount.Value == 2m)
{
if ((double)Conversions.ToSingle(plDistance.Text) == 0.0d)
{
plDistance.BackColor = Color.Pink;
Interaction.MsgBox("When printing two pocket labels, you must specify a vertical distance" + Constants.vbCrLf + "between the top lines of the two labels.", MsgBoxStyle.Exclamation, "No Distance Specified");
plDistance.Focus();
return;
}
}
}
if (string.IsNullOrEmpty(Strings.Trim(OutputBox.Text)))
{
Interaction.Beep();
InputBox.Focus();
return;
}
editText = OutputBox.Text;
barcodenum = InputBox.Text;
if ((editText ?? "") != (origText ?? "") & !string.IsNullOrEmpty(barcodenum) & logEdits.Checked)
{
dayTime = DateTime.Now.ToString("ddd MMM d, yyyy HH:mm", CultureInfo.InvariantCulture);
logentry = dayTime + Constants.vbTab + barcodenum + Constants.vbTab + origText.Replace(Constants.vbCrLf, "|") + Constants.vbTab + editText.Replace(Constants.vbCrLf, "|");
writeFile(mypath + "changelog.txt", logentry, true);
editText = "";
origText = "";
}
if (OutputBox.Text.Contains("** ERROR **"))
{
Interaction.Beep();
Interaction.MsgBox("Could not find this barcode number in Alma.", MsgBoxStyle.Exclamation, "Barcode Number Error");
return;
}
if (OutputBox.Text.Contains("Java: **"))
{
Interaction.Beep();
Interaction.MsgBox("Could not contact Alma.", MsgBoxStyle.Exclamation, "Connection Error");
}
lencheck = checkLineLength();
chkline = Strings.Split(OutputBox.Text, Constants.vbCrLf);
if (lencheck != 99)
{
// chkline = Split(OutputBox.Text, vbCrLf)
Interaction.MsgBox(Operators.ConcatenateObject(Operators.ConcatenateObject(Operators.ConcatenateObject(Operators.ConcatenateObject(Operators.ConcatenateObject("Line #" + lencheck + ":" + Constants.vbCrLf, chkline.GetValue(lencheck - 1)), Constants.vbCrLf), " contains more than "), maxchars), " characters."));
return;
}
if (chkline.Length > maxlines)
{
Interaction.Beep();
Interaction.MsgBox("Lable contains more than " + maxlines + " lines.", MsgBoxStyle.Exclamation, "Too Many Lines");
return;
}
if (lblXMLWarn.Visible == true)
{
Interaction.Beep();
Interaction.MsgBox("An XML <field> used in your settings is incorrect.", MsgBoxStyle.Exclamation, "XML Reference Error");
return;
}
// ********************
// Use DOS Batch File
// ********************
if (useDOSBatch.Checked)
{
string txtout = "";
int extraLines = Conversions.ToInteger(dosBlankLines.Text);
string addcr = "";
int tabpos = 0;
int k = 0;
int extraSpaces = Conversions.ToInteger(dosPlColNum.Text);
int tabcount = Conversions.ToInteger(dosPlTabNum.Text);
string addsp = "";
Array taray;
string mg = "";
if (chkUsePocketLabels.Checked)
{
taray = packagePocket().Split(Conversions.ToChar(Constants.vbCrLf));
txtout = "";
var loopTo = taray.Length - 1;
for (k = 0; k <= loopTo; k++)
{
tabpos = Conversions.ToInteger(taray.GetValue(k).ToString().Replace(Constants.vbLf, "").IndexOf(Constants.vbTab));
if (dosPlUseCol.Checked)
{
addsp = new string(' ', extraSpaces - tabpos);
txtout = Conversions.ToString(Operators.ConcatenateObject(Operators.ConcatenateObject(txtout, taray.GetValue(k).ToString().Replace(Constants.vbTab, addsp)), Constants.vbCrLf));
}
else
{
if (tabcount > 1)
{
addsp = new string(Conversions.ToChar(Constants.vbTab), tabcount);
}
else
{
addsp = Constants.vbTab;
}
txtout = Conversions.ToString(Operators.ConcatenateObject(Operators.ConcatenateObject(txtout, taray.GetValue(k).ToString().Replace(Constants.vbTab, addsp)), Constants.vbCrLf));
}
}
txtout = txtout + terminator(taray.Length);
}
else
{
txtout = txtout + OutputBox.Text + terminator(OutputBox.Lines.Length);
}
viaDOS(txtout);
return;
}
if (UseDesktop.Checked)
{
getPrintParams();
PrintDocument2.PrinterSettings.PrinterName = inPrinterName.Text;
PrintDocument2.PrintController = new StandardPrintController();
if (chkUsePocketLabels.Checked)
{
labelin = packagePocket();
labelin = labelin.Replace(Constants.vbCrLf, "|");
}
else
{
labelin = OutputBox.Text.Replace(Constants.vbCrLf, "|");
}
// 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(Conversions.ToChar(Constants.vbCrLf));
repeat = (int)Math.Round(LabelRepeat.Value);
if (repeat > 1 & ManualPrint.Text != "Stop Printing")
{
ManualPrint.Text = "Stop Printing";
printProgress.Visible = true;
Application.DoEvents();
}
var loopTo1 = repeat;
for (i = 1; i <= loopTo1; i++)
{
Application.DoEvents();
if (stopPrinting)
{
SetPrintButtonText();
stopPrinting = false;
printProgress.Visible = false;
break;
}
try
{
printProgress.Text = "Printing " + i + " of" + repeat;
Application.DoEvents();
PrintDocument2.Print();
}
catch (Exception ex)
{
Interaction.MsgBox("Printer settings are not correct." + Constants.vbCrLf + "Make sure a valid printer has been selected, and try again." + Constants.vbCrLf + ex.ToString(), MsgBoxStyle.Exclamation, "Printer Selection Error");
break;
}
}
// ********************
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();
}
if (UseLaser.Checked) // SAVE TO BATCH
{
repeat = (int)Math.Round(LabelRepeat.Value);
if (repeat > 5 && MessageBox.Show(repeat + " labels will be printed.", "Confirm Multipl Label Request", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
return;
if (chkUsePocketLabels.Checked)
{
batchText = packagePocket();
}
else
{
batchText = OutputBox.Text;
}
repeat = (int)Math.Round(LabelRepeat.Value);
var loopTo2 = repeat;
for (i = 1; i <= loopTo2; i++)
sendToBatch2(batchText);
writeStat("B"); // add B to end of statrec and write to statfile
OutputBox.Text = "";
plOutput.Text = "";
TempLabelBox.Text = "";
InputBox.Text = "";
InputBox.Focus();
}
if (UseFTP.Checked)
{
repeat = (int)Math.Round(LabelRepeat.Value);
if (repeat > 5 && MessageBox.Show(repeat + " labels will be printed.", "Confirm Multipl Label Request", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.Cancel)
return;
ftpPrint();
}
}
private void zplPrintBtn_Click(object sender, EventArgs e)
{
// TODO JF
string barcode = getval("barcode");
string title = getval("title");
if (title.Length > 21)
{
title = title.Substring(0, 20);
}
if (OutputBox.Text.Length > 0)
{
string labelData = title + Constants.vbCrLf + barcode + Constants.vbCrLf + OutputBox.Text;
// MessageBox.Show(labelData);
string labelTxt = labelData.Replace(Constants.vbCrLf, "|");
zplPrint(labelTxt);
}
if (zplBatchAL.Count > 0)
{
foreach (Object obj in zplBatchAL)
{
string labelData = obj.ToString();
// MessageBox.Show(labelData);
string labelTxt = labelData.Replace(Constants.vbCrLf, "|");
zplPrint(labelTxt);
}
}
OutputBox.Text = "";
InputBox.Text = "";
zplBatchPreview.Text = "";
zplBatchAL.Clear();
}
private void zplPrint(string labelStr)
{
var lineAr = new List<string>(labelStr.Split('|'));
string title = lineAr[0];
string barcode = lineAr[1];
lineAr.RemoveRange(0,2);
// MessageBox.Show(lineAr.Count.ToString());
int maxLineLn = 0;
foreach (String line in lineAr)
{
if (line.Length > maxLineLn)
{
maxLineLn = line.Length;
}
}
// ZPL Command(s)
int so = Convert.ToInt16(numudSplitOffset.Value);
int to = Convert.ToInt16(numupTopOffset.Value);
int xa = so;
int ya = to;
string ZPLString = "^XA^CI28";
xa = so - 55;
ya = to + 25;
ZPLString += "^FO" + xa + "," + ya + "^A0R40,40^FD" + title + "^FS";
xa = so - 125;
ZPLString += "^FO" + xa + "," + ya + "^A0R50,50^FD" + barcode + "^FS";
xa = so + 15;
int xb = so + 16;
int yb = to + 26;
if (lineAr.Count <= 6 && maxLineLn <= 8)
{
if (lineAr.Count >= 1)
{
ya = to + 30;
ZPLString += "^FO" + xa + "," + ya + "^A0N50,50^FD" + lineAr[0] + "^FS";