Advertisement
Ortund

Untitled

Oct 26th, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.12 KB | None | 0 0
  1. Private Sub AddUpdateOrg(ByVal OrganizationName As String, ByVal Action As String, Optional ByVal Target As Integer = Nothing)
  2.     ' ###############################################################
  3.     ' #                ADD OR UPDATE AN ORGANIZATION                #
  4.     ' # ============================================================#
  5.     ' # PARAMETERS                                                  #
  6.     ' # ----------                                                  #
  7.     ' # OrganizationName As String                                  #
  8.     ' # The organization name that is to be stored in the database. #
  9.     ' #                                                             #
  10.     ' # Action As String                                            #
  11.     ' # What action will be taken by this procedure, add or update. #
  12.     ' #                                                             #
  13.     ' # Optional Target As Integer (Default: Nothing)               #
  14.     ' # If updating an existing record, specify the OrganizationID  #
  15.     ' # of the target organization.                                 #
  16.     ' ###############################################################
  17.  
  18.     ' Get the list of Modules selected for this organization
  19.     Dim ModuleList As New List(Of Integer)
  20.     For i As Integer = 0 To chkModules.Items.Count - 1
  21.         If chkModules.Items(i).Selected Then
  22.             ModuleList.Add(chkModules.Items(i).Value)
  23.         End If
  24.     Next
  25.  
  26.     Dim sql As String = Nothing
  27.  
  28.     Select Case Action
  29.         Case "Add"
  30.             sql = "insert into Organizations(OrganizationName) values ('" & OrganizationName & "')"
  31.  
  32.         Case "Update"
  33.             sql = "update Organizations set OrganizationName = '" & OrganizationName & "' " & _
  34.                 "where OrganizationID = " & Target
  35.     End Select
  36.  
  37.     Dim dr As SqlDataReader = d.GetReader("select * from OrgModules where OrgID = " & Target)
  38.     If dr.HasRows Then
  39.         dr.Close()
  40.         UpdateModules(Target, ModuleList, "update")
  41.     Else
  42.         dr.Close()
  43.         UpdateModules(Target, ModuleList, "insert")
  44.     End If
  45.     d.DoCommand(sql)
  46. End Sub
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement