B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Activity
Version=7.01
@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 tipov As String
	Dim Printer1 As EscPosPrinter
	Dim MAC_IMPRESORA 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 d As Cursor
    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
	Private B_VENTA As Button
	Dim PASA_IMP As String
	Dim sucursal As String
	Dim FACTURA As String
	Dim CREDITO As String
	Private b_factura As Button
	Dim perfil As String
	Private CH_TA As CheckBox
	Private CH_TC As CheckBox
	Private CH_TB As CheckBox
	Private CH_TD As CheckBox
	Private E_CUANTOS_E As EditText
	Private B_GUARDAR As Button
	Private TIPOEX As String
	Private B_EXIBI As Button
	Private Panel1 As Panel
	Dim t3 As Timer
	Private ruta_tienda As String
	Private t_tenc As Label
	Private E_RES_E As EditText
	Private B_E_NEXT As Button
	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 LA_GEO As Label
	Private LA_GPS As Label
	Private B_GPS As Button
	Private MONTO_RPOMO_2021 As String
	Private REGALO_PROMO_2021 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

	   ruta = File.DirInternal
	   

    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=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_BFACTURA,CAT_CL_BCREDITO  from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	    s=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")
			FACTURA = c.GetString("CAT_CL_BFACTURA")
			CREDITO = c.GetString("CAT_CL_BCREDITO")
	
			 
			' 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=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
		Printer1.Initialize(Me, "Printer1")
		
	End If
	'la impresion anterior
	'If FirstTime Then
	'	btAdmin.Initialize("BlueTeeth")
	'	cmp20.Initialize("Printer")
	'End If
End Sub

Sub Activity_Resume
	
	
	
	BT_QR.Enabled = False
	b_factura.Visible = False
FACTURA =0
If g.GPSEnabled=False Then
	  ToastMessageShow("Habilitar el GPS", True)
	  StartActivity(g.LocationSettingsIntent)
	 Else
	  g.Start(0,0)
	 End If
	
			skmt.Initialize(ruta,"kmt.db", True)
	c=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,CAT_CL_BFACTURA,CAT_CL_BCREDITO, gestion  from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	    s=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")
			 '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")
			 m_lat =c.GetString("CAT_CL_LAT")
			 m_lon =c.GetString("CAT_CL_LONG")
			FACTURA = c.GetString("CAT_CL_BFACTURA")
			CREDITO = c.GetString("CAT_CL_BCREDITO")
			ruta_tienda = c.GetString("CAT_CL_RUTA")
			
			If c.GetString("gestion") ="2" Then
				gest.Enabled = False
				Tels.Enabled = False
			End If
			
			If l_total.Text <> Null Then

			If la_cuenta.Text.Contains("N") = True Then
			FACTURA  = 0
			End If
				
			If FACTURA = "1" Then
			b_factura.Visible = True
			
			End If
			End If
			
			If CREDITO = "1" Then
			Msgbox("ALTO","Este cliente no se le puede vender ya que tienen adeudo en su crédito")
			B_VENTA.Visible = False
			gest.Enabled = False
			Else
			B_VENTA.Visible = True
			gest.Enabled = True
				
			End If 

			' Msgbox(c.GetString("CAT_CL_NUM_SERIEFISICO"),"AVISO")
			 If c.GetString("CAT_CL_NUM_SERIEFISICO") = "0"  Then
			 L_QR.Visible = True
			 Else
			 L_QR.Visible = False				
			End If
			S2=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=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=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=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=skmt.ExecQuery("select count(*) as CUANTOS FROM CAT_VERIFICACION")
'	    c.Position=0
'		If c.GetString("CUANTOS") <> 0 Then
'			
'		c2=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=skmt.ExecQuery("select count(*) as CUANTOS FROM CAT_VERIFICACION")
'	    c.Position=0
'	If c.GetString("CUANTOS") <> 0 Then
'		c2=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
 '         	  skmt.ExecNonQuery2("INSERT INTO HIST_VERIFICACION VALUES (?,?,?)", Array As Object(la_cuenta.Text,c2.GetString("CAT_VE_IDPROD"), 1))
'	
'			Else
'		  	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")
	
	' la impresion anterior
	'cmp20.Initialize("Printer")
	'StartPrinter
	'If PASA_IMP = "1" Then
	
	c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("MACIMP"))
	c.Position =0
	MAC_IMPRESORA = c.GetString("CAT_VA_VALOR")
'	Msgbox(MAC_IMPRESORA, "MAC")
	c.Close
'	c2=	skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM TMP_PROMO_ESP_REGALO WHERE CLIENTE IN (Select CUENTA from cuentaa)")
'	c2.Position = 0
'	If c2.GetString("CUANTOS") > 0 Then
'		c=skmt.ExecQuery("SELECT CLIENTE , MONTO , REGALO FROM TMP_PROMO_ESP_REGALO WHERE CLIENTE IN (Select CUENTA from cuentaa)")
'		c.Position = 0
'		If MONTO_COMPRA = 0 Then
'		MONTO_RPOMO_2021 = c.GetString("MONTO")
'		REGALO_PROMO_2021 = c.GetString("REGALO")
'		Msgbox("EL CLIENTE TIENE PROMOCION ESPECIAL " & REGALO_PROMO_2021 &" SI VENDE MAS DE "& MONTO_RPOMO_2021, "AVISO")
'		S=skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
'		s.Position = 0
'		
'		If S.GetString("CUANTOS") > 0 Then
'			If l_total.Text > MONTO_RPOMO_2021 -1 Then
'				skmt.ExecNonQuery2("delete from PEDIDO where PE_PROID = ? AND PE_CLIENTE IN (SELECT CUENTA from cuentaa)", Array As Object ("KMTS1"))
'				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_TIPO) VALUES(?,?,?,?,?,?,?,?,?,?,?) ", Array As Object ("KMTS1",0,0,1, REGALO_PROMO_2021,"KMTS1",la_cuenta.Text, sDate & sTime, usuario,ruta_tienda,Main.tipov))
'				Msgbox("REGALO DADO","AVISO")
'			End If
'		End If
'		End If
	
	
	If Printer1.IsConnected = False Then
		
		Printer1.Connect
		
	Else
		Printer1.DisConnect
		Printer1.Connect
		
	End If
	
gest.enabled = False
	Tels.Enabled = False
	B_GPS.Enabled = False
	
	'End If
	
End Sub

Sub Printer1_Connected (Success As Boolean)
	If Success Then
		ToastMessageShow("Connected successfully", False)
		skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("MACIMP"))
		skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("MACIMP",Main.mac_impresora))

		
		B_IMP.Enabled = True
	Else
		Msgbox(Printer1.ConnectedErrorMsg, "Error connecting.")
	End If
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
	Dim sDate,sTime As String
	
	Dim l1, l2 As Location
	l1.Initialize2(lat_gps, lon_gps)
	l2.Initialize2(m_lat, m_lon)
	LA_GPS.TextColor = Colors.Blue
	LA_GPS.Text = "CON UBICACION GPS"
	B_GPS.Enabled = True
	
	'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.Enabled = True
	
	' Msgbox(m_lat & " " & m_lon & " " & distance, "UBICA")
	c=skmt.ExecQuery("select gestion  from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	c.Position = 0
	If distance < 30 Then
		LA_GEO.TextColor = Colors.Blue
		
		If c.GetString("gestion") <> "2" Then
			Tels.Enabled = True
			gest.Enabled = True
		
		Else If c.GetString("gestion") = "2" Then
			Tels.Enabled = False
			gest.Enabled = False
		
		End If
		c=skmt.ExecQuery("SELECT COUNT(*) AS CUANTOS FROM CLIENTES_GPS WHERE CLIENTE IN  (Select CUENTA from cuentaa)")
		c.Position = 0
		If c.GetString("CUANTOS") >0 Then
			B_GPS.Enabled = False
		End If
		
	Else
	c.Close
			LA_GEO.TextColor = Colors.Red
	'comentar estas lineas cuando se ponga la geo cerca
'		Tels.Enabled = True
'		gest.Enabled = True
	
'		
'	'	If ALMACEN = "1" Then
			Tels.Enabled = False
			gest.Enabled = False
'	'	End If
	End If

	
	LA_GEO.Text = "Distancia de la tienda en MTS " & distance
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
		   
	skmt.ExecNonQuery("DELETE FROM HIST_GPS")
	
	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)
	
	'   skmt.ExecNonQuery("delete from PRODUCTOA")
	'  skmt.ExecNonQuery2("INSERT INTO PRODUCTOA VALUES (?)", Array As Object(la_producto.Text))
	'  Dim cuantos As String
  	'c=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=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=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
 '         		skmt.ExecNonQuery("delete from PROID")
'	  			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
	
	'''' lo de la encuesta que se desactiva
'	
'	DateTime.DateFormat = "MM/dd/yyyy"
'	sDate=DateTime.Date(DateTime.Now)
'	sTime=DateTime.Time(DateTime.Now)
'	c=skmt.ExecQuery("Select CUENTA from cuentaa")
'	c.Position=0
'	clie_id = c.GetString("CUENTA")
'	c=skmt.ExecQuery("select USUARIO from usuarioa")
'	c.Position=0
'	usuario = c.GetString("USUARIO")
'	
'	c=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("Manejas/vendes salsas Huichol?","Encuesta","SI","","NO",LoadBitmap(File.DirAssets,"alert2.png"))
'		If res = DialogResponse.POSITIVE Then
'			Panel2.Visible  = True
'			CONTADOR_E = 1
'			t_tenc.Text = "A quien se lo compras ?"
'			E_RES_E.InputType =E_RES_E.INPUT_TYPE_TEXT
'			E_RES_E.Text = ""
'		Else
'			Main.tipov = "PREVENTA"
'			StartActivity(colonia2)
'		End If
'	Else
'		Main.tipov = "PREVENTA"
'		StartActivity(colonia2)
'	End If
	Main.tipov = "PREVENTA"
	StartActivity(colonia2)

End Sub

Sub Tels_Click
     ' skmt.ExecNonQuery("delete from PEDIDO")
	  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
		'printer.Close
		Printer1.Disconnect
			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
	
	d=skmt.ExecQuery("select gestion  from kmt_info where CAT_CL_CODIGO In (Select cuenta from cuentaa)")
	d.Position = 0
	If d.GetString("gestion") <> "2" Then
	
	DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
    c=skmt.ExecQuery("Select CUENTA from cuentaa")
	c.Position=0
	clie_id = c.GetString("CUENTA")
	c=skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	
	c=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
	skmt.ExecNonQuery("delete from NOVENTA where NV_CLIENTE In (select cuenta from cuentaa)")
	skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE In (select cuenta from cuentaa)")
	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))
	skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2  where CAT_CL_CODIGO In (select cuenta from cuentaa)")		
	End If
	
	s=skmt.ExecQuery2("select SUM(PE_COSTO_TOT) AS TOTAL FROM PEDIDO WHERE PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("PREVENTA"))
	s.Position =0
	Log(s.RowCount)
	If s.GetString("TOTAL") <> "null" Or s.GetString("TOTAL") <> Null Then
		If  s.GetString("TOTAL") < 149 Then
			skmt.ExecNonQuery("DELETE FROM PEDIDO WHERE PE_CLIENTE IN (Select CUENTA from cuentaa)")
			skmt.ExecNonQuery("DELETE FROM PEDIDO_CLIENTE WHERE PC_CLIENTE IN (Select CUENTA from cuentaa)")
		End If
	End If
	
	'printer.Close
	Printer1.Disconnect
	StartActivity(seleccion)
	
	Else If d.GetString("gestion") = "2" Then
		Log("estoy aqui")
		Printer1.Disconnect
		StartActivity(seleccion)
	End If
End Sub
Sub NUEVO_Click
	StartActivity(nuevocliente)
End Sub
Sub HIST_Click
	StartActivity(Historico)
End Sub

Sub BT_QR_Click
	

    '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)
	
End Sub


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

	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

	c=skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	c.Close
	
	TAMANO = 5
	ESPACIO = 21
	BLANCO = " "
	Printer1.WriteString("PROFINA"  & CRLF)
	Printer1.WriteString("RESUMEN DIA"  & CRLF)
	Printer1.WriteString(sDate & " " &  sTime  & CRLF)
	
	Printer1.WriteString("Vendedor:" & usuario  & CRLF)
	
	
	Printer1.WriteString("----------PRODUCTOS----------"  & CRLF)
	' aqui es donde esta el pedo de julieta de los descuentos quitar el precio2 pero meter un if para saber si es ruta especial o es normal o que show.
	s=skmt.ExecQuery("select PE_PROID, PE_PRONOMBRE, SUM(PE_CANT) AS CUANTOS from PEDIDO GROUP BY PE_PROID, PE_PRONOMBRE ")
	
	
	If S.RowCount>0 Then
		For i=0 To S.RowCount -1
			S.Position=i
	
			Printer1.WriteString(s.GetString("PE_PROID")  & "  " & s.GetString("PE_PRONOMBRE")& CRLF)
			
			Printer1.WriteString("     CANTIDAD:....." & s.GetString("CUANTOS")& CRLF)
	
					
			TAMANO = TAMANO + 1
			If TAMANO > 40 Then
				
				t3.Initialize("T3", 4000) ' 1000 = 1 second
				t3.Enabled = True
				Wait For  t3_tick
				TAMANO = 0
			End If
		Next
	End If
	s.Close
	's=skmt.ExecQuery("select SUM(PE_COSTO_TOT) AS TOTAL FROM PEDIDO")
	's.Position =0
	'If s.GetString("TOTAL") - s.GetString("TOTAL2") <> 0 Then
'		Printer1.WriteString("Descuento:     $" & 	 (s.GetString("TOTAL2") -  s.GetString("TOTAL")))
'	End If
'	Printer1.WriteString("Total Preventa:   $" & s.GetString("TOTAL"))
'	s.Close
	
	 
	
	

'	Printer1.WriteString(CRLF)
'	Printer1.WriteString("-----------RMI----------------"  & CRLF)
'	Printer1.WriteString(CRLF)
	'c=skmt.ExecQuery2("select  count(*) as CUANTOS from pedido where substr(pe_pronombre,1,6) = ? GROUP BY PE_PRONOMBRE", Array As String("CAMBIO"))
	'c.Position =0
	'Cuantos = c.GETSTRING("CUANTOS")
	'c.Close
	'If Cuantos >0 Then
	c=skmt.ExecQuery("select  SUM(PE_CANT) AS CANTIDAD from pedido where pe_cedis <> pe_proid ")
	
	If C.RowCount>0 Then
		For i=0 To C.RowCount -1
			C.Position=i
	
			Printer1.WriteString("TOTAL PRODUCTOS " & "....."& C.GetString("CANTIDAD")   & CRLF)
			
					
	
		Next
	End If
	
	c.Close
	'End If
	
	Printer1.WriteString("----------CLIENTES----------"  & CRLF)
	' aqui es donde esta el pedo de julieta de los descuentos quitar el precio2 pero meter un if para saber si es ruta especial o es normal o que show.
	s=skmt.ExecQuery("select PE_CLIENTE,  SUM(PE_COSTO_TOT) AS TOTAL from PEDIDO GROUP BY PE_CLIENTE")
	
	
	If S.RowCount>0 Then
		For i=0 To S.RowCount -1
			S.Position=i
	
			Printer1.WriteString(s.GetString("PE_CLIENTE")  &"......" & s.GetString("TOTAL")& CRLF)
			
			
					
			TAMANO = TAMANO + 1
			If TAMANO > 40 Then
				
				t3.Initialize("T3", 4000) ' 1000 = 1 second
				t3.Enabled = True
				Wait For  t3_tick
				TAMANO = 0
			End If
		Next
	End If
	s.Close
	
	c=skmt.ExecQuery("select  SUM(PE_COSTO_TOT) AS TOTAL from pedido ")
	
	If C.RowCount>0 Then
		For i=0 To C.RowCount -1
			C.Position=i
	
			Printer1.WriteString("TOTAL PEDIDOS " & "....."& C.GetString("TOTAL")   & CRLF)
			
					
	
		Next
	End If
	
	c.Close
	'Printer1.WriteString("------------------------------" & CRLF)
	'Printer1.WriteString("Nombre y Firma"  & CRLF)
	'Printer1.WriteString(CRLF)
	'Printer1.WriteString(CRLF)
	'Printer1.WriteString(CRLF)
	Printer1.WriteString("______________________________" & CRLF)
	Printer1.WriteString("------------------------------" & CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString(CRLF)
	
		
	
End Sub


Sub B_IMP2_Click
	
	s=skmt.ExecQuery2("select SUM(PE_COSTO_TOT) AS TOTAL FROM PEDIDO WHERE PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("PREVENTA"))
	s.Position =0
	
		
	If  s.GetString("TOTAL") > 149 Then
	
	c=skmt.ExecQuery2("select count(*) AS CUANTOS from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("PERFIL"))
	c.Position =0
	perfil = c.GetString("CUANTOS")
	c.Close
	
	If perfil > 0 Then
	c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("PERFIL"))
	c.Position =0
	perfil = c.GetString("CAT_VA_VALOR")
	c.Close
	End If
	
	c=skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	c.Close
	c=skmt.ExecQuery2("SELECT CAT_VA_VALOR FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION =?", Array As String ("SUCURSAL"))
	     c.Position = 0
	sucursal = c.GetString("CAT_VA_VALOR")
	c.Close 
	
	TAMANO = 0
	ESPACIO = 15
	BLANCO = " "
	Try

		
		'printer.Initialize(cmp20.OutputStream)
		'Printer1.Reset
		'Dim bmp As Bitmap
		'bmp.InitializeResize(File.DirAssets, "kelloggs.png", 376, 129, True) 'ignore
		'Dim myimage As AnImage = Printer1.ImageToBWIMage(bmp)
	
		'myimage = Printer1.DitherImage2D(myimage, 128)
	
'		myimage= Printer1.PackImage(myimage)
'		Printer1.WriteString(CRLF) ' nudge the printer to show the user something is happening
'		Printer1.PrintImage(myimage)
'	Printer1.WriteString(Printer1.REVERSE)
'		Printer1.Justify = 1
	
		Printer1.WriteString("Profina S.A. de C.V." & CRLF)
		Printer1.WriteString("RFC: PRO8204139J6" & CRLF)
	'printer.WriteLine("KELLOGG COMPANY MEXICO")
	'printer.WriteLine(SUCURSAL)
	'	Printer1.WriteString("ORIENTE" & CRLF)
	'printer.WriteLine("NORTE")
'		Printer1.WriteString(Printer1.DEFAULTS)
		Printer1.WriteString(sDate &" " & sTime & CRLF)
		Printer1.WriteString("Vendedor: " & usuario & CRLF)
		Printer1.WriteString("Ruta: " & ruta_tienda & CRLF)
		Printer1.WriteString("Tienda: " & La_nombre.Text & CRLF)
		Printer1.WriteString("ID.Cliente: " &  la_cuenta.Text & CRLF)
		Printer1.WriteString("Calle: " & la_Calle.Text & CRLF)
		Printer1.WriteString("Colonia: " & la_col.Text & CRLF)
		Printer1.WriteString("C.P.: " & la_cp.Text & CRLF)
		Printer1.WriteString("Entre calle1: " & l_entre1.Text & CRLF)
		Printer1.WriteString("Entre Calle2: " & l_entre2.Text & CRLF)
		Printer1.WriteString(" " & CRLF)
		Printer1.WriteString("------------------------------"  & CRLF)
		
	
	
	'printer.WriteLine(sDate)
	'printer.WriteLine(sTime)
	'printer.WriteLine("Vendedor:" & usuario)
	'printer.WriteLine("Tienda: " & La_nombre.Text)
	'printer.WriteLine("ID.Cliente: " &  la_cuenta.Text)
	'printer.WriteLine("Calle: " & la_Calle.Text)
	'printer.WriteLine("Colonia: " & la_col.Text)
	'printer.WriteLine("C.P.: " & la_cp.Text)
	'printer.WriteLine("Entre calle1: " & l_entre1.Text)
	'printer.WriteLine("Entre Calle2: " & l_entre2.Text)
	
'		Printer1.WriteString(Printer1.REVERSE)
'		Printer1.Justify = 1
	
		Printer1.WriteString("PRE-VENTA" & CRLF)
		Printer1.WriteString("------------------------------"  & CRLF)
			
	'printer.WriteLine("-----------ENTREGA------------")
	
	s=skmt.ExecQuery2("select PE_PROID, 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, PE_PROID, PE_CEDIS FROM PEDIDO WHERE PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("PREVENTA"))
	If S.RowCount>0 Then
		For i=0 To S.RowCount -1
			S.Position=i
			If s.GetString("PE_CEDIS") = s.GetString("PE_PROID") Then
'					Printer1.WriteString(Printer1.ULINE0)
					Printer1.WriteString(s.GetString("PE_PRONOMBRE") & CRLF)
				'printer.WriteLine(s.GetString("PE_PRONOMBRE"))
				
	        Else
'					Printer1.WriteString(Printer1.DEFAULTS)
					
					Printer1.WriteString(s.GetString("PE_CANT") & " " & s.GetString("PE_PRONOMBRE") & CRLF)
				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
					Printer1.WriteString(s.GETSTRING("PE_PROID") &BLANCO & s.GETSTRING("PE_CANT") & " X $" & s.GETSTRING("PE_COSTOU") & "   $" & s.GETSTRING("PE_COSTO_TOT") & CRLF)
				TAMANO = 0
				ESPACIO = 15
				BLANCO = " "
			End If
		Next
	End If
    s.Close	
		Printer1.WriteString(CRLF)
	
	s=skmt.ExecQuery2("select SUM(PE_COSTO_TOT) AS TOTAL FROM PEDIDO WHERE PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa)", Array As String("PREVENTA"))
	s.Position =0
	
'		Printer1.WriteString( Printer1.BOLD & "Total entrega:   $" & Printer1.WIDE & s.GetString("TOTAL") & CRLF)
		Printer1.WriteString("------------------------------"  & CRLF)
		
		Printer1.WriteString(  "Total Pre Venta:   $" & s.GetString("TOTAL") & CRLF)

		s.Close
'' ESTO PARA PONER EL NUMERO DE PRODUCTOS 
'		s=skmt.ExecQuery2("select SUM(PE_CANT) AS TOTAL FROM PEDIDO WHERE PE_TIPO = ? AND PE_CLIENTE IN (Select CUENTA from cuentaa) and NVL(PE_CEDI,1) <> PE_PROID", Array As String("PREVENTA"))
'		s.Position =0
	
'		Printer1.WriteString( Printer1.BOLD & "Total entrega:   $" & Printer1.WIDE & s.GetString("TOTAL") & CRLF)
'		Printer1.WriteString(  "No. Productos: " & s.GetString("TOTAL") & CRLF)

'		s.Close


'	printer.WriteLine("------------VENTA-------------")
'	printer.WriteLine("TOTAL COMPRA: $:" & total_cliente)
		Printer1.WriteString(CRLF)
		Printer1.WriteString(CRLF)
	'	Printer1.WriteString(Printer1.SINGLE)
		'Printer1.WriteString("------------------------------")
	'	Printer1.WriteString(Printer1.HIGH)
	'	Printer1.Justify = 1
	
		Printer1.WriteString("Nombre y Firma del cliente" & CRLF)
		Printer1.WriteString(CRLF)
		Printer1.WriteString(CRLF)
		Printer1.WriteString(CRLF)
	'	Printer1.WriteString(Printer1.DEFAULTS) 
	'	Printer1.WriteString(Printer1.SINGLE)
		Printer1.WriteString("______________________________" & CRLF)
		Printer1.WriteString("------------------------------" & CRLF)
		Printer1.WriteString("----ESTE TICKET NO ES UN -----" & CRLF)
		Printer1.WriteString("--COMPROBANTE FISCAL, SOLO ES-" & CRLF)
		Printer1.WriteString("--------INFORMATIVO-----------" & CRLF)
		Printer1.WriteString("------------------------------" & CRLF)
		Printer1.WriteString(CRLF)
		Printer1.WriteString(CRLF)
		Printer1.WriteString(CRLF)
	'printer.Close
	Catch
		Printer1.Disconnect
		StartActivity(seleccion)
	End Try
'	printer.

	Else
		Msgbox("Venta menor a 150 ", "AVISO")
		
		
	End If
	
End Sub

Sub Printer_Connected (Success As Boolean)
	If Success Then
		
    B_IMP.Enabled = True
	PASA_IMP = "1"		
	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
		'FLEOS	
		'cmp20.ConnectInsecure(btAdmin,PairedDevices.Get(PairedDevices.GetKeyAt(0)),1)
		cmp20.Connect(PairedDevices.Get(PairedDevices.GetKeyAt(0)))
			
		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_VENTA_Click
	Main.tipov = "VENTA"
	StartActivity(colonia2)
End Sub



Sub b_factura_Click
	
End Sub

Sub CH_TA_CheckedChange(Checked As Boolean)
	
End Sub

Sub CH_TC_CheckedChange(Checked As Boolean)
	
End Sub

Sub CH_TB_CheckedChange(Checked As Boolean)
	
End Sub

Sub CH_TD_CheckedChange(Checked As Boolean)
	
End Sub

Sub B_GUARDAR_Click

	If CH_TA.Checked = True Then
	TIPOEX = "TIPO A"
	ELSE If CH_TB.Checked = True Then
	TIPOEX = "TIPO B"
	ELSE If CH_TC.Checked = True Then
	TIPOEX = "TIPO C"
	ELSE If CH_TD.Checked = True Then
	TIPOEX = "TIPO D"
	End If
	
	Panel1.Visible = False
	B_EXIBI.Visible = True
	b_factura.Visible = True
	HIST.Visible = True
	c=skmt.ExecQuery("select CUENTA from cuentaa")
	c.Position = 0
	cuenta = c.GetString("CUENTA")
	
	skmt.ExecNonQuery2("INSERT INTO HIST_EXIBIDORES(CAT_CL_CLIENTE,CAT_CL_EXHIBIDOR,CAT_CL_BEXHIBIDOR) VALUES(?,?,?)", Array As Object(cuenta,TIPOEX,E_CUANTOS_E.Text))
	
End Sub

Sub B_EXIBI_Click
	Panel1.Visible = True
	B_EXIBI.Visible = False
	b_factura.Visible = False
	HIST.Visible = False
End Sub



Sub B_E_NEXT_Click
If E_RES_E.Text <> "" Then
	If CONTADOR_E = 1 Then
		CONTADOR_E = 2
			t_tenc.Text = "En cuanto lo vende? "
		HR_RES1 = E_RES_E.Text
			E_RES_E.Text = ""
		ELSE IF CONTADOR_E = 2 Then
			CONTADOR_E = 3
			t_tenc.Text = "Información Adicional? "
			HR_RES2 = E_RES_E.Text
			E_RES_E.Text = ""
'	ELSE IF CONTADOR_E = 3 Then
'		CONTADOR_E = 4
'			t_tenc.Text = "A quien se lo compras"
'		'HR_RES2 = E_RES_E.Text
'		E_RES_E.Text = ""
'	ELSE IF CONTADOR_E = 4 Then
'		CONTADOR_E = 5
'			t_tenc.Text = "En cuanto lo vende? "
'		HR_RES3 = E_RES_E.Text
'			E_RES_E.Text = ""
'							
	ELSE IF CONTADOR_E = 3 Then
			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, "SI",HR_RES1,HR_RES2,HR_RES3,E_RES_E.Text,sDate&sTime, usuario))
			Main.tipov = "PREVENTA"
			Panel2.Visible = False
			
			StartActivity(colonia2)

	End If
Else
	Msgbox("MONTO NO VALIDO","AVISO")
End If	
End Sub

Sub B_GPS_Click
	
	Dim result As Int
	result = Msgbox2("Esta seguro de cambiar las coordenadas de este cliente", "Aviso GPS", "SI", "", "NO", LoadBitmap(File.DirAssets, "alerta.jpg"))
	If result = DialogResponse.Positive Then
	skmt.ExecNonQuery2("UPDATE  kmt_info SET CAT_CL_LAT = ?, CAT_CL_LONG = ? where CAT_CL_CODIGO In (Select cuenta from cuentaa)", Array As Object(lat_gps, lon_gps))
	skmt.ExecNonQuery2("INSERT INTO CLIENTES_GPS(CLIENTE, LAT, LON) VALUES (?,?,?)", Array As Object(la_cuenta.Text,lat_gps, lon_gps))
	Activity_Resume
	End If
	
	
	
	
End Sub