Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Imports RSS.ClassDB
Imports RSS.CFunction1
Imports RSS.CConstant
Public Class frmExDateMakeExcise
    Dim date1 As Date
    Dim inv, srno As Integer   'for invoice number
    Dim PerId As Integer  'for retrive permit id
    Dim PerName As String 'for permit holder name
    Dim PerLicence As Integer 'For permit holder licence no.
    Dim PerValidity As String   'For prmit holders validity
    Dim PerAddress As String    'For prmit holders Address
    Dim ml As Double = 0    'for cheking limit
    Dim Tml As Double = 0     'for total ml
    Dim amt As Double = 0        'for calculating total
    Dim limit As Integer = 0
    Dim qtylimit As Integer = 0
    Private Sub txtmonth_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtmonth.KeyDown
        Try
            If e.KeyCode = Keys.Enter Then

                If Val(txtmonth.Text) < 1 Or Val(txtmonth.Text) > 12 Then
                    txtmonth.Text = ""
                Else
                    txtyear.Focus()
                End If

            End If
            If e.KeyData = Keys.Escape Then
                txtdate.Focus()
            End If
            If e.KeyData = Keys.F12 Then
                Me.Close()
            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub frmExDateMakeExcise_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Try
            DATACLOSE()
            ExDateCheck = False
            Me.Dispose()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub frmExDateMakeExcise_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        
    End Sub

    Private Sub txtdate_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtdate.KeyDown
        Try
            If e.KeyCode = Keys.Enter Then

                If Val(txtdate.Text) < 1 Or Val(txtdate.Text) > 31 Then
                    txtdate.Text = ""
                Else
                    txtmonth.Focus()
                End If

            End If
            If e.KeyData = Keys.Escape Then
                Me.Close()
            End If
            If e.KeyData = Keys.F12 Then
                Me.Close()
            End If

        Catch ex As Exception

        End Try
        
    End Sub

    Private Sub txtdate_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtdate.TextChanged
        Try
            If txtdate.TextLength = 2 Then
                If Val(txtdate.Text) < 1 Or Val(txtdate.Text) > 31 Then
                    txtdate.Text = ""
                Else
                    txtmonth.Focus()
                End If
            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub txtyear_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtyear.KeyDown
        Try
            If e.KeyCode = Keys.Enter Then

                If Val(txtyear.TextLength) = 4 Then
                    Dim date11 As String = Val(txtdate.Text) & "/" & Val(txtmonth.Text) & "/" & Val(txtyear.Text)
                    dtpdatesetCB.Value = FormatDateTime(date11, DateFormat.ShortDate)
                    'MsgBox(dtpdatesetCB.Value)
                    DatePresent(dtpdatesetCB.Value)
                    Me.Dispose()

                Else

                    txtyear.Text = ""
                End If

            End If
            If e.KeyData = Keys.Escape Then
                txtmonth.Focus()
            End If
            If e.KeyData = Keys.F12 Then
                Me.Close()
            End If

        Catch ex As Exception
            MsgBox("Date Is Not Valid")
            txtyear.Text = Date.Today.Year
            txtmonth.Text = Date.Today.Month
            txtdate.Text = Date.Today.Day
            txtdate.Focus()
        End Try
        
    End Sub

    Private Sub txtyear_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtyear.TextChanged
        Try
            If txtyear.TextLength <= 4 Then


            Else
                txtyear.Text = ""
            
            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub txtmonth_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtmonth.TextChanged
        Try
            If txtmonth.TextLength <= 2 Then
                If Val(txtmonth.Text) < 1 Or Val(txtmonth.Text) > 12 Then
                    txtmonth.Text = ""

                End If
            End If
        Catch ex As Exception

        End Try
    End Sub

    Public Function DatePresent(ByVal dateF As Date)
        Try
            Dim dt As New DataTable
            GetDataTable("select date from ExFinalBillDetails", dt)
            For i = 0 To dt.Rows.Count - 1
                If FormatDateTime(dt.Rows(i).Item(0), DateFormat.ShortDate) = dateF Then
                    ExDateCheck = True
                End If
            Next
            If ExDateCheck = True Then
                If DialogResult.Yes = MsgBox("Allready Excise Done For " & dateF & " Do U Want To Repalce It.????", MsgBoxStyle.YesNo) Then
                    DeleteExBill(dateF)
                    FrmName = "DelEx"
                    frmExBill_Correction.Rearrange()
                    CreateExBill(dateF)
                Else

                End If
            Else
                CreateExBill(dateF)
                MsgBox("excise created for " & dateF)
            End If
        Catch ex As Exception

        End Try
        Return False
    End Function

    Public Function DeleteExBill(ByVal dateE As Date)
        Try
            Dim dateDel As Date = FormatDateTime(dateE.Date, DateFormat.ShortDate)
            'dateDel = dtpdatesetCB.Value.Date
            'dateDel = FormatDateTime(dateDel, DateFormat.ShortDate)
            Dim dt As New DataTable
            GetDataTable("select * from ExFinalBill", dt)
            For i = 0 To dt.Rows.Count - 1
                If dt.Rows(i).Item(2) = dateDel Then
                    'Dim dt2 As New DataTable
                    GetDataTable("delete * from ExFinalBillDetails where invoice=" & dt.Rows(i).Item(1))
                    ' SaveData(dt2, DBOpeartion.DELETE, "ExFinalBillDetails", "invoice", False)
                    'Dim dt1 As New DataTable
                    GetDataTable("delete * from ExFinalBill where invoice=" & dt.Rows(i).Item(1))
                    'SaveData(dt1, DBOpeartion.DELETE, "ExFinalBill", "invoice", False)
                End If
            Next

        Catch ex As Exception

        End Try
        'MsgBox("Excise Bill Deleted Date " & dateDel)
        Return False
    End Function

    
    '********************Temp****************************
    Public Function CreateExBill(ByVal dated As Date)
        Try
            date1 = dated
            date1 = FormatDateTime(date1, DateFormat.ShortDate)
            GetDataTable("delete * from ExTemp")
            ' While date1 <= date2
            ' MsgBox(date1 & "---" & date2)
            Dim ADD As Boolean = False
            Dim dt As New DataTable
            GetDataTable("select * from BILLFINAL", dt)
            

            Dim dtMain As New DataTable
            GetDataTable("select DATE, BILLNO from BILLFINAL where TABLE_NO<>'XYZ' AND TYPE<>'Cancel'", dtMain)
            For K = 0 To dtMain.Rows.Count - 1 '******Main******
                ADD = False
                dtMain.Rows(K).Item(0) = FormatDateTime(dtMain.Rows(K).Item(0), DateFormat.ShortDate)
                'MsgBox(FormatDateTime(dtMain.Rows(K).Item(0), DateFormat.ShortDate))
                date1 = FormatDateTime(date1, DateFormat.ShortDate)
                Dim datetemp As New Date
                datetemp = FormatDateTime(dtMain.Rows(K).Item(0), DateFormat.ShortDate)
                If datetemp = date1 Then
                    Dim dtBillRet As New DataTable

                    GetDataTable("select * from finalbill where DEPT='Liquior' AND BILLNO=" & Val(dtMain.Rows(K).Item(1)), dtBillRet)
                     



                    Dim BILLNO = Val(dtMain.Rows(K).Item(1))
                    For I = 0 To dtBillRet.Rows.Count - 1
                        If dtBillRet.Rows(I).Item(11) <> "NIP 1/2" And dtBillRet.Rows(I).Item(11) <> "PEG_L" And dtBillRet.Rows(I).Item(11) <> "PEG_S" Then
                            Dim dtExTemp As New DataTable
                            GetDataTable("select * from ExTemp", dtExTemp)
                            ' If dtExTemp.Rows.Count > 0 Then
                            Dim dtInner As New DataTable
                            GetDataTable("select ITEM from ExTemp", dtInner)
                            If dtInner.Rows.Count > 0 Then
                                For J = 0 To dtInner.Rows.Count - 1
                                    'MsgBox(dtBillRet.Rows(I).Item(3) & " & " & dtInner.Rows(J).Item(0))
                                    If dtBillRet.Rows(I).Item(3).ToString = dtInner.Rows(J).Item(0).ToString Then
                                        dtBillRet.Rows(I).Item(0).ToString()
                                        MsgBox(dtBillRet.Rows(I).Item(3).ToString)
                                        Dim addQty As Integer = 0
                                        Dim dtInAlready As New DataTable
                                        GetDataTable("select * from ExTemp where ITEM='" & dtInner.Rows(J).Item(0) & "'", dtInAlready)
                                        If dtInAlready.Rows.Count > 0 Then
                                            addQty = Val(dtInAlready.Rows(0).Item(1)) + Val(dtBillRet.Rows(I).Item(4))
                                            dtInAlready.Rows(0).Item(1) = Val(addQty)
                                            dtInAlready.Rows(0).Item(3) = Val(dtInAlready.Rows(0).Item(2)) * Val(addQty)
                                            SaveData(dtInAlready, CConstant.DBOpeartion.MODIFY, "ExTemp", "ITEM", False)
                                            ADD = True
                                        End If

                                    End If
                                Next
                            End If
                            If ADD = False Then
                                Dim exRate As New DataTable
                                GetDataTable("select exciserate from item where item='" & dtBillRet.Rows(I).Item(3) & "'", exRate)

                                dtExTemp.Rows.Add()
                                dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(0) = dtBillRet.Rows(I).Item(3)
                                dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(1) = dtBillRet.Rows(I).Item(4)
                                dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(2) = Val(exRate.Rows(0).Item(0))
                                dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(3) = Val(dtBillRet.Rows(I).Item(4)) * Val(exRate.Rows(0).Item(0))
                                dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(4) = dtBillRet.Rows(I).Item(7)
                                dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(5) = dtBillRet.Rows(I).Item(8)
                                dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(6) = dtBillRet.Rows(I).Item(9)
                                dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(7) = dtBillRet.Rows(I).Item(10)
                                dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(8) = dtBillRet.Rows(I).Item(11)
                                dtExTemp.Rows(dtExTemp.Rows.Count - 1).Item(9) = dtBillRet.Rows(I).Item(12)
                                ' MsgBox(dtBillRet.Rows(I).Item(12))
                                SaveData(dtExTemp, CConstant.DBOpeartion.ADD, "ExTemp", "ITEM", False)
                            End If

                        End If
                    Next
                End If

            Next

            '********************* Distribution *********************


            Dim qty As Integer
            ' Dim cnt As Integer=0
            Dim dtDis As New DataTable
            GetDataTable("select * from ExTemp", dtDis)
            Dim ml As Integer = 0
            Dim tml As Integer = 0
            For p = 0 To dtDis.Rows.Count - 1
                qty = Val(dtDis.Rows(p).Item(1))
                Dim x As Integer = 1
                Dim cnt180 As Integer = 0




                Dim dtlimt As New DataTable
                GetDataTable("Select limit from ExUnitLimit where Unit=" & Val(dtDis.Rows(p).Item(7)), dtlimt)
                If dtlimt.Rows.Count > 0 Then
                    qtylimit = Val(dtlimt.Rows(0).Item(0))
                Else
                    Dim dtlimt2 As New DataTable
                    GetDataTable("select * from ExStoreInfo where code=1", dtlimt2)

                    If dtlimt2.Rows.Count > 0 Then
                        limit = Val(dtlimt2.Rows(0).Item(4))
                        qtylimit = Val(dtlimt2.Rows(0).Item(5))
                    End If
                End If
                


                While Val(qty) >= x
                    Dim exit1 As Boolean = False
                    
                    ml = Val(ml) + Val(dtDis.Rows(p).Item(7))
                    tml = Val(tml) + Val(dtDis.Rows(p).Item(7))
                    If Val(dtDis.Rows(p).Item(7)) = 180 Then
                        If Val(Val(tml) / Val(dtDis.Rows(p).Item(7))) < qtylimit Then
                          
                            If Val(Val(tml) / Val(dtDis.Rows(p).Item(7))) = qty Then
                                GetPerHld()
                                SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), Val(Val(ml) / Val(dtDis.Rows(p).Item(7))))
                                SaveBill()
                                qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
                                ml = 0
                                tml = 0
                                Exit While
                            End If

                        Else


                            SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), Val(Val(ml) / Val(dtDis.Rows(p).Item(7))))

                            GetPerHld()
                            SaveBill()
                            'CAlAmt()
                            qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
                            ml = 0
                            tml = 0
                            
                            If tml <= limit And qty = x Then
                                exit1 = True
                            End If
                        End If
                    End If
                    
                    If tml <= limit And qty = x Or qty = Val(Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))) Then

                        If exit1 = True Then
                        Else
                            GetPerHld()
                        End If

                        ' MsgBox(PerId)
                        SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), qty) 'Val(Val(ml) / Val(dtDis.Rows(p).Item(7))))
                        GetPerHld()
                        SaveBill()
                    

                        qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
                        ml = 0
                        tml = 0
                        If exit1 = True Then
                            Exit While
                            qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
                        End If
                    End If
                    

                    If tml >= limit And Val(Val(ml) / Val(dtDis.Rows(p).Item(7))) > 1 Then  '**************
                        If tml <= limit And Val(Val(ml) / Val(dtDis.Rows(p).Item(7))) < qtylimit Then
                        Else
                            If Val(Val(ml) / Val(dtDis.Rows(p).Item(7))) < qtylimit Then
                                If tml > limit Then
                                    ml = ml - Val(Val(dtDis.Rows(p).Item(7)))
                                End If
                            Else
                                Dim a As Integer
                                a = Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
                                a = a - qtylimit
                                ml = ml - Val(Val(dtDis.Rows(p).Item(7)) * a)
                            End If

                        End If

                        GetPerHld()
                        SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), Val(Val(ml) / Val(dtDis.Rows(p).Item(7))))

                        SaveBill()
                        'CAlAmt()
                        qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
                        ml = 0
                        tml = 0
                    End If
                    If ml >= limit And Val(Val(ml) / Val(dtDis.Rows(p).Item(7))) = 1 Then
                        GetPerHld()
                        Dim dtx, dt1 As New DataTable
                        tml = 0

                        If Val(dtDis.Rows(p).Item(7)) > limit Then
                            dtx = New DataTable
                            GetDataTable("select max(invoice) from ExFinalBillDetails", dtx)
                            If IsDBNull(dtx) = True Then

                            Else
                                dt1 = New DataTable
                                GetDataTable("select * from ExFinalBillDetails where invoice=" & Val(dtx.Rows(0).Item(0)), dt1)
                                If dt1.Rows.Count > 0 Then
                                    If Val(dt1.Rows(0).Item(7)) <= limit Then
                                        tml = Val(dt1.Rows(0).Item(2))
                                        SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), 1)
                                        '-----------------------
                                        GetPerHld()
                                        SaveBill()
                                        qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
                                        ml = 0

                                    End If
                                End If

                            End If
                        End If
                        '------------------------------
                        If ml > 0 Then

                            SaveBillDetail(dtDis.Rows(p).Item(8), dtDis.Rows(p).Item(9), 1)
                            GetPerHld()
                            SaveBill()
                            qty = Val(qty) - Val(Val(ml) / Val(dtDis.Rows(p).Item(7)))
                            ml = 0
                        End If
                    End If

                End While


            Next
            '-----------------------------------------------
            GetDataTable("delete * from ExTemp")
            '-------------------------------------------------
         
            MsgBox("Excise Bill Completed...", vbInformation)
        Catch ex As Exception

        End Try
        Return False

    End Function
    'for getting permitt holder name
    Public Function GetPerHld()
        Try
            Dim dtHldId As New DataTable
            GetDataTable("select PerHldId from ExStoreInfo where code=1", dtHldId)
            RetrivePerHldName(dtHldId.Rows(0).Item(0))
            PerId = dtHldId.Rows(0).Item(0)
            RetriveInvoiceNo()
        Catch ex As Exception

        End Try
        Return False
    End Function

    Public Function SaveBillDetail(ByVal packing As String, ByVal brand As String, ByVal qty As Integer)
        Try
            Dim dtSDetail As New DataTable
            GetDataTable("select * from ExFinalBillDetails", dtSDetail)
            dtSDetail.Rows.Add()
            Dim dtsr As New DataTable
            dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(0) = GETSRNO()
            inv = RetriveInvoiceNo()
            dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(1) = RetriveInvoiceNo()
            dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(2) = date1

            dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(4) = qty
            Dim dtItem As New DataTable
            GetDataTable("select * from item where BRAND='" & brand & "' AND PACKING='" & packing & "'", dtItem)

            dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(3) = dtItem.Rows(0).Item(1)
            dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(5) = Val(dtItem.Rows(0).Item(8))
            dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(6) = Val(dtItem.Rows(0).Item(8)) * Val(qty)
            dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(7) = dtItem.Rows(0).Item(4)
            dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(8) = Val(dtItem.Rows(0).Item(5))
            dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(9) = dtItem.Rows(0).Item(6)
            dtSDetail.Rows(dtSDetail.Rows.Count - 1).Item(10) = dtItem.Rows(0).Item(16)
            SaveData(dtSDetail, CConstant.DBOpeartion.ADD, "ExFinalBillDetails", "invoice", False)
        Catch ex As Exception

        End Try
        Return False
    End Function
    Public Function GETSRNO()
        Try
            Dim dtn As New DataTable
            GetDataTable("select max(srno) from ExFinalBill", dtn)
            If IsDBNull(dtn.Rows(0).Item(0)) Then
                Return 1
            Else
                Return Val(dtn.Rows(0).Item(0)) + 1
            End If
        Catch ex As Exception

        End Try
        Return False
    End Function

    Public Function SaveBill()
        Try
            Dim dtSBill As New DataTable
            GetDataTable("select * from ExFinalBill", dtSBill)
            dtSBill.Rows.Add()
            dtSBill.Rows(dtSBill.Rows.Count - 1).Item(0) = GETSRNO()
            inv = RetriveInvoiceNo()
            dtSBill.Rows(dtSBill.Rows.Count - 1).Item(1) = RetriveInvoiceNo()
            dtSBill.Rows(dtSBill.Rows.Count - 1).Item(2) = date1
            dtSBill.Rows(dtSBill.Rows.Count - 1).Item(3) = PerName
            dtSBill.Rows(dtSBill.Rows.Count - 1).Item(4) = PerLicence
            dtSBill.Rows(dtSBill.Rows.Count - 1).Item(5) = PerValidity
            dtSBill.Rows(dtSBill.Rows.Count - 1).Item(6) = PerAddress
         
            Dim sum As Double = 0
            Dim dtTotal As New DataTable
            GetDataTable("select invoice,date,amt from ExFinalBillDetails where invoice=" & inv, dtTotal)
            For i = 0 To dtTotal.Rows.Count - 1
                dtTotal.Rows(i).Item(1) = FormatDateTime(dtTotal.Rows(i).Item(1), DateFormat.ShortDate)
                date1 = FormatDateTime(date1, DateFormat.ShortDate)
                If dtTotal.Rows(i).Item(1) = date1 Then
                    sum = Val(sum) + Val(dtTotal.Rows(i).Item(2))
                End If
            Next
            dtSBill.Rows(dtSBill.Rows.Count - 1).Item(7) = Val(sum)
            SaveData(dtSBill, CConstant.DBOpeartion.ADD, "ExFinalBill", "invoice", False)

            '******* Save Holder Number ***********
            Dim dtHldNO As New DataTable
            GetDataTable("select code from ExPremiteHolder where name='" & PerName & "'", dtHldNO)
            Dim dtHldSave As New DataTable
            GetDataTable("select PerHldId,date,code from ExStoreInfo where code=1", dtHldSave)
            Dim dtMaxCode As New DataTable
            GetDataTable("select max(code) from ExPremiteHolder", dtMaxCode)
            If Val(dtHldNO.Rows(0).Item(0)) = Val(dtMaxCode.Rows(0).Item(0)) Then
                dtHldSave.Rows(0).Item(0) = 1
            Else
                dtHldSave.Rows(0).Item(0) = Val(dtHldNO.Rows(0).Item(0)) + 1
            End If

            SaveData(dtHldSave, CConstant.DBOpeartion.MODIFY, "ExStoreInfo", "code", False)


        Catch ex As Exception

        End Try
        Return False
    End Function
    
    Public Function RetrivePerHldName(ByRef id As Integer)
        Try
            Dim d1 As New DataTable
            GetDataTable("select * from ExPremiteHolder where code=" & id, d1)
            PerName = d1.Rows(0).Item(1)
            PerLicence = d1.Rows(0).Item(2)
            PerValidity = d1.Rows(0).Item(3)
            PerAddress = d1.Rows(0).Item(5)
        Catch ex As Exception

        End Try
        Return False
    End Function

    Public Function RetriveInvoiceNo()
        '*************** Retrive Old Details *******************
        Try
            Dim dtEx1, dtEx2 As New DataTable
            GetDataTable("select max(invoice) from ExFinalBill", dtEx1)
            If IsDBNull(dtEx1.Rows(0).Item(0)) Then
                Return 1
            Else

                Return Val(dtEx1.Rows(0).Item(0)) + 1
            End If
    
        Catch ex As Exception

        End Try
        Return False
    End Function

    Private Sub frmExDateMakeExcise_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim dt As New DataTable
            GetDataTable("select * from ExStoreInfo where code=1", dt)

            If dt.Rows.Count > 0 Then
                limit = Val(dt.Rows(0).Item(4))
                qtylimit = Val(dt.Rows(0).Item(5))
            End If
            dtpdateset.Format = DateTimePickerFormat.Short
            dtpdateset.Value = FormatDateTime(Now.Date, DateFormat.ShortDate)
            txtdate.Text = dtpdateset.Value.Day
            txtmonth.Text = dtpdateset.Value.Month
            txtyear.Text = dtpdateset.Value.Year
        Catch ex As Exception

        End Try
    End Sub
End Class
Posted
Updated 23-May-15 0:35am
v2
Comments
Mehdi Gholam 23-May-15 6:32am    
Optimize what? You just dumped some code here.
OriginalGriff 23-May-15 6:39am    
Optimise it for what?
Minimum memory footprint?
Minimum time?
Or what?

1 solution

Hi there,
Okay that is a lot of code - no worry, we can fix that.
What I suggest you do is organize this code into separate classes (Friend, Shared) and add reference to that class to call on that function.
Then, you must run it against Microsoft Minimum Recommended Rules in Code Analysis - you should get around 100 - 200 warnings with your code. Then you MUST solve those. Run the Code Analysis again against the Microsoft Extended Correctness Rules.
If you want your code to be "perfect" run it against the Microsoft All Rules. 500 warnings approximately.

-iProgramIt
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900