my full aspx.vb:
Code:
and my full aspx.vb
Imports Keith.ProjectManager.Bll
Imports Keith.ProjectManager.BO
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Partial Class views_suppliers
Inherits System.Web.UI.Page
Private CommandNames As String = String.Empty
'create instance of params
Private myParams As New Params
Dim ActivePagedData As New PagedDataSource()
Dim InActivePagedData As New PagedDataSource()
#Region "Page_Load"
'=============================================================================================
'handles page load events
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'add textboxes that need to be cleared by onFocus
txtSvName.Attributes.Add("onFocus", "Clear(this)")
txtSvContact.Attributes.Add("onFocus", "Clear(this)")
txtSvEmail.Attributes.Add("onFocus", "Clear(this)")
txtSvFax.Attributes.Add("onFocus", "Clear(this)")
txtSvMobile.Attributes.Add("onFocus", "Clear(this)")
txtSvPhysical.Attributes.Add("onFocus", "Clear(this)")
txtSvPostal.Attributes.Add("onFocus", "Clear(this)")
txtSvTel.Attributes.Add("onFocus", "Clear(this)")
txtSvWeb.Attributes.Add("onFocus", "Clear(this)")
txtSvPhysical.TextMode = TextBoxMode.MultiLine
txtSvPostal.TextMode = TextBoxMode.MultiLine
'just for testing updateprogress control
System.Threading.Thread.Sleep("1000")
'populate datasource's only if it's not a pastback
If Not IsPostBack Then
myParams.OrderBy = String.Empty
myParams.Search = String.Empty
myParams.Activated = String.Empty
myParams.ActivatedPage = 0
myParams.DeactivatedPage = 0
Populate_rpActive(myParams)
Populate_rpInActive(myParams)
End If
End Sub
#End Region
#Region "Populate Datasources"
'=============================================================================================
'populate and bind rpProjectList datasource
Sub Populate_rpActive(ByVal myParams As Params)
'Dim CategoryList As New CategoryList
'set activated to true to bring up the activated results
myParams.Activated = "true"
myParams.Search = String.Empty
'populate the datasource
ActivePagedData.DataSource = SuppliersManager.GetList(myParams)
'set datasource parameters
ActivePagedData.AllowPaging = True
ActivePagedData.PageSize = 10
If myParams.ActivatedPage = 0 Then
myParams.ActivatedPage = 0
ActivePagedData.CurrentPageIndex = 0
Else
ActivePagedData.CurrentPageIndex = myParams.ActivatedPage
End If
myParams.PageCount = ActivePagedData.PageCount
btnPrev.Text = "< Previous"
btnPrev.Visible = (Not ActivePagedData.IsFirstPage)
btnNext.Text = "Next >"
btnNext.Visible = (Not ActivePagedData.IsLastPage)
lblActivePagingPages.Text = "Page " & ActivePagedData.CurrentPageIndex + 1 & " of " & ActivePagedData.PageCount
lblActivePagingPages.CssClass = "PageNumbers"
'for paging
If ActivePagedData.PageCount = 0 Then
lblActivePagingPages.Visible = False
btnNext.Visible = False
btnPrev.Visible = False
Else
lblActivePagingPages.Visible = True
End If
'for sorting
If ActivePagedData.Count <= 1 Then
lbtnActiveName.Enabled = False
lbtnActiveContact.Enabled = False
lbtnActiveMobile.Enabled = False
lbtnActiveTel.Enabled = False
lbtnActiveWeb.Enabled = False
Else
lbtnActiveName.Enabled = True
lbtnActiveContact.Enabled = True
lbtnActiveMobile.Enabled = True
lbtnActiveTel.Enabled = True
lbtnActiveWeb.Enabled = True
End If
'only bind data if there is data
If ActivePagedData.PageCount > 0 Then
rpActiveList.DataSource = ActivePagedData
rpActiveList.DataBind()
End If
End Sub
'=============================================================================================
'populate and bind rpDeactivatedProjects datasource
Sub Populate_rpInActive(ByVal myParams As Params)
'Dim CategoryList As New CategoryList
'set activated to true to bring up the activated results
myParams.Activated = "false"
myParams.Search = String.Empty
'populate the datasource
InActivePagedData.DataSource = SuppliersManager.GetList(myParams)
'set datasource parameters
InActivePagedData.AllowPaging = True
InActivePagedData.PageSize = 10
If myParams.DeactivatedPage = 0 Then
myParams.DeactivatedPage = 0
InActivePagedData.CurrentPageIndex = 0
Else
InActivePagedData.CurrentPageIndex = myParams.DeactivatedPage
End If
myParams.PageCount = InActivePagedData.PageCount
btnInActivePrev.Text = "< Previous"
btnInActivePrev.Visible = (Not InActivePagedData.IsFirstPage)
btnInActiveNext.Text = "Next >"
btnInActiveNext.Visible = (Not InActivePagedData.IsLastPage)
lblInActivePagingPages.Text = "Page " & InActivePagedData.CurrentPageIndex + 1 & " of " & InActivePagedData.PageCount
lblInActivePagingPages.CssClass = "PageNumbers"
'for paging
If InActivePagedData.PageCount = 0 Then
lblInActivePagingPages.Visible = False
btnInActiveNext.Visible = False
btnInActivePrev.Visible = False
Else
lblInActivePagingPages.Visible = True
End If
'for sorting
If InActivePagedData.Count <= 1 Then
lbtnInActiveName.Enabled = False
lbtnInActiveContact.Enabled = False
lbtnInActiveMobile.Enabled = False
lbtnInActiveTel.Enabled = False
lbtnInActiveWeb.Enabled = False
Else
lbtnInActiveName.Enabled = True
lbtnInActiveContact.Enabled = True
lbtnInActiveMobile.Enabled = True
lbtnInActiveTel.Enabled = True
lbtnInActiveWeb.Enabled = True
End If
'only bind data if there is data
If InActivePagedData.PageCount > 0 Then
rpInActiveList.DataSource = InActivePagedData
rpInActiveList.DataBind()
End If
End Sub
'=============================================================================================
'run validations/operations on rpProjectList
Protected Sub rpActive_OnItemDataBound(ByVal s As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
'declare my controls and create an instance of Projects
Dim Suppliers As Suppliers = e.Item.DataItem
'if an empty result is retuurned then only show the ddl to select a project
If Suppliers.Idkey = 0 Then
pnlActiveSubContent.Visible = False
ElseIf Suppliers.Idkey <> 0 Then
pnlActiveSubContent.Visible = True
End If
End If
End Sub
'=============================================================================================
'run validations/operations on rpDeactivatedProjects
Protected Sub rpInActive_OnItemDataBound(ByVal s As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
'declare my controls and create an instance of Projects
Dim imgbtnDelete As ImageButton = e.Item.FindControl("imgbtnDelete")
Dim Suppliers As Suppliers = e.Item.DataItem
'image button
imgbtnDelete.ImageUrl = "../Icons/trashfull.png"
'if an empty result is retuurned then only show the ddl to select a project
If Suppliers.Idkey = 0 Then
pnlInActiveSubContent.Visible = False
ElseIf Suppliers.Idkey <> 0 Then
pnlInActiveSubContent.Visible = True
End If
End If
End Sub
#End Region
#Region "Update,Save,Delete,Activate,Deactivate"
'=============================================================================================
'put code in here that needs to be run on the btnSave event
Protected Sub btnSave_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
'populate Projects and save new data
Dim mySuppliers As Suppliers = New Suppliers
mySuppliers.Name = txtSvName.Text
mySuppliers.Contact = txtSvContact.Text
mySuppliers.Email = txtSvEmail.Text
mySuppliers.Fax = txtSvFax.Text
mySuppliers.Mobile = txtSvMobile.Text
mySuppliers.Physical = txtSvPhysical.Text
mySuppliers.Postal = txtSvPostal.Text
mySuppliers.Tel = txtSvTel.Text
mySuppliers.Web = txtSvWeb.Text
'set values manually
mySuppliers.CreatedDate = Now()
mySuppliers.EditedDate = Now()
mySuppliers.CreatedBy = HttpContext.Current.Session("UserID")
mySuppliers.EditedBy = 0
mySuppliers.Idkey = 0
SuppliersManager.Save(mySuppliers)
'set params back to default
myParams.OrderBy = String.Empty
myParams.Search = String.Empty
myParams.Activated = String.Empty
myParams.ActivatedPage = 0
myParams.DeactivatedPage = 0
'bind the datasource to repeater to show updated results
Populate_rpActive(myParams)
're-set the textboxes
txtSvName.Text = "Company Name"
txtSvContact.Text = "Contact"
txtSvEmail.Text = "Email"
txtSvFax.Text = "Fax"
txtSvMobile.Text = "Mobile"
txtSvTel.Text = "Tel"
txtSvWeb.Text = "Website"
'txtSvPhysical.Text = "Physical"
'txtSvPostal.Text = "Postal"
End Sub
'=============================================================================================
'repeater OnItemCommand event, handles all actions ie. buttons inside the repeater
Protected Sub rpActive_OnItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs) Handles rpActiveList.ItemCommand
CommandNames = e.CommandName
Dim mySupplier As Suppliers = New Suppliers
Select Case CommandNames
Case "Delete"
'populate Projects with the idkey that must be deleted and pass it to ProjectsManager.Delete
mySupplier.Idkey = CType(e.CommandArgument, Integer)
SuppliersManager.Delete(mySupplier)
'bind the datasource to repeater to show updated results
Populate_rpActive(myParams)
Populate_rpInActive(myParams)
Case "Deactivate"
'populate Projects with the idkey that must be deactivated and pass it to ProjectsManager.Deactivate
mySupplier.Idkey = CType(e.CommandArgument, Integer)
mySupplier.EditedBy = HttpContext.Current.Session("UserID")
SuppliersManager.Deactivate(mySupplier)
'bind the datasource to repeater to show updated results
Populate_rpActive(myParams)
Populate_rpInActive(myParams)
Case "Activate"
'populate Projects with the idkey that must be activated and pass it to ProjectsManager.Deactivate
mySupplier.Idkey = CType(e.CommandArgument, Integer)
mySupplier.EditedBy = HttpContext.Current.Session("UserID")
SuppliersManager.Activate(mySupplier)
'bind the datasource to repeater to show updated results
Populate_rpActive(myParams)
Populate_rpInActive(myParams)
End Select
End Sub
Protected Sub update_details(ByVal s As Object, ByVal e As System.EventArgs)
Dim mySuppliers As Suppliers
Dim fieldlist As New ArrayList
'populate Suppliers BO with the database record from the form hidden idkey
mySuppliers = New Suppliers
mySuppliers.Idkey = CInt(hdn_sID.Value)
mySuppliers = SuppliersManager.GetItem(mySuppliers.Idkey)
mySuppliers.Idkey = hdn_sID.Value
If Not txtName.Text = mySuppliers.Name Then
fieldlist.Add("name")
mySuppliers.Name = txtName.Text
End If
If Not txtMobile.Text = mySuppliers.Mobile Then
fieldlist.Add("mobile")
mySuppliers.Mobile = txtMobile.Text
End If
If Not txtContact.Text = mySuppliers.Contact Then
fieldlist.Add("contact")
mySuppliers.Contact = txtContact.Text
End If
If Not txtEmail.Text = mySuppliers.Email Then
fieldlist.Add("email")
mySuppliers.Email = txtEmail.Text
End If
If Not txtTel.Text = mySuppliers.Tel Then
fieldlist.Add("tel")
mySuppliers.Tel = txtTel.Text
End If
If Not txtFax.Text = mySuppliers.Fax Then
fieldlist.Add("fax")
mySuppliers.Email = txtEmail.Text
End If
If Not txtWeb.Text = mySuppliers.Web Then
fieldlist.Add("web")
mySuppliers.Web = txtWeb.Text
End If
If Not txtPhysical.Text = mySuppliers.Physical Then
fieldlist.Add("physical")
mySuppliers.Physical = txtPhysical.Text
End If
If Not txtPostal.Text = mySuppliers.Postal Then
fieldlist.Add("postal")
mySuppliers.Postal = txtPostal.Text
End If
'check to see if any records need to be updated, if so, update them
If Not fieldlist.Count = 0 Then
SuppliersManager.Update(mySuppliers)
fieldlist.RemoveRange(0, fieldlist.Count)
End If
CloseModalPopup(s, e)
End Sub
#End Region
#Region "Paging"
Public Sub Prev_Click(ByVal obj As Object, ByVal e As EventArgs)
myParams.ActivatedPage = myParams.ActivatedPage - 1
Populate_rpActive(myParams)
End Sub
Public Sub Next_Click(ByVal obj As Object, ByVal e As EventArgs)
myParams.ActivatedPage = myParams.ActivatedPage + 1
Populate_rpActive(myParams)
End Sub
Public Sub InActivePrev_Click(ByVal obj As Object, ByVal e As EventArgs)
myParams.DeactivatedPage = myParams.DeactivatedPage - 1
Populate_rpInActive(myParams)
End Sub
Public Sub InActiveNext_Click(ByVal obj As Object, ByVal e As EventArgs)
myParams.DeactivatedPage = myParams.DeactivatedPage + 1
Populate_rpInActive(myParams)
End Sub
#End Region
Public Sub Populate_ModalPopup(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Dim mySuppliers As Suppliers = New Suppliers
'loop over all the items in rpActiveList repeater
Dim hdn_idkey As String = sender.CommandArgument
mySuppliers.Idkey = CInt(hdn_idkey)
mySuppliers = SuppliersManager.GetItem(mySuppliers.Idkey)
hdn_sID.Value = mySuppliers.Idkey
txtName.Text = mySuppliers.Name
txtContact.Text = mySuppliers.Contact
txtMobile.Text = mySuppliers.Mobile
txtEmail.Text = mySuppliers.Email
txtTel.Text = mySuppliers.Tel
txtFax.Text = mySuppliers.Fax
txtWeb.Text = mySuppliers.Web
txtPhysical.Text = mySuppliers.Physical
txtPostal.Text = mySuppliers.Postal
ModalPopupExtender1.Show()
End Sub
Public Sub CloseModalPopup(ByVal sender As Object, ByVal e As EventArgs)
ModalPopupExtender1.Hide()
End Sub
End Class
It still does not work
Bookmarks