📄 productcontrol.ascx.vb
字号:
Imports NetShopForge.Library.Product
Partial Class Admin_Product_Controls_ProductControl
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
hfSearchText.Value = ""
BindSearch()
BindData()
End If
End Sub
Private Sub BindSearch()
'bind category type
Category.CategoryTree.Instance.SetCategoryList(ddlCategory, "全部类别")
'
'bind Produt type
ddlProductType.Items.Clear()
ddlProductType.Items.Add(New ListItem("全部商品类型", -1))
Dim p() As String = Resources.Enum.ProductType.Split(",")
For Each value As Product.ProductType In [Enum].GetValues(GetType(Product.ProductType))
ddlProductType.Items.Add(New ListItem(p(CInt(value)), CInt(value)))
Next
End Sub
Private Sub BindData()
Dim totalRecords As Integer = 0
Dim SearchText As String = hfSearchText.Value
Dim producList As Generic.List(Of ProductInfo)
Dim sqlWhere As String = ""
If SearchText.Trim().Length <> 0 Then
SearchText = SearchText.Replace("*", "%")
SearchText = SearchText.Replace("?", "_")
sqlWhere = String.Format("LOWER({1}) LIKE '{0}'", SearchText.ToLower.Replace("'", "''"), ddlSearch.SelectedValue)
End If
Dim strAND As String = ""
If sqlWhere.Length > 0 Then strAND = " And "
If ddlProductType.SelectedIndex > 0 Then
sqlWhere += strAND & "ProductType=" & ddlProductType.SelectedValue
End If
For i As Integer = 0 To cbSearchList.Items.Count - 1
If sqlWhere.Length > 0 Then strAND = " And "
If cbSearchList.Items(i).Selected Then
Select Case cbSearchList.Items(i).Value
Case "IsSpecialOffer"
sqlWhere += strAND & "(IsSpecialOffer=1)"
Case "IsSellWell"
sqlWhere += strAND & "(IsSellWell=1)"
Case "IsValid"
sqlWhere += strAND & "(IsValid=1)"
Case "IsCommend"
sqlWhere += strAND & "(IsCommend=1)"
Case "IsNewArrival"
sqlWhere += strAND & "(IsNewArrival=1)"
Case "zeroStorageQty"
sqlWhere += strAND & "(StorageQty=0)"
End Select
End If
Next
If ddlCategory.SelectedValue = -1 Then
producList = ProductController.GetProductList(Pager.PageSize, Pager.CurrentPageIndex, totalRecords, sqlWhere)
Else
producList = ProductController.GetProductList(Pager.PageSize, Pager.CurrentPageIndex, totalRecords, CInt(ddlCategory.SelectedValue), sqlWhere)
End If
Pager.RecordCount = totalRecords
gvProduct.DataSource = producList
gvProduct.DataBind()
Pager.CustomInfoHTML = "记录总数:" + Pager.RecordCount.ToString()
Pager.CustomInfoHTML += " 总页数:" + Pager.PageCount.ToString()
Pager.CustomInfoHTML += " 当前页:" + Pager.CurrentPageIndex.ToString()
End Sub
Protected Sub ChangePage(ByVal src As Object, ByVal e As EventArgs) Handles Pager.PageChanged
BindData()
End Sub
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
hfSearchText.Value = txtSearch.Text
If hfSearchText.Value = "输入查询关键字" Then hfSearchText.Value = ""
Pager.CurrentPageIndex = 1
BindData()
txtSearch.Text = ""
gvProduct.Visible = True
End Sub
Protected Sub gvProduct_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvProduct.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lbProductType As Label = CType(e.Row.FindControl("lbProductType"), Label)
Dim p() As String = Resources.Enum.ProductType.Split(",")
Dim i As Integer = Integer.Parse(lbProductType.Text)
lbProductType.Text = p(i)
End If
End Sub
Protected Sub btnAddNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
My.Response.Redirect("~/Admin/Product/Product.aspx?mode=addnew")
End Sub
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Try
Dim r As GridViewRow
For Each r In gvProduct.Rows
Dim quantity As Integer = CType(r.FindControl("txtQuantiy"), TextBox).Text
Dim price As String = CType(r.FindControl("txtPrice"), TextBox).Text
Dim IsCommend As Boolean = CType(r.FindControl("cbIsCommend"), CheckBox).Checked
Dim IsNewArrival As Boolean = CType(r.FindControl("cbIsNewArrival"), CheckBox).Checked
Dim IsSpecialOffer As Boolean = CType(r.FindControl("cbIsSpecialOffer"), CheckBox).Checked
Dim IsSellWell As Boolean = CType(r.FindControl("cbIsSellWell"), CheckBox).Checked
Dim IsValid As Boolean = CType(r.FindControl("cbIsValid"), CheckBox).Checked
Dim ItemOrder As Integer = CType(r.FindControl("txtItemOrder"), TextBox).Text
Dim productID As Integer = gvProduct.DataKeys(r.RowIndex).Value
Product.ProductController.UpdataProductQuick(productID, price, quantity, IsSpecialOffer, IsSellWell, IsValid, IsNewArrival, IsCommend, ItemOrder)
Next
BindData()
ResultMessageControl1.ShowSuccess("更新成功!")
Catch ex As Exception
ResultMessageControl1.ShowSuccess("更新失败!" & ex.Message)
End Try
End Sub
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -