CSDN博客

img huanghui22

Seller

发表于2004/10/25 7:23:00  1139人阅读

分类:

Imports CyberRS2.CSMS.Common

Imports CyberRS2.CSMS.DataAccess

Imports CyberRS2.CSMS.Entity

Imports CyberRS2.CSMS.Facade

 

Namespace Page.Management.Seller

    ' Class Name         : Seller_MT

    ' Purpose       :

    ' Description         :

    ' Builder             : StevenHuang, 10/21/2004

    ' Modicication         :

    ' Be referenced        : N/A

    ' Remark             :

    ' Version             :

    Public Class Seller_MT

        Inherits System.Web.UI.Page

 

#Region " Web Form 砞璸ㄣ玻ネ祘Α絏 "

 

        ' Web Form 砞璸ㄣ┮惠㊣

        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

 

        End Sub

        Protected WithEvents btnNew As System.Web.UI.WebControls.ImageButton

        Protected WithEvents btnOK As System.Web.UI.WebControls.ImageButton

        Protected WithEvents btnCancel As System.Web.UI.WebControls.ImageButton

        Protected WithEvents InputArea As System.Web.UI.HtmlControls.HtmlGenericControl

 

        Protected WithEvents txtCName As System.Web.UI.WebControls.TextBox

        Protected WithEvents rbtMan As System.Web.UI.WebControls.RadioButton

        Protected WithEvents rbtWoman As System.Web.UI.WebControls.RadioButton

        Protected WithEvents txtMobile As System.Web.UI.WebControls.TextBox

        Protected WithEvents txtEmail As System.Web.UI.WebControls.TextBox

        Protected WithEvents txtTelZone As System.Web.UI.WebControls.TextBox

        Protected WithEvents txtTelNo As System.Web.UI.WebControls.TextBox

        Protected WithEvents txtTelSubNo As System.Web.UI.WebControls.TextBox

        Protected WithEvents ddlCompanyName As System.Web.UI.WebControls.DropDownList

        Protected WithEvents ddlQryCompanyName As System.Web.UI.WebControls.DropDownList

        Protected WithEvents txtSale As System.Web.UI.WebControls.TextBox

        Protected WithEvents rbtSalesCode As System.Web.UI.WebControls.RadioButton

        Protected WithEvents rbtSalesName As System.Web.UI.WebControls.RadioButton

        Protected WithEvents btnQry As System.Web.UI.WebControls.ImageButton

        Protected WithEvents dtgSellers As System.Web.UI.WebControls.DataGrid

        Protected WithEvents datagridArea As System.Web.UI.HtmlControls.HtmlGenericControl

 

        '猔種: 箇痙竚琌 Web Form 砞璸ㄣ惠璶兜ヘ

        '叫づ埃┪簿笆ウ

        Private designerPlaceholderDeclaration As System.Object

 

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

            'CODEGEN:  Web Form 砞璸ㄣ┮惠よ猭㊣

            '叫づㄏノ祘Α絏絪胯竟秈︽э

            InitializeComponent()

        End Sub

 

#End Region

 

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            '硂柑竚ㄏノ祘Α絏﹍て呼

 

            'Make the page expire immediately

            Response.Cache.SetCacheability(HttpCacheability.NoCache)

           

            If Not IsPostBack Then

                If Authorization.Pass(Me) = False Then

                    'Authorization failed

                    Page.Response.Redirect("login.aspx")

                Else

                    'Authorization success

                    'company_name databind()

                    DataSourceGenerator.SetDelegateDataSource(Me.ddlQryCompanyName.Items)

                    DataSourceGenerator.SetDelegateDataSource(Me.ddlCompanyName.Items)

                    'Set edit area

                    Select Case Page.Request.QueryString("action")

                        Case "show"

                            ShowData(Page.Request.QueryString("id"))

 

                            'Set readonly

                            SetPageState(False)

                        Case Else

                            InputArea.Visible = False

                    End Select

                End If

            Else

            End If

           

        End Sub

 

        'Refresh the datagrid's data

        Private Sub DataGridBind(Optional ByVal PageIndex As Int32 = 0)

            Dim SellerAccess As New BIZ_SellerFacade

            Dim Sellers As New BIZ_SellerCollection

            DataSourceGenerator.SetDelegateDataSource(Me.ddlCompanyName.Items)

            'viewstate=Query

            If viewstate.Item("Seller_Status") = "Query" Then

                Dim str As String

                SellerAccess.GetAllSellers(Sellers)

                If Me.ddlQryCompanyName.SelectedIndex <> 0 Then

                    str = "company_name='" & Me.ddlQryCompanyName.SelectedItem.Text & "'"

                End If

                If Me.rbtSalesCode.Checked = True And Me.txtSale.Text <> "" Then

                    If str <> "" Then

                        str &= " and pk_salescode='" & Me.txtSale.Text & "'"

                    Else

                        str = "pk_salescode='" & Me.txtSale.Text & "'"

                    End If

                ElseIf Me.rbtSalesName.Checked = True And Me.txtSale.Text <> "" Then

                    If str <> "" Then

                        str &= " and seller_cname='" & Me.txtSale.Text & "'"

                    Else

                        str = "seller_cname='" & Me.txtSale.Text & "'"

                    End If

                End If

                Sellers.DefaultView.RowFilter = str

                Me.dtgSellers.DataSource = Sellers.DefaultView

                Me.dtgSellers.CurrentPageIndex = PageIndex

                viewstate.Add("PageIndex", PageIndex)

                Me.dtgSellers.DataBind()

                Session.Add("Sellers", Sellers)

 

            End If

            'viewstate=view

            If viewstate.Item("Seller_Status") = "Show" Then

                Sellers = Session.Item("Sellers")

                Me.dtgSellers.DataSource = Sellers

                Me.dtgSellers.CurrentPageIndex = PageIndex

                viewstate.Add("PageIndex", PageIndex)

                Me.dtgSellers.DataBind()

 

            End If

            'viewstate=add

            If viewstate.Item("Seller_Status") = "Add" Or viewstate.Item("Seller_Status") = "Edit" Or viewstate.Item("Seller_Status") = "Delete" Then

                SellerAccess.GetAllSellers(Sellers)

                Me.dtgSellers.DataSource = Sellers

                Me.dtgSellers.CurrentPageIndex = PageIndex

                viewstate.Add("PageIndex", PageIndex)

                Me.dtgSellers.DataBind()

            End If

            'If dtgSellers.DataSource Is Nothing Then

            '    Me.datagridArea.Visible = False

            'End If

 

        End Sub

 

        'Show data in page according to the given salescode

        Private Sub ShowData(ByVal ID As String)

            Dim SellerAccess As New BIZ_SellerFacade

            Dim Seller As New BIZ_Seller

            Dim CompanyAccess As New BIZ_CompanyFacade

            Dim Company As New BIZ_Company

            viewstate.Item("Seller_Status") = "Show"

            Me.DataGridBind()

            Seller.pk_SalesCode = ID

            SellerAccess.GetASeller(Seller)

            DataSourceGenerator.SetSelectedIndex(Me.ddlCompanyName, Seller.fk_Company_ID)

            'Save seller into session(when Edit need)

            Session.Add("Seller", Seller)

            With Seller

                Me.txtCName.Text = Seller.Seller_CName

                If Seller.Gender = 0 Then

                    Me.rbtMan.Checked = True

                Else

                    Me.rbtWoman.Checked = True

                End If

                Me.txtTelZone.Text = Seller.Telephone_Zone

                Me.txtTelNo.Text = Seller.Telephone_No

                Me.txtTelSubNo.Text = Seller.Telephone_extNo

                Me.txtMobile.Text = Seller.Mobile

                Me.txtEmail.Text = Seller.Email

            End With

            InputArea.Visible = True

        End Sub

 

      

#Region "button"

        Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnNew.Click

            'Clear

            Me.txtCName.Text = ""

            Me.ddlCompanyName.SelectedIndex = 0

            Me.rbtMan.Checked = True

            Me.rbtWoman.Checked = False

            Me.txtTelZone.Text = ""

            Me.txtTelNo.Text = ""

            Me.txtTelSubNo.Text = ""

            Me.txtMobile.Text = ""

            Me.txtEmail.Text = ""

            SetPageState(True)

            InputArea.Visible = True

            viewstate.Item("Seller_Status") = "Add"

        End Sub

 

        Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnCancel.Click

            InputArea.Visible = False

        End Sub

 

        Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnOK.Click

            Dim Seller As BIZ_Seller

            Dim SellerAccess As New BIZ_SellerFacade

 

            If viewstate.Item("Seller_Status") = "Edit" Then

                'Get seller data from session first

                Seller = Session.Item("Seller")

            Else

                'viewstate="Add"

                'Get a new instance

                Seller = New BIZ_Seller

            End If

            'set Table Seller property value

            With Seller

                Seller.Seller_CName = Me.txtCName.Text

                Seller.fk_Company_ID = Me.ddlCompanyName.SelectedValue

                If Me.rbtMan.Checked = True Then

                    Seller.Gender = 0

                Else

                    Seller.Gender = 1

                End If

                Seller.Telephone_Zone = Me.txtTelZone.Text

                Seller.Telephone_No = Me.txtTelNo.Text

                Seller.Telephone_extNo = Me.txtTelSubNo.Text

                Seller.Mobile = Me.txtMobile.Text

                Seller.Email = Me.txtEmail.Text

                Seller.Flag = 1

                If viewstate.Item("Seller_Status") = "Edit" Then

                    .Upd_ID = "Steven"

                    If SellerAccess.UpdateASeller(Seller) = EDataAccessState.Normal Then

                        AlertScript.ShowAlert(Me, "", AlertScript.Message.ModifySuccess)

                    Else

                        AlertScript.ShowAlert(Me, "", AlertScript.Message.ModifyFailed)

                    End If

                Else

                    'add a new seller to the Biz_seller Table

                    ''''''Dim serialNumberAccess As New CMN_SerialNumberFacade

                    ''''''Dim serialNumber As New CMN_SerialNumber

                    ''''''serialNumber.pk_System_ID = "CSMS"

                    ''''''serialNumber.pk_Serial_ID = "Biz_Seller"

                    ''''''serialNumberAccess.GetASerialNumber(serialNumber)

                    Dim sellers As New BIZ_SellerCollection

                    SellerAccess.GetAllSellersFalgEqual0or1(sellers)

                    Dim filter As String = "fk_company_id='" & Seller.fk_Company_ID & "'"

                    Dim strMaxSalescode As String = sellers.Compute("max(pk_salescode)", filter)

 

                    .pk_SalesCode = strMaxSalescode.Substring(0, 3) + Me.GenerateSalesCode(strMaxSalescode.Substring(3, 3))

                    .Create_ID = "Steven"

                    'serialNumber.Serial_Number = Me.GenerateSalesCode(serialNumber.Serial_Number)

                    If SellerAccess.AddASeller(Seller) = EDataAccessState.Normal Then

                        AlertScript.ShowAlert(Me, "", AlertScript.Message.AddSuccess)

                    Else

                        AlertScript.ShowAlert(Me, "", AlertScript.Message.AddFailed)

                    End If

                End If

            End With

 

            'Refresh data

            DataGridBind(viewstate.Item("PageIndex"))

            'Hide edit area

            InputArea.Visible = False

        End Sub

 

        Private Sub btnQry_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnQry.Click

            'Hide edit area

            InputArea.Visible = False

            viewstate.Item("Seller_Status") = "Query"

            Me.DataGridBind()

        End Sub

#End Region

 

#Region "dategrid"

        Private Sub dtgSellers_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dtgSellers.PageIndexChanged

            DataGridBind(e.NewPageIndex)

        End Sub

 

        Private Sub dtgSellers_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dtgSellers.ItemDataBound

            'Ignore the column title

            If e.Item.ItemIndex <> -1 Then

                e.Item.Cells(0).Text = e.Item.ItemIndex + 1

                'Add delete confirm

                Dim btn As ImageButton = e.Item.Cells(6).FindControl("btnDelete")

                btn.Attributes.Add("onClick", "javascript:return confirm('絋﹚璶埃盾?');")

            End If

        End Sub

 

        Private Sub dtgSellers_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dtgSellers.EditCommand

            Dim link As HyperLink = e.Item.Cells(1).FindControl("lnkSeller")

            ShowData(link.Text)

            SetPageState(True)

            viewstate.Item("Seller_Status") = "Edit"

        End Sub

 

        Private Sub dtgSellers_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dtgSellers.DeleteCommand

            Dim Seller As New BIZ_Seller

            Dim link As HyperLink = e.Item.Cells(1).FindControl("lnkSeller")

            Seller.pk_SalesCode = link.Text

            Dim SellerAccess As New BIZ_SellerFacade

            If SellerAccess.RemoveASeller(Seller) = EDataAccessState.Normal Then

                AlertScript.ShowAlert(Me, "", AlertScript.Message.DeleteSuccess)

            Else

                AlertScript.ShowAlert(Me, "", AlertScript.Message.DeleteFailed)

            End If

            viewstate.Item("Seller_Status") = "Delete"

            'Refresh data

            DataGridBind()

            'Hide edit area

            InputArea.Visible = False

        End Sub

#End Region

 

#Region "another"

        Private Function GenerateSalesCode(ByVal str As String) As String

            Dim i As Integer

            Dim strSaleCode As String

            i = Integer.Parse(str)

            If i >= 0 And i < 9 Then

                i = i + 1

                strSaleCode = "00" + i.ToString

            ElseIf i >= 10 And i < 99 Then

                i = i + 1

                strSaleCode = "0" + i.ToString

            Else

                i = i + 1

                strSaleCode = i.ToString

            End If

            Return strSaleCode

        End Function

 

        'Set edit area state, enabled or disabled

        Private Sub SetPageState(ByVal EditEnabled As Boolean)

            Me.txtCName.ReadOnly = Not EditEnabled

            Me.txtCName.CssClass = Convertor.SetStateCSS(txtCName.CssClass, EditEnabled)

            Me.ddlCompanyName.Enabled = EditEnabled

            Me.ddlCompanyName.CssClass = Convertor.SetStateCSS(Me.ddlCompanyName.CssClass, EditEnabled)

            Me.rbtMan.Enabled = EditEnabled

            Me.rbtWoman.Enabled = EditEnabled

            Me.txtTelZone.ReadOnly = Not EditEnabled

            Me.txtTelZone.CssClass = Convertor.SetStateCSS(txtTelZone.CssClass, EditEnabled)

            Me.txtTelNo.ReadOnly = Not EditEnabled

            Me.txtTelNo.CssClass = Convertor.SetStateCSS(txtTelNo.CssClass, EditEnabled)

            Me.txtTelSubNo.ReadOnly = Not EditEnabled

            Me.txtTelSubNo.CssClass = Convertor.SetStateCSS(txtTelSubNo.CssClass, EditEnabled)

            Me.txtMobile.ReadOnly = Not EditEnabled

            Me.txtMobile.CssClass = Convertor.SetStateCSS(txtMobile.CssClass, EditEnabled)

            Me.txtEmail.ReadOnly = Not EditEnabled

            Me.txtEmail.CssClass = Convertor.SetStateCSS(txtEmail.CssClass, EditEnabled)

 

            Me.btnOK.Visible = EditEnabled

        End Sub

 

 

        Private Sub rbtMan_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtMan.CheckedChanged

            If Me.rbtMan.Checked = True Then

                Me.rbtWoman.Checked = False

            Else

                Me.rbtWoman.Checked = True

            End If

        End Sub

 

        Private Sub rbtWoman_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtWoman.CheckedChanged

            If Me.rbtWoman.Checked = True Then

                Me.rbtMan.Checked = False

            Else

                Me.rbtMan.Checked = True

            End If

        End Sub

 

        Private Sub rbtSalesCode_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtSalesCode.CheckedChanged

            If Me.rbtSalesCode.Checked = True Then

                Me.rbtSalesName.Checked = False

            Else

                Me.rbtSalesName.Checked = True

            End If

        End Sub

 

        Private Sub rbtSalesName_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtSalesName.CheckedChanged

            If Me.rbtSalesName.Checked = True Then

                Me.rbtSalesCode.Checked = False

            Else

                Me.rbtSalesCode.Checked = True

            End If

        End Sub

#End Region

 

    End Class

End Namespace






Public Function GetAllSellersFalgEqual0or1(ByRef sellers As BIZ_SellerCollection) As EDataAccessState

            '莉┮Τノ綪扳(flag<>0)

            Return sellers.GetCollection("SELECT BIZ_Seller.*,biz_company.company_Name FROM BIZ_Seller,biz_company WHERE BIZ_Seller.fk_company_id=biz_company.pk_company_id", Nothing)

        End Function

阅读全文
0 0

相关文章推荐

img
取 消
img