
'v1.3.3 - 20100127 - Disabled duplicate record check on non RGBC Customer details

Imports System.Web.Configuration
Imports Superbowl.sqlDB

Partial Public Class NonRGBCCustomerDetails
   Inherits System.Web.UI.Page

   Private Shared strCustomerNo As String = "0"
   'Private Shared strFilter As String = "refSegmentID = 0"
   Private db As New sqlDB
   Private ds As DataSet
   Private dr As DataRow

   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      lblMessage.Text = ""
      'sdsChannel.FilterExpression = strFilter

      If Not Page.IsPostBack Then
         WebConfigurationManager.AppSettings("strPage") = "CustomerDetails"
         If WebConfigurationManager.AppSettings("ULEVEL") <> 5 Then
            btnSave.Enabled = False
         End If
         Try
            strCustomerNo = Nz(Request.QueryString("CID"), "")
         Catch ex As Exception
            strCustomerNo = "0"
         End Try

         If strCustomerNo <> "0" And strCustomerNo.Length > 0 Then
            'load controls				
            Try
               dr = db.GetRow(db.sql_get_Not_RGBC_Customer(strCustomerNo))

               txtCustomerNo.Text = strCustomerNo
               txtCustomerNo.ReadOnly = True
               strCustomerName.Text = Nz(dr!strCustomerName, "")

               lblSegment.Text = Nz(dr!strSegment, "n/a")

               ddlBranch.SelectedValue = Nz(dr!refBranchID, 0)
               ddlRep.SelectedValue = Nz(dr!refRepID, "")
               ddlChannelSegment.SelectedValue = Nz(dr!refChannelSegmentID, 0)

               ddlType1.SelectedValue = Nz(dr!refType1ID, 0)
               ddlType2.SelectedValue = Nz(dr!refType2ID, 0)
               strSnellArea.Text = Nz(dr!strSnellArea, "")

               chkActive.Checked = dr!blnActive
               lblLastEdit.Text = Nz(dr!strLastUser, "unknown") & " - " & SqlDate(Nz(dr!dtStamp, ""), "d MMMM yyyy HH:mm")

            Catch ex As IndexOutOfRangeException                'dr = ds.tables(0).rows(0) doesn't exist
               lblMessage.Text = "Customer, <font color=black>" & strCustomerNo & "</font>, was not found!"
            End Try
         Else
            txtCustomerNo.ReadOnly = False
         End If

      End If

   End Sub

   Private Sub CustomerDetails_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete

   End Sub

   Protected Sub txtCustomerNo_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtCustomerNo.TextChanged
      If db.CountRows("SELECT * FROM mstNot_RGBC_Customer WHERE strCustomerNo = '" & sqlDB.CleanString(txtCustomerNo.Text.Trim) & "' ") > 0 Then
         Response.Redirect("NonRGBCCustomerDetails.aspx?CID=" & sqlDB.CleanString(txtCustomerNo.Text.Trim))
      Else
         'If strCustomerName.Text.Length = 0 Then
         '  strCustomerName.Text = txtCustomerNo.Text.Trim & " "
         'End If
         strCustomerName.Focus()
      End If
   End Sub

   Protected Sub ddlRep_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlRep.SelectedIndexChanged
      Try
         dr = db.GetRow("SELECT * FROM mstSegment INNER JOIN mstRep ON refSegmentID = SegmentID WHERE RepID = " & ddlRep.SelectedValue)
         lblSegment.Text = Nz(dr!strSegment, "")
         'strFilter = "refSegmentID = " & dr!SegmentID & " OR refSegmentID = 0"
      Catch ex As Exception
         lblSegment.Text = ""
         'strFilter = "refSegmentID = 0"
      Finally
         'sdsChannel.FilterExpression = strFilter
      End Try

      ddlChannelSegment.Focus()
   End Sub

   Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click

      lblMessage.Text = ""

      If txtCustomerNo.Text.Trim.Length = 0 Then lblMessage.Text &= "<BR>Customer Number Required"
      If strCustomerName.Text.Trim.Length = 0 Then lblMessage.Text &= "<BR>Customer Name Required"
      If ddlBranch.SelectedIndex < 1 Then lblMessage.Text &= "<BR>Branch Required"
      If ddlRep.SelectedIndex < 1 Then lblMessage.Text &= "<BR>Sales Rep Required"

      'v1.3.3 - 20100127 - Disabled duplicate record check on non RGBC Customer details
      'If db.CountRows(db.sql_get_Not_RGBC_Customer(strCustomerNo, strCustomerName.Text)) > 0 Then lblMessage.Text &= "<BR> Customer already exists"

      If Not lblMessage.Text.Length > 0 Then          'redundant validation check	
         Try
            '1- Update/insert into MST
            If strCustomerNo <> "0" And strCustomerNo.Length > 0 Then 'Update
               Try                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             'ddlType1.SelectedValue, ddlType2.SelectedValue
                  sqlDB.doQueryDS(db.sql_update_Not_RGBC_Customer(txtCustomerNo.Text, strCustomerName.Text, strSnellArea.Text, ddlRep.SelectedValue, ddlBranch.SelectedValue, ddlChannelSegment.SelectedValue, CInt(chkActive.Checked), ddlType1.SelectedValue, ddlType2.SelectedValue, Session.Item("User")))

               Catch ex As Exception
                  Throw New DataException("Update Failed.<BR><BR>" & ex.Message)
               End Try

            Else 'Insert
               Try                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ', ddlType1.SelectedValue, ddlType2.SelectedValue
                  sqlDB.doQueryDS(db.sql_insert_Not_RGBC_Customer(txtCustomerNo.Text, strCustomerName.Text, strSnellArea.Text, ddlRep.SelectedValue, ddlBranch.SelectedValue, ddlChannelSegment.SelectedValue, CInt(chkActive.Checked), ddlType1.SelectedValue, ddlType2.SelectedValue, Session.Item("User")))
                  strCustomerNo = sqlDB.CleanString(txtCustomerNo.Text)

                  sqlDB.doQueryDS("INSERT INTO dwdCustomer ( strCustomerNo) VALUES ('" & strCustomerNo & "')")

               Catch ex As Exception
                  Throw New DataException("Insert Failed.<BR><BR>" & ex.Message)
               End Try
            End If

            Response.Redirect("NonRGBCCustomerList.aspx")
         Catch ex As Exception
            lblMessage.Text &= "<BR>" & ex.Message
         End Try
      End If
   End Sub

   Protected Sub btnClose_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
      Response.Redirect("NonRGBCCustomerList.aspx")
   End Sub

End Class