Private Sub cmdRenew_Click(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles cmdRenew.Click
Me.EnableFrameSepAddressButtons(False)
Dim strMessage As String
Try
Dim intIndexfield As Integer
Dim strMagId As String
Dim intIssyr As Integer
Dim iProdIssues As Integer
Dim dr_selectMagazine As DataRow
Dim dr_MagInfo As DataRow
Dim dr_loadCustomerInfo As DataRow
Dim dt_RenewalDate As Date
'Implemented 3/31/2003
'Check the Magazine subscription plan versus the payment
plan first!
If Me.gridMagazineList.DataSource Is Nothing Then
Exit Sub
End If
'Check the status of the account before continuing.
Accounts that are not PIF
'wont' be allowed to renew magazines
Dim bm As BindingManagerBase =
Me.gridMagazineList.BindingContext(Me.gridMagazineList.DataSource,
Me.gridMagazineList.DataMember)
If bm.Count > 0 Then
Dim drDataRow As DataRow = CType(bm.Current,
DataRowView).Row
intIndexfield = IfIsNullInt(drDataRow("IndexField"))
If intIndexfield = 0 Then
strMessage = "Invalid Magazine Selection"
Exit Sub
End If
Else
Exit Sub
End If
dr_selectMagazine =
sql_fCustomer.selectMagazine(intIndexfield).Rows(0)
If (dr_selectMagazine("inactive") = 1) Then
strMessage = "The magazine is inactive and cannot be
renewed."
Exit Sub
End If
If (dr_selectMagazine("OD_Status") = 40 Or
dr_selectMagazine("OD_Status") = 94) Or
IfIsNullDate((dr_selectMagazine("OD_Next_prod_date"))) = "" Or
(dr_selectMagazine("Od_numiss") - dr_selectMagazine("od_issuessent"))
<= 0 Then
strMessage = "This magazine has been Cancelled or there
are not more issues left to be Renewed!"
Exit Sub
Else
'this is the override that allows
'for Renewal, even if the date isn't close.
If UserInfo.haveAccess("RenewalData_Entry_Override")
Then
'we do want to prevent too fast of a renewal... 4
month is set by Vikki
If dtoday <
(CDate(dr_selectMagazine("CurrentProdDate")).AddMonths(4)) Then
strMessage = "You must wait until [" &
CDate(dr_selectMagazine("CurrentProdDate")).AddMonths(4).Date.ToString
& "] to do renewal for this magazine."
Exit Sub
End If
Else
dr_loadCustomerInfo =
sql_fCustomer.loadCustomerInfo(lngCustNumber, mnordernumber).Rows(0)
'adding "IfIsNullSng" to Order_Amount_Due
strMagId = IfIsNullString(Me.txtMagID.Text.Trim)
dr_MagInfo =
sql_fCustomer.MagInfo(strMagId).Rows(0)
'need to be able to renew single year half PIFs
' (dr_loadCustomerInfo("order_current_status") =
109)
If ((dr_loadCustomerInfo("order_current_status") =
109)) Or _
(dr_loadCustomerInfo("order_current_status") =
89) Or ((dr_loadCustomerInfo("Order_current_status") = 39) _
And
(IfIsNullSingle(dr_loadCustomerInfo("Order_Amount_Due")) <
IfIsNullSingle(dr_loadCustomerInfo("Order_current_monthly_Payment"))))
Then
dt_RenewalDate =
(CDate(dr_selectMagazine("OD_Prod_Date_1")).AddYears( _
(CSng(dr_selectMagazine("OD_Issuessent")) /
CSng(dr_selectMagazine("OD_Issues_Year"))))).AddMonths(-3)
If dtoday <= dt_RenewalDate Then
strMessage = "The current production for
this magazine hasn't expired yet, the next possible order date is after
[" & dt_RenewalDate & "]"
Exit Sub
End If
Else
strMessage = "This account needs to be PIF or
in good standing in order to renew Magazines!"
Exit Sub
End If
End If
End If
If (dr_selectMagazine("OD_Status") = 123) Then
strMessage = "The magazine is waiting production,
renewing at the moment. It cannot be renewed again until after next
production."
Exit Sub
End If
'Gets Information from tblMags on a specific magazine
strMagId = IfIsNullString(Me.txtMagID.Text.Trim)
If strMagId <> "" Then
dr_MagInfo = sql_fCustomer.MagInfo(strMagId).Rows(0)
intIssyr = dr_MagInfo("IssYr")
If dr_MagInfo("inactive") Then
strMessage = "This magazine is Inactive!"
Exit Sub
End If
'The total # of issues left will be ordered, unless the
magazine is only for 1 year or the the maximum
'# of issues that can be sent is less than the issues
left
If dr_MagInfo("MagSingYear") Then
iProdIssues = intIssyr
Else
'Magazines, unless the MaxISS is smaller
(fulfillment house won't let us order any more).
If dr_MagInfo("MaxIss") >
dr_selectMagazine("OD_NUMIss") - dr_selectMagazine("Od_Issuessent")
Then
iProdIssues = dr_selectMagazine("OD_NUMIss") -
dr_selectMagazine("Od_issuessent")
Else
iProdIssues = dr_MagInfo("MaxIss")
End If
End If
sql_fCustomer.ProductionRenewal_Queue(lngCustNumber,
mnordernumber, intIndexfield, iProdIssues, dtoday, intIssyr, strMagId,
False)
sql_fCustomer.InsertMagEdit_Queue((dr_selectMagazine("Custnum")),
(dr_selectMagazine("Ordernum")), intIndexfield, "Renewed Magazine by
using the renew button: " & dr_selectMagazine("OD_Mag_ID"),
(UserInfo.userID), True)
strMessage = "Done!"
LoadMagInfo()
Exit Sub
Else
strMessage = "MagID is blank"
Exit Sub
End If
Catch ex As Exception
ErrorTrap(ex,
System.Reflection.MethodInfo.GetCurrentMethod.Name, "")
Finally
If Not strMessage Is Nothing Then
MessageBox.Show(Me, strMessage, "",
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Me.EnableFrameSepAddressButtons(True)
End Try
End Sub