001.
Option
Explicit
On
002.
Option
Strict
On
003.
Imports
GAF
004.
Imports
GAF.Biz.Accounting
005.
Imports
System.Transactions
006.
Imports
System.Drawing.Printing
007.
008.
Public
Class
frmPO
009.
Dim
db
As
New
dbMpiBizDataContext()
010.
Dim
CreditTerm
As
String
=
""
011.
Dim
ICompany
As
IQueryable(Of Company)
012.
Dim
IUnit
As
IQueryable(Of Unit)
013.
Dim
IPurchaseRequisition
As
IOrderedQueryable(Of PurchaseRequisition)
014.
Dim
anyData()
As
String
015.
Dim
QuantityPerUnit
As
Integer
= 0
016.
Dim
CurrentProduct(8)
As
String
017.
Dim
sw
As
New
Stopwatch()
018.
Dim
ProcessTime
As
Double
019.
Dim
_ToolStripStatusLabel
As
New
ToolStripStatusLabel()
020.
021.
Dim
UseFont
As
New
Font(
"MS Sans Serif"
, 10)
022.
Dim
prDoc
As
New
PrintDocument()
023.
Dim
prDlg
As
New
PrintDialog()
024.
025.
Public
Sub
New
(
ByRef
refToolStripStatusLabel
As
ToolStripStatusLabel)
026.
InitializeComponent()
027.
_ToolStripStatusLabel = refToolStripStatusLabel
028.
End
Sub
029.
030.
Private
Sub
frmPO_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
031.
Me
.WindowState = FormWindowState.Maximized
032.
sw.Reset()
033.
sw.Start()
034.
With
lsvProductLists
035.
.Columns.Add(
"รหัสสินค้า"
, 70, HorizontalAlignment.Left)
036.
.Columns.Add(
"ชื่อสินค้า"
, 350, HorizontalAlignment.Left)
037.
.Columns.Add(
"ต้นทุนต่อชิ้น"
, 90, HorizontalAlignment.Right)
038.
.Columns.Add(
"จำนวน"
, 50, HorizontalAlignment.Right)
039.
.Columns.Add(
"หน่วย"
, 135, HorizontalAlignment.Left)
040.
.Columns.Add(
"รวมเป็นเงิน"
, 75, HorizontalAlignment.Right)
041.
.Columns.Add(
""
, 0, HorizontalAlignment.Right)
042.
.Columns.Add(
""
, 0, HorizontalAlignment.Right)
043.
.Columns.Add(
""
, 0, HorizontalAlignment.Right)
044.
.View = View.Details
045.
.GridLines =
True
046.
End
With
047.
048.
ICompany = From c
In
db.Companies Where c.CompanyID <>
"000"
049.
If
ICompany.Count > 0
Then
050.
With
cboCompany
051.
.BeginUpdate()
052.
.DisplayMember =
"CompanyName"
053.
.ValueMember =
"CompanyID"
054.
.DataSource = ICompany.ToList()
055.
.EndUpdate()
056.
End
With
057.
End
If
058.
059.
RemoveHandler
cboUnit.SelectedValueChanged,
AddressOf
cboUnit_SelectedValueChanged
060.
IUnit = From u
In
db.Units
061.
If
IUnit.Count > 0
Then
062.
With
cboUnit
063.
.BeginUpdate()
064.
.DisplayMember =
"UnitName"
065.
.ValueMember =
"UnitID"
066.
.DataSource = IUnit.ToList()
067.
.EndUpdate()
068.
End
With
069.
End
If
070.
AddHandler
cboUnit.SelectedValueChanged,
AddressOf
cboUnit_SelectedValueChanged
071.
cmdSave.Enabled =
False
072.
dtpStart.Value = DateTime.Today.AddMonths(-1)
073.
dtpEnd.Value = DateTime.Today
074.
txtDCCash.ContextMenu =
New
ContextMenu()
075.
txtDcDateDiscountReceivedCreditTerm.ContextMenu =
New
ContextMenu()
076.
txtDcRateDiscountReceivedCreditTerm.ContextMenu =
New
ContextMenu()
077.
txtCreditDateDiscountReceivedCreditTerm.ContextMenu =
New
ContextMenu()
078.
cboCompany.ContextMenu =
New
ContextMenu()
079.
cboUnit.ContextMenu =
New
ContextMenu()
080.
txtLastCost.ContextMenu =
New
ContextMenu()
081.
txtAmount.ContextMenu =
New
ContextMenu()
082.
CheckCreditTerm()
083.
txtDCCash.Text =
"0"
084.
ClearProduct()
085.
ClearPODetails()
086.
ClearNet()
087.
088.
AddHandler
prDoc.PrintPage,
New
PrintPageEventHandler(
AddressOf
Me
.StringToPrint_Print)
089.
prDoc.DocumentName =
"สั่งซื้อสินค้า"
090.
prDlg.Document = prDoc
091.
092.
sw.
Stop
()
093.
ProcessTime = sw.ElapsedMilliseconds / 1000
094.
_ToolStripStatusLabel.Text =
"เวลาที่ใช้ : "
& ProcessTime.ToString(
"0.0000"
) &
" วินาที"
095.
End
Sub
096.
097.
Private
Sub
ClearProduct()
098.
lblProductID.Text =
""
099.
lblProductName.Text =
""
100.
txtLastCost.Text =
"1"
101.
txtAmount.Text =
"1"
102.
QuantityPerUnit = 0
103.
lblProductTotal.Text =
"0"
104.
Array.Clear(CurrentProduct, 0, CurrentProduct.Length)
105.
End
Sub
106.
107.
Private
Sub
ClearPODetails()
108.
txtPONo.Text =
""
109.
dtpReceiveDate.Value = DateTime.Today
110.
dtpPaidDate.Value = DateTime.Today
111.
End
Sub
112.
113.
Private
Sub
ClearCreditTerm()
114.
CreditTerm =
""
115.
txtDCCash.Text =
"0"
116.
txtDcDateDiscountReceivedCreditTerm.Text =
"0"
117.
txtDcRateDiscountReceivedCreditTerm.Text =
"0"
118.
txtCreditDateDiscountReceivedCreditTerm.Text =
"0"
119.
End
Sub
120.
121.
Private
Sub
ClearNet()
122.
lblTotal.Text =
"0.0"
123.
lblDiscountReceived.Text =
"0.0"
124.
lblInputVAT.Text =
"0.0"
125.
lblNet.Text =
"0.0"
126.
lblNetInText.Text =
""
127.
End
Sub
128.
129.
Private
Sub
cboCompany_SelectedValueChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
cboCompany.SelectedValueChanged
130.
ClearProduct()
131.
ClearPODetails()
132.
ClearNet()
133.
dgvProductLists.DataSource =
Nothing
134.
dgvPRList.DataSource =
Nothing
135.
dgvPRDList.DataSource =
Nothing
136.
lsvProductLists.Items.Clear()
137.
CheckCreditTerm()
138.
139.
If
CreditTerm =
""
Then
Exit
Sub
140.
If
CreditTerm.ToLower() <>
"c"
Then
141.
142.
<span style=
"background-color:red;"
>
Dim
ct
As
New
CreditTerm(CreditTerm)
143.
optCredit.Checked =
True
144.
txtDcDateDiscountReceivedCreditTerm.Text = ct.GetDcDate.ToString()
145.
txtDcRateDiscountReceivedCreditTerm.Text = ct.GetDcRate.ToString()
146.
txtCreditDateDiscountReceivedCreditTerm.Text = ct.GetCreditDate.ToString()
147.
dtpPaidDate.Value = DateTime.Today.AddDays(
Double
.Parse(txtCreditDateDiscountReceivedCreditTerm.Text)).NextWorkingDay(HolidayMode.SundayOnly)
148.
Else
149.
optCash.Checked =
True
150.
txtDCCash.Focus()
151.
txtDCCash.SelectAll()
152.
End
If
153.
txtSearch.Focus()
154.
txtSearch.SelectAll()
155.
End
Sub
156.
157.
Private
Sub
CheckCreditTerm()
158.
If
cboCompany.SelectedValue IsNot
Nothing
Then
159.
For
Each
c
In
ICompany
160.
If
c.CompanyID = cboCompany.SelectedValue.ToString()
Then
161.
CreditTerm = c.DiscountReceivedCreditTerm
162.
Exit
For
163.
End
If
164.
Next
165.
End
If
166.
End
Sub
167.
168.
Private
Sub
txtSearch_KeyDown(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyEventArgs)
Handles
txtSearch.KeyDown
169.
If
txtSearch.Text.Trim() =
""
Then
Exit
Sub
170.
If
e.KeyCode = Keys.Enter
Then
171.
sw.Reset()
172.
sw.Start()
173.
Dim
ps = From p
In
db.Products _
174.
Where p.ProductID.Contains(txtSearch.Text.Trim()) _
175.
OrElse
p.ProductNameTH.Contains(txtSearch.Text.Trim()) _
176.
AndAlso
p.ProductTypeID <>
"2"
_
177.
AndAlso
p.IsSaleMix =
"0"
_
178.
AndAlso
p.CompanyID = cboCompany.SelectedValue.ToString() _
179.
Order By p.ProductNameTH _
180.
Select
New
With
{ _
181.
.ProductID = p.ProductID, _
182.
.ProductName = p.ProductNameTH, _
183.
.LastCost = p.LastCost _
184.
}
185.
If
ps.Count() > 0
Then
186.
dgvProductLists.DataSource = ps.ToList()
187.
FormatDgvProductLists()
188.
Else
189.
dgvProductLists.DataSource =
Nothing
190.
MessageBox.Show(
"เงื่อนไขที่คุณป้อน ไม่ตรงกับรายการสินค้าที่มีอยู่ !!!"
,
"ผลการค้นหา"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
191.
txtSearch.Focus()
192.
txtSearch.SelectAll()
193.
End
If
194.
sw.
Stop
()
195.
ProcessTime = sw.ElapsedMilliseconds / 1000
196.
_ToolStripStatusLabel.Text =
"เวลาที่ใช้ : "
& ProcessTime.ToString(
"0.0000"
) &
" วินาที"
197.
End
If
198.
End
Sub
199.
200.
Private
Sub
FormatDgvProductLists()
201.
With
dgvProductLists
202.
If
.RowCount > 0
Then
203.
.Columns(0).HeaderText =
"รหัสสินค้า"
204.
.Columns(1).HeaderText =
"ชื่อสินค้า"
205.
.Columns(2).HeaderText =
"ต้นทุนสินค้าต่อชิ้น"
206.
.Columns(0).Width = 100
207.
.Columns(1).Width = 280
208.
.Columns(2).Width = 115
209.
End
If
210.
End
With
211.
End
Sub
212.
213.
Private
Sub
dgvProductLists_CellMouseUp(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.DataGridViewCellMouseEventArgs)
Handles
dgvProductLists.CellMouseUp
214.
If
e.RowIndex = -1
Then
Exit
Sub
215.
With
dgvProductLists
216.
lblProductID.Text = .Rows.Item(e.RowIndex).Cells(
"ProductID"
).Value.ToString()
217.
lblProductName.Text = .Rows.Item(e.RowIndex).Cells(
"ProductNameTH"
).Value.ToString()
218.
txtLastCost.Text = .Rows.Item(e.RowIndex).Cells(
"LastCost"
).Value.ToString()
219.
txtLastCost.Focus()
220.
txtLastCost.SelectAll()
221.
End
With
222.
CalculateTotal()
223.
End
Sub
224.
225.
Private
Sub
cboUnit_SelectedValueChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
cboUnit.SelectedValueChanged
226.
CalculateTotal()
227.
End
Sub
228.
229.
Private
Sub
CalculateTotal()
230.
If
txtLastCost.Text.Trim() =
""
Then
Exit
Sub
231.
If
txtAmount.Text.Trim() =
""
Then
Exit
Sub
232.
For
Each
u
In
IUnit
233.
If
u.UnitID = cboUnit.SelectedValue.ToString()
Then
234.
QuantityPerUnit = Convert.ToInt32(u.QuantityPerUnit)
235.
Exit
For
236.
End
If
237.
Next
238.
lblProductTotal.Text = (
Integer
.Parse(txtLastCost.Text) *
Integer
.Parse(txtAmount.Text) * QuantityPerUnit).ToString()
239.
End
Sub
240.
241.
Private
Sub
dgvProductLists_CellFormatting(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.DataGridViewCellFormattingEventArgs)
Handles
dgvProductLists.CellFormatting
242.
If
dgvProductLists.Columns(e.ColumnIndex).Name =
"LastCost"
Then
243.
e.CellStyle.Format =
"#,##0"
244.
e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
245.
End
If
246.
End
Sub
247.
248.
Private
Sub
cmdAddProduct_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
cmdAddProduct.Click
249.
If
(lblProductID.Text.Trim() =
""
)
OrElse
(lblProductName.Text.Trim() =
""
)
Then
250.
txtSearch.Focus()
251.
txtSearch.SelectAll()
252.
Exit
Sub
253.
End
If
254.
If
Double
.Parse(txtLastCost.Text) = 0.0
Then
255.
txtSearch.Focus()
256.
txtSearch.SelectAll()
257.
Exit
Sub
258.
End
If
259.
If
CInt
(txtAmount.Text) = 0
Then
260.
txtAmount.Focus()
261.
txtAmount.SelectAll()
262.
Exit
Sub
263.
End
If
264.
265.
Dim
i
As
Integer
= 0
266.
Dim
lvi
As
ListViewItem
267.
Dim
ProductID
As
String
=
""
268.
For
i = 0
To
lsvProductLists.Items.Count - 1
269.
ProductID = lsvProductLists.Items(i).SubItems(0).Text
270.
If
lblProductID.Text.Trim() = ProductID
Then
271.
MessageBox.Show(
"คุณเลือกรายการสินค้า ซ้ำกัน !!!"
,
"ผลการตรวจสอบ"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
272.
ClearProduct()
273.
txtSearch.Focus()
274.
Exit
Sub
275.
End
If
276.
Next
277.
278.
For
Each
u
In
IUnit
279.
If
u.UnitID = cboUnit.SelectedValue.ToString()
Then
280.
QuantityPerUnit = Convert.ToInt32(u.QuantityPerUnit)
281.
Exit
For
282.
End
If
283.
Next
284.
285.
anyData =
New
String
() { _
286.
lblProductID.Text.Trim(), _
287.
lblProductName.Text, _
288.
txtLastCost.Text, _
289.
txtAmount.Text, _
290.
cboUnit.Text, _
291.
lblProductTotal.Text, _
292.
cboUnit.SelectedValue.ToString(), _
293.
" "
, _
294.
QuantityPerUnit.ToString() _
295.
}
296.
lvi =
New
ListViewItem(anyData)
297.
lsvProductLists.Items.Add(lvi)
298.
ClearProduct()
299.
CalculateNet()
300.
cmdSave.Enabled =
True
301.
Array.Clear(CurrentProduct, 0, CurrentProduct.Length)
302.
End
Sub
303.
304.
Private
Sub
cmdClearProduct_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
cmdClearProduct.Click
305.
ClearProduct()
306.
txtSearch.Focus()
307.
txtSearch.SelectAll()
308.
End
Sub
309.
310.
Private
Sub
dgvProductLists_CellMouseDown(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.DataGridViewCellMouseEventArgs)
Handles
dgvProductLists.CellMouseDown
311.
If
e.RowIndex = -1
Then
Exit
Sub
312.
For
Each
u
In
IUnit
313.
If
u.UnitID = cboUnit.SelectedValue.ToString()
Then
314.
QuantityPerUnit = Convert.ToInt32(u.QuantityPerUnit)
315.
Exit
For
316.
End
If
317.
Next
318.
319.
With
dgvProductLists
320.
CurrentProduct(0) = .Rows.Item(e.RowIndex).Cells(
"ProductID"
).Value.ToString()
321.
CurrentProduct(1) = .Rows.Item(e.RowIndex).Cells(
"ProductNameTH"
).Value.ToString()
322.
CurrentProduct(2) = .Rows.Item(e.RowIndex).Cells(
"LastCost"
).Value.ToString()
323.
CurrentProduct(3) = txtAmount.Text
324.
CurrentProduct(4) = cboUnit.Text
325.
CurrentProduct(5) = (
Integer
.Parse(CurrentProduct(2)) *
Integer
.Parse(CurrentProduct(3)) * QuantityPerUnit).ToString()
326.
CurrentProduct(6) = cboUnit.SelectedValue.ToString()
327.
CurrentProduct(7) =
""
328.
CurrentProduct(8) = QuantityPerUnit.ToString()
329.
End
With
330.
End
Sub
331.
332.
Private
Sub
dgvProductLists_MouseMove(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.MouseEventArgs)
Handles
dgvProductLists.MouseMove
333.
If
e.Button = Windows.Forms.MouseButtons.Left
Then
334.
Dim
AnyData
As
DataObject
335.
AnyData =
New
DataObject()
336.
AnyData.SetData(DataFormats.Text, CurrentProduct)
337.
Dim
dde
As
DragDropEffects
338.
dde = dgvProductLists.DoDragDrop(AnyData, DragDropEffects.Copy)
339.
End
If
340.
End
Sub
341.
342.
Private
Sub
lsvProductLists_DragEnter(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.DragEventArgs)
Handles
lsvProductLists.DragEnter
343.
If
(CurrentProduct(0) =
""
)
OrElse
(CurrentProduct(1) =
""
)
Then
Exit
Sub
344.
If
(e.Data.GetDataPresent(DataFormats.Text,
True
))
Then
345.
e.Effect = DragDropEffects.Copy
346.
End
If
347.
End
Sub
348.
349.
Private
Sub
lsvProductLists_DragDrop(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.DragEventArgs)
Handles
lsvProductLists.DragDrop
350.
CurrentProduct =
DirectCast
(e.Data.GetData(DataFormats.Text,
True
),
String
())
351.
Dim
i
As
Integer
= 0
352.
Dim
lvi
As
ListViewItem
353.
Dim
ProductID
As
String
=
""
354.
For
i = 0
To
lsvProductLists.Items.Count - 1
355.
ProductID = lsvProductLists.Items(i).SubItems(0).Text
356.
If
CurrentProduct(0) = ProductID
Then
357.
MessageBox.Show(
"คุณเลือกรายการสินค้า ซ้ำกัน !!!"
,
"ผลการตรวจสอบ"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
358.
Exit
Sub
359.
End
If
360.
Next
361.
lvi =
New
ListViewItem(CurrentProduct)
362.
lsvProductLists.Items.Add(lvi)
363.
CalculateNet()
364.
cmdSave.Enabled =
True
365.
Array.Clear(CurrentProduct, 0, CurrentProduct.Length)
366.
End
Sub
367.
368.
Private
Sub
CalculateNet()
369.
Dim
i
As
Integer
370.
Dim
Total
As
Double
= 0.0
371.
Dim
DiscountReceived
As
Double
= 0.0
372.
Dim
VATRate
As
Double
= BizConfig.VATRate / 100
373.
With
lsvProductLists
374.
For
i = 0
To
.Items.Count - 1
375.
Total +=
Double
.Parse(lsvProductLists.Items(i).SubItems(5).Text)
376.
Next
377.
End
With
378.
If
optCash.Checked =
True
Then
379.
DiscountReceived =
Double
.Parse(txtDCCash.Text) / 100
380.
Else
381.
DiscountReceived = 0.0
382.
End
If
383.
lblTotal.Text = Total.ToString(
"#,##0"
)
384.
lblDiscountReceived.Text = (
Double
.Parse(lblTotal.Text) * DiscountReceived).ToString(
"#,##0.00"
)
385.
Dim
TotalBeforeVAT =
Double
.Parse(lblTotal.Text) -
Double
.Parse(lblDiscountReceived.Text)
386.
lblInputVAT.Text = (TotalBeforeVAT * VATRate).ToString(
"#,##0.00"
)
387.
Dim
Net =
Double
.Parse(lblTotal.Text) -
Double
.Parse(lblDiscountReceived.Text) +
Double
.Parse(lblInputVAT.Text)
388.
lblNet.Text = Net.ToString(
"#,##0.00"
)
389.
lblNetInText.Text = Net.ToThaiWord()
390.
End
Sub
391.
392.
Private
Sub
txtSearchPR_KeyDown(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyEventArgs)
Handles
txtSearchPR.KeyDown
393.
If
txtSearchPR.Text.Trim() =
""
Then
Exit
Sub
394.
If
e.KeyCode = Keys.Enter
Then
395.
SearchPR()
396.
End
If
397.
End
Sub
398.
399.
Private
Sub
cmdSearch_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
cmdSearch.Click
400.
If
txtSearchPR.Text.Trim() =
""
AndAlso
optPRNo.Checked =
True
Then
Exit
Sub
401.
SearchPR()
402.
End
Sub
403.
404.
Private
Sub
SearchPR()
405.
sw.Reset()
406.
sw.Start()
407.
If
optPRNo.Checked =
True
Then
408.
IPurchaseRequisition = From pr
In
db.PurchaseRequisitions _
409.
Where pr.PRNo = txtSearchPR.Text.Trim() _
410.
AndAlso
pr.IsComplete =
"0"
_
411.
Order By pr.PRDate
412.
ElseIf
optDuration.Checked =
True
Then
413.
IPurchaseRequisition = From pr
In
db.PurchaseRequisitions _
414.
Where pr.PRDate >= dtpStart.Value
AndAlso
pr.PRDate <= dtpEnd.Value _
415.
AndAlso
pr.IsComplete =
"0"
_
416.
Order By pr.PRDate
417.
End
If
418.
dgvPRDList.DataSource =
Nothing
419.
If
IPurchaseRequisition.Count() > 0
Then
420.
dgvPRList.DataSource = IPurchaseRequisition.ToList()
421.
FormatDgvPRList()
422.
cmdSave.Enabled =
True
423.
sw.
Stop
()
424.
ProcessTime = sw.ElapsedMilliseconds / 1000
425.
_ToolStripStatusLabel.Text =
"เวลาที่ใช้ : "
& ProcessTime.ToString(
"0.0000"
) &
" วินาที"
426.
Else
427.
dgvPRList.DataSource =
Nothing
428.
cmdSave.Enabled =
False
429.
MessageBox.Show(
"เงื่อนไขที่คุณป้อน ไม่ตรงกับรายการขอซื้อที่มีอยู่ !!!"
,
"ผลการค้นหา"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
430.
txtSearchPR.Focus()
431.
txtSearchPR.SelectAll()
432.
End
If
433.
End
Sub
434.
435.
Private
Sub
FormatDgvPRList()
436.
With
dgvPRList
437.
If
.RowCount > 0
Then
438.
.Columns(3).HeaderText =
"เลขที่ใบขอซื้อ"
439.
.Columns(4).HeaderText =
"วันที่ขอซื้อ"
440.
.Columns(5).HeaderText =
"วันที่ต้องการสินค้า"
441.
.Columns(3).
ReadOnly
=
True
442.
.Columns(4).
ReadOnly
=
True
443.
.Columns(5).
ReadOnly
=
True
444.
.Columns(0).Visible =
False
445.
.Columns(1).Visible =
False
446.
.Columns(2).Visible =
False
447.
.Columns(3).Width = 150
448.
.Columns(4).Width = 190
449.
.Columns(5).Width = 190
450.
.Columns(6).Visible =
False
451.
.Columns(7).Visible =
False
452.
.Columns(8).Visible =
False
453.
.Columns(9).Visible =
False
454.
End
If
455.
End
With
456.
End
Sub
457.
458.
Private
Sub
dgvPRList_CellFormatting(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.DataGridViewCellFormattingEventArgs)
Handles
dgvPRList.CellFormatting
459.
If
e.ColumnIndex = -1
Then
Exit
Sub
460.
If
dgvPRList.Columns(e.ColumnIndex).Name =
"PRDate"
Then
461.
e.CellStyle.Format =
"d MMMM yyyy"
462.
End
If
463.
If
dgvPRList.Columns(e.ColumnIndex).Name =
"RequiredDate"
Then
464.
e.CellStyle.Format =
"d MMMM yyyy"
465.
End
If
466.
End
Sub
467.
468.
Private
Sub
dgvPRList_CellMouseUp(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.DataGridViewCellMouseEventArgs)
Handles
dgvPRList.CellMouseUp
469.
If
e.RowIndex = -1
Then
Exit
Sub
470.
Dim
CurrentPRID = dgvPRList.Rows.Item(e.RowIndex).Cells(
"PRID"
).Value.ToString()
471.
Dim
PRDList = From prd
In
db.PurchaseRequisitionDetails _
472.
From p
In
db.Products _
473.
From u
In
db.Units _
474.
Where prd.ProductID = p.ProductID _
475.
AndAlso
prd.UnitID = u.UnitID _
476.
AndAlso
prd.PRID = CurrentPRID _
477.
AndAlso
p.CompanyID = cboCompany.SelectedValue.ToString() _
478.
AndAlso
prd.PRStatus =
"ยังไม่ดำเนินการ"
_
479.
Order By p.ProductNameTH _
480.
Select
New
With
{ _
481.
.PRID = prd.PRID, _
482.
.ProductID = prd.ProductID, _
483.
.ProductName = p.ProductNameTH, _
484.
.NumberToOrder = prd.NumberToOrder, _
485.
.UnitName = u.UnitName, _
486.
.PRStatus = prd.PRStatus, _
487.
.UnitID = prd.UnitID, _
488.
.LastCost = p.LastCost _
489.
}
490.
If
PRDList.Count() > 0
Then
491.
dgvPRDList.DataSource = PRDList.ToList()
492.
FormatDgvPRDList()
493.
Else
494.
dgvPRDList.DataSource =
Nothing
495.
MessageBox.Show(
"ไม่มีรายการขอซื้อสินค้าของบริษัทนี้ !!!"
,
"ผลการตรวจสอบ"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
496.
End
If
497.
End
Sub
498.
499.
Private
Sub
FormatDgvPRDList()
500.
With
dgvPRDList
501.
If
.RowCount > 0
Then
502.
.Columns(1).HeaderText =
"รหัสสินค้า"
503.
.Columns(2).HeaderText =
"ชื่อสินค้า"
504.
.Columns(3).HeaderText =
"จำนวน"
505.
.Columns(4).HeaderText =
"หน่วย"
506.
.Columns(5).HeaderText =
"สถานะขอซื้อ"
507.
.Columns(0).Visible =
False
508.
.Columns(1).Width = 100
509.
.Columns(2).Width = 240
510.
.Columns(3).Width = 60
511.
.Columns(4).Width = 120
512.
.Columns(5).Width = 110
513.
.Columns(6).Visible =
False
514.
.Columns(7).Visible =
False
515.
End
If
516.
End
With
517.
End
Sub
518.
519.
Private
Sub
dgvPRDList_CellFormatting(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.DataGridViewCellFormattingEventArgs)
Handles
dgvPRDList.CellFormatting
520.
If
dgvPRDList.Columns(e.ColumnIndex).Name =
"NumberToOrder"
Then
521.
e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
522.
End
If
523.
End
Sub
524.
525.
Private
Sub
dgvPRDList_CellMouseDown(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.DataGridViewCellMouseEventArgs)
Handles
dgvPRDList.CellMouseDown
526.
If
e.RowIndex = -1
Then
Exit
Sub
527.
For
Each
u
In
IUnit
528.
If
u.UnitID = dgvPRDList.Rows.Item(e.RowIndex).Cells(
"UnitID"
).Value.ToString()
Then
529.
QuantityPerUnit = Convert.ToInt32(u.QuantityPerUnit)
530.
Exit
For
531.
End
If
532.
Next
533.
534.
With
dgvPRDList
535.
CurrentProduct(0) = .Rows.Item(e.RowIndex).Cells(
"ProductID"
).Value.ToString()
536.
CurrentProduct(1) = .Rows.Item(e.RowIndex).Cells(
"ProductNameTH"
).Value.ToString()
537.
CurrentProduct(2) = .Rows.Item(e.RowIndex).Cells(
"LastCost"
).Value.ToString()
538.
CurrentProduct(3) = .Rows.Item(e.RowIndex).Cells(
"NumberToOrder"
).Value.ToString()
539.
CurrentProduct(4) = .Rows.Item(e.RowIndex).Cells(
"UnitName"
).Value.ToString()
540.
CurrentProduct(5) = (
Integer
.Parse(CurrentProduct(2)) *
Integer
.Parse(CurrentProduct(3)) * QuantityPerUnit).ToString()
541.
CurrentProduct(6) = .Rows.Item(e.RowIndex).Cells(
"UnitID"
).Value.ToString()
542.
CurrentProduct(7) = .Rows.Item(e.RowIndex).Cells(
"PRID"
).Value.ToString()
543.
CurrentProduct(8) = QuantityPerUnit.ToString()
544.
End
With
545.
End
Sub
546.
547.
Private
Sub
dgvPRDList_MouseMove(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.MouseEventArgs)
Handles
dgvPRDList.MouseMove
548.
If
e.Button = Windows.Forms.MouseButtons.Left
Then
549.
Dim
AnyData
As
DataObject
550.
AnyData =
New
DataObject()
551.
AnyData.SetData(DataFormats.Text, CurrentProduct)
552.
Dim
dde
As
DragDropEffects
553.
dde = dgvProductLists.DoDragDrop(AnyData, DragDropEffects.Copy)
554.
End
If
555.
End
Sub
556.
557.
Private
Sub
dgvPRDList_CellMouseUp(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.DataGridViewCellMouseEventArgs)
Handles
dgvPRDList.CellMouseUp
558.
With
dgvPRDList
559.
lblProductID.Text = .Rows.Item(e.RowIndex).Cells(
"ProductID"
).Value.ToString()
560.
lblProductName.Text = .Rows.Item(e.RowIndex).Cells(
"ProductNameTH"
).Value.ToString()
561.
txtLastCost.Text = .Rows.Item(e.RowIndex).Cells(
"LastCost"
).Value.ToString()
562.
End
With
563.
CalculateTotal()
564.
End
Sub
565.
566.
Private
Sub
lsvProductLists_DoubleClick(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
lsvProductLists.DoubleClick
567.
Dim
i
As
Integer
= 0
568.
For
i = 0
To
lsvProductLists.SelectedItems.Count - 1
569.
Dim
lvi
As
ListViewItem
570.
lvi = lsvProductLists.SelectedItems(i)
571.
lsvProductLists.Items.Remove(lvi)
572.
Next
573.
If
(lsvProductLists.Items.Count = 0)
Then
cmdSave.Enabled =
False
574.
CalculateNet()
575.
End
Sub
576.
577.
Private
Sub
dtpReceiveDate_ValueChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
dtpReceiveDate.ValueChanged
578.
If
dtpReceiveDate.Value < DateTime.Today
Then
dtpReceiveDate.Value = DateTime.Today
579.
dtpReceiveDate.Value = dtpReceiveDate.Value.NextWorkingDay(HolidayMode.SundayOnly)
580.
End
Sub
581.
582.
Private
Sub
dtpPaidDate_ValueChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
dtpPaidDate.ValueChanged
583.
If
dtpPaidDate.Value < DateTime.Today
Then
dtpPaidDate.Value = DateTime.Today
584.
dtpPaidDate.Value = dtpPaidDate.Value.NextWorkingDay(HolidayMode.SundayOnly)
585.
End
Sub
586.
587.
Private
Sub
txtCreditDateDiscountReceivedCreditTerm_TextChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
txtCreditDateDiscountReceivedCreditTerm.TextChanged
588.
If
txtCreditDateDiscountReceivedCreditTerm.Text.Trim() =
""
Then
txtCreditDateDiscountReceivedCreditTerm.Text =
"0"
589.
dtpPaidDate.Value = DateTime.Today.AddDays(
Double
.Parse(txtCreditDateDiscountReceivedCreditTerm.Text)).NextWorkingDay(HolidayMode.SundayOnly)
590.
End
Sub
591.
592.
Private
Sub
cmdSave_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
cmdSave.Click
593.
If
txtPONo.Text.Trim() =
""
Then
594.
MessageBox.Show(
"กรุณาใส่หมายเลขใบสั่งซื้อด้วย !!!"
,
"ผลการตรวจสอบ"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
595.
txtPONo.Focus()
596.
Exit
Sub
597.
End
If
598.
If
MessageBox.Show(
"คุณต้องการบันทึกรายการสั่งซื้อสินค้า ใช่หรือไม่?"
,
"คำยืนยัน"
, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes
Then
599.
sw.Reset()
600.
sw.Start()
601.
Try
602.
Using ts
As
New
TransactionScope()
603.
Dim
FirstID
As
String
=
""
604.
Dim
SecondID
As
Integer
= 0
605.
Dim
oids = From oid
In
db.Orders _
606.
Order By oid.OrderID Descending Take (1)
607.
608.
Dim
LastOrderID
As
String
=
""
609.
If
oids.Count() = 1
Then
610.
FirstID = oids.SingleOrDefault().OrderID.Left(4)
611.
SecondID =
Integer
.Parse(oids.SingleOrDefault().OrderID.Right(6))
612.
SecondID += 1
613.
LastOrderID =
String
.Format(FirstID,
"0000"
) & SecondID.ToString(
"000000"
)
614.
Else
615.
LastOrderID = BizConfig.CurrentBranchID &
"000001"
616.
End
If
617.
618.
Dim
o
As
New
Order()
619.
o.OrderID = LastOrderID
620.
o.BranchID = BizConfig.CurrentBranchID
621.
o.CompanyID = cboCompany.SelectedValue.ToString()
622.
o.PONo = txtPONo.Text.Trim()
623.
If
optCash.Checked =
True
Then
624.
o.CreditTerm =
"c"
625.
ElseIf
optCredit.Checked =
True
Then
626.
o.CreditTerm = txtDcRateDiscountReceivedCreditTerm.Text &
"/"
& txtDcDateDiscountReceivedCreditTerm.Text &
",n/"
& txtCreditDateDiscountReceivedCreditTerm.Text
627.
End
If
628.
o.FreightIn = 0.0
629.
o.FID =
"000"
630.
o.OrderDate = DateTime.Today
631.
o.ReceiveDate = dtpReceiveDate.Value
632.
o.PaidDate = dtpPaidDate.Value
633.
o.Total =
Double
.Parse(lblTotal.Text)
634.
o.DiscountReceived =
Double
.Parse(lblDiscountReceived.Text)
635.
o.VATRate = BizConfig.VATRate
636.
o.InputVAT =
Double
.Parse(lblInputVAT.Text)
637.
o.Net =
Double
.Parse(lblNet.Text)
638.
o.IsComplete =
"0"
639.
o.IsPaid =
"0"
640.
o.IsNormal =
"1"
641.
o.InventorySystems = BizConfig.InventorySystem
642.
o.IsEntryToJournal =
"0"
643.
o.OrderBy = UserAuthentication.UserName
644.
o.ReceivedBy =
""
645.
o.PaidBy =
""
646.
647.
Dim
i
As
Integer
648.
Dim
od
As
OrdersDetail =
Nothing
649.
Dim
pb
As
ProductOnBranch =
Nothing
650.
Dim
ProductID
As
String
=
""
651.
Dim
ProductIDList(lsvProductLists.Items.Count)
As
String
652.
With
lsvProductLists
653.
For
i = 0
To
.Items.Count - 1
654.
ProductID = .Items(i).SubItems(0).Text
655.
ProductIDList(i) = ProductID
656.
od =
New
OrdersDetail()
657.
od.OrderID = LastOrderID
658.
od.ProductID = ProductID
659.
od.NumberToOrder =
Integer
.Parse(.Items(i).SubItems(3).Text)
660.
od.UnitID = .Items(i).SubItems(6).Text
661.
od.NumberToReceived = 0
662.
663.
If
optCash.Checked =
True
Then
664.
If
Integer
.Parse(txtDCCash.Text) > 0
Then
665.
Dim
Cost =
Double
.Parse(.Items(i).SubItems(2).Text)
666.
Dim
Amount =
Integer
.Parse(.Items(i).SubItems(3).Text)
667.
Dim
QuantityPerUnit =
Integer
.Parse(.Items(i).SubItems(8).Text)
668.
Dim
DiscountPerPiece = ((
Integer
.Parse(txtDCCash.Text) / 100) * Cost)
669.
od.Cost = Cost - DiscountPerPiece
670.
od.DiscountPerUnit = DiscountPerPiece
671.
od.Total = ((Cost - DiscountPerPiece) * Amount * QuantityPerUnit)
672.
Else
673.
od.Cost =
Double
.Parse(.Items(i).SubItems(2).Text)
674.
od.DiscountPerUnit = 0.0
675.
od.Total =
Double
.Parse(.Items(i).SubItems(5).Text)
676.
End
If
677.
ElseIf
optCredit.Checked =
True
Then
678.
od.Cost =
Double
.Parse(.Items(i).SubItems(2).Text)
679.
od.DiscountPerUnit = 0.0
680.
od.Total =
Double
.Parse(.Items(i).SubItems(5).Text)
681.
End
If
682.
od.OrderStatusID =
"0"
683.
o.OrdersDetails.Add(od)
684.
685.
Dim
ProductInOrder =
Integer
.Parse(.Items(i).SubItems(3).Text) *
Integer
.Parse(.Items(i).SubItems(8).Text)
686.
Dim
ps = db.ProductOnBranches.FirstOrDefault(
Function
(id) id.ProductID = ProductID)
687.
If
ps IsNot
Nothing
Then
688.
Dim
OldProductInOrder = ps.ProductInOrder
689.
ps.ProductInOrder = OldProductInOrder + ProductInOrder
690.
Else
691.
pb =
New
ProductOnBranch()
692.
pb.ProductID = ProductID
693.
pb.BranchID = BizConfig.CurrentBranchID
694.
pb.UnitID = .Items(i).SubItems(6).Text
695.
pb.QuantityWithUnit = 0.0
696.
pb.RealQuantity = 0
697.
pb.ProductInOrder = ProductInOrder
698.
699.
pb.LowLimitToOrder = 0
700.
db.ProductOnBranches.InsertOnSubmit(pb)
701.
End
If
702.
Next
703.
704.
Dim
prds = From prd
In
db.PurchaseRequisitionDetails _
705.
Where ProductIDList.Contains(prd.ProductID)
706.
For
Each
p
In
prds
707.
If
p.PRStatus =
"ยังไม่ดำเนินการ"
Then
708.
p.PRStatus =
"อยู่ระหว่างสั่งซื้อ"
709.
End
If
710.
Next
711.
End
With
712.
db.Orders.InsertOnSubmit(o)
713.
db.SubmitChanges()
714.
ts.Complete()
715.
End
Using
716.
sw.
Stop
()
717.
ProcessTime = sw.ElapsedMilliseconds / 1000
718.
_ToolStripStatusLabel.Text =
"เวลาที่ใช้ : "
& ProcessTime.ToString(
"0.0000"
) &
" วินาที"
719.
720.
If
prDlg.ShowDialog = Windows.Forms.DialogResult.OK
Then
721.
prDoc.Print()
722.
End
If
723.
724.
ClearPODetails()
725.
ClearCreditTerm()
726.
ClearProduct()
727.
ClearNet()
728.
lsvProductLists.Items.Clear()
729.
dgvProductLists.DataSource =
Nothing
730.
dgvPRList.DataSource =
Nothing
731.
dgvPRDList.DataSource =
Nothing
732.
MessageBox.Show(
"บันทึกรายการสั่งซื้อสินค้า เรียบร้อยแล้ว !!!"
,
"ผลการทำงาน"
, MessageBoxButtons.OK, MessageBoxIcon.Information)
733.
txtSearch.Focus()
734.
txtSearch.SelectAll()
735.
Catch
ex
As
Exception
736.
MessageBox.Show(
"ไม่สามารถบันทึกรายการสั่งซื้อได้ เนื่องจาก "
& ex.Message,
"ข้อผิดพลาด"
, MessageBoxButtons.OK, MessageBoxIcon.Warning)
737.
End
Try
738.
End
If
739.
End
Sub
740.
741.
Private
Sub
StringToPrint_Print(
ByVal
sender
As
Object
,
ByVal
e
As
PrintPageEventArgs)
742.
AnyString(e.Graphics, cboCompany.Text, 240, 170)
743.
AnyString(e.Graphics, txtPONo.Text, 550, 125)
744.
AnyString(e.Graphics, DateTime.Today.ToLongDateString(), 550, 170)
745.
AnyString(e.Graphics, dtpPaidDate.Text, 550, 195)
746.
AnyString(e.Graphics, dtpReceiveDate.Text, 550, 220)
747.
Dim
PrintCreditTerm
As
String
=
""
748.
If
optCash.Checked =
True
Then
749.
PrintCreditTerm =
"เงินสด"
750.
ElseIf
optCredit.Checked =
True
Then
751.
PrintCreditTerm = txtDcRateDiscountReceivedCreditTerm.Text &
"/"
& txtDcDateDiscountReceivedCreditTerm.Text &
",n/"
& txtCreditDateDiscountReceivedCreditTerm.Text
752.
End
If
753.
AnyString(e.Graphics, PrintCreditTerm, 195, 195)
754.
755.
Dim
i
As
Integer
= 0
756.
Dim
CurrentYPosition
As
Integer
= 330
757.
Dim
strColumn1
As
String
=
""
758.
Dim
strColumn2
As
String
=
""
759.
Dim
strColumn3
As
Double
= 0.0
760.
Dim
strColumn4
As
Double
= 0.0
761.
Dim
strColumn5
As
String
=
""
762.
Dim
strColumn6
As
Double
= 0.0
763.
For
i = 0
To
lsvProductLists.Items.Count - 1
764.
strColumn1 = lsvProductLists.Items(i).SubItems(0).Text
765.
strColumn2 = lsvProductLists.Items(i).SubItems(1).Text
766.
strColumn3 =
CDbl
(lsvProductLists.Items(i).SubItems(2).Text)
767.
strColumn4 =
CDbl
(lsvProductLists.Items(i).SubItems(3).Text)
768.
strColumn5 = lsvProductLists.Items(i).SubItems(4).Text
769.
strColumn6 =
CDbl
(lsvProductLists.Items(i).SubItems(5).Text)
770.
AnyString(e.Graphics, strColumn1, 135, CurrentYPosition)
771.
If
strColumn2.Length > 25
Then
772.
AnyString(e.Graphics, strColumn2.Left(25) &
"..."
, 230, CurrentYPosition)
773.
Else
774.
AnyString(e.Graphics, strColumn2, 230, CurrentYPosition)
775.
End
If
776.
AnyString(e.Graphics, strColumn3.ToString(
"#,##0"
), 435, CurrentYPosition)
777.
AnyString(e.Graphics, strColumn4.ToString(), 500, CurrentYPosition)
778.
AnyString(e.Graphics, strColumn5, 540, CurrentYPosition)
779.
AnyString(e.Graphics, strColumn6.ToString(), 625, CurrentYPosition)
780.
CurrentYPosition = CurrentYPosition + 20
781.
Next
782.
AnyString(e.Graphics, BizConfig.VATRate.ToString(), 235, 590)
783.
AnyString(e.Graphics, lblDiscountReceived.Text, 585, 565)
784.
AnyString(e.Graphics, lblInputVAT.Text, 585, 590)
785.
AnyString(e.Graphics, lblNet.Text, 585, 615)
786.
End
Sub
787.
788.
Private
Sub
AnyString(
ByVal
g
As
Graphics,
ByVal
printString
As
String
,
ByVal
xPos
As
Integer
,
ByVal
yPos
As
Integer
)
789.
Dim
anyPoint
As
New
PointF(xPos, yPos)
790.
g.DrawString(printString, UseFont, Brushes.Black, anyPoint)
791.
End
Sub
792.
793.
Private
Sub
dtpEnd_ValueChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
dtpEnd.ValueChanged
794.
If
dtpEnd.Value > DateTime.Today
Then
795.
dtpEnd.Value = DateTime.Today
796.
End
If
797.
End
Sub
798.
799.
Private
Sub
optPRNo_CheckedChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
optPRNo.CheckedChanged
800.
If
optPRNo.Checked =
True
Then
801.
txtSearchPR.Enabled =
True
802.
dtpStart.Enabled =
False
803.
dtpEnd.Enabled =
False
804.
dgvPRList.Columns.Clear()
805.
dgvPRList.DataSource =
Nothing
806.
dgvPRDList.DataSource =
Nothing
807.
txtSearchPR.Focus()
808.
End
If
809.
End
Sub
810.
811.
Private
Sub
optDuration_CheckedChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
optDuration.CheckedChanged
812.
If
optDuration.Checked =
True
Then
813.
txtSearchPR.Enabled =
False
814.
dtpStart.Enabled =
True
815.
dtpEnd.Enabled =
True
816.
dtpStart.Value = DateTime.Today.AddMonths(-1)
817.
dtpEnd.Value = DateTime.Today
818.
dgvPRList.Columns.Clear()
819.
dgvPRList.DataSource =
Nothing
820.
dgvPRDList.DataSource =
Nothing
821.
dtpStart.Focus()
822.
End
If
823.
End
Sub
824.
825.
Private
Sub
frmPO_FormClosed(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.FormClosedEventArgs)
Handles
MyBase
.FormClosed
826.
db.Connection.Close()
827.
End
Sub
828.
829.
Private
Sub
cboCompany_KeyPress(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyPressEventArgs)
Handles
cboCompany.KeyPress
830.
e.Handled =
True
831.
End
Sub
832.
833.
Private
Sub
cboCompany_KeyDown(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyEventArgs)
Handles
cboCompany.KeyDown
834.
e.Handled =
True
835.
End
Sub
836.
837.
Private
Sub
cboUnit_KeyPress(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyPressEventArgs)
Handles
cboUnit.KeyPress
838.
e.Handled =
True
839.
End
Sub
840.
841.
Private
Sub
cboUnit_KeyDown(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyEventArgs)
Handles
cboUnit.KeyDown
842.
e.Handled =
True
843.
End
Sub
844.
845.
Private
Sub
txtDCCash_KeyPress(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyPressEventArgs)
Handles
txtDCCash.KeyPress
846.
If
e.KeyChar <
"0"
Or
e.KeyChar >
"9"
Then
847.
e.Handled =
True
848.
End
If
849.
End
Sub
850.
851.
Private
Sub
txtDcDateDiscountReceivedCreditTerm_KeyPress(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyPressEventArgs)
Handles
txtDcDateDiscountReceivedCreditTerm.KeyPress
852.
If
e.KeyChar <
"0"
Or
e.KeyChar >
"9"
Then
853.
e.Handled =
True
854.
End
If
855.
End
Sub
856.
857.
Private
Sub
txtDcRateDiscountReceivedCreditTerm_KeyPress(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyPressEventArgs)
Handles
txtDcRateDiscountReceivedCreditTerm.KeyPress
858.
If
e.KeyChar <
"0"
Or
e.KeyChar >
"9"
Then
859.
e.Handled =
True
860.
End
If
861.
End
Sub
862.
863.
Private
Sub
txtCreditDateDiscountReceivedCreditTerm_KeyPress(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyPressEventArgs)
Handles
txtCreditDateDiscountReceivedCreditTerm.KeyPress
864.
If
e.KeyChar <
"0"
Or
e.KeyChar >
"9"
Then
865.
e.Handled =
True
866.
End
If
867.
End
Sub
868.
869.
Private
Sub
txtLastCost_KeyPress(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyPressEventArgs)
Handles
txtLastCost.KeyPress
870.
If
e.KeyChar <
"0"
Or
e.KeyChar >
"9"
Then
871.
e.Handled =
True
872.
End
If
873.
End
Sub
874.
875.
Private
Sub
txtAmount_KeyPress(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.Windows.Forms.KeyPressEventArgs)
Handles
txtAmount.KeyPress
876.
If
e.KeyChar <
"0"
Or
e.KeyChar >
"9"
Then
877.
e.Handled =
True
878.
End
If
879.
End
Sub
880.
881.
Private
Sub
optCash_CheckedChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
optCash.CheckedChanged
882.
If
optCash.Checked =
True
Then
883.
ClearCreditTerm()
884.
txtDCCash.Enabled =
True
885.
txtDcDateDiscountReceivedCreditTerm.Enabled =
False
886.
txtDcRateDiscountReceivedCreditTerm.Enabled =
False
887.
txtCreditDateDiscountReceivedCreditTerm.Enabled =
False
888.
dtpPaidDate.Value = DateTime.Today.NextWorkingDay(HolidayMode.SundayOnly)
889.
txtDCCash.Focus()
890.
txtDCCash.SelectAll()
891.
End
If
892.
End
Sub
893.
894.
Private
Sub
optCredit_CheckedChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
optCredit.CheckedChanged
895.
If
optCredit.Checked =
True
Then
896.
txtDCCash.Text =
"0"
897.
txtDCCash.Enabled =
False
898.
txtDcDateDiscountReceivedCreditTerm.Enabled =
True
899.
txtDcRateDiscountReceivedCreditTerm.Enabled =
True
900.
txtCreditDateDiscountReceivedCreditTerm.Enabled =
True
901.
txtDcDateDiscountReceivedCreditTerm.Focus()
902.
txtDcDateDiscountReceivedCreditTerm.SelectAll()
903.
End
If
904.
End
Sub
905.
906.
Private
Sub
cmdClear_Click(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
cmdClear.Click
907.
lsvProductLists.Items.Clear()
908.
ClearNet()
909.
cmdSave.Enabled =
False
910.
txtSearch.Focus()
911.
txtSearch.SelectAll()
912.
End
Sub
913.
914.
Private
Sub
txtDCCash_TextChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
txtDCCash.TextChanged
915.
If
txtDCCash.Text.Trim() =
""
Then
txtDCCash.Text =
"0"
916.
CalculateNet()
917.
End
Sub
918.
919.
Private
Sub
txtDcDateDiscountReceivedCreditTerm_TextChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
txtDcDateDiscountReceivedCreditTerm.TextChanged
920.
If
txtDcDateDiscountReceivedCreditTerm.Text.Trim() =
""
Then
txtDcDateDiscountReceivedCreditTerm.Text =
"0"
921.
End
Sub
922.
923.
Private
Sub
txtDcRateDiscountReceivedCreditTerm_TextChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
txtDcRateDiscountReceivedCreditTerm.TextChanged
924.
If
txtDcRateDiscountReceivedCreditTerm.Text.Trim() =
""
Then
txtDcRateDiscountReceivedCreditTerm.Text =
"0"
925.
End
Sub
926.
927.
Private
Sub
txtLastCost_TextChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
txtLastCost.TextChanged
928.
If
txtLastCost.Text.Trim() =
""
Then
txtLastCost.Text =
"1"
929.
If
Integer
.Parse(txtLastCost.Text) = 0
Then
txtLastCost.Text =
"1"
930.
End
Sub
931.
932.
Private
Sub
txtAmount_TextChanged(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
txtAmount.TextChanged
933.
If
txtAmount.Text.Trim() =
""
Then
txtAmount.Text =
"1"
934.
If
Integer
.Parse(txtAmount.Text) = 0
Then
txtAmount.Text =
"1"
935.
End
Sub
936.
End
Class