﻿
Partial Class includes_package_details_inc
    Inherits System.Web.UI.UserControl
    Private _user As MembershipUser
    Private _userProfile As ProfileCommon
    Private _webWS As New WebWS
    Public _selectedLanguage As String = ""

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.QueryString("lang") IsNot Nothing Then
            _selectedLanguage = Request.QueryString("lang").ToString
        Else
            If Session("lang") IsNot Nothing Then
                _selectedLanguage = Session("lang").ToString
            Else
                If Request.Cookies("lang") IsNot Nothing Then
                    _selectedLanguage = Request.Cookies("lang").Value.ToString
                End If
            End If
        End If
        WebDiv.Visible = "false"
        Session("lang") = _selectedLanguage
        If Session("EditUserFromAdmin") Or Session("EditUserFromManagement") Then
            Dim _guid As Guid = New Guid(Request.QueryString("uid"))
            _user = Membership.GetUser(_guid)
        Else
            _user = Membership.GetUser()
        End If
        _userProfile = Profile.GetProfile(_user.UserName)
        Dim _storeId As Integer = _userProfile.StoreId
        '_storeId = 600
        Dim _dataSet As New System.Data.DataSet
        _dataSet = _webWS.GetStorePackagesByStoreId(_storeId)
        Dim _CountPckg As Integer = _dataSet.Tables(0).Rows.Count 'quantaty of  StorePackages for current Store
        'If store has any packages
        If _CountPckg > 0 Then
            BasePrintDriverEmptyDiv.Visible = False
            Dim _currency As String = ""
            Select Case _userProfile.Country ' curruncy should be change according the Country not language
                Case "Argentina", "Uruguay"
                    _currency = "u$s"
                Case "Canada"
                    _currency = "CAD"
                Case Else
                    _currency = "USD"
            End Select
            Dim _message As String = "" 'create table for Base Module Packages
            'General Info about Base Module and Free Submission
            _message = "<table border='0' cellspacing='0' cellpadding='0'>" _
            & "<tr><td>" & GetLocalResourceObject("PackageType") & _dataSet.Tables(0).Rows(0).Item("PackageName") & "</td></tr>" _
            & "<tr><td>" & GetLocalResourceObject("PackageDescription") & _dataSet.Tables(0).Rows(0).Item("PackageDescription") & "</td></tr>" _
             & "<tr><td>" & GetLocalResourceObject("FreeJobsSubmissions") & _dataSet.Tables(0).Rows(0).Item("FreeJobDescription") & "</td></tr>" _
            & " </table> </br>"
            'Create Header for Base Module Package Table
            _message = _message & "<table width='100%' border='0' cellspacing='0' cellpadding='3' style='background-color: White; border: solid 1px #7AC141;' >" _
        & "<tr bgcolor='#7AC141'><td align='left' valign='top' style='color:#ffffff; padding:5px; font-size:14px' width='70% ' >" _
        & GetLocalResourceObject("PrintDriverPackagesLabel") _
        & "</td><td align='center' valign='top' style='color:#ffffff; padding:5px' width='30%'>" _
        & GetLocalResourceObject("MonthlyFeeLabel") _
        & "</td></tr>"
            Dim i As Integer ' number of row in dataSet
            Dim _totalPriceMessage As String = "" 'Table content for TotalPriceLabel
            Dim _totalMonthlyFee As Double = 0
            Dim _maximumMonthlyFee As Double = 0 'check 
            Dim _maxMonthlyBool As Boolean = False

            For i = 0 To 1
                _message = _message & "<tr bgcolor='#e7f8c2'><td align='left' valign='top' style='color:#71950d; background-color:#ffffff' width='70%'>" _
            & _dataSet.Tables(0).Rows(i).Item("ModuleName") _
             & "</td><td align='center' valign='top' style='color:#4a4a4a;  border-left: solid 1px #7AC141; border-right: solid 1px #7AC141;' width='30%'>" _
            & _currency & " " & String.Format("{0:n}", _dataSet.Tables(0).Rows(i).Item("PackagePrice")) _
            & "</td></tr>"
                _totalMonthlyFee = _totalMonthlyFee + _dataSet.Tables(0).Rows(i).Item("PackagePrice")
                If _dataSet.Tables(0).Rows(i).Item("MaxMonthlyFee") > 0 Then
                    _maximumMonthlyFee = _dataSet.Tables(0).Rows(i).Item("MaxMonthlyFee")
                    _maxMonthlyBool = True
                Else
                    _maximumMonthlyFee = _maximumMonthlyFee + _dataSet.Tables(0).Rows(i).Item("PackagePrice")
                End If
            Next i
            _message = _message & "</table>"
            BasePrintDriverTable.Text = _message

          
            'Check if Store has WebSubmission Package 
            If _CountPckg > 2 Then

                WebDiv.Visible = True
                Dim _messageweb As String = ""
                Dim _dataSetDomainName As New System.Data.DataSet
                _dataSetDomainName = _webWS.GetDomainName(_storeId)
                _messageweb = _messageweb & "<table width='100%' border='0' cellspacing='0' cellpadding='3' style='background-color: White; border: solid 1px #7AC141;' >" _
      & "<tr bgcolor='#7AC141'><td  align='left' valign='top' style='color:#ffffff; padding:5px; font-size:14px' width='70%'>" _
      & GetLocalResourceObject("WebPackagesLabel") _
      & "</td><td align='center' valign='top' style='color:#ffffff; padding:5px' width='30%'>" _
      & GetLocalResourceObject("MonthlyFeeLabel") _
      & "</td></tr>"
                Do While i < _CountPckg
                    _messageweb = _messageweb & "<tr bgcolor='#e7f8c2'><td align='left'  valign='top' style='color:#71950d;  background-color:#ffffff' width='70%'>" _
                & _dataSet.Tables(0).Rows(i).Item("ModuleName") & "</br>"
                    If _dataSet.Tables(0).Rows(i).Item("ModuleId") = 4 Then
                        _messageweb = _messageweb & "<font color='#4a4a4a'>(http://" & _dataSetDomainName.Tables(0).Rows(0).Item("DomainName") & ".goprint2.com)</font>"
                    End If
                    _messageweb = _messageweb & "</td><td align='center' valign='top' style='color:#4a4a4a; border-left: solid 1px #7AC141; border-right: solid 1px #7AC141;' width='30%'>" _
                 & _currency & " " & String.Format("{0:n}", _dataSet.Tables(0).Rows(i).Item("PackagePrice")) _
                & "</td></tr>"
                    _totalMonthlyFee = _totalMonthlyFee + _dataSet.Tables(0).Rows(i).Item("PackagePrice")
                    _maximumMonthlyFee = _maximumMonthlyFee + _dataSet.Tables(0).Rows(i).Item("PackagePrice").ToString()
                    i = i + 1
                Loop
                _messageweb = _messageweb & "</table>"

                WebModuleTable.Text = _messageweb

            End If
            Dim _totalMonthlyFeeStr As String = String.Format("{0:n}", _totalMonthlyFee)
            Dim _maximumMonthlyFeeStr As String = String.Format("{0:n}", _maximumMonthlyFee)
            _totalPriceMessage = "<table width='60%' border='0' cellspacing='0' cellpadding='3' style='border: solid 1px #7AC141;' align='right'>" _
            & "<tr bgcolor='#e7f8c2'><td align='right' style='color:#4a4a4a'> " & GetLocalResourceObject("TotalMonthlyFee") _
            & "</td> <td align='left' style='color:#4a4a4a'>" & _currency & " " & _totalMonthlyFeeStr _
            & "</td> <tr bgcolor='#e7f8c2'><td align='right' style='color:#4a4a4a'> " & GetLocalResourceObject("PricePerSubmission") _
             & "</td> <td align='left' style='color:#4a4a4a'>" & _currency & " " & String.Format("{0:n}", _dataSet.Tables(0).Rows(0).Item("PricePerClick")) _
            & "</td></tr>"
            If _maxMonthlyBool = True Then
                _totalPriceMessage = _totalPriceMessage & "<tr bgcolor='#e7f8c2'><td align='right' style='color:#4a4a4a'> " & GetLocalResourceObject("MaximumMonthlyFee") _
            & "</td> <td align='left' style='color:#4a4a4a'>" & _currency & " " & _maximumMonthlyFeeStr _
            & "</td> "
            End If
            _totalPriceMessage = _totalPriceMessage & "</table>"
            TotalPriceLabel.Text = _totalPriceMessage
        Else
            BasePrintDriverEmptyDiv.Visible = True
            BasePrintDriverDiv.Visible = False
            WebDiv.Visible = False
            TotalPriceDiv.Visible = False
        End If

    End Sub
End Class
