Sub Class_Globals
Public mypage As Page
Private myIncassoPage As Page
Private myNavControl As NavigationController
Private myTableView As TableView
Private myTableViewCell As TableView
Private dbData As SQL
Private myCode As String
Private lData As Label
Private lDocType As Label
Private lImporto As Label
Private lNumber As Label
Private lTotale As Label
Private lTotPar As Label
Private bAddDel As Button
Private lImportoC As Label
Private lModpagC As Label
Private bAnnulla As Button
Private bok As Button
Private tfIncasso As TextField
Private key As gStructKeyDoc
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(nav As NavigationController,code As String)
myCode = code
myNavControl = nav
mypage.Initialize("myPage")
mypage.RootPanel.LoadLayout("pCustomerInfoMastrino")
myTableView.RowHeight = 167
prepare
myNavControl.ShowPage(mypage)
End Sub
Private Sub myPage_Resize(Width As Int, Height As Int)
myTableView.SetLayoutAnimated(400, 0.5, 0, 0, mypage.RootPanel.Width,100%y)
If myTableView.NumberOfSections > 0 Then
For Each tc As TableCell In myTableView.GetItems(0)
tc.CustomView.Width = myTableView.Width
If myTableViewCell.NumberOfSections > 0 Then
For Each tci As TableCell In myTableViewCell.GetItems(0)
tci.CustomView.Width = myTableView.Width - 40
Next
End If
Next
End If
End Sub
Sub myPage_click
mypage.ResignFocus
End Sub
Sub myPage_BarButtonClick(tag As String)
Select Case tag
Case "exit"
myNavControl.RemoveCurrentPage
End Select
End Sub
Sub prepare
Dim rs,rs1 As ResultSet
key.Initialize
myTableView.Clear
dbData.Initialize(File.DirDocuments,"dbData",True)
Try
dbData.BeginTransaction
' vendite
Dim totval,totpar As Double
rs = dbData.ExecQuery("SELECT * from h_credits where d04 = '"&myCode&"'")
Do While rs.NextRow
Dim p As Panel
p.Initialize("P")
p.Width = myTableView.Width
p.Height = 167
p.LoadLayout("pCustomerMastrinoTableViewCell")
myTableViewCell.RowHeight = 30
DateTime.DateFormat = "yyyyMMdd"
lData.text = DateTime.GetDayOfMonth(DateTime.DateParse(rs.GetString("D03")))&"/"&DateTime.GetMonth(DateTime.DateParse(rs.GetString("D03")))&"/"&DateTime.GetYear(DateTime.DateParse(rs.GetString("D03")))
lNumber.Text = rs.GetString("D02")
rs1 = dbData.ExecQuery("Select * from settings where k01 = 'DOCUMENTS' and D01 = '"&rs.GetString("D01")&"'")
Do While rs1.NextRow
lDocType.Text = rs1.GetString("D01")
Loop
totpar = 0
rs1 = dbData.ExecQuery("Select * from r_credits where d05 = '"&myCode&"' and D02 = '"&rs.GetString("D02")&"' and D03 = '"&rs.GetString("D03")&"' order by D04")
Do While rs1.NextRow
Dim psub As Panel
psub.Initialize("PSUB")
psub.Width = myTableView.Width - 40
psub.Height = 30
psub.LoadLayout("pCustomerMastrinoTCCell")
key.tDoc = rs1.GetString("D01")
key.nrdoc = rs1.GetString("D02")
key.dtdoc = rs1.GetString("D03")
key.nrriga = rs1.GetString("D04")
key.cli = rs1.GetString("D05")
key.tipo = "SUB"
Dim b As Bitmap
b.Initialize(File.DirAssets,"Minus_25.png")
Globals.SetBackgroundImage(bAddDel,b,0)
bAddDel.Tag = key
lModpagC.Text = rs1.GetString("D07")
lImportoC.Text = Globals.FormatNumber(rs1.GetDouble("D06"),"VD")
Dim tci As TableCell = myTableViewCell.AddSingleLine("")
tci.ShowSelection = False
tci.AccessoryType = tci.ACCESSORY_NONE
tci.CustomView = psub
totpar = totpar + rs1.GetDouble("D06")
Loop
If (rs.GetDouble("D05") - totpar) <> 0 Then
Dim padd As Panel
padd.Initialize("Pi")
padd.Width = myTableView.Width - 40
padd.Height = 30
padd.LoadLayout("pCustomerMastrinoTCCell")
key.tDoc = rs.GetString("D01")
key.nrdoc = rs.GetString("D02")
key.dtdoc = rs.GetString("D03")
key.cli = rs.GetString("D05")
key.tipo = "ADD"
Dim b As Bitmap
b.Initialize(File.DirAssets,"Plus_25.png")
Globals.SetBackgroundImage(bAddDel,b,0)
bAddDel.Tag = key
Dim tci As TableCell = myTableViewCell.AddSingleLine("")
tci.ShowSelection = False
tci.AccessoryType = tci.ACCESSORY_NONE
tci.CustomView = padd
End If
If (rs.GetDouble("D05")-totpar) <> 0 Then
lTotPar.Text = Globals.FormatNumber((rs.GetDouble("D05")-totpar),"VD")
lImporto.Text = Globals.FormatNumber(rs.GetDouble("D05"),"VD")
totval = totval + rs.GetDouble("D05")
totval = totval - totpar
Dim tc As TableCell = myTableView.AddSingleLine("")
tc.ShowSelection = False
tc.AccessoryType = tc.ACCESSORY_NONE
tc.CustomView = p
End If
Loop
myTableViewCell.ReloadAll
myTableView.ReloadAll
lTotale.Text = Globals.FormatNumber(totval,"VD")
dbData.TransactionSuccessful
dbData.Close
Catch
Msgbox("Errore tmCustomerMastrino prepare (Database)","Errore")
dbData.Rollback
dbData.Close
End Try
End Sub
Sub bAddDel_Click
Dim btn As Button = Sender
Dim no As NativeObject = btn
Dim Parent As Panel = no.GetField("superview") 'get the button's parent
Dim b As Button = Parent.GetView(1) 'this is the text field index (based on the order in the layout file).
key = b.Tag
If key.tipo = "ADD" Then
myIncassoPage.Initialize("Incasso")
myIncassoPage.rootpanel.LoadLayout("pCustomerInfoAddIncasso")
Globals.ShowPage(mypage,myIncassoPage)
tfIncasso.Text = "0,00"
tfIncasso.KeyboardType = tfIncasso.TYPE_DECIMAL_PAD
tfIncasso.RequestFocus
Else
delete
End If
End Sub
Sub bAnnulla_click
Globals.HidePage(mypage)
End Sub
Sub bOk_click
Save
Globals.HidePage(mypage)
End Sub
Sub Save
dbData.Initialize(File.DirDocuments,"dbData",True)
Try
dbData.BeginTransaction
' ultima riga
Dim n As Int = dbData.ExecQuerySingleResult("Select count(*) from r_credits where d01 = '"&key.tDoc&"' and d02 = '"&key.nrdoc&"' and d03 = '"&key.dtdoc&"' and D05 = '"&key.cli&"'")
' salvo l'incasso
Dim inc As Double
Dim incStr As String
incStr = tfIncasso.Text
incStr = incStr.Replace(",",".")
inc = incStr
DateTime.DateFormat = "yyyyMMdd"
dbData.ExecNonQuery("INSERT INTO r_credits VALUES (null,'"&key.tDoc&"','"&key.nrdoc&"','"&key.dtdoc&"','"&(n+1)&"','"&key.cli&"','"&Globals.FormatNumber(inc,"F")&"','"&DateTime.Date(DateTime.Now)&" - Incasso"&"','','','','','','','','','')")
dbData.TransactionSuccessful
dbData.close
prepare
Catch
Msgbox("Errore tmCustomerInfoAddIncasso Save (Database)","Errore")
dbData.Rollback
dbData.Close
End Try
End Sub
Sub delete
dbData.Initialize(File.DirDocuments,"dbData",True)
Try
dbData.BeginTransaction
dbData.ExecNonQuery("Delete from r_credits where D01 = '"&key.tDoc&"' and D02 = '"&key.nrdoc&"' and D03 = '"&key.dtdoc&"' and D04 = '"&key.nrriga&"' and d05 = '"&key.cli&"'")
dbData.TransactionSuccessful
dbData.close
prepare
Catch
Msgbox("Errore tmCustomerInfoAddIncasso Save (Database)","Errore")
dbData.Rollback
dbData.Close
End Try
End Sub