-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm1.vb
2877 lines (2873 loc) · 126 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
#Region "Imports"
Imports System.IO
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports Microsoft.Office.Interop
Imports System.Text.RegularExpressions
Imports System.Collections
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Runtime.Serialization
#End Region
Public Class Form1
#Region "Class Private Variables"
' Dim RcmdItems As New List(Of RecommendedBuyItem)
'Public OneFinalPOItems As New List(Of RecommendedBuyItem)
Dim AppUser As String = ""
'Dim CurrentUser As CurrentUser
'Dim UserVendors As New List(Of ItemVendor)
'Dim UserVendorItems As New List(Of VendorItems)
'Dim TabVendors As New List(Of String)
Dim ApplicationVersion As String = ""
'Public SelectedVendor As String
'Public VERCONN As String = "Data Source=ecom-db2;Initial Catalog=ECOMVER;UID=mgr;PWD=doall"
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Debug.Print(vbCrLf & Now.ToString)
AppUser = My.Application.GetEnvironmentVariable("USERNAME")
If AppUser.ToUpper = "FEDERICO" Then AppUser = InputBox("User", "Enter Runas user", "", , )
If AppUser.ToUpper = "TSCHMIDT" Then AppUser = InputBox("User", "Enter Runas user", "", , )
If Not {"BRIAN", "SCOTTM", "PAUL", "CATHY", "EDLYN", "TRACEY"}.Contains(AppUser.ToUpper) Then
MsgBox("You are not authorized to access this application.", MsgBoxStyle.Exclamation, "Access Error")
Me.Close()
End If
User = New CurrentUser(AppUser)
UserVendorItemsList = New List(Of VendorItems)
For Each Vendor As String In User.Vendors
'Debug.Print(Vendor)
Dim tmpVI As New VendorItems(Vendor)
If tmpVI.WorkingItems.Count > 0 Then
UserVendorItemsList.Add(tmpVI)
VendorTabs.TabPages.Add(tmpVI.TabPage)
AddHandler tmpVI.VendorAdded, AddressOf VendorAdded
AddHandler tmpVI.VendorEmpty, AddressOf VendorEmpty
End If
Next
End Sub
Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
If VendorTabs.TabPages.Count > 0 Then
If VendorTabs.SelectedTab.Name = User.ID Then
FinalizePOToolStripMenuItem.Enabled = False
End If
End If
End Sub
Private Sub VendorAdded(ByVal vi As VendorItems)
UserVendorItemsList.Add(vi)
If vi.VendorNumber = User.ID Then
VendorTabs.TabPages.Add(vi.TabPage)
AddHandler vi.VendorAdded, AddressOf VendorAdded
AddHandler vi.VendorEmpty, AddressOf VendorEmpty
Exit Sub
End If
Dim tmplist As New List(Of String)
For Each v As VendorItems In UserVendorItemsList
If v.VendorNumber <> User.ID Then
tmplist.Add(v.VendorNumber)
End If
Next
tmplist.Sort()
Dim i As Integer = 0
For Each s As String In tmplist
If s = vi.VendorNumber Then
VendorTabs.TabPages.Insert(i, vi.TabPage)
End If
i += 1
Next
AddHandler vi.VendorAdded, AddressOf VendorAdded
AddHandler vi.VendorEmpty, AddressOf VendorEmpty
End Sub
Private Sub VendorEmpty(ByVal vi As VendorItems)
Dim id As String = vi.VendorNumber
For Each t As TabPage In VendorTabs.TabPages
If t.Name = vi.VendorNumber Then
VendorTabs.TabPages.Remove(t)
End If
Next
UserVendorItemsList.RemoveAll(VendorItems.FindPredicateByVendorId(vi.VendorNumber))
End Sub
Private Sub FinalizePOToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FinalizePOToolStripMenuItem.Click
Dim CurrentVendorItems As VendorItems = UserVendorItemsList.Find(VendorItems.FindPredicateByVendorId(VendorTabs.SelectedTab.Name))
If CurrentVendorItems.VendorNumber = User.ID Then
MsgBox("You cannot create a PO for the short list.", MsgBoxStyle.Exclamation, "In Short List")
Exit Sub
End If
If CurrentVendorItems.ItemsWithoutRECDATE.Length > 1 Then
MsgBox("These items do not have a Due Date set." & vbCrLf & CurrentVendorItems.ItemsWithoutRECDATE, MsgBoxStyle.Exclamation, "Items withour Due Date")
Exit Sub
End If
Dim tmpListOfHigherCostItems As New List(Of String)
Dim CostierItems As New List(Of RecommendedBuyItem)
For Each i As RecommendedBuyItem In CurrentVendorItems.WorkingItems
Dim increase As Decimal = 0
If i.OriginalVendorCost > 0 Then
increase = ((i.VendorCost - i.OriginalVendorCost) / i.OriginalVendorCost) * 100
Else
increase = 99999
End If
If increase >= 2 Then
Dim mrgnPrior As Decimal = 0
tmpListOfHigherCostItems.Add(String.Format("{0,-21}{1,-9}{2,-9}{3,-9}{4,-15}{5}", i.ITEMNO, i.OriginalVendorCost, i.VendorCost, increase.ToString("f2") & "%", i.OriginalMargin.ToString("f2") & "%", i.Margin.ToString("f2") & "%"))
CostierItems.Add(i)
End If
Next
If tmpListOfHigherCostItems.Count > 0 Then
Dim sRprt As String = String.Format("{0,-21}{1,-9}{2,-9}{3,-9}{4,-15}{5}" & Environment.NewLine, "ITEM", "Old Cost", "New Cost", "Increase", "Margin Before", "Margin After")
For Each i As String In tmpListOfHigherCostItems
sRprt &= i & Environment.NewLine
Next
Dim ApprovalWindow As New ManagerApprovalWindow
ApprovalWindow.InfoLabel.Text = "These items have cost increases of over 2%:" & Environment.NewLine & Environment.NewLine & sRprt & Environment.NewLine & "Please enter Manager approval password:"
If DialogResult.Yes = ApprovalWindow.ShowDialog Then
For Each i As RecommendedBuyItem In CostierItems
LogThis("ITMCOSTAPPRV", i.ITEMNO & " manager approved item cost increase from " & i.OriginalVendorCost & " to " & i.VendorCost, i.ITEMID)
Next
Else
Exit Sub
End If
End If
If CurrentVendorItems.TotalCostHigher() Then
Exit Sub
End If
'after checking price increase manager approval
Dim FinalDocumentPath As String = CurrentVendorItems.FinalDocumentPath
If FinalDocumentPath = "" Then
MsgBox("Error creating final document.", MsgBoxStyle.Exclamation, "Error creating final document")
Exit Sub
End If
Dim FinalizeWindow As New EnterPOForm(CurrentVendorItems)
Dim result As DialogResult
With FinalizeWindow
.DestinationFolder = FinalDocumentPath
.POCommentsTextBox.Text = CurrentVendorItems.Vendor.POComments
.FinalReportWebBrowser.DocumentText = CurrentVendorItems.FinalHTMLReport
result = .ShowDialog()
CurrentVendorItems.FinalPOComments = .POCommentLines
End With
If Not result = DialogResult.OK Then Return
If CurrentVendorItems.FinalizePurchaseOrderSuccess() Then
Using sr As New StreamWriter(FinalDocumentPath & "FINALPURCHASEORDER.HTML")
sr.WriteLine(CurrentVendorItems.FinalHTMLReport)
sr.Flush()
End Using
MsgBox("PO " & CurrentVendorItems.PONUMBER & " entered sucessfully")
Else
MsgBox("something went wrong entering po")
End If
End Sub
Private Sub CreateQuoteForVendorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateQuoteForVendorToolStripMenuItem.Click
Dim CurrentVendorItems As VendorItems = UserVendorItemsList.Find(VendorItems.FindPredicateByVendorId(VendorTabs.SelectedTab.Name))
Dim ProposalDocument As String = CurrentVendorItems.ProposalDocumentPath
If ProposalDocument = "" Then
MsgBox("Error creating proposal document.", MsgBoxStyle.Exclamation, "Error creating proposal document")
Exit Sub
End If
Dim FileName As String = New FileInfo(ProposalDocument).Name
Dim anEmailPreviewWindow As New EmailPreviewForm
Dim result As DialogResult
With anEmailPreviewWindow
.FullFilePath = ProposalDocument
.FromTextBox.Text = User.MAILADDRESS.ToString
.ToTextBox.Text = CurrentVendorItems.Vendor.Email
.BccTextBox.Text = User.Email
.AttachmentLink.Text = FileName
.SubjectTextBox.Text = "Ecommerce company PO " & FileName.Substring(2, 9)
.HTMLPreviewWebBrowser.DocumentText = CurrentVendorItems.EmailBodyInHTML
result = .ShowDialog
End With
If result = DialogResult.OK Then CurrentVendorItems.UpdateLastEmailDate()
End Sub
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
With My.Application.Info.Version
ApplicationVersion = .Major & "." & .MajorRevision & "." & .Minor & "." & .MinorRevision
End With
With My.Application.Info
MsgBox(.AssemblyName & vbCrLf & .CompanyName & vbCrLf & ApplicationVersion, MsgBoxStyle.Information, "About PO Maker")
End With
End Sub
Private Sub VendorTabs_Selected(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles VendorTabs.Selected
If e.TabPage.Name = User.ID Then
FinalizePOToolStripMenuItem.Enabled = False
Else
FinalizePOToolStripMenuItem.Enabled = True
End If
End Sub
End Class
Public Class VendorItems
Implements IComparable(Of VendorItems)
#Region "Class Private Variables"
Private oTab As New TabPage
Private WithEvents oDataViewGrid As New DataGridView
Private oAddressLabel As New Label
Private oCommentsLabel1 As New Label
Private oVendorCommentslabel As New TextBox
Private oCommentsLabel2 As New Label
Private oPOCommentslabel As New TextBox
Private oRequestLabel As New Label
Private oRequestText As New TextBox
Private oDueDatePicker As New DateTimePicker
Private oSetPODateButton As New Button
Private WithEvents oEditDescriptionButton As New Button
Private oCountlabel As New ToolStripStatusLabel
Private oTotallabel As New ToolStripStatusLabel
Private oPOlabel As New ToolStripStatusLabel
Private oInfolabel As New ToolStripStatusLabel
Private oEmailLabel As New ToolStripStatusLabel
Private oStatusStrip As New StatusStrip
Private oVendorNumber As String = ""
Private oVendor As ItemVendor
Private oWorkingItems As New List(Of RecommendedBuyItem)
Private oInitialItems As New List(Of RecommendedBuyItem)
Private oFinalPOComments As New List(Of String)
Private oPONumber As String = ""
Private oPODate As String = ""
Private oLastEmailDate As String = ""
Private oPopUpMenu As New ContextMenuStrip
Private WithEvents oMoveToVendor As New ToolStripMenuItem
Private WithEvents oMoveToShortList As New ToolStripMenuItem
Private WithEvents oItemEventHistory As New ToolStripMenuItem
Private VERCONN As String = "Data Source=ecom-db2;Initial Catalog=ECOMVER;UID=xxx;PWD=xxxx"
#End Region
Public Event VendorAdded(ByVal vi As VendorItems)
Public Event VendorEmpty(ByVal vi As VendorItems)
Sub New(ByVal VendorNumber As String)
oVendorNumber = VendorNumber.ToUpper
oWorkingItems = GetVendorItems()
If oWorkingItems.Count > 0 Then
oVendor = New ItemVendor(VendorNumber)
SetTempPONumberDate()
SetLastEmailDate()
SetDataViewGrid()
SetStatusStrip()
SetNewTab()
oInitialItems = DeepCopy(oWorkingItems)
End If
End Sub
#Region "Class Properties"
ReadOnly Property VendorNumber() As String
Get
Return oVendorNumber
End Get
End Property
ReadOnly Property Vendor() As ItemVendor
Get
Return oVendor
End Get
End Property
ReadOnly Property WorkingItems() As List(Of RecommendedBuyItem)
Get
Return oWorkingItems
End Get
End Property
ReadOnly Property WorkingTotalPurchase() As Decimal
Get
Dim i As Decimal = 0
For Each anitem As RecommendedBuyItem In oWorkingItems
i += anitem.VendorCost * anitem.TotalQtyToBuy
Next
Return i
End Get
End Property
ReadOnly Property PONUMBER() As String
Get
Return oPONumber.Trim
End Get
End Property
ReadOnly Property TabPage() As TabPage
Get
Return oTab
End Get
End Property
ReadOnly Property ProposalDocumentPath As String
Get
Dim TmpPO As String = ValidatePONumber()
If TmpPO = "" Then Return ""
Dim tmpFolderName As String = RootDocFolder & oVendorNumber & "\" & TmpPO & "\"
Dim tmpFileName = "PO" & TmpPO & "." & Now.ToString("yyyyMMddhhmm") & ".xls"
If File.Exists("C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE") Or File.Exists("C:\Program Files\Microsoft Office\Office14\EXCEL.EXE") Then tmpFileName &= "x"
'If {"PAUL", "KATIE"}.Contains(User.ID) Then tmpFileName &= "x"
If Not Directory.Exists(tmpFolderName) Then
Try
Directory.CreateDirectory(tmpFolderName)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "PO Directory Creation Error")
tmpFolderName = My.Computer.FileSystem.SpecialDirectories.Temp & "\"
End Try
End If
Dim tmpResult As String = tmpFolderName & tmpFileName
Dim xlsApp As New Excel.Application
Dim xlsWrkbk As Excel.Workbook = xlsApp.Workbooks.Add
Dim xlsWSheet As Excel.Worksheet = xlsWrkbk.Worksheets(1)
Dim rowcntr As Integer = 1
With xlsWSheet
.Range("A1").Value = "Product Number"
.Range("B1").Value = "Vendor Model Number"
.Range("C1").Value = "Description"
.Range("D1").Value = "Qty"
.Range("D1").ColumnWidth = 8.57
.Range("E1").Value = "Confirm"
.Range("E1").ColumnWidth = 8.14
.Range("F1").Value = "Cost"
.Range("F1").ColumnWidth = 10
.Range("F1").EntireColumn.NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
.Range("G1").Value = "Confirm"
.Range("G1").ColumnWidth = 8.14
.Range("H1").Value = "ETA's"
.Range("H1").ColumnWidth = 13.43
.Range("I1").Value = "Comments"
.Range("I1").ColumnWidth = 22.29
.Range("A1:I1").Font.Bold = True
.Range("A1:I1").HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter
For Each oneitem As RecommendedBuyItem In oWorkingItems
If oneitem.TotalQtyToBuy > 0 Then
rowcntr += 1
.Range("A" & rowcntr).Value = oneitem.ITEMNO
.Range("B" & rowcntr).Value = oneitem.VendorItemNo
.Range("C" & rowcntr).Value = oneitem.Description
.Range("D" & rowcntr).Value = oneitem.TotalQtyToBuy
.Range("F" & rowcntr).Value = oneitem.VendorCost
End If
Next
.Range("A1:I" & rowcntr).Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = BorderStyle.FixedSingle
.Range("A1:I" & rowcntr).Borders(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = BorderStyle.FixedSingle
.Range("A1:I" & rowcntr).Borders(Excel.XlBordersIndex.xlEdgeRight).LineStyle = BorderStyle.FixedSingle
.Range("A1:I" & rowcntr).Borders(Excel.XlBordersIndex.xlEdgeTop).LineStyle = BorderStyle.FixedSingle
.Range("A1:I" & rowcntr).Borders(Excel.XlBordersIndex.xlInsideHorizontal).LineStyle = BorderStyle.FixedSingle
.Range("A1:I" & rowcntr).Borders(Excel.XlBordersIndex.xlInsideVertical).LineStyle = BorderStyle.FixedSingle
.Range("A1").EntireColumn.AutoFit()
.Range("B1").EntireColumn.AutoFit()
.Range("C1").EntireColumn.AutoFit()
End With
Try
xlsWrkbk.SaveAs(tmpResult)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error Saving Vendor Quote Spreadsheet")
End Try
xlsApp.Quit()
Return tmpResult
End Get
End Property
ReadOnly Property FinalDocumentPath As String
Get
Dim TmpPO As String = ValidatePONumber()
If TmpPO = "" Then Return ""
Dim tmpFolderName As String = RootDocFolder & oVendorNumber & "\" & TmpPO & "\"
If Not Directory.Exists(tmpFolderName) Then
Try
Directory.CreateDirectory(tmpFolderName)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "PO Directory Creation Error")
tmpFolderName = My.Computer.FileSystem.SpecialDirectories.Temp & "\"
End Try
End If
Return tmpFolderName
End Get
End Property
ReadOnly Property ItemsWithoutRECDATE() As String
Get
Dim result As String = ""
For Each i As RecommendedBuyItem In oWorkingItems
If String.IsNullOrWhiteSpace(i.RECDATE) Then
result &= i.ITEMNO & vbCrLf
End If
Next
Return result
End Get
End Property
Public Property FinalPOComments() As List(Of String)
Get
Return oFinalPOComments
End Get
Set(ByVal value As List(Of String))
oFinalPOComments = value
End Set
End Property
ReadOnly Property FinalHTMLReport As String
Get
Dim htmlcontent As New System.Text.StringBuilder
With htmlcontent
.Append("<!DOCTYPE html><html><head><style>body{Font-family:courier}td{font-size:14px;}</style><title>PO " & PONUMBER & "</title></head><body>")
.Append("<h3><p>PO Number: " & PONUMBER & "      PO Date: " & CDate(oPODate).ToShortDateString & "      Finalized Date: " & Now.ToShortDateString & "</p></h3>")
.Append("<p><h4>" & Vendor.ContactNameAndAddressHTML & "<h4>")
If oFinalPOComments.Count > 0 Then
.Append("<p><h4>Final PO Comments for Receving Ticket:<br><br>")
For Each s As String In FinalPOComments
.Append(s & "<br>")
Next
.Append("<br></h4>")
End If
.Append("</td></tr></table><br>")
.Append("<table border=""1""><col align=""left"" /><col align=""left"" /><col align=""center"" /><col align=""center"" /><col align=""right"" /><col align=""right"" />")
.Append("<tr><th>Item Number</th><th>Description</th><th>Due Date</th><th>Quantity</th><th>Cost</th><th>Total</th></tr>")
For Each r As RecommendedBuyItem In oWorkingItems
.Append("<tr><td>" & r.ITEMNO & "</td><td>" & r.Description & "</td><td>" & r.RECDATE & "</td><td>" & r.TotalQtyToBuy & "</td><td>" & r.VendorCost.ToString("f2") & "</td><td>" & r.TotalVendorCost.ToString("f2") & "</td></tr>")
Next
.Append("<tfoot><tr><td colspan=""5""></td><th>" & WorkingTotalPurchase.ToString("f2") & "</th></tr></tfoot></table></body></html>")
Return .ToString
End With
End Get
End Property
ReadOnly Property EmailBodyInHTML As String
Get
Dim tmpResult As New System.Text.StringBuilder
tmpResult.Append("<p>Hello")
If Vendor.ContactFullName.Length > 3 Then tmpResult.Append(" " & Vendor.ContactFullName)
tmpResult.Append(",</p><p>Attached is a new purchase order, ecommerce company PO " & oPONumber & "</p>")
If Not String.IsNullOrEmpty(oRequestText.Text.Trim) Then tmpResult.Append("<p>" & oRequestText.Text.Trim & "</p>")
If oVendor.POCommentsHTML.Length > 3 Then tmpResult.Append("<p>The payment terms are as follow: <br><br>" & oVendor.POCommentsHTML & "<br>")
tmpResult.Append("</p><p>Please open the attached spreadsheet to confirm pricing, availability and delivery date as soon as possible. " & _
"<u>Reply to this email with confirmation of receipt.</u> <u>If any changes need to be made to the order, please note them in the attached spreadsheet.</u> " & _
"If you do not provide confirmation via email and ship the order it will be refused.</p>" & _
"<p>Any pricing, availability and/or delivery discrepancies need to be agreed upon before the order is finalized. " & _
"<u>Please note we will only pay the agreed upon costs and accept the agreed upon quantities.</u> Any excess quantities, unordered items or prices those not " & _
"matching the final order confirmation will be cancelled and returned at your expense. This is a <u>legally binding agreement</u> to purchase/provide the " & _
"products in the attached purchase order. Any variance from the order confirmation must be agreed to via email or writing. Any verbal agreements may or may " & _
"not be honored at our sole discretion.</p>")
Dim HTMSignature As String = GetUserOutlookHTMLSignature()
If HTMSignature.ToUpper.Contains("BODY") Then
Dim i As Integer = HTMSignature.ToUpper.IndexOf("<BODY") + 4
Return HTMSignature.Insert(HTMSignature.IndexOf(">", i) + 1, tmpResult.ToString)
Else
Return "<HTML><BODY>" & tmpResult.ToString & "</BODY></HTML>"
End If
End Get
End Property
#End Region
#Region "Class Private Subs"
Private Sub SetNewTab()
Dim adlbW As Integer = 230
Dim cW As Integer = 240
Dim cLbH As Integer = 17
With oAddressLabel
.Text = oVendor.ContactNameAndAddress
.Dock = DockStyle.None
.Location = New Point(0, 5)
.Size = New Size(adlbW, 125)
.BorderStyle = BorderStyle.Fixed3D
End With
With oEditDescriptionButton
.Name = "MultyDescriptionEdit"
.Location = New Point(0, 130)
.Size = New Size(155, 20)
.Text = "Replace Text in Descriptions"
End With
With oCommentsLabel1
.Text = "Vendor Comments"
.Dock = DockStyle.None
.Location = New Point(adlbW + 5, 5)
.Size = New Size(cW, cLbH)
.BorderStyle = BorderStyle.FixedSingle
End With
With oVendorCommentslabel
.Multiline = True
.ReadOnly = True
.Text = oVendor.VendorComments
.Dock = DockStyle.None
.WordWrap = False
.ScrollBars = ScrollBars.Horizontal
.Location = New Point(adlbW + 5, 25)
.Size = New Size(cW, 130)
.BorderStyle = BorderStyle.Fixed3D
End With
With oCommentsLabel2
.Text = "PO Comments"
.Dock = DockStyle.None
.Location = New Point(cW + adlbW + 10, 5)
.Size = New Size(cW, cLbH)
.BorderStyle = BorderStyle.FixedSingle
End With
With oPOCommentslabel
.Multiline = True
.ReadOnly = True
.Text = oVendor.POComments
.Dock = DockStyle.None
.WordWrap = False
.ScrollBars = ScrollBars.Horizontal
.Location = New Point(cW + adlbW + 10, 25)
.Size = New Size(cW, 130)
.BorderStyle = BorderStyle.Fixed3D
End With
With oRequestLabel
.Text = "Special Requests"
.Dock = DockStyle.None
.Location = New Point(cW + cW + adlbW + 15, 5)
.Size = New Size(280, cLbH)
.BorderStyle = BorderStyle.FixedSingle
End With
With oRequestText
.Name = "RequestTextBox"
.Multiline = True
.Dock = DockStyle.None
.WordWrap = False
.ScrollBars = ScrollBars.Both
.Location = New Point(cW + cW + adlbW + 15, 25)
.Size = New Size(280, 110)
.BorderStyle = BorderStyle.Fixed3D
End With
With oDueDatePicker
.Name = "RECDATE"
.Location = New Point(cW + cW + adlbW + 15, cLbH + 120)
.Format = DateTimePickerFormat.Short
.Size = New Size(120, 20)
.Value = Today.AddDays(14)
End With
With oSetPODateButton
.Name = "SetPODateButton"
.Location = New Point(cW + cW + adlbW + 15 + 125, cLbH + 120)
.Size = New Size(155, 20)
.Text = "Set PO Items Due Dates"
AddHandler .Click, AddressOf SetPODatesButton_Click
End With
If oVendorNumber = User.ID Then
oTab.Text = "Short List"
Else
oTab.Text = oVendorNumber
End If
oMoveToShortList.Text = "Move To Short List"
oMoveToVendor.Text = "Move to Vendor"
oItemEventHistory.Text = "Item Activity History"
With oPopUpMenu
.Items.Add(oMoveToVendor)
If Not oVendorNumber = User.ID Then
.Items.Add(New ToolStripSeparator)
.Items.Add(oMoveToShortList)
End If
.Items.Add(New ToolStripSeparator)
.Items.Add(oItemEventHistory)
End With
oTab.Name = oVendorNumber
With oTab.Controls
.Add(oAddressLabel)
.Add(oEditDescriptionButton)
.Add(oCommentsLabel1)
.Add(oVendorCommentslabel)
.Add(oCommentsLabel2)
.Add(oPOCommentslabel)
.Add(oRequestLabel)
.Add(oRequestText)
If Not oVendorNumber = User.ID Then
.Add(oDueDatePicker)
.Add(oSetPODateButton)
End If
.Add(oDataViewGrid)
.Add(oStatusStrip)
End With
End Sub
Private Sub SetDataViewGrid()
Dim ItemNoColumn As New DataGridViewTextBoxColumn
With ItemNoColumn
.Name = "cItemNo"
.HeaderText = "Item Number"
.CellTemplate.ValueType = GetType(String)
.Width = 145
.ReadOnly = True
End With
Dim VendorItemNoColumn As New DataGridViewTextBoxColumn
With VendorItemNoColumn
.Name = "cVendorItemNo"
.HeaderText = "Vendor Item Number"
.CellTemplate.ValueType = GetType(String)
.Width = 145
End With
Dim ItemDescColumn As New DataGridViewTextBoxColumn
With ItemDescColumn
.Name = "cDescription"
.HeaderText = "Description"
.CellTemplate.ValueType = GetType(String)
.Width = 340
.MaxInputLength = 70
End With
Dim VendorNameColumn As New DataGridViewTextBoxColumn
With VendorNameColumn
.Name = "cVendor"
.HeaderText = "Vendor"
.CellTemplate.ValueType = GetType(String)
.Width = 50
.ReadOnly = True
End With
Dim DueDateColumn As New DataGridViewTextBoxColumn
With DueDateColumn
.Name = "cDueDate"
.HeaderText = "Due Date"
.Width = 70
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.CellTemplate.ValueType = GetType(Date)
.DefaultCellStyle.Format = "d"
If oVendorNumber = User.ID Then
.ReadOnly = True
End If
End With
Dim VendorPriceColumn As New DataGridViewTextBoxColumn
With VendorPriceColumn
.Name = "cVendorPrice"
.HeaderText = "Cost"
.CellTemplate.ValueType = GetType(Decimal)
.Width = 50
If oVendorNumber = User.ID Then
.ReadOnly = True
End If
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
End With
Dim TotalItemsToBuyColumn As New DataGridViewTextBoxColumn
With TotalItemsToBuyColumn
.Name = "cFinalNumberToBuy"
.HeaderText = "Total to Buy"
.CellTemplate.ValueType = GetType(Integer)
.Width = 80
If oVendorNumber = User.ID Then
.ReadOnly = True
End If
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
Dim TotalItemsCostColumn As New DataGridViewTextBoxColumn
With TotalItemsCostColumn
.Name = "cTotalItemsCost"
.HeaderText = "Total Cost"
.Width = 70
.ReadOnly = True
.Visible = True
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
End With
Dim ItemsIDColumn As New DataGridViewTextBoxColumn
With ItemsIDColumn
.Name = "cItemID"
.HeaderText = "Item ID"
.Width = 50
.ReadOnly = True
.Visible = False
End With
Dim ItemsEDPNOColumn As New DataGridViewTextBoxColumn
With ItemsEDPNOColumn
.Name = "cItemEDPNO"
.HeaderText = "Item EDPNO"
.Width = 50
.ReadOnly = True
.Visible = False
End With
Dim tmpResult As New DataGridView
With oDataViewGrid
.TabIndex = 1
.Location = New Point(0, 160)
.Size = New Size(1007, 485)
.Dock = DockStyle.Bottom
.Name = "DataGridView"
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize
.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.EditMode = DataGridViewEditMode.EditOnEnter
.RowHeadersWidth = 40
.MultiSelect = False
.Columns.Insert(0, ItemNoColumn)
.Columns.Insert(1, VendorItemNoColumn)
.Columns.Insert(2, ItemDescColumn)
.Columns.Insert(3, VendorNameColumn)
.Columns.Insert(4, DueDateColumn)
.Columns.Insert(5, VendorPriceColumn)
.Columns.Insert(6, TotalItemsToBuyColumn)
.Columns.Insert(7, TotalItemsCostColumn)
.Columns.Insert(8, ItemsIDColumn)
.Columns.Insert(9, ItemsEDPNOColumn)
For Each item As RecommendedBuyItem In oWorkingItems
.Rows.Add(item.DataGridViewRow)
Next
End With
End Sub
Private Sub SetStatusStrip()
oCountlabel.Text = "Items: " & oWorkingItems.Count
oTotallabel.Text = "Total: " & WorkingTotalPurchase
oPOlabel.Text = "PO: " & oPONumber & " " & oPODate
oEmailLabel.Text = "Last Email: " & oLastEmailDate
With oStatusStrip
.Name = "StatusStrip"
.Dock = DockStyle.Bottom
.Items.Insert(0, oCountlabel)
.Items.Insert(1, New ToolStripSeparator)
.Items.Insert(2, oTotallabel)
.Items.Insert(3, New ToolStripSeparator)
.Items.Insert(4, oPOlabel)
.Items.Insert(5, New ToolStripSeparator)
.Items.Insert(6, oEmailLabel)
.Items.Insert(7, New ToolStripSeparator)
.Items.Insert(8, oInfolabel)
End With
End Sub
Private Sub SetVendor()
If oVendorNumber = User.ID Then
oVendor = New ItemVendor(User)
Else
Using conn As New SqlConnection(SELECTVENDORSDB)
Dim QueryString As String = "SELECT * FROM dbo.VENDORDFROM WHERE VENDORNO = '" & oVendorNumber & "'"
Dim cmd As New SqlCommand(QueryString, conn)
Try
conn.Open()
Dim r As SqlDataReader = cmd.ExecuteReader
If r.HasRows Then
r.Read()
oVendor = New ItemVendor(r)
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error getting vendor info")
End Try
End Using
End If
End Sub
Private Sub SetTempPONumberDate()
If oVendorNumber = User.ID Then
oPONumber = "SHORTLIST"
Return
End If
Dim tmpPO As Integer = 0
For Each i As RecommendedBuyItem In oWorkingItems
If i.TempPONumber <> "" Then
If CInt(i.TempPONumber) > tmpPO Then
tmpPO = CInt(i.TempPONumber)
oPONumber = i.TempPONumber
oPODate = i.TempPODateTime
End If
End If
Next
End Sub
Private Sub SetLastEmailDate()
If oVendorNumber = User.ID Then
oLastEmailDate = ""
Return
End If
For Each i As RecommendedBuyItem In oWorkingItems
If i.LastEmailDate <> "" Then oLastEmailDate = i.LastEmailDate
Next
End Sub
Private Sub SetPODatesButton_Click()
Dim aDate As String = oDueDatePicker.Value.ToString("M/d/yy")
For Each r As DataGridViewRow In oDataViewGrid.Rows
Dim c As DataGridViewCell = r.Cells.Item("cDueDate")
Dim tmpValue As String = ""
If Trim(c.Value.ToString) = "" Then
c.Value = aDate
oWorkingItems.Find(RecommendedBuyItem.FindPredicateByItemId(r.Cells("cItemID").Value)).UpdateRecDateInfo(aDate)
End If
Next
End Sub
Private Sub ValidateVendorItemNumber(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs)
Dim anItem As RecommendedBuyItem = oWorkingItems.Find(RecommendedBuyItem.FindPredicateByItemId(oDataViewGrid.Rows(e.RowIndex).Cells("cItemID").Value))
Dim ErrorText As String = ""
Dim NewValue As String = ""
NewValue = e.FormattedValue.ToString()
If NewValue.Length > 20 Then
ErrorText = "Vendor Item Number cannot be more than 20 characters long"
oDataViewGrid.Rows(e.RowIndex).ErrorText = ErrorText
MsgBox(ErrorText, MsgBoxStyle.Exclamation, "Data Error")
e.Cancel = True
Else
anItem.UpdateVendorItemNumber(NewValue)
End If
End Sub
Private Sub ValidateDescription(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs)
Dim anItem As RecommendedBuyItem = oWorkingItems.Find(RecommendedBuyItem.FindPredicateByItemId(oDataViewGrid.Rows(e.RowIndex).Cells("cItemID").Value))
Dim ErrorText As String = ""
Dim NewValue As String = ""
NewValue = e.FormattedValue.ToString()
If (String.IsNullOrEmpty(NewValue)) Then
ErrorText = "Description must not be empty"
oDataViewGrid.Rows(e.RowIndex).ErrorText = ErrorText
MsgBox(ErrorText, MsgBoxStyle.Exclamation, "Data Error")
e.Cancel = True
ElseIf NewValue.Length > 70 Then
ErrorText = "Description cannot be more than 70 characters long"
oDataViewGrid.Rows(e.RowIndex).ErrorText = ErrorText
MsgBox(ErrorText, MsgBoxStyle.Exclamation, "Data Error")
e.Cancel = True
Else
anItem.UpdateDescription(NewValue)
End If
End Sub
Private Sub ValidateDueDate(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs)
If oVendorNumber = User.ID Then Return
Dim anItem As RecommendedBuyItem = oWorkingItems.Find(RecommendedBuyItem.FindPredicateByItemId(oDataViewGrid.Rows(e.RowIndex).Cells("cItemID").Value))
Dim ErrorText As String = ""
Dim NewValue As String = ""
NewValue = e.FormattedValue.ToString()
If Not (String.IsNullOrEmpty(NewValue)) Then
If IsDate(NewValue) Then
Dim ss As DateTime = CDate(NewValue)
If ss.Ticks < Now.Ticks Then
ErrorText = "Due date must not be in the past."
oDataViewGrid.Rows(e.RowIndex).ErrorText = ErrorText
MsgBox(ErrorText, MsgBoxStyle.Exclamation, "Date Format Error")
e.Cancel = True
ElseIf NewValue <> anItem.RECDATE Then
anItem.UpdateRecDateInfo(NewValue)
End If
Else
ErrorText = NewValue & " is not a date"
oDataViewGrid.Rows(e.RowIndex).ErrorText = ErrorText
MsgBox(ErrorText, MsgBoxStyle.Exclamation, "Date Format Error")
e.Cancel = True
End If
Else
anItem.UpdateRecDateInfo(NewValue)
End If
End Sub
Private Sub ValidateCost(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs)
Dim anItemRow As DataGridViewRow = oDataViewGrid.Rows(e.RowIndex)
Dim anItem As RecommendedBuyItem = oWorkingItems.Find(RecommendedBuyItem.FindPredicateByItemId(anItemRow.Cells("cItemID").Value))
Dim ErrorText As String = ""
Dim NewValue As String = ""
NewValue = e.FormattedValue.ToString()
If (String.IsNullOrEmpty(NewValue)) Then
ErrorText = "Cost must not be empty"
oDataViewGrid.Rows(e.RowIndex).ErrorText = ErrorText
MsgBox(ErrorText, MsgBoxStyle.Exclamation, "Data Error")
e.Cancel = True
ElseIf Not (IsNumeric(NewValue.ToString)) Then
ErrorText = "Cost must be a number"
oDataViewGrid.Rows(e.RowIndex).ErrorText = ErrorText
MsgBox(ErrorText, MsgBoxStyle.Exclamation, "Data Error")
e.Cancel = True
Else ' new value is number
Dim oldcost As Decimal = anItem.VendorCost
Dim newcost As Decimal = CDec(NewValue)
If oldcost = newcost Then
Debug.Print("same cost")
Return
End If
If newcost = 0 Then
If MsgBoxResult.Yes = MsgBox("Okay to set price of 0 dollars for the item?", MsgBoxStyle.YesNoCancel, "Zero Cost Confirm") Then
UpdateCost(NewValue, anItem, anItemRow)
Else
ErrorText = "Item Zero Cost Error"
oDataViewGrid.Rows(e.RowIndex).ErrorText = ErrorText
e.Cancel = True
End If
End If
If newcost > oldcost Then
Debug.Print("Validating Cost. Cost higher. New: " & newcost & " old: " & oldcost)
Dim increase As Decimal = 0
If oldcost > 0 Then
increase = ((newcost - oldcost) / oldcost) * 100
Else
increase = 99999
End If
Debug.Print("Cost percent increase: " & increase.ToString("f2"))
If increase >= 2 Then
'Dim ApprovalWindow As New ManagerApprovalWindow
'ApprovalWindow.InfoLabel.Text =
' "Old Cost: " & oldcost & vbCrLf & "New Cost: " & newcost & vbCrLf & _
' "Increase: " & increase.ToString("f2") & "%" & vbCrLf & vbCrLf & _
' "Cost Increases equal or over 2% requiere manager approval." & vbCrLf & vbCrLf & _
' "Please enter manager password below to continue." & vbCrLf & _
' "Or click Cancel to abort change."
Dim s As String =
"Old Cost: " & oldcost & vbCrLf & "New Cost: " & newcost & vbCrLf & _
"Increase: " & increase.ToString("f2") & "%" & vbCrLf & vbCrLf & _
"You will need manager approval to exit vendor if any item with an increase of over 2% percent remains in the PO."
MsgBox(s, MsgBoxStyle.Exclamation, "PO Item Cost Increase Alert")
oInfolabel.Text = "At least one item with over 2% cost increase in PO."
UpdateCost(NewValue, anItem, anItemRow)
'If DialogResult.Yes = ApprovalWindow.ShowDialog Then
' LogThis("ITMCOSTAPPRV", "Manager approved item cost increase from " & oldcost & " to " & newcost, anItem.ITEMID)
' UpdateCost(NewValue, anItem, anItemRow)
'Else
' ErrorText = "Cost increases of 2% or more require manager approval"
' oDataViewGrid.Rows(e.RowIndex).ErrorText = ErrorText
' e.Cancel = True
'End If
Else ' increase is less than 2%
Debug.Print("new cost lower then 2%")
UpdateCost(NewValue, anItem, anItemRow)
End If
Else ' newcost is lower than old cost
UpdateCost(NewValue, anItem, anItemRow)
End If
End If
End Sub
Private Sub UpdateCost(ByVal NewValue As Decimal, ByVal item As RecommendedBuyItem, ByVal itemRow As DataGridViewRow)
item.UpdateVendorCost(NewValue)
itemRow.Cells("cTotalItemsCost").Value = item.TotalVendorCost
oInitialItems.Find(RecommendedBuyItem.FindPredicateByItemId(item.ITEMID)).UpdateVendorCost(NewValue, False)
Debug.Print("Initial: " & InitialTotalPurchase & " Working: " & WorkingTotalPurchase)
oTotallabel.Text = "Total: " & WorkingTotalPurchase
End Sub
Private Sub ValidateTotalToBuy(ByVal sender As Object, ByVal e As DataGridViewCellValidatingEventArgs)
Dim anItemRow As DataGridViewRow = oDataViewGrid.Rows(e.RowIndex)
Dim anItem As RecommendedBuyItem = oWorkingItems.Find(RecommendedBuyItem.FindPredicateByItemId(anItemRow.Cells("cItemID").Value))
Dim ErrorText As String = ""
Dim NewValue As String = ""
NewValue = e.FormattedValue.ToString()
If (String.IsNullOrEmpty(NewValue)) Then
ErrorText = "Quantity to buy must not be empty"
oDataViewGrid.Rows(e.RowIndex).ErrorText = ErrorText
MsgBox(ErrorText, MsgBoxStyle.Exclamation, "Data Error")
e.Cancel = True
ElseIf Not (IsNumeric(NewValue.ToString)) Then
ErrorText = "Quantity must be a number"
oDataViewGrid.Rows(e.RowIndex).ErrorText = ErrorText
MsgBox(ErrorText, MsgBoxStyle.Exclamation, "Data Error")
e.Cancel = True
Else 'Quantity is a number
Dim oldqty As Integer = anItem.TotalQtyToBuy
Dim newqty As Integer = CInt(NewValue)
If oldqty = newqty Then Return
If newqty = 0 Then
MoveToOtherVendor(anItem.CreateLeftOverQuantityItem(oldqty, User.ID))
anItemRow.Cells.Item("cFinalNumberToBuy").Value = 0
anItemRow.Cells.Item("cTotalItemsCost").Value = 0
anItem.UpdatePOQtyToBuy("0", True)
Exit Sub
End If
If newqty < oldqty Then
Dim difference As Integer = oldqty - newqty
MoveToOtherVendor(anItem.CreateLeftOverQuantityItem(difference, User.ID))
anItem.UpdatePOQtyToBuy(newqty)
anItemRow.Cells("cTotalItemsCost").Value = anItem.TotalVendorCost
CheckTotalCostDifference()
Else ' new qty is greater than old qty
Dim QtyFromOtherTab As Integer = ExtraQuantityFromOtherTab(anItem, newqty - oldqty)
Debug.Print("Qty from other tab: " & QtyFromOtherTab)
If QtyFromOtherTab > 0 Then
oInitialItems.Find(RecommendedBuyItem.FindPredicateByItemId(anItem.ITEMID)).UpdatePOQtyToBuy(anItem.TotalQtyToBuy + QtyFromOtherTab, False)
End If
anItem.UpdatePOQtyToBuy(newqty)
anItemRow.Cells("cTotalItemsCost").Value = anItem.TotalVendorCost
CheckTotalCostDifference()
End If
oTotallabel.Text = "Total: " & WorkingTotalPurchase
End If
End Sub
Private Sub MoveToOtherVendor(ByVal anItem As RecommendedBuyItem)
Dim OtherVendorItemsList As VendorItems = UserVendorItemsList.Find(VendorItems.FindPredicateByVendorId(anItem.Vendor))
If IsNothing(OtherVendorItemsList) Then
Debug.Print("Destination Vendor " & anItem.Vendor & " not found")
OtherVendorItemsList = New VendorItems(anItem.Vendor)
RaiseEvent VendorAdded(OtherVendorItemsList)
Else
Debug.Print("Destination Vendor " & anItem.Vendor & " found")
Dim tmpItem As RecommendedBuyItem = Nothing
Try
tmpItem = OtherVendorItemsList.WorkingItems.Find(RecommendedBuyItem.FindPredicateByEDPNO(anItem.EDPNO))
Catch ex As Exception
End Try
If IsNothing(tmpItem) Then
OtherVendorItemsList.AddItem(anItem)
Else
OtherVendorItemsList.DeleteItem(tmpItem)
OtherVendorItemsList.AddItem(anItem.MergeItem(tmpItem))
End If
End If
End Sub
Private Sub oDataViewGrid_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles oDataViewGrid.CellEndEdit
oDataViewGrid.Rows(e.RowIndex).ErrorText = String.Empty
End Sub
Private Sub oDataViewGrid_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles oDataViewGrid.CellMouseClick
oDataViewGrid.ClearSelection()
If e.RowIndex >= 0 And e.ColumnIndex >= 0 And e.Button = MouseButtons.Right Then
oDataViewGrid.Rows(e.RowIndex).Selected = True
Dim r As Rectangle = oDataViewGrid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True)
oPopUpMenu.Show(sender, r.Left + e.X, r.Top + e.Y)
End If
End Sub
Private Sub oDataViewGrid_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles oDataViewGrid.CellValidating
Select Case oDataViewGrid.Columns(e.ColumnIndex).HeaderText
Case "Vendor Item Number"
ValidateVendorItemNumber(sender, e)
Case "Description"
ValidateDescription(sender, e)
Case "Due Date"
ValidateDueDate(sender, e)
Case "Cost"
ValidateCost(sender, e)
Case "Total to Buy"
ValidateTotalToBuy(sender, e)
Case Else
Return
End Select
End Sub
Private Sub oDataViewGrid_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles oDataViewGrid.Validating
For Each row As DataGridViewRow In oDataViewGrid.Rows
If row.Cells.Item("cFinalNumberToBuy").Value = 0 Then
Dim itmid As String = row.Cells.Item("cItemID").Value
oDataViewGrid.Rows.Remove(row)
oInitialItems.RemoveAll(RecommendedBuyItem.FindPredicateByItemId(itmid))
oWorkingItems.RemoveAll(RecommendedBuyItem.FindPredicateByItemId(itmid))
End If
Next
End Sub
Private Sub oMoveToShortList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles oMoveToShortList.Click
Dim anItem As RecommendedBuyItem = oWorkingItems.Find(RecommendedBuyItem.FindPredicateByItemId(oDataViewGrid.SelectedRows.Item(0).Cells("cItemID").Value))
anItem.UpdateVendor(User.ID, True)
MoveToOtherVendor(anItem)
DeleteItem(anItem)