B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Activity
Version=6.8
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Dim g As GPS
	Dim ruta As String
'	Dim skmt As SQL
	Dim clie_id As String
    Dim sDate,sTime As String
	Dim usuario As String
    Dim total_cliente As String
	Dim m_lat As String
	Dim m_lon As String
	Dim btAdmin As BluetoothAdmin
	Dim cmp20 As Serial
	Dim printer As TextWriter
	Dim PairedDevices As Map
	Dim L As List
	Dim TAMANO As Int
	Dim ESPACIO As Int
    Dim BLANCO As String
	Dim cuenta As String
	Dim tipo_venta As String
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

    Dim c As Cursor
	Dim s As Cursor
	Dim c2 As Cursor
	Dim ListView1 As ListView
	Dim la_cuenta As Label
	Dim La_nombre As Label
	Dim la_Calle As Label
	Dim la_numero As Label
	Dim la_nint As Label
	Dim la_edo As Label
	Dim la_pob As Label
	Dim la_col As Label
	Dim la_cp As Label
	Dim la_zona As Label
	Dim gest As Button
	Dim la_saldotot As Label
	Dim la_saldooper As Label
	
	Dim Tels As Button
	Dim Label10 As Label
	Dim Label11 As Label
	
	Dim Tar As Button
	
	Dim la_comm As Label
	Dim la_actdte As Label
	Dim la_usuario As Label
	Dim la_resultado As Label
	Dim l_entre1 As Label
	Dim l_entre2 As Label
	Dim l_atiende As Label
	Dim l_atiende2 As Label
	Dim DATOS As Button
	Dim Guardar As Button
	Dim NUEVO As Button
    Dim lat_gps, lon_gps As String

	Dim l_total As Label
	Dim c2 As Cursor
	Dim S2 As Cursor
	Private s As Cursor
	Dim res As String
	Private HIST As Button
	Private MONTO_COMPRA As String
	Private META As String
	Private META2 As String
	Private VERIFICA As String
	Private L_QR As Label
	Private BT_QR As Button
		Private qr As QRCode
    Dim sc As Zxing_scanner
   Dim CODIGO As String

	Private b_mapa As Button
	Dim CUANTOS As String
	Private B_IMP As Button
	Dim Toggla As Toggle
	Dim tgl As Toggle
	Private Panel1 As Panel
	Private I_COMPRA As EditText
	Private B_GUARDA_C As Button
	Private b_venta As Button
	Dim ALMACEN As String
	Private LA_GPS As Label
	Private B_E_NEXT As Button
	Private E_RES_E As EditText
	Private t_tenc As Label
	Private Panel2 As Panel
	Private CONTADOR_E As String
	Private HR_RES1 As String
	Private HR_RES2 As String
	Private HR_RES3 As String
	Private EXISTE As String
	Private TELEFONO As String
	
	
	Private RB1 As RadioButton
	Private RB2 As RadioButton
	Private RB3 As RadioButton
	Private RB4 As RadioButton
	Private RB5 As RadioButton
	
	Private stay_hh As String
	Private stay_mi As String
	Private stay_ss As String
	
	Private LA_GEO As Label
	Dim result As Int
	Private cercavalor As String
	
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'Do not forget to load the layout file created with the visual designer. For example:
	'Activity.LoadLayout("Layout1")
	If(FirstTime) Then
	 g.Initialize("GPS")
	End If
	Activity.RemoveAllViews
    Activity.LoadLayout("info_gral")
	
	' valido donde escribo el archivo de la base de datos de kmt
'	If File.ExternalWritable Then
'	   ruta = File.DirDefaultExternal
'	Else
'	   ruta = File.DirInternal
'	   
'	End If
'    If File.Exists(ruta, "kmt.db") = False Then
'		File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db")
'	End If
'		skmt.Initialize(ruta,"kmt.db", True)
		c=Starter.skmt.execQuery("select CAT_CL_CODIGO,CAT_CL_RUTA,CAT_CL_NOMBRE,CAT_CL_ATIENDE1,CAT_CL_ATIENTE2,CAT_CL_TELEFONO,CAT_CL_EMAIL,CAT_CL_CALLE,CAT_CL_NOEXT,CAT_CL_NOINT,CAT_CL_CALLE1,CAT_CL_CALLE2,CAT_CL_COLONIA,CAT_CL_MUNI,CAT_CL_EDO,CAT_CL_CP,CAT_CL_LONG,CAT_CL_LAT,CAT_CL_MTOCOMPRA  from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	    s=Starter.skmt.execQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	    s.Position=0

	  ' ListView1.Clear
	   
	   'If c.RowCount>0 Then
	    '  For i=0 To c.RowCount -1
		     c.Position=0
			 la_cuenta.Text = c.GetString("CAT_CL_CODIGO")
			 cuenta = c.GetString("CAT_CL_CODIGO")
			 La_nombre.Text = c.GetString("CAT_CL_NOMBRE")
			 la_Calle.Text = c.GetString("CAT_CL_CALLE") & c.GetString("CAT_CL_NOEXT")
			 la_col.Text = c.GetString("CAT_CL_COLONIA")
			 la_edo.Text = c.GetString("CAT_CL_EDO")
'			 la_cp.Text = c.GetString("CAT_CL_CP")
			 l_entre1.Text = c.GetString("CAT_CL_CALLE1")
			 l_entre2.Text = c.GetString("CAT_CL_CALLE2")
			 l_atiende.Text = c.GetString("CAT_CL_ATIENDE1")
			 l_atiende2.Text = c.GetString("CAT_CL_ATIENTE2")
			 la_saldotot.Text = c.GetString("CAT_CL_TELEFONO")
			 la_saldooper.Text = c.GetString("CAT_CL_EMAIL")
			 l_total.Text = s.GetString("TOTAL_CLIE")
			 total_cliente = s.GetString("TOTAL_CLIE")
			 MONTO_COMPRA = c.GetString("CAT_CL_MTOCOMPRA")
			 
			' la_producto.Text = c.GetString("CDPROD")
			 'la_numero.Text = c.GetString("CDNUMEXT")
			 'la_nint.Text = c.GetString("CDNUMINT")
			 'la_pob.Text = c.GetString("CFSDOGLOBAL")
			 
			 'la_saldooper.Text = c.GetString("CAT_CL_FALTA")
			 'Label10.Text = "FECHA DE ALTA"
			 'Label11.Text = "# ENCUESTAS"
			 
			'c=starter.skmt.execQuery("select MGCTA, MGACTT, MGGESTT, MGDTEACTT, COMM  from hist_gest where MGCTA In (Select cuenta from cuentaa)")
	 		'c.Position=0
			'la_comm.Text = c.GetString("COMM")
			'la_actdte.Text = C.GetString("MGDTEACTT")
			'la_usuario.Text = c.GetString("MGGESTT")
			'la_resultado.Text = c.GetString("MGACTT")
			
			 
			 'la_padre.Text = c.GetString("PR_CF_FECHA_DISP")
			 'la_no_ird.Text = c.GetString("PR_CF_SALDO_ACORT")
			 
	' se crea o no el archivo de la base de ddatos de kmt
	'NOTAS SI SE MODIFICA LA ESTRUCTURA SE QUITA EL IF Y SE VA DIRECTO A LA SENTENCIA FILE.COPY PARA QUE 
	'TOME LA NUEVA ESTRUCTURA ES MUY IMPORTANTE TENER EL IF DE LO CONTRARIO SOLO LO ESCRIBE UNA VEZ Y LO BORRA
	'SI SE REGRESA A ESTE ACTIVIDAD.
			 'ListView1.AddTwoLines(c.GetString("pr_cd_nombre"),c.GetString("pr_cd_colonia"))
	    '  Next
	   'End If
	If FirstTime Then
		btAdmin.Initialize("BlueTeeth")
		cmp20.Initialize("Printer")
	End If
End Sub

Sub Activity_Resume
	BT_QR.Enabled = False
	tgl.Initialize
	LA_GPS.TextColor = Colors.Red
    LA_GPS.Text = "SIN UBICACION GPS"
'	tgl.TurnGPSOn
	gest.Visible = False
	
	c=Starter.skmt.execQuery("select USUARIO from usuarioa")
	c.Position=0
	If c.GetString("USUARIO") = "KMTS1" Then gest.Visible = True
	
	cercavalor = 0
	
	If g.GPSEnabled=False Then
		  ToastMessageShow("Habilitar el GPS", True)
		  StartActivity(g.LocationSettingsIntent)
	 Else
	'	Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION)
	  g.Start(0,0)
	  ToastMessageShow("Buscando ubicación", False)
	 End If
	
'			skmt.Initialize(ruta,"kmt.db", True)
		c=Starter.skmt.execQuery("select CAT_CL_CODIGO,CAT_CL_RUTA,CAT_CL_NOMBRE,CAT_CL_ATIENDE1,CAT_CL_ATIENTE2,CAT_CL_TELEFONO,CAT_CL_EMAIL,CAT_CL_CALLE,CAT_CL_NOEXT,CAT_CL_NOINT,CAT_CL_CALLE1,CAT_CL_CALLE2,CAT_CL_COLONIA,CAT_CL_MUNI,CAT_CL_EDO,CAT_CL_CP,CAT_CL_LONG,CAT_CL_LAT,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO  from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	    s=Starter.skmt.execQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	    s.Position=0

	  ' ListView1.Clear
	   
	   'If c.RowCount>0 Then
	    '  For i=0 To c.RowCount -1
		     c.Position=0
			 la_cuenta.Text = c.GetString("CAT_CL_CODIGO")
			 La_nombre.Text = c.GetString("CAT_CL_NOMBRE")
			 la_Calle.Text = c.GetString("CAT_CL_CALLE") & " " & c.GetString("CAT_CL_NOEXT")
			 la_col.Text = c.GetString("CAT_CL_COLONIA")
			 la_edo.Text = c.GetString("CAT_CL_EDO")
	'		 la_cp.Text = c.GetString("CAT_CL_CP")
			 l_entre1.Text = c.GetString("CAT_CL_CALLE1")
			 l_entre2.Text = c.GetString("CAT_CL_CALLE2")
			 l_atiende.Text = c.GetString("CAT_CL_ATIENDE1")
			 l_atiende2.Text = c.GetString("CAT_CL_ATIENTE2")
			 TELEFONO  = c.GetString("CAT_CL_TELEFONO")
			 'la_saldooper.Text = c.GetString("CAT_CL_EMAIL")
			 l_total.Text = s.GetString("TOTAL_CLIE")
			 total_cliente = s.GetString("TOTAL_CLIE")
			 m_lat =c.GetString("CAT_CL_LAT")
			 m_lon =c.GetString("CAT_CL_LONG")
	' ESTO ES PARA FORSAR A PEDIR LA FOTO Y EL GPS		 
			' Msgbox(c.GetString("CAT_CL_NUM_SERIEFISICO"),"AVISO")
	'		 If c.GetString("CAT_CL_NUM_SERIEFISICO") = "0"  Then
	'		 L_QR.Visible = True
	'		 gest.Enabled = False
	'		 Tels.Enabled = False
	'		 Else
	'		 L_QR.Visible = False
			 gest.Enabled = True
			 Tels.Enabled = True
			 				
	'		End If
			S2=Starter.skmt.execQuery("select count(*) AS CUANTOS from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa)")
		    S2.Position =0 
			CUANTOS = S2.GetString("CUANTOS")
			S2.Close
			If CUANTOS > 0 Then
			c2=Starter.skmt.execQuery("select sum(HVD_COSTO_TOT) AS TOTAL from HIST_VENTAS WHERE HVD_CLIENTE IN (Select CUENTA from cuentaa)")
			c2.Position =0
			 MONTO_COMPRA = c2.GetString("TOTAL")
			c2.Close
			Else
			  MONTO_COMPRA = "0"
			End If 
			
			 la_saldotot.Text = MONTO_COMPRA
			 If MONTO_COMPRA <> "0" Then
			 META2 = 300 -  MONTO_COMPRA
			 Else
			 	META2 = 300
			 End If
			 If META2 < 1 Then
			 	META2 = "CUBIERTO"
			End If
		     la_saldooper.Text = META2
			   
			' la_producto.Text = c.GetString("CDPROD")
			 'la_numero.Text = c.GetString("CDNUMEXT")
			 'la_nint.Text = c.GetString("CDNUMINT")
			 'la_pob.Text = c.GetString("CFSDOGLOBAL")
			 
			 'la_saldooper.Text = c.GetString("CAT_CL_FALTA")
			 'Label10.Text = "FECHA DE ALTA"
			 'Label11.Text = "# ENCUESTAS"
			 
	
			 'c=starter.skmt.execQuery("select MGCTA, MGACTT, MGGESTT, MGDTEACTT, COMM  from hist_gest where MGCTA In (Select cuenta from cuentaa)")
	 		'c.Position=0
			'la_comm.Text = c.GetString("COMM")
			'la_actdte.Text = C.GetString("MGDTEACTT")
			'la_usuario.Text = c.GetString("MGGESTT")
			'la_resultado.Text = c.GetString("MGACTT")
'
'
'
''''''''''''''''''esto es para los pup de validacion 
'	
'	
'	s=starter.skmt.execQuery("select count(*) as CUANTOS from HIST_VERIFICACION where HVE_CLIENTE IN (Select cuenta from cuentaa)")	
'	s.Position=0
'	If s.GetString("CUANTOS") = 0 Then
'		
'			If MONTO_COMPRA > 300 Then
'				META = "FELICIDADES ESTE CLIENTE YA ALCANZO LA META DE VENTA"
'			Else
'				META2 = 300 -  MONTO_COMPRA 
'		
'				META = "FALTA POR ALCANZAR META, LA VENTA MINIMA PARA HOY ES DE : " & META2
'			   
'			End If
'		c=starter.skmt.execQuery("select count(*) as CUANTOS FROM CAT_VERIFICACION")
'	    c.Position=0
'		If c.GetString("CUANTOS") <> 0 Then
'			
'		c2=starter.skmt.execQuery("select CAT_VE_IDPROD, CAT_VE_NOMBRE, CAT_VE_ORDEN FROM CAT_VERIFICACION ORDER BY CAT_VE_ORDEN ")
 '        If c2.RowCount>0 Then
'	      For i=0 To c2.RowCount -1
''		  	c2.Position =i
'			VERIFICA = VERIFICA & "-------VALIDAR-------   " & c2.GetString("CAT_VE_NOMBRE")
'			
'	      	
'		  Next
'		End If
'	End If		
'		c.Close
'		c2.Close
'			
'		Msgbox(" Instrucciones:     " & META &" para este clinete el adicional " & VERIFICA &" y el cliente cuenta con 6 promos.","Indicaciones")

'	c=starter.skmt.execQuery("select count(*) as CUANTOS FROM CAT_VERIFICACION")
'	    c.Position=0
'	If c.GetString("CUANTOS") <> 0 Then
'		c2=starter.skmt.execQuery("select CAT_VE_IDPROD, CAT_VE_NOMBRE, CAT_VE_ORDEN FROM CAT_VERIFICACION ORDER BY CAT_VE_ORDEN ")
 '        If c2.RowCount>0 Then
''	      For i=0 To c2.RowCount -1
'		  	c2.Position =i
'			'ToastMessageShow(c2.GetString("CAT_GP_NOMBRE"), True)
'
'		  	res =  Msgbox2("Tiene el cliente  " & c2.GetString("CAT_VE_NOMBRE"),"Verificacion", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
'	      	If res = DialogResponse.POSITIVE Then
 '         	  starter.skmt.execNonQuery2("INSERT INTO HIST_VERIFICACION VALUES (?,?,?)", Array As Object(la_cuenta.Text,c2.GetString("CAT_VE_IDPROD"), 1))
'	
'			Else
'		  	starter.skmt.execNonQuery2("INSERT INTO HIST_VERIFICACION VALUES (?,?,?)", Array As Object(la_cuenta.Text,c2.GetString("CAT_VE_IDPROD"), 0))
'	
'			End If
'		  Next
'		End If
'	End If
'	c.Close
'	End If
'	s.Close

''''''''''''''''''''''''''' hasta aqui es todo para los pups de validacion.
' para imprimir			  	
'	Toggla.TurnBluetoothOn
'	btAdmin.Initialize("BlueTeeth")
'	cmp20.Initialize("Printer")
'	StartPrinter
	c=starter.skmt.execQuery("select  ID_ALMACEN from CAT_ALMACEN")
	C.Position =0
	ALMACEN = C.GetString("ID_ALMACEN")
	C.Close
'	If ALMACEN = "34" Then
'		b_venta.Visible = True
'	Else
'		b_venta.Visible = False
'		
'	End If
'	C=starter.skmt.execQuery2("SELECT COUNT(*) AS CUANTOS FROM HIST_CLIENTE_CANT_PROMOS WHERE HCCP_CLIENTE IN (Select cuenta from cuentaa) AND HCCP_PROMO =?", Array As String(c.GetString("CAT_GP_ID")))
'	C.Position =0
'	If C.GetString("CUANTOS")  > 0 Then
'	BOTON_PROMO
'		starter.skmt.execNonQuery2("INSERT INTO  PEDIDO (PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO,PE_RUTA,PE_FOLIO) VALUES(?,?,?,?,?,?,?,?,?,?,?) ", Array As Object (L_PROID.text,0, 0, cantidad.text, l_desc.text, L_PROID.Text,clie_id, sDate & sTime, usuario,cl_ruta,fila.tipo_venta))
'		
'			
'	Else
'	
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub GPS_LocationChanged (Location1 As Location)
lat_gps=Location1.Latitude
lon_gps=Location1.Longitude
	BT_QR.Enabled = True
	LA_GPS.TextColor = Colors.Blue
	LA_GPS.Text = "CON UBICACION GPS"
	
	
	Dim l1, l2 As Location
	l1.Initialize2(lat_gps, lon_gps)
	l2.Initialize2(m_lat, m_lon)
   
	'now we need the distance between our location and the target location

	Dim distance As Long
	distance =    l1.DistanceTo(l2)  'the result is in meter

	gest.Visible = True
	
	If distance < 20 Then
		LA_GEO.TextColor = Colors.Blue
	Else
		LA_GEO.TextColor = Colors.Red
	'	If cercavalor = 0 Then
	'	result = Msgbox2("No estas en las coordenadas del cliente registradas en sistema, Estas en el cliente?", "Coordenadas Erroneas", "SI", "", "NO", LoadBitmap(File.DirAssets, "alerta.jpg"))
	'	If result = DialogResponse.Positive Then 
	'		starter.skmt.execNonQuery2("INSERT INTO HIST_GEOCERCA (HGCLIENTE, HGDATE, HGLAT, HGLON) VALUES(?,?,?,?) ", Array As Object (cuenta, sDate & sTime, lat_gps,lon_gps))
	'	End If
	'	cercavalor = 1
	'	End If
	End If
	LA_GEO.Text= distance
	
	
	Starter.skmt.execNonQuery("DELETE FROM HIST_GPS")
	
	Starter.skmt.execNonQuery2("INSERT INTO  HIST_GPS (HGDATE, HGLAT, HGLON) VALUES(?,?,?) ", Array As Object (sDate & sTime, lat_gps,lon_gps))

End Sub


Sub ListView1_ItemLongClick (Position As Int, Value As Object)
	
End Sub

Sub gest_Click
    'StartActivity(telefonos)
	
	'   starter.skmt.execNonQuery("delete from PRODUCTOA")
	'  starter.skmt.execNonQuery2("INSERT INTO PRODUCTOA VALUES (?)", Array As Object(la_producto.Text))
	'  Dim cuantos As String
  	'c=starter.skmt.execQuery("select count(*) as cuantos from HIST_VISITAS WHERE HIST_VI_CREDITO IN (SELECT CUENTA FROM CUENTAA) ")
    '    c.Position = 0
	'    cuantos = c.GetString("cuantos")
	'	ToastMessageShow(cuantos,True)
	'If cuantos > 0 Then
	'StartActivity(gestion)
	'Else If cuantos = 0 Then

''''' ESTE CODIGO SIRVE PARA MANDAR EN PUPUP LA PROMOCIONES E IR PREGUNTANDO UNO A UNO.
''' DESDE EL CURSOR Y TODO EL IF DE ABAJO SON 20 LINEAS.
'	c=starter.skmt.execQuery("select count(*) as CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
'	    c.Position=0
'	If c.GetString("CUANTOS") = 0 Then
'		c2=starter.skmt.execQuery2("select  CAT_GP_NOMBRE, CAT_GP_PRECIO, CAT_GP_ALMACEN, CAT_GP_IMG from cat_gunaprod where CAT_GP_ALMACEN > 0 and CAT_GP_CLASIF = ? AND CAT_GP_TIPO = ? AND CAT_GP_SUBTIPO = ?  AND CAT_GP_ID IN (SELECT HP_CODIGO_PROMOCION FROM HIST_PROMOS WHERE HP_CLIENTE IN (Select cuenta from cuentaa) )", Array As String("PROMOS", "PROMOS", "PROMOS"))
 '        If c2.RowCount>0 Then
'	      For i=0 To c2.RowCount -1
'		  	c2.Position =i
'			'ToastMessageShow(c2.GetString("CAT_GP_NOMBRE"), True)
''
'		  	res =  Msgbox2(" " & c2.GetString("CAT_GP_NOMBRE"),"IR......", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
'	      	If res = DialogResponse.POSITIVE Then
 '        		starter.skmt.execNonQuery("delete from PROID")
'	  			starter.skmt.execNonQuery2("INSERT INTO PROID VALUES (?)", Array As Object(c2.GetString("CAT_GP_NOMBRE")))
'	  			StartActivity(pedidos)
'		  		i = c2.RowCount
'		  	else if i = c2.RowCount -1 Then
'		  			StartActivity(colonia2)
'		  	End If
'		  Next
'		Else
'			StartActivity(colonia2)
'		End If
'	Else
'		StartActivity(colonia2)
'	End If
'	c.Close
	''''' HASTA AQUI TERMINA LO DE LOS PUPUPS
'	c=starter.skmt.execQuery("select  ID_ALMACEN from CAT_ALMACEN")
'	C.Position =0
'	ALMACEN = C.GetString("ID_ALMACEN")
'	C.Close
'	
'	DateTime.DateFormat = "MM/dd/yyyy"
'	sDate=DateTime.Date(DateTime.Now)
'	sTime=DateTime.Time(DateTime.Now)
'	s=starter.skmt.execQuery("select COUNT(*) AS CUANTOS   from HIST_ENCUESTA where HE_CLIE In (Select cuenta from cuentaa)")
'	s.Position= 0
'If s.GetString("CUANTOS") = 0 Then
'
'If  ALMACEN = 3  Then
'
'			res =  Msgbox2("VENDEN PEDEGREE?","PEDEGREE", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
'	If res = DialogResponse.POSITIVE Then
'				starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "SI",sDate & sTime,"PEDEGREE"))
'				Panel2.Visible  = True
'				CONTADOR_E = 1
'				t_tenc.Text = "Donde lo compran"
'				E_RES_E.InputType =E_RES_E.INPUT_TYPE_TEXT
'				E_RES_E.Text = ""
'		
'		
'	Else
'				starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "NO",sDate & sTime,"PEDEGREE"))
'				tipo_venta = "PREVENTA"
'				StartActivity(colonia2)
'	End If
'		Else
'			tipo_venta = "PREVENTA"
'			StartActivity(colonia2)
'End If
'
'Else
'		tipo_venta = "PREVENTA"
'		StartActivity(colonia2)
'	End If



'	DateTime.DateFormat = "MM/dd/yyyy"
'	sDate=DateTime.Date(DateTime.Now)
'	sTime=DateTime.Time(DateTime.Now)
'	c=starter.skmt.execQuery("Select CUENTA from cuentaa")
'	c.Position=0
'	clie_id = c.GetString("CUENTA")
'	c=starter.skmt.execQuery("select USUARIO from usuarioa")
'	c.Position=0
'	usuario = c.GetString("USUARIO")
'	
'	c=starter.skmt.execQuery("SELECT COUNT(*) AS CUANTOS FROM HIST_ENCUESTA WHERE HE_CUENTA IN (Select CUENTA from cuentaa)")
'	c.Position=0
'	EXISTE  = c.GetString("CUANTOS")
'	c.Close
'	If EXISTE = 0 Then
'	res = Msgbox2("Manejan/Venden toallas sanitarias Saba  SI/NO","Encuesta","SI","","NO",LoadBitmap(File.DirAssets,"alert2.png"))
'	If res = DialogResponse.POSITIVE Then
'		Panel2.Visible  = True
'		CONTADOR_E = 1
'		t_tenc.Text = "Buenas Noches con Alas 8 piezas"
'		E_RES_E.InputType =E_RES_E.INPUT_TYPE_DECIMAL_NUMBERS
'		E_RES_E.Text = ""
'	Else
'		starter.skmt.execNonQuery2("INSERT INTO HIST_ENCUESTA(HE_CUENTA, HE_MANEJA, HE_RES1, HE_RES2, HE_RES3, HE_RES4,HE_FECHA,HE_USUARIO) VALUES (?,?,?,?,?,?,?,?)", Array As Object(clie_id, "NO","0","0","0","0",sDate&sTime, usuario))
'		Main.tipov = "PREVENTA"
'		StartActivity(colonia2)
'		
'	End If
'	Else
'		Main.tipov = "PREVENTA"
'		StartActivity(colonia2)
'	End If

		tipo_venta = "PREVENTA"
		StartActivity(colonia2)

End Sub

Sub Tels_Click
'	DateTime.DateFormat = "MM/dd/yyyy"
'	sDate=DateTime.Date(DateTime.Now)
'	sTime=DateTime.Time(DateTime.Now)
'	' starter.skmt.execNonQuery("delete from PEDIDO")
'	c=starter.skmt.execQuery2("SELECT CAT_VA_VALOR FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String("CUESTIONARIO"))
'	c.Position =0
'	If c.GetString("CAT_VA_VALOR") = "1" Then
'
'		res =  Msgbox2("El cliente maneja CAMEL ?","CAMEL", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
'		If res = DialogResponse.POSITIVE Then
'			starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "SI",sDate & sTime,"TIENE"))
'			res = Msgbox2("Donde compra Camel?","Donde Compra","BAT","OTRO","MAYOREO",LoadBitmap(File.DirAssets,"alert2.png"))
'			If res = DialogResponse.POSITIVE Then
'				starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "BAT",sDate & sTime,"COMPRA"))
'			ELSE IF res = DialogResponse.CANCEL Then
'				starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "OTRO",sDate & sTime,"COMPRA"))
'			Else IF res = DialogResponse.NEGATIVE Then
'				starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "MAYOREO",sDate & sTime,"COMPRA"))
'	
'			End If
'			StartActivity(nopago)
'		Else
'			starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "NO",sDate & sTime,"TIENE"))
'	
'			StartActivity(nopago)
'		End If
'	Else
'	
'		StartActivity(nopago)
'	End If
'	DateTime.DateFormat = "MM/dd/yyyy"
'	sDate=DateTime.Date(DateTime.Now)
'	sTime=DateTime.Time(DateTime.Now)
'	s=starter.skmt.execQuery("select COUNT(*) AS CUANTOS   from HIST_ENCUESTA where HE_CLIE In (Select cuenta from cuentaa)")
'	s.Position= 0
'	If s.GetString("CUANTOS") = 0 Then
'
'		If  TELEFONO = "0" Then
'
'			res =  Msgbox2("Permanecera abierto los proximos días ?","Apertura", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
'			If res = DialogResponse.POSITIVE Then
'				starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "SI",sDate & sTime,"CBOCAS"))
'				Panel2.Visible  = True
'				CONTADOR_E = 1
'				t_tenc.Text = "Teléfono del cliente"
'				E_RES_E.InputType =E_RES_E.INPUT_TYPE_DECIMAL_NUMBERS
'				E_RES_E.Text = ""
'		
'		
'			Else
'				starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "NO",sDate & sTime,"CBOCAS"))
'				Panel2.Visible  = True
'				CONTADOR_E = 1
'				t_tenc.Text = "Teléfono del cliente"
'				E_RES_E.InputType =E_RES_E.INPUT_TYPE_DECIMAL_NUMBERS
'				E_RES_E.Text = ""
'			End If
'		Else
'			StartActivity(nopago)
'		End If
'
'	Else
'		StartActivity(nopago)
'	End If

	StartActivity(nopago)
	  
End Sub
Sub Activity_KeyPress (key As Int) As Boolean
    ' BACK key pressed
    If key=KeyCodes.KEYCODE_BACK Then
            ' I want to capture the key here so I return True
			StartActivity(colonia)
            'Return True
    End If
    ' Returning False signals the system to handle the key
    Return False
End Sub

Sub Tar_Click
	 StartActivity(tarjeta)
End Sub
Sub DATOS_Click
	 StartActivity(telefonos)
End Sub
Sub Guardar_Click
	DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
    c=Starter.skmt.execQuery("Select CUENTA from cuentaa")
	c.Position=0
	clie_id = c.GetString("CUENTA")
	c=Starter.skmt.execQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	
	c=Starter.skmt.execQuery("select sum(pe_costo_tot) as TOTAL_CLIE, SUM(PE_CANT) AS CANT_CLIE, COUNT(*) AS CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	c.Position=0
	If c.GetString("CUANTOS") > 0 Then
	Starter.skmt.execNonQuery("delete from NOVENTA where NV_CLIENTE In (select cuenta from cuentaa)")
	Starter.skmt.execNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
	Starter.skmt.execNonQuery2("insert into pedido_cliente(PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT) VALUES (?,?,?,?,?,?,?)", Array As Object(clie_id, sDate & sTime, usuario, c.GetString("CANT_CLIE"),c.GetString("TOTAL_CLIE"), lon_gps, lat_gps))
	Starter.skmt.execNonQuery("UPDATE kmt_info set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")		
	End If
	c.Close
	DateTime.TimeFormat = "HHmmss"
	sTime=DateTime.Time(DateTime.Now)
	Starter.skmt.execNonQuery2("UPDATE HIST_STAY_STORE set HSS_OUT = ?  where HSS_OUT = 0 AND  HSS_CODIGO In (select cuenta from cuentaa)", Array As Object(sTime))
'  starter.skmt.execNonQuery("UPDATE HIST_STAY_STORE set HSS_TOT = HSS_OUT - HSS_IN where HSS_CODIGO In (select cuenta from cuentaa)")
	
Try
c=Starter.skmt.execQuery(" Select (substr(HSS_OUT,1,2) - substr(HSS_IN,1,2)) - Case when  (substr(HSS_OUT,3,2) - substr(HSS_IN,3,2)) < 0 Then 1 Else 0 end HORAS_TOTALES, " & _
	"Case when  (substr(HSS_OUT,3,2) - substr(HSS_IN,3,2)) < 0 Then (substr(HSS_OUT,3,2) + 60 - substr(HSS_IN,3,2)) " & _
	"	Else (substr(HSS_OUT,3,2) - substr(HSS_IN,3,2)) End - Case when  (substr(HSS_OUT,5,2) - substr(HSS_IN,5,2)) < 0 Then 1 Else 0 end  MINUTOS_TOTALES, " & _
	"Case when  (substr(HSS_OUT,5,2) - substr(HSS_IN,5,2)) < 0 Then (substr(HSS_OUT,5,2) + 60 - substr(HSS_IN,5,2)) " & _
	"	Else (substr(HSS_OUT,5,2) - substr(HSS_IN,5,2)) end SEGUNDOS_TOTALES " & _
	"	from HIST_STAY_STORE where HSS_CODIGO In (Select cuenta from cuentaa) ")
	c.Position = 0
	stay_hh = c.GetString("HORAS_TOTALES") * 60 * 60
	stay_mi = c.GetString("MINUTOS_TOTALES") * 60
	stay_ss = c.GetString("SEGUNDOS_TOTALES")
	
	starter.skmt.execNonQuery2("UPDATE HIST_STAY_STORE set HSS_TOT = ?  where HSS_CODIGO In (select cuenta from cuentaa)", Array As Object(stay_hh + stay_mi + stay_ss))
	

	starter.skmt.execNonQuery2("UPDATE HIST_STAY_OUT set HSO_FIN = ?  ", Array As Object(sTime))
Catch
	ToastMessageShow(".",True)
End Try	
	DateTime.TimeFormat = "HH:mm:ss"
	
	StartActivity(seleccion)
End Sub
Sub NUEVO_Click
	StartActivity(nuevocliente)
End Sub
Sub HIST_Click
	StartActivity(Historico)
End Sub

Sub BT_QR_Click
	
'ESTO HACE EL CODIGO QR
    'StartActivity(QR_MODULE)
'	Dim scan_width As Int
'	Dim scan_height As Int
'	scan_width = 400
'	scan_height = 400
'	sc.BeginScan("sc","CODIGO CLIENTE",scan_width,scan_height)
' FIN CODIGO QR
	'CODIGO PARA TOMAR LA FOTO
Msgbox("Recuerda este punto se tomara como la ubicación de la tienda","AVISO")
	StartActivity(foto)
	
End Sub




Sub sc_result(atype As String,Values As String)
    'Log("Type : " & atype)
    'Log("Value : " & Values)
	CODIGO = Values

	starter.skmt.execNonQuery2("UPDATE kmt_info set CAT_CL_NUM_SERIEFISICO = ?, CAT_CL_LONG = ?, CAT_CL_LAT =? where CAT_CL_CODIGO In (select cuenta from cuentaa)", Array As Object(CODIGO, lon_gps, lat_gps))
	  
End Sub
Sub sc_noScan
    Log("nothing returned from the scan !!!!!")
End Sub
Sub calc_ean_checksum(number As String) As String           'this has now become redundant as I am only interested in QR Codes
    Dim i As Int
    Dim cO As Char
    Dim soma As Int
    Dim n As Int
    Dim digit As Float
   
    soma = 0
    For i=0 To number.Length - 1
        digit = number.SubString2(i,i+1)
        n= digit * ((i Mod 2) * 2 + 1)   
        soma=soma+n
    Next
    Return number & ( ( 10 - ( soma Mod 10 )) Mod 10 )
End Sub

Sub b_mapa_Click
	StartActivity(mapas)
End Sub

Sub B_IMP_Click
	TAMANO = 0
	ESPACIO = 21
	BLANCO = " "
	printer.Initialize(cmp20.OutputStream)
	printer.WriteLine("DURAKELO S.A. de C.V.")
	printer.WriteLine("RFC: DUR-011025-T12")
	printer.WriteLine("Tel.: 618-826-0104")
	printer.WriteLine("Vendedor: KMTS ")
	printer.WriteLine("Tienda: " & La_nombre.Text)
	printer.WriteLine("-----------PREVENTA-----------")
	s=starter.skmt.execQuery("select PE_PRONOMBRE, PE_CANT, length(pe_cant) as L_CANT, PE_COSTOU, length(PE_COSTOU) as L_COSTOU, PE_COSTO_TOT, length(PE_COSTO_TOT) as L_COSTO_TOT FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
	If S.RowCount>0 Then
	  For i=0 To S.RowCount -1
	S.Position=i
	printer.WriteLine(s.GetString("PE_CANT") & " " & s.GetString("PE_PRONOMBRE"))
	TAMANO = s.GetLong("L_CANT") + TAMANO
	TAMANO = s.GetLong("L_COSTOU") + TAMANO
	TAMANO = s.GetLong("L_COSTO_TOT") + TAMANO
	
	ESPACIO = ESPACIO - TAMANO
	
	For E=0 To ESPACIO -1 
		BLANCO = " " & BLANCO
	Next
			printer.WriteLine(BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") )
			TAMANO = 0
			ESPACIO = 21
			BLANCO = " "
	 
	 Next
	End If
	printer.WriteLine("Total Preventa:   $" & total_cliente)
	printer.WriteLine("------------VENTA-------------")
	printer.WriteLine(" ")
	printer.WriteLine("TOTAL:   $" & total_cliente)
	printer.WriteLine(" ")
	printer.WriteLine("----ESTE TICKET NO ES UN -----")
	printer.WriteLine("--COMPROBANTE FISCAL, SOLO ES-")
	printer.WriteLine("--------INFORMATIVO-----------")
	printer.WriteLine("------------------------------")
	printer.WriteLine(" ")
	printer.Flush
'	printer.Close
	
End Sub

Sub Printer_Connected (Success As Boolean)
	If Success Then
		
    B_IMP.Enabled = True
			
	Else
		B_IMP.Enabled = False
		If Msgbox2("", "Printer Error","Reprint","Cancel","",Null) = DialogResponse.POSITIVE Then
			StartPrinter
		End If
	End If
End Sub

Sub StartPrinter
	Dim PairedDevices As Map
	Dim L As List
	Dim resimp As Int

	ToastMessageShow("Printing.....",True)

	PairedDevices.Initialize

	Try
		PairedDevices = cmp20.GetPairedDevices
	Catch
		Msgbox("Getting Paired Devices","Printer Error")
		printer.Close
		cmp20.Disconnect
	End Try

	If PairedDevices.Size = 0 Then
		Msgbox("Error Connecting to Printer - Printer Not Found","")
		Return
	End If

	If PairedDevices.Size = 1 Then
		Try
			cmp20.ConnectInsecure(btAdmin,PairedDevices.Get(PairedDevices.GetKeyAt(0)),1)
		Catch
			Msgbox("Connecting","Printer Error")
			printer.Close
			cmp20.Disconnect
		End Try
	Else
		L.Initialize

		For i = 0 To PairedDevices.Size - 1
			L.Add(PairedDevices.GetKeyAt(i))
		Next

		resimp = InputList(L, "Choose device", -1)

		If resimp <> DialogResponse.CANCEL Then
			cmp20.Connect(PairedDevices.Get(L.Get(resimp)))
			
		End If
	End If
End Sub


Sub B_GUARDA_C_Click
	
		
	starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, I_COMPRA.Text,sDate & sTime,"COMPRA"))
	Panel1.Visible = False
	BT_QR.Visible= True
		
	StartActivity(colonia2)
End Sub

Sub b_venta_Click
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	s=starter.skmt.execQuery("select COUNT(*) AS CUANTOS   from HIST_ENCUESTA where HE_CLIE In (Select cuenta from cuentaa)")
	s.Position= 0
	If s.GetString("CUANTOS") = 0 Then

		c=starter.skmt.execQuery2("SELECT CAT_VA_VALOR FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String("CUESTIONARIO"))
		c.Position =0
		If c.GetString("CAT_VA_VALOR") = "2" Then

			res =  Msgbox2("El cliente maneja CAZARES ?","CAZARES", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
			If res = DialogResponse.POSITIVE Then
				starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "SI",sDate & sTime,"TIENE"))
				Panel1.Visible =True
				I_COMPRA.Text = ""
				BT_QR.Visible= False
		
		
			Else
				starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, "NO",sDate & sTime,"TIENE"))
				tipo_venta = "VENTA"
				StartActivity(colonia2)
			End If
		Else
			tipo_venta = "VENTA"
			StartActivity(colonia2)
		End If

	Else
		tipo_venta = "VENTA"
		StartActivity(colonia2)
	End If
End Sub

Sub B_E_NEXT_Click
	
	If E_RES_E.Text <> "" Then
		
			
			starter.skmt.execNonQuery2("insert into HIST_ENCUESTA(HE_CLIE, HE_RES, HE_FECHA, HE_TIPO) VALUES (?,?,?,?)", Array As Object(la_cuenta.Text, E_RES_E.Text,sDate & sTime,"DONDE"))
			'Main.tipov = "PREVENTA"
			Panel2.Visible = False
			
			StartActivity(colonia2)

	Else
		Msgbox("SIN RESPUESTA","AVISO")
	End If
	
	
End Sub

Sub RB1_CheckedChange(Checked As Boolean)
	If RB1.Checked = True Then
		E_RES_E.Text = "CENTRAL DE ABASTOS"
	End If
End Sub

Sub RB2_CheckedChange(Checked As Boolean)
	If RB2.Checked = True Then
		E_RES_E.Text = "AUTOSERVICIO"
	End If
	
End Sub

Sub RB3_CheckedChange(Checked As Boolean)
	If RB3.Checked = True Then
		E_RES_E.Text = "CLUB DE PRECIO"
	End If
	
End Sub

Sub RB4_CheckedChange(Checked As Boolean)
	If RB4.Checked = True Then
		E_RES_E.Text = "DIRECTO PEDEGREE"
	End If
	
End Sub