/
PO.cs
2962 lines (2805 loc) · 114 KB
/
PO.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.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Collections.Generic;
namespace EM
{
/// <summary>
/// Summary description for PO.
/// </summary>
///
public class PO : KeyBasedForm,
HelperFunctions.DataGridClientInterface,
IAllowComboBoxUpdates
{
private System.Windows.Forms.Label label1;
private AutoCompleteComboBox m_statusCombo;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private AutoCompleteTextBox m_dateEdt;
private System.Windows.Forms.Button m_dateBtn;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
// My variables
private AutoCompleteComboBox m_shipCodeCombo;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private AutoCompleteTextBox m_fobEdt;
private System.Windows.Forms.Label label6;
private AutoCompleteComboBox m_termsCombo;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private AutoCompleteTextBox m_cancelDateEdt;
private System.Windows.Forms.Button m_cancelDateBtn;
private AutoCompleteTextBox m_commentEdt;
private EM.EMDataSet m_emDataSet = new EM.EMDataSet();
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Label label13;
private AutoCompleteTextBox m_totalCostEdit;
private AutoCompleteTextBox m_totalCostUSEdit;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.Label label15;
private AutoCompleteComboBox customerCombo;
private AutoCompleteComboBox millCombo;
private System.Windows.Forms.Button removeItemBtn;
private System.Windows.Forms.Button moveUpBtn;
private System.Windows.Forms.Button moveDownBtn;
private System.Windows.Forms.Button printPOBtn;
private System.Windows.Forms.Button printAckBtn;
//private System.Windows.Forms.DataGrid poGrid;
private System.Windows.Forms.Label label9;
private AutoCompleteComboBox umCombo;
public AutoCompleteTextBox m_purchaseEdt;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.GroupBox groupBox5;
private System.Windows.Forms.Button addNewMillBtn;
private System.Windows.Forms.Button addNewMillLocationBtn;
private System.Windows.Forms.Button addNewCustomerBtn;
private System.Windows.Forms.Button addNewCustomerLocationBtn;
private System.Windows.Forms.TabPage commentPage;
private System.Windows.Forms.Label labelMillConfirmation;
private EM.AutoCompleteTextBox millConfirmationNumberEdit;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Button insertRowBtn;
private System.Windows.Forms.Label labelAckDate;
private EM.AutoCompleteTextBox ackDateEdt;
private System.Windows.Forms.Button ackDateBtn;
private System.Windows.Forms.Label label26;
private System.Windows.Forms.Label label27;
private EM.AutoCompleteTextBox exchangeDateEdt;
private System.Windows.Forms.Button exchangeDateBtn;
private System.Windows.Forms.ComboBox currencyCombo;
private System.Windows.Forms.TabPage purchaseOrderPage;
private System.Windows.Forms.TabPage weightPage;
private System.Windows.Forms.TabPage containerTrackingPage;
private System.Windows.Forms.Panel containerTrackingPanel;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.GroupBox containerItemDetailsGroupBox;
private System.Windows.Forms.Panel containerItemDetailsPanel;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.Button refreshContainerItemtn;
private System.Windows.Forms.Button goToContainerBtn;
private System.Windows.Forms.TabControl m_tabControl;
private EM.AutoCompleteComboBox customerLocationCombo;
private EM.AutoCompleteComboBox millLocationCombo;
private EM.AutoCompleteTextBox millCountryEdt;
private EM.AutoCompleteTextBox millAddressEdt;
private EM.AutoCompleteTextBox customerCountryEdt;
private EM.AutoCompleteTextBox customerAddressEdt;
private System.Windows.Forms.CheckBox surchargeCheck;
private System.Windows.Forms.Button showGradeTotalsBtn;
private System.Windows.Forms.Label label28;
private EM.AutoCompleteTextBox invoiceEdt;
private System.Windows.Forms.Label revisedAckLabel;
private EM.AutoCompleteTextBox ackRevisedDateEdt;
private System.Windows.Forms.Button ackRevisedDateBtn;
private System.Windows.Forms.Label label30;
private System.Windows.Forms.Button invoiceDateBtn;
private System.Windows.Forms.GroupBox invoiceGroup;
private EM.AutoCompleteTextBox invoiceDateEdt;
private System.Windows.Forms.Label label31;
private System.Windows.Forms.Label statusLabel;
private GroupBox groupBox1;
private GroupBox groupBox2;
private AutoCompleteComboBox custContactCombo;
private AutoCompleteComboBox millContactCombo;
private Button addMillContact;
private Button addCustomerContact;
private Button changeBtn;
private CheckBox btnApplyConfirmationToEntirePO;
private TabPage millConfirmationPage;
private AutoCompleteTextBox m_exchangeRateEdt;
public override void ClearDataSet()
{
using (new TurnOffConstraints(m_emDataSet))
{
EMDataSet.POHeaderTblRow row = GetHeaderRow();
foreach (string s in fieldsToRemember)
{
oldValues[s] = row[s];
}
m_emDataSet.BOLItemTbl.Clear();
m_emDataSet.BOLTbl.Clear();
m_emDataSet.ContBundleTbl.Clear();
m_emDataSet.ContainerTbl.Clear();
m_emDataSet.POItemTbl.Clear();
m_emDataSet.POHeaderTbl.Clear();
}
}
public new EMDataSet.POHeaderTblRow GetHeaderRow()
{
return (EMDataSet.POHeaderTblRow)base.GetHeaderRow();
}
public bool AllowComboBoxUpdates
{
get
{
return allowComboBoxUpdates;
}
set
{
allowComboBoxUpdates = value;
}
}
public object[] m_textBoxes;
public string[] m_fieldNames;
public string[] m_dateFieldNames;
public AutoCompleteTextBox[] m_dateBoxes;
System.Collections.Hashtable oldValues = new Hashtable();
string[] fieldsToRemember = new string[]{"MillID","MillLocationID","CustomerID",
"CustomerLocationID"};
public override void InitializeDataRow(DataRow rowIn)
{
EMDataSet.POHeaderTblRow row = (EMDataSet.POHeaderTblRow)rowIn;
EMDataSet.POHeaderTblRow oldRow = GetHeaderRow();
foreach (string s in fieldsToRemember)
{
row[s] = oldValues[s];
}
row.PODate = DateTime.Today;
row.Terms = "Net 30";
row.Status = "Open";
row.MillConfirmationAppliesToEntirePO = 1;
}
public override bool IsChanged()
{
DataTable header = GetHeaderTable().GetChanges();
DataTable child = m_emDataSet.POItemTbl.GetChanges();
if (header != null)
return true;
if (child != null)
return true;
return false;
}
private void OnDateLeave(object sender, System.EventArgs e)
{
AutoCompleteTextBox dateBox = null;
string dateField="";
for (int i=0;i<this.m_dateBoxes.Length;i++)
{
if (sender == m_dateBoxes[i])
{
dateBox = m_dateBoxes[i];
dateField = m_dateFieldNames[i];
break;
}
}
Debug.Assert(dateBox != null);
EMDataSet.POHeaderTblRow row = GetHeaderRow();
try
{
if (dateBox.Text == "")
row[dateField] = DBNull.Value;
else
row[dateField] = dateBox.Text;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
if (row.IsNull(dateField))
{
dateBox.Text = "";
}
else
{
dateBox.Text = HelperFunctions.ToDateText(
(DateTime)row[dateField]);
}
}
public override string[] GetSortOrder()
{
return new string[]{"Status","PODate","PONumber"};
}
public override bool IsDeleteAllowed()
{
if (GetAllDetailRows().Length != 0)
{
MessageBox.Show("Delete of the purchase order is not allowed " +
"unless all items in the purchase order have been deleted",
"Can't delete");
return false;
}
return true;
}
public void MoveToNewCell(DataGrid grid)
{
DataGridCell cell = grid.CurrentCell;
int row = cell.RowNumber;
int column = cell.ColumnNumber;
if (column == 0)
column =1;
else
column = 0;
grid.CurrentCell = new DataGridCell(row,column);
}
public void OnGridItemClicked(int selectedRow)
{
try
{
FromControls();
EMDataSet.POHeaderTblRow headerRow = GetHeaderRow();
if (headerRow.IsCustomerIDNull())
{
throw new Exception("Customer must be chosen before you can use the item selection window");
}
EMDataSet.POItemTblRow rowOut = HelperFunctions.GetRowFromSeqNumber(m_emDataSet.POItemTbl,
selectedRow+1);
if ((rowOut != null) && (!rowOut.IsAcknowledgeDateNull()))
{
MessageBox.Show("Item can not be changed since it has already been acknowledged.\n" +
"Remove acknowledgement date first.","Can't change acknowledged item",
MessageBoxButtons.OK,MessageBoxIcon.Stop);
return;
}
int count;
string finish;
string treatment;
EMDataSet.ItemTblRow rowIn = ChooseItem.CreateNewRow(headerRow.CustomerID
,out count,out finish,out treatment);
if (rowIn == null)
return;
using (new OpenConnection(EM.IsWrite.No,AdapterHelper.Connection))
AdapterHelper.FillItem(m_emDataSet,rowIn.ItemID);
// The first row is a description only row, if there is
// more than 1 row. If there is more than 1 row, then there
// will actually be an additional row (because of this description
// only row)
if (count != 1)
++count;
for (int z=0;z<count;z++)
{
if (rowIn.IsItemNameNull())
poGrid.SetItem(new QuickGrid.Index(selectedRow+z,1),"");
else
poGrid.SetItem(new QuickGrid.Index(selectedRow+z,1),rowIn.ItemName);
poGrid.SetItem(new QuickGrid.Index(selectedRow+z,0),finish);
poGrid.SetItem(new QuickGrid.Index(selectedRow+z,2),treatment);
if (z==0)
{
if (rowIn.IsItemDescNull())
poGrid.SetItem(
new QuickGrid.Index(selectedRow+z,3),"");
else
poGrid.SetItem(
new QuickGrid.Index(selectedRow+z,3),rowIn.ItemDesc);
}
//for (int i=4;i<poGrid.VisibleColumns;i++)
//{
// poGrid.SetItem(new QuickGrid.Index(selectedRow+z,i),"");
// }
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
bool DoesItemNameExist()
{
foreach (EMDataSet.POItemTblRow childRow in m_emDataSet.POItemTbl.Rows)
{
if (!DataInterface.IsRowAlive(childRow))
{
continue;
}
if (!childRow.IsItemIDNull())
return true;
}
return false;
}
public override bool IsValid()
{
EMDataSet.POHeaderTblRow row = GetHeaderRow();
if (row.IsPONumberNull() || row.PONumber == "")
{
MessageBox.Show("Save aborted. PO Number must be completed");
return false;
}
bool doesItemNameExist = DoesItemNameExist();
if (!doesItemNameExist)
return true;
string[] requiredFields =
{"PODate","PONumber","Terms","ShipCode","FOB"};
string[] friendlyTitles =
{ "Purchase order date","PONumber","Terms","Ship Via","FOB"};
string errorMessage;
if (!HelperFunctions.AreRequiredFieldsFilledIn(row,
requiredFields,friendlyTitles,
out errorMessage))
return false;
// Double check that both the mill confirmation number and the mill
// confirmation date are both filled out.
bool millConfirmationNumberExists = false;
bool millConfirmationDateExists = false;
if (row.IsMillConfirmationAppliesToEntirePONull() ||
row.MillConfirmationAppliesToEntirePO == 1)
{
millConfirmationNumberExists = !row.IsMillConfirmationNumberNull() &&
row.MillConfirmationNumber != "";
millConfirmationDateExists= !row.IsMillAcknowledgeDateNull();
if (millConfirmationNumberExists != millConfirmationDateExists)
{
MessageBox.Show("Save Aborted: Error, cannot commit changes: " +
"If Mill Confirmation Number exists then " +
"Mill Confirmation Date must also exist, and vice-versa");
return false;
}
}
else
{
foreach (EMDataSet.POItemTblRow itemRow in row.GetPOItemTblRows())
{
millConfirmationNumberExists = !itemRow.IsMillConfirmationNumberNull() &&
itemRow.MillConfirmationNumber != "";
millConfirmationDateExists = !itemRow.IsMillAcknowledgeDateNull();
if (millConfirmationNumberExists != millConfirmationDateExists)
{
MessageBox.Show("Save Aborted: Error, cannot commit changes: " +
"If Mill Confirmation Number exists then " +
"Mill Confirmation Date must also exist, and vice-versa");
return false;
}
}
}
return true;
}
public string[] DecimalFieldsToBeMonitored()
{
return new string[]{"CustAmount"};
}
public void NewGridTotal(string fieldName,decimal total)
{
NewGridTotal(total);
}
public void NewGridTotal(decimal total)
{
EMDataSet.POHeaderTblRow row = GetHeaderRow();
string otherTotal = total.ToString();
row.OtherTotal = total;
if (row.IsExchangeRateNull())
{
row.USTotal = row.OtherTotal;
m_totalCostUSEdit.Text = otherTotal;
}
else
{
row.USTotal = row.OtherTotal * row.ExchangeRate;
}
UpdateCurrencyControls();
}
public void FromSelectedGrid()
{
FromGrid(m_tabControl.SelectedIndex);
}
public void FromGrid(int index)
{
if (index == 0)
{
HelperFunctions.FromGrid(GetHeaderRow().POID,
m_emDataSet,poGrid,true);
}
else if (index == 1){}
else if (index == 2){}
else if (index == 3)
{
HelperFunctions.FromGrid(GetHeaderRow().POID, m_emDataSet, millConfirmationGrid,
false);
}
else
{
Debug.Assert(false);
}
FixUMButNoUpdates(umCombo.Text);
}
public override void FromControls()
{
// Depending on the selected tab, we commit changes from the particular grids
FromSelectedGrid();
EMDataSet.POHeaderTblRow row = GetHeaderRow();
for (int i=0;i<m_textBoxes.Length;i++)
{
try
{
row[m_fieldNames[i]] = GetText(m_textBoxes[i]);
}
catch (Exception e)
{
throw new Exception("Could not parse field:" + m_fieldNames[i] + "\n" +
e.Message);
}
}
try
{
if (m_exchangeRateEdt.Text.Length == 0)
row["ExchangeRate"] = 1;
else
row["ExchangeRate"] = m_exchangeRateEdt.Text;
}
catch( Exception e)
{
throw new Exception("Could not parse field: Exchange Rate" + e.Message);
}
for (int i=0;i<m_dateBoxes.Length;i++)
{
if (m_dateBoxes[i].Text == "")
row[m_dateFieldNames[i]] = DBNull.Value;
else
{
try
{
row[m_dateFieldNames[i]] =
System.DateTime.Parse(m_dateBoxes[i].Text);
}
catch(Exception ex)
{
string errorMessage = "Didn't understand the text for field \"" +
this.m_dateFieldNames[i] +
"\"\nOriginal Error: " + ex.Message;
Exception newEx = new Exception(errorMessage,ex);
throw newEx;
}
}
}
// First update the total:
decimal total = 0;
foreach (EMDataSet.POItemTblRow detailRow in GetAllDetailRows())
{
if (!detailRow.IsCustAmountNull() &&
detailRow.IsCancelDateNull())
total += detailRow.CustAmount;
}
row.OtherTotal = total;
decimal exchange;
if (row.IsExchangeRateNull())
exchange = 1;
else
exchange = row.ExchangeRate;
row.USTotal = total * exchange;
if (row.IsSurchargesInEffectNull())
{
if (this.surchargeCheck.Checked)
row.SurchargesInEffect = surchargeCheck.Checked;
}
else
{
row.SurchargesInEffect = this.surchargeCheck.Checked;
}
if (this.btnApplyConfirmationToEntirePO.Checked == false)
row.MillConfirmationAppliesToEntirePO = 0;
else
{
row.MillConfirmationAppliesToEntirePO = 1;
}
}
public static void CompareForValidaty(EMDataSet unsavedDataSet,EMDataSet currentDataSet)
{
DataInterface.CheckForChanges("POItemNumber","Sequence Number","SeqNumber",
"SeqNumber",currentDataSet.POItemTbl,
unsavedDataSet.POItemTbl);
}
public override void CommitTablesToDatabase()
{
using (DataInterface.CreateLockFile("po.lock"))
using (new OpenConnection(IsWrite.Yes,AdapterHelper.Connection))
{
EMDataSet tempDataSet = new EMDataSet();
using (new TurnOffConstraints(tempDataSet))
{
AdapterHelper.FillCurrency(tempDataSet);
AdapterHelper.FillPOHeader(tempDataSet,base.CurrentKey);
AdapterHelper.FillPOItem(tempDataSet,base.CurrentKey);
AdapterHelper.FillOutConstraints(tempDataSet);
}
if (!IsEmptyTable())
{
EMDataSet.POHeaderTblRow row = GetHeaderRow();
if (DataInterface.IsRowAlive(row))
CompareForValidaty(m_emDataSet,tempDataSet);
}
AdapterHelper.CommitPOChanges(m_emDataSet);
}
}
void UpdateCurrencyControls()
{
EMDataSet.POHeaderTblRow row = GetHeaderRow();
if (row.IsExchangeRateNull())
m_exchangeRateEdt.Text = "";
else
m_exchangeRateEdt.Text = row.ExchangeRate.ToString();
if (row.IsOtherTotalNull())
m_totalCostEdit.Text = "";
else
m_totalCostEdit.Text = row.OtherTotal.ToString("N2");
if (row.IsUSTotalNull())
m_totalCostUSEdit.Text = "";
else
m_totalCostUSEdit.Text = row.USTotal.ToString("N2");
}
private void OnCurrencyChanged(object sender, System.EventArgs e)
{
if (!allowComboBoxUpdates)
return;
object o = currencyCombo.SelectedItem;
TaggedItem tagged = (TaggedItem)o;
EMDataSet.POHeaderTblRow row = GetHeaderRow();
row.CurrencyID = tagged.key;
}
public override void UpdateControls()
{
using (new StopComboBoxUpdates(this))
{
UpdateGrid();
EMDataSet.POHeaderTblRow row = GetHeaderRow();
for (int i=0;i<m_textBoxes.Length;i++)
{
SetText(m_textBoxes[i],row[m_fieldNames[i]].ToString());
}
for (int i=0;i<m_dateBoxes.Length;i++)
{
object field = row[m_dateFieldNames[i]];
if (field is DateTime)
{
m_dateBoxes[i].Text = HelperFunctions.ToDateText((DateTime)field);
}
else
m_dateBoxes[i].Text = "";
}
if (!row.IsCommentsNull() && row.Comments != "")
{
commentPage.Text = "Comments (not empty)";
}
else
commentPage.Text = "Comments (empty)";
DataRow currencyRow = null;
if (!row.IsCurrencyIDNull())
currencyRow = m_emDataSet.CurrencyTbl.FindByCurrencyID(row.CurrencyID);
DataInterface.UpdateComboBox(m_emDataSet.CurrencyTbl.DefaultView,
"CurrencyID","CurrencyName",currencyCombo,currencyRow);
UpdateCurrencyControls();
UpdateMillCombo();
UpdateCustomerCombo();
UpdateEnabled();
this.surchargeCheck.Checked = false;
if (!row.IsSurchargesInEffectNull())
{
if (row.SurchargesInEffect)
this.surchargeCheck.Checked = true;
}
this.btnApplyConfirmationToEntirePO.Checked =
row.MillConfirmationAppliesToEntirePO != 0;
bool makeConfirmationVisible = btnApplyConfirmationToEntirePO.Checked;
labelMillConfirmation.Visible = makeConfirmationVisible;
millConfirmationNumberEdit.Visible = makeConfirmationVisible;
labelAckDate.Visible = makeConfirmationVisible;
ackDateEdt.Visible = makeConfirmationVisible;
ackDateBtn.Visible = makeConfirmationVisible;
//invoiceGroup.Visible = makeConfirmationVisible;
revisedAckLabel.Visible = makeConfirmationVisible;
ackRevisedDateEdt.Visible = makeConfirmationVisible;
ackRevisedDateBtn.Visible = makeConfirmationVisible;
}
}
object GetContainerCheckField(DataRow rowIn,bool isMetric,string field)
{
EMDataSet.POItemTblRow row = (EMDataSet.POItemTblRow)rowIn;
string[] itemFields = {"SeqNumber","POItemNumber","Length","SizeOfItem","Qty"};
if (Array.IndexOf(itemFields,field) != -1) // found
{
return row[field];
}
decimal bundleWeight = 0;
decimal bolWeight = 0;
EMDataSet.ContBundleTblRow[] bundles = row.GetContBundleTblRows();
foreach (EMDataSet.ContBundleTblRow bundleRow in bundles)
{
decimal currentBundleWeight = 0;
if (isMetric)
{
if (!bundleRow.IsMetricShipQtyNull())
currentBundleWeight += bundleRow.MetricShipQty;
}
else
{
if (!bundleRow.IsEnglishShipQtyNull())
currentBundleWeight += bundleRow.EnglishShipQty;
}
if (DataInterface.IsContainerItemDone(bundleRow))
{
bolWeight += currentBundleWeight;
}
else
{
if (!bundleRow.ContainerTblRow.IsStatusNull() &&
bundleRow.ContainerTblRow.Status == "Closed")
bolWeight += currentBundleWeight;
}
bundleWeight += currentBundleWeight;
}
if (field == "ContainerWeight")
return bundleWeight;
if (field == "BOLWeight")
return bolWeight;
if (field == "CancelDate")
return row["CancelDate"];
if (field == "PercentPickedUp")
{
if (row.IsQtyNull())
return DBNull.Value;
if (row.Qty == 0)
return DBNull.Value;
decimal qty = row.Qty;
decimal deviation = (bolWeight/qty) * 100;
return deviation;
}
if (field == "ItemName")
{
if (row.IsItemIDNull())
return DBNull.Value;
return row.ItemTblRow.ItemName;
}
throw new Exception("BUG Unknown field");
}
public object GetPOItemFieldForGrid(DataRow sourceRow,
bool isMetric,string fieldName)
{
if (fieldName == "Finish")
{
EMDataSet.POItemTblRow row = (EMDataSet.POItemTblRow)sourceRow;
if (row.IsFinishIDNull())
return "";
string finish = HelperFunctions.GetFinishType("Finish",row.FinishID);
return finish;
}
if (fieldName == "Treatment")
{
EMDataSet.POItemTblRow row = (EMDataSet.POItemTblRow)sourceRow;
if (row.IsTreatmentIDNull())
return "";
string finish = HelperFunctions.GetFinishType("Treatment",row.TreatmentID);
return finish;
}
if (fieldName == "ItemName")
{
EMDataSet.POItemTblRow row = (EMDataSet.POItemTblRow)sourceRow;
// For the mill confirmation - only show the combined item name (grade + finish)
if (m_tabControl.SelectedIndex == 3)
return HelperFunctions.GetItemName(row);
if (row.IsItemIDNull())
return "";
string name = row.ItemTblRow.ItemName;
return name;
}
return sourceRow[fieldName];
}
void UpdateGrid()
{
using (new StopComboBoxUpdates(this))
{
// Disable remove, moveup, and movedown for the ack grid
int selectedIndex = m_tabControl.SelectedIndex;
bool enableDelete = (selectedIndex == 0);
bool isEmptyTable = base.IsEmptyTable();
enableDelete = enableDelete & !isEmptyTable;
insertRowBtn.Enabled = enableDelete;
moveUpBtn.Enabled = enableDelete;
moveDownBtn.Enabled = enableDelete;
removeItemBtn.Enabled = enableDelete;
// Not sure why I'm updating the UM combo when trying to update
// the grid.
bool isKg = DataInterface.IsMetric(m_emDataSet.POItemTbl);
if (isKg)
{
umCombo.Text = "kg";
}
else
{
umCombo.Text = "lbs";
}
this.FixUMButNoUpdates(umCombo.Text);
EMDataSet.POItemTblDataTable itemTable = m_emDataSet.POItemTbl;
if (selectedIndex == 0) // is PO grid
{
List<String> poFields = new List<String>(new String[]
{
"Finish","ItemName","Treatment","ItemDesc",
"SizeOfItem","Length",
"ItemAccessCode","DateRequired","MillShipDate","Qty",
"CustRate","CustAmount","CancelDate",
"Comments"});
if (!GetHeaderRow().IsMillConfirmationAppliesToEntirePONull() &&
GetHeaderRow().MillConfirmationAppliesToEntirePO == 0)
{
poFields.AddRange(new String[] { "MillConfirmationNumber", "MillAcknowledgeDate" });
//"InvoiceNumber","InvoiceDate"});
}
poFields.AddRange(new String[]{"POItemNumber","SeqNumber"});
FormSupport.GridWizard(poGrid,m_emDataSet.POItemTbl,isKg,
IsNewAllowed.Yes,IsReadOnly.No,"SeqNumber",
new FormSupport.GetFieldDelegate(GetPOItemFieldForGrid)
,this,poFields.ToArray());
poGrid.SetCancelColumn("CancelDate");
}
else if (selectedIndex == 2) // for container check
{
FormSupport.GridWizard(containerCheckGrid,itemTable,isKg,IsNewAllowed.No,
IsReadOnly.Yes,"SeqNumber",new FormSupport.GetFieldDelegate(this.GetContainerCheckField)
,null,"ItemName","SizeOfItem","Length","Qty",
"ContainerWeight","BOLWeight","PercentPickedUp","CancelDate","SeqNumber","POItemNumber");
containerCheckGrid.SetCancelColumn("CancelDate");
}
else if (selectedIndex == 1) // for weight table
{
FinishTypeGrid.DoIt(this.weightGrid,base.CurrentKey,isKg,m_emDataSet);
}
else if (selectedIndex == 3)
{
List<String> poFields = new List<String>(new String[]
{
"*ItemName",
"*SizeOfItem","*Length",
"*ItemAccessCode","*Qty","*CancelDate"});
if (!GetHeaderRow().IsMillConfirmationAppliesToEntirePONull() &&
GetHeaderRow().MillConfirmationAppliesToEntirePO == 0)
{
poFields.AddRange(new String[] { "MillConfirmationNumber", "MillAcknowledgeDate" });
//"InvoiceNumber","InvoiceDate"});
}
poFields.AddRange(new String[] { "POItemNumber", "SeqNumber" });
FormSupport.GridWizard(millConfirmationGrid, m_emDataSet.POItemTbl, isKg,
IsNewAllowed.No, IsReadOnly.No, "SeqNumber",
new FormSupport.GetFieldDelegate(GetPOItemFieldForGrid)
, this, poFields.ToArray());
millConfirmationGrid.SetCancelColumn("CancelDate");
}
else Debug.Assert(false);
}
}
public override DataTable GetHeaderTable()
{
return m_emDataSet.POHeaderTbl;
}
public override OleDbConnection GetConnection()
{
return AdapterHelper.Connection;
}
public override string GetTableName()
{
return "tblPOHeader2";
}
public override void FillTablesFromDatabase()
{
m_emDataSet.Clear();
using (TurnOffConstraints doIt = new TurnOffConstraints(m_emDataSet))
{
AdapterHelper.FillPOHeader(m_emDataSet,base.CurrentKey);
AdapterHelper.FillTerms(m_emDataSet);
AdapterHelper.FillShippingCode(m_emDataSet);
DataInterface.UpdateComboBox(m_emDataSet.ShippingCodeTbl,"ShipCode",m_shipCodeCombo);
DataInterface.UpdateComboBox(m_emDataSet.PaymentTermsTbl,"Terms",m_termsCombo);
AdapterHelper.FillCompany(m_emDataSet);
AdapterHelper.FillAllLocations(m_emDataSet);
AdapterHelper.FillAllContacts(m_emDataSet);
AdapterHelper.FillCountry(m_emDataSet);
AdapterHelper.FillCurrency(m_emDataSet);
if (IsEmptyTable())
return;
AdapterHelper.FillPOItem(m_emDataSet,GetHeaderRow().POID);
foreach (EMDataSet.POItemTblRow itemRow in m_emDataSet.POItemTbl)
{
AdapterHelper.FillContBundleFromPOItemNumber(m_emDataSet,itemRow.POItemNumber);
}
foreach (EMDataSet.ContBundleTblRow bundleRow in m_emDataSet.ContBundleTbl)
{
AdapterHelper.FillContainerHeader(m_emDataSet,bundleRow.ContID);
AdapterHelper.FillBOLFromContBundleID(m_emDataSet,bundleRow.ContainerBundleID);
}
foreach (EMDataSet.BOLItemTblRow bolItemRow in m_emDataSet.BOLItemTbl)
{
AdapterHelper.FillBillOfLading(m_emDataSet,bolItemRow.BOLID);
}
AdapterHelper.FillOutConstraints(m_emDataSet);
}
}
void UpdateCompanyCombo(string companyType,
AutoCompleteComboBox combo,
object compID)
{
string filter = "CompType = '" + companyType + "'";
DataView compView = new DataView(m_emDataSet.CompanyTbl,filter,"CompName",
DataViewRowState.CurrentRows);
DataRow compRow = null;
if (!(compID is DBNull))
compRow = compView.Table.Rows.Find(compID);
DataInterface.UpdateComboBox(compView,
"CompID","CompName",combo,compRow);
}
void UpdateComboBoxesBasedOnCompany(object companyIDObj,
DataTable table, string idField, string valueField,
object comboID,
AutoCompleteComboBox combo)
{
if (companyIDObj is DBNull)
{
combo.Items.Clear();
}
int companyID = (int)companyIDObj;
string filter = "CompID = " + companyID;
DataView locationView = new DataView(table, filter, valueField,
DataViewRowState.CurrentRows);
DataRow locationRow = null;
if (!(comboID is DBNull))
locationRow = locationView.Table.Rows.Find(comboID);
DataInterface.UpdateComboBox(locationView, idField, valueField,
combo, locationRow);
}
void UpdateLocationCombo(object companyIDObj,
AutoCompleteComboBox combo,
object locationID,AutoCompleteTextBox address,
AutoCompleteTextBox country,
AutoCompleteComboBox contactCombo,
object contactIDObj)
{
address.Text = "";
country.Text = "";
UpdateComboBoxesBasedOnCompany(companyIDObj,
m_emDataSet.LocationTbl, "LocID", "LocName", locationID,
combo);
UpdateComboBoxesBasedOnCompany(companyIDObj, m_emDataSet.ContactsTbl,
"ContactID", "LastName", contactIDObj, contactCombo);
EMDataSet.LocationTblRow locationRow = null;
if (!(locationID is DBNull))
locationRow = m_emDataSet.LocationTbl.FindByLocID((int)locationID);
if (locationRow!=null)
{
address.Text = locationRow.Address;
country.Text = locationRow.CountryTblRow.CountryName;
}
}
void UpdateMillCombo()
{
EMDataSet.POHeaderTblRow row = GetHeaderRow();
object millID = row["MillID"];
UpdateCompanyCombo("Vendor",millCombo,millID);
UpdateMillLocationCombo();
}
void UpdateMillLocationCombo()
{
EMDataSet.POHeaderTblRow row = GetHeaderRow();
object millID = row["MillID"];
UpdateLocationCombo(millID,this.millLocationCombo,row["MillLocationID"],
millAddressEdt,millCountryEdt,millContactCombo,
row["VendContactID"]);
}
void UpdateCustomerCombo()
{
EMDataSet.POHeaderTblRow row = GetHeaderRow();
object customerID = row["CustomerID"];
UpdateCompanyCombo("Customer",customerCombo,customerID);
UpdateCustomerLocationCombo();
}
void UpdateCustomerLocationCombo()
{
EMDataSet.POHeaderTblRow row = GetHeaderRow();
object customerID = row["CustomerID"];
UpdateLocationCombo(customerID,this.customerLocationCombo,row["CustomerLocationID"]
,customerAddressEdt,customerCountryEdt,custContactCombo,
row["ShipToContactID"]);
}
static void Enable(Object o,bool enable)
{
AutoCompleteComboBox combo = o as AutoCompleteComboBox;
if (combo != null)
combo.Enabled = enable;
AutoCompleteTextBox text = o as AutoCompleteTextBox;
if (text != null)