Wednesday, December 21, 2011

M_Core Module V-1


Folowing text is a part of ERP2011 M_Core module...(Will Update Soon)
Copy Paste or Click Here Download Codes.


Imports System.Data.SqlClient
Module Core
    Public DbCon As SqlClient.SqlConnection = _
     New SqlClient.SqlConnection(My.MySettings.Default.ERP2011ConStr)


    Public StProc As String
    Public DbConCmd As SqlClient.SqlCommand = New SqlClient.SqlCommand
    Public AppMode As String
    Public FindSqlStr As String
    'Core.DbConCmd.CommandType = CommandType.StoredProcedure
    Private P_FindSqlStr As String
    Public FindReturnInt As Integer
    Public FindReturnStr As String
    Public MyApp As Form = SalesMain
    Public MyUserLogin As String
    Public MyUserLoginID As Integer
    Public SesID As Int32
    Public SesState As Boolean


#Region "Properties Region"


    Public Class User_Loged


        Property P_User As Integer
        Property P_User_Name As String
        Property P_Login_Date As Date


    End Class


#End Region


    Public Sub LoadTab(ByVal MyParentFrm As Form, ByVal MyForm As Form)
        Dim DocAccounts As Form = MyForm
        DocAccounts.MdiParent = MyParentFrm
        DocAccounts.Show()
        DocAccounts.WindowState = FormWindowState.Maximized
    End Sub


    Public Sub FindRec(ByVal FindFrmLbl As String, ByVal ParentSql As String, ByVal ChildSql As String, ByVal MyControl As Control)
        Dim FndFrm As New FindFrm()
        FndFrm.Show()
        FndFrm.Label1.Text = FindFrmLbl
        FndFrm.ParentSql = ParentSql
        FndFrm.ChildSql = ChildSql
        'FndFrm.TrgFrm = Me
        FndFrm.TrgCtr = MyControl
        'FndFrm.ChkSelect = Me.ChkSelect
    End Sub
    Public Sub FillDate(ByVal MyDate As TextBox)
        Dim DtFrm As New InsertDate()
        DtFrm.Show()
        DtFrm.TargetDate = MyDate
    End Sub


    Public Sub FillDate2(ByVal ContainerFrm As Form, ByVal MyDate As TextBox)
        'If AccountsMainFrm.Visible = False Then
        Dim DocAccounts As Form = ContainerFrm
        Dim MyChildFrm As Form = New InsertDate
        DocAccounts.MdiParent = ContainerFrm
        DocAccounts.Show()
        DocAccounts.WindowState = FormWindowState.Maximized
        'End If


        MyChildFrm.TopLevel = False
        ContainerFrm.Controls.Add(MyChildFrm)
        MyChildFrm.Show()
        MyChildFrm.Location = New Point(100, 100)
        MyChildFrm.FormBorderStyle = FormBorderStyle.Sizable
    End Sub
    Public Sub LoadSubForm(ByVal ParentFrm As Form, ByVal ContainerFrm As Form, ByVal MyChildFrm As Form)


        'If AccountsMainFrm.Visible = False Then
        Dim DocAccounts As Form = ContainerFrm
        DocAccounts.MdiParent = ParentFrm
        DocAccounts.Show()
        DocAccounts.WindowState = FormWindowState.Maximized
        'End If


        MyChildFrm.TopLevel = False
        ContainerFrm.Controls.Add(MyChildFrm)
        MyChildFrm.Show()
        MyChildFrm.BringToFront()
        MyChildFrm.Location = New Point(100, 100)
        MyChildFrm.FormBorderStyle = FormBorderStyle.Sizable


    End Sub


    Public Sub ComboFillSql(ByVal MyCombo As ComboBox, ByVal FillBy As String)
        Try


            Core.DbCon.Close()
            Core.DbCon.Open()


            Dim DbConCmd As New SqlClient.SqlCommand(FillBy, Core.DbCon)
            DbConCmd.CommandType = CommandType.Text


            'With DbConCmd.Parameters 'Core.DbConCmd.Parameters
            '.AddWithValue("@FindID", FindBy)
            'End With


            DbConCmd.ExecuteNonQuery()


            Dim dt = New DataTable
            'Dim sda = New SqlDataAdapter(FillBy, Core.DbCon)
            Dim sda = New SqlDataAdapter(DbConCmd)


            sda.Fill(dt)


            MyCombo.DataSource = dt
            MyCombo.ValueMember = dt.Columns(0).ColumnName
            MyCombo.DisplayMember = dt.Columns(1).ColumnName


            Core.DbCon.Close()
        Catch
            Core.DbCon.Close()
        End Try
        Core.DbCon.Close()
    End Sub


    Public Sub ComboFillSimple(ByVal MyCombo As ComboBox, ByVal FillBy As String)
        Try


            Core.DbCon.Close()
            Core.DbCon.Open()


            Dim DbConCmd As New SqlClient.SqlCommand(FillBy, Core.DbCon)
            DbConCmd.CommandType = CommandType.StoredProcedure


            ' With DbConCmd.Parameters 'Core.DbConCmd.Parameters
            '.AddWithValue("@FindID", FindBy)
            'End With


            DbConCmd.ExecuteNonQuery()


            Dim dt = New DataTable
            'Dim sda = New SqlDataAdapter(FillBy, Core.DbCon)
            Dim sda = New SqlDataAdapter(DbConCmd)


            sda.Fill(dt)


            MyCombo.DataSource = dt
            MyCombo.ValueMember = dt.Columns(0).ColumnName
            MyCombo.DisplayMember = dt.Columns(1).ColumnName


            Core.DbCon.Close()
        Catch
            'MsgBox("Error ocured")
            Core.DbCon.Close()
        End Try
        Core.DbCon.Close()
    End Sub


    Public Sub ComboFill(ByVal MyCombo As ComboBox, ByVal FillBy As String, ByVal FindBy As Integer)


        Try


            Core.DbCon.Close()
            Core.DbCon.Open()


            Dim DbConCmd As New SqlClient.SqlCommand(FillBy, Core.DbCon)
            DbConCmd.CommandType = CommandType.StoredProcedure


            With DbConCmd.Parameters 'Core.DbConCmd.Parameters
                .AddWithValue("@FindID", FindBy)
            End With


            DbConCmd.ExecuteNonQuery()


            Dim dt = New DataTable
            'Dim sda = New SqlDataAdapter(FillBy, Core.DbCon)
            Dim sda = New SqlDataAdapter(DbConCmd)


            sda.Fill(dt)


            MyCombo.DataSource = dt
            MyCombo.ValueMember = dt.Columns(0).ColumnName
            MyCombo.DisplayMember = dt.Columns(1).ColumnName


            Core.DbCon.Close()
        Catch
            'MsgBox("Error ocured")
            Core.DbCon.Close()
        End Try
        Core.DbCon.Close()


    End Sub
    Public Function Insert_Account(ByVal p1 As Integer, ByVal p2 As Integer, ByVal p3 As String) As String
        Core.DbCon.Open()
        StProc = "Accounts.Accounts_insert"
        Dim recs As String
        Dim cmd As New SqlClient.SqlCommand(Core.StProc, Core.DbCon)
        cmd.CommandType = CommandType.StoredProcedure


        With cmd.Parameters 'Core.DbConCmd.Parameters
            .AddWithValue("@acid", p1)
            .AddWithValue("@acname", p3)
            .AddWithValue("@acsubtype", p2)
        End With


        recs = cmd.ExecuteNonQuery().ToString
        'Core.DbConCmd.ExecuteNonQuery()


        Core.DbCon.Close()
        Return recs
    End Function
End Module

No comments:

Post a Comment