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 reqManager As DBRequestManager
	 Dim conectado As String
'	 Dim skmt As SQL
	 Dim t1 As Timer
	 Dim sb As StringBuilder
	 Dim PHONE As Phone
	Dim g As GPS
	 
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 trabajar As Button
	Dim lat_gps, lon_gps As String
	Dim c As Cursor
	Dim d As Cursor
	Dim b As Cursor
	Dim e As Cursor
	Dim f As Cursor
	Dim D2 As Cursor
	Dim lv As ListView
	Dim cargar As Button
	Dim pendiente As Button
	Dim foto1() As Byte
	Dim usuario As String
	Dim connecta As Button
	Dim conn As String
	Dim Subir As Button
	Dim cmd As DBCommand
	Dim TOPE As Int
	Dim COUNT_CLIE As Int
	Dim fecha As String
	Dim drop As Double
	Dim efectiva As Double
	
	Dim L_MONTOD As Label
	Dim l_cuantosc As Label
	Dim l_drop As Label
	Dim l_efectiva As Label
	Dim l_ctast As Label
	Dim BUSCA As Button
	Dim Cuantos As String
	Dim l_cuantosn As Label
	Dim e_ruta As EditText
	Dim l_porvisitar As Label
	Dim b_mapa As Button
	Dim l_ruta As Label
	Dim ALMACEN As String
	Private img2 As ImageView
	Dim Listo1 As String
	Dim Listo2 As String
	Dim Listo3 As String
	Dim Listo4 As String
	Dim Listo5 As String
	Dim EJECUTANDO As String
	Dim RES As String
	Dim inve As String
	Dim cuantos_pedidosc As String
	Dim cuantos_pedido As String
	Dim cuantos_noventa As String
	Dim datos_iguales As String
	Dim p As PhoneId
	Dim imei As String
	Dim SERVER As String
	
	
	Private inv As Button
	Private P1 As Panel
	Private CLAVE As EditText
	Private B_OK_PAS As Button
	Dim PASO As String
	Private USUARIO1 As EditText
	Dim connecta1 As Double
	Dim armafolio As String
	Private NUEVO As Button
	Private S_CC As Label
	Private S_CP As Label
	Private S_CH As Label
	Private PB2 As ProgressBar
	Private PB1 As ProgressBar
	Private L_P_1 As Label
	Private L_P_2 As Label
	Private L_P_3 As Label
	Private CARGA As String
	Private PORCENTAJE As String
	Private P_RESUMEN As Panel
	Private B_OK_RES As Button
	Private Resumen As Button
	Private L_CUANTOST As Label
	Private img3 As ImageView
	
	Private ImageView3 As ImageView
	Private ImageView5 As ImageView
	Private L_TICKPROM As Label
	Private L_MARCAS As ListView
	Private ImageView9 As ImageView
	Private E_RUTA2 As EditText
	Private resdia As ImageView
	Private hacer_ped As ImageView
	Private nvo_cliente As ImageView
	Private tickets_dia As ImageView
	
	Private l_monto_ks As Label
	Private l_monto_kp As Label
	Private l_monto_k As Label

	Private l_monto_c1 As Label
	Private l_monto_c2 As Label
	Private l_monto_c3 As Label
	
	Private l_encuesta As Label
	
	
	Private bpv1 As BatteryProgressView
	Dim batterystatus(11) As Int
	Private bu As BatteryUtilities

	
	Private Panel4 As Panel
	Private L_NES As Label
	Private L_REAL As Label
	Private L_ALCANCE As Label
	Private L_VPLAN As Label
	Private L_VREAL As Label
	Private L_EFEC_VIS As Label
	Private L_VISITCC As Label
	Private L_EFEC_PV As Label
	Private L_EFEC_PURA As Label
	Private L_CTE_PROMO As Label
	Private L_REDEN_PROMO As Label
	Private L_LIN_TICK As Label
	Private SCROLL_RESDIA As ScrollView
	Private L_ACUMULADO As Label
	Private L_UNILEVER As Label
	Private L_RECHAZOP As Label
	Private L_RECHAZOM As Label
	Private L_VTA_3MES As Label
	Private L_VTA_2MES As Label
	Private L_VTA_1MES As Label
	Private L_MES_PY As Label
	Private L_FREC_DE_CREAL As Label
	Private L_FREC_DE_COBJ As Label
	Private L_COB_VISIT As Label
	Private L_VISIT_REAL As Label
	Private L_VISIT_PLAN As Label
	Private L_ECO As Label
	Private L_COB_CCC As Label
	Private L_CTES As Label
	Private L_VPO_VTA As Label
	Private L_VPO_OBJ As Label
	Private L_DS_VTA As Label
	Private L_DS_OBJ As Label
	Private L_DRA_VTA As Label
	Private L_DRA_OBJ As Label
	Private L_ALCANCEM As Label
	Private L_TENDENCIA As Label
	Private L_VTA_ACUM As Label
	Private L_OBJ_MES As Label
	Private L_DS_OBJD As Label
	Private L_DS_VTAD As Label
	Private LPT As String
	Private STEYIN As String
	Private STEYOUT As String
	
	Private L_PRIO As Label
	Private L_SECUND As Label
	Private L_COMP As Label
	
	
	Private stay_hh As String
	Private stay_mi As String
	Private stay_ss As String
	
	Dim sDate,sTime As String
	Dim HORAINGRESO As String
	
	Private L_QUALA As Label
	Private L_FERRERO As Label
	Private L_SANMARCOS As Label
	Private L_CAMPARI As Label
	Private L_IBERIA As Label
	Private L_BEPENSA As Label
	Private L_SCJ As Label
	Private L_MEDJ As Label
	Private L_DURACELL As Label
	Private L_GUNA As Label
	Private L_KIMB As Label
	Private L_TRESM As Label
	Private L_REDB As Label
	Private Btn_Ubicar As Button
	Private B_COMM As Button
	Private L_TOTAL_MM As Label
	Private L_TOTAL_VIVE As Label
	Private L_TOTAL_GUNA As Label
	Private L_TOTAL_BA As Label
	Private L_TOTAL_COMIS As Label
	Private L_TOTAL_MM_1 As Label
	Private L_TOTAL_VIVE_1 As Label
	Private L_TOTAL_GUNA_1 As Label
	Private L_TOTAL_BA_1 As Label
	Private L_TOTAL_COMIS_1 As Label
	Private B_OK_COMISS As Button
	Private Panel_C As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    EJECUTANDO=1
	'SERVER = "http://201.99.139.28:1782"
	'SERVER = "http://keymon.com.mx:1782"
	SERVER = "http://177.244.63.54:1782"
	
	If FirstTime Then
		reqManager.Initialize(Me, SERVER)
	End If
	Activity.LoadLayout("seleccion")
	Dim ruta As String
	img2.Visible =False

	' 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(FirstTime) Then
		g.Initialize("GPS")
	End If
	' 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.
'	If File.Exists(ruta, "kmt.db") = False Then
'		File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db")
'	End If
	DateTime.DateFormat = "MM/dd/yyyy"
		fecha=DateTime.Date(DateTime.Now)
'	skmt.Initialize(ruta,"kmt.db", True)
	'c=starter.skmt.execQuery2("select CAT_CO_CONFIGURACION from CAT_CODIGOS where CAT_CO_PONDERACION =1 AND CAT_CO_ACCION = ?", Array As String("SERVER"))
    'c.Position =0 
	'SERVER = c.GetString("CAT_CO_CONFIGURACION")
	'c.Close
	
	b=Starter.skmt.execQuery("Select count(*) as CUANTOS from pedido_cliente")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
	d=Starter.skmt.execQuery("select count(*) as TOTAL_VISITAR from kmt_info where gestion = 0")
	D.Position=0
    b.Close
	e=Starter.skmt.execQuery("select count(*) as POR_VISITAR from kmt_info")
	e.Position=0
	f=Starter.skmt.execQuery("select count(*) as CAT_CL_RUTA from kmt_info")
	f.Position=0
	l_ruta.Text = f.GetString("CAT_CL_RUTA")
	f.Close
	If l_ruta.Text = 0 Then
	l_ruta.Text =0
	Else
	f=Starter.skmt.execQuery("select CAT_CL_RUTA from kmt_info")
	f.Position=0
	l_ruta.Text = f.GetString("CAT_CL_RUTA")
	f.Close
	End If
	If Cuantos  = 0 Then
	L_MONTOD.Text =0
	l_cuantosc.Text = 0
	l_cuantosn.Text = 0
	drop = 0
	l_drop.Text = 0
	efectiva = 0
	l_efectiva.text =0
    l_ctast.Text = d.GetString("TOTAL_VISITAR")
	l_porvisitar.Text = e.GetString("POR_VISITAR")
	Else
	c=Starter.skmt.execQuery("select  sum(pc_monto) as MONTO_DIA, count(pc_cliente) AS CLIENTES_DIA  from pedido_cliente ") 
	b=Starter.skmt.execQuery("select count(*) as CUANTOS from noventa")
	'where pc_fecha = ?", Array As String(fecha)
	C.Position=0
	b.Position=0
	L_MONTOD.Text = c.GetString("MONTO_DIA")
	l_cuantosc.Text = c.GetString("CLIENTES_DIA")
	l_cuantosn.Text = b.GetString("CUANTOS")
	drop = c.GetString("MONTO_DIA") / c.GetString("CLIENTES_DIA")
	l_drop.Text = Round2(drop,2)
	efectiva = c.GetString("CLIENTES_DIA") / e.GetString("POR_VISITAR")
	l_efectiva.text = Round2(efectiva*100,2)
    l_ctast.Text = d.GetString("TOTAL_VISITAR")
	l_porvisitar.Text = e.GetString("POR_VISITAR")
	End If
	
End Sub


Sub IsConnectedToInternet As Boolean
	Dim r As Reflector
 
	r.Target = r.GetContext
	r.Target = r.RunMethod2("getSystemService", "connectivity", "java.lang.String")
	r.Target = r.RunMethod("getActiveNetworkInfo")
 
	If r.Target <> Null Then
		Return r.RunMethod("isConnectedOrConnecting")
	End If
 
	Return False
End Sub

Sub Activity_Resume
	'SERVER =  "http://201.99.139.28:1782"
	'SERVER = "http://keymon.com.mx:1782"
	'SERVER = "http://177.244.63.54:1782"
	SERVER = "http://187.189.244.154:1782"
	HORAINGRESO ="000000"
		reqManager.Initialize(Me, SERVER)
	
	PASO =0
'    c=starter.skmt.execQuery("select noversion from version")
'	c.Position=0
'	If c.GetString("NOVERSION") <> "2.1" Then
'		ToastMessageShow("EXISTE UNA NUEVA VERSION ACTUALIZA POR FAVOR." , True)
'		cargar.Visible = False
'		Subir.Visible = False
'		connecta.Visible = False
'		trabajar.Visible = False
'		BUSCA.Visible = False
'	    inv.Visible = False	
'		
 '   End If
	'  c.Close
	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)
	End If
	c=starter.skmt.execQuery2("select count(*) as CUANTOS from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("FECHA"))
	c.Position =0 
	If c.GetString("CUANTOS") = 0 Then
		cmd.Initialize
	cmd.Name = "select_fecha"
	reqManager.ExecuteQuery(cmd , 0, "fecha")
	
		Msgbox("AJUSTAR FECHA","AVISO")
		Activity_Resume
	Else
	c=starter.skmt.execQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("FECHA"))
	c.Position =0 
	Dim sDate,sTime As String

		DateTime.DateFormat = "yyyyMMdd"
		sDate=DateTime.Date(DateTime.Now)

		If c.GetString("CAT_VA_VALOR") > sDate Then
		Msgbox("AJUSTAR LA FECHA YA QUE ES MENOR AL SISTEMA" ,"AVISO")
		Activity_Resume
		End If	
	End If
	
	
'	SCROLL_RESDIA.Visible = False
'	P_RESUMEN.Visible=False
'	Panel4.Visible = False
	
	If EJECUTANDO =0 Then
	Listo1 = 0
	Listo2 = 0
	Listo3 = 0
	Listo4 = 0
	Listo5 = 0
	inve = 0
	img2.Visible =False
	End If
	DateTime.DateFormat = "MM/dd/yyyy"
		fecha=DateTime.Date(DateTime.Now)
	b=starter.skmt.execQuery("Select count(*) as CUANTOS from pedido_cliente")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
	ToastMessageShow(Cuantos , True)

	d=starter.skmt.execQuery("select count(*) as TOTAL_VISITAR from kmt_info where gestion = 0")
	D.Position=0
    b.Close
	e=starter.skmt.execQuery("select count(*) as POR_VISITAR from kmt_info")
	e.Position=0
	f=starter.skmt.execQuery("select count(*) as CAT_CL_RUTA from kmt_info")
	f.Position=0
	l_ruta.Text = f.GetString("CAT_CL_RUTA")
	f.Close
	If l_ruta.Text = 0 Then
	l_ruta.Text =0
	Else
	f=starter.skmt.execQuery("select CAT_CL_RUTA from kmt_info")
	f.Position=0
	l_ruta.Text = f.GetString("CAT_CL_RUTA")
	f.Close
	End If
	If Cuantos  = 0 Then
	L_MONTOD.Text =0
	l_cuantosc.Text = 0
	l_cuantosn.Text = 0
		L_CUANTOST.Text = 0
	drop = 0
	l_drop.Text = 0
	efectiva = 0
	l_efectiva.text =0
    l_ctast.Text = d.GetString("TOTAL_VISITAR")
	l_porvisitar.Text = e.GetString("POR_VISITAR")
	d.Close
	e.Close
	Else
		c=starter.skmt.execQuery("select  SUM(PE_COSTO_TOT) as MONTO_DIA, COUNT(DISTINCT(PE_CLIENTE)) AS CLIENTES_DIA  from PEDIDO ")
	b=starter.skmt.execQuery("select count(*) as CUANTOS from noventa")
	'where pc_fecha = ?", Array As String(fecha)
	C.Position=0
	b.Position=0
	L_MONTOD.Text = c.GetString("MONTO_DIA")
	l_cuantosc.Text = c.GetString("CLIENTES_DIA")
	
	D2=starter.skmt.execQuery("select  COUNT(*) AS CUANTOS   from PEDIDO ")
	D2.Position = 0
	LPT = D2.GetString("CUANTOS") / l_cuantosc.Text
	D2.Close
	
	D2=starter.skmt.execQuery("select  SUM(HSS_TOT) AS TOTAL from HIST_STAY_STORE ")
	D2.Position = 0
	STEYIN = D2.GetString("TOTAL")
	D2.Close
	
		D2=starter.skmt.execQuery("select  (HSO_FIN - HSO_INI) AS TOTAL from HIST_STAY_OUT ")
	
		D2=starter.skmt.execQuery(" Select (substr(HSO_FIN,1,2) - substr(HSO_INI,1,2)) - Case when  (substr(HSO_FIN,3,2) - substr(HSO_INI,3,2)) < 0 Then 1 Else 0 end HORAS_TOTALES, " & _
	"Case when  (substr(HSO_FIN,3,2) - substr(HSO_INI,3,2)) < 0 Then (substr(HSO_FIN,3,2) + 60 - substr(HSO_INI,3,2)) " & _
	"	Else (substr(HSO_FIN,3,2) - substr(HSO_INI,3,2)) End - Case when  (substr(HSO_FIN,5,2) - substr(HSO_INI,5,2)) < 0 Then 1 Else 0 end  MINUTOS_TOTALES, " & _
	"Case when  (substr(HSO_FIN,5,2) - substr(HSO_INI,5,2)) < 0 Then (substr(HSO_FIN,5,2) + 60 - substr(HSO_INI,5,2)) " & _
	"	Else (substr(HSO_FIN,5,2) - substr(HSO_INI,5,2)) end SEGUNDOS_TOTALES " & _
	"	from HIST_STAY_OUT  ")
		D2.Position = 0
		stay_hh = D2.GetString("HORAS_TOTALES") * 60 * 60
		stay_mi = D2.GetString("MINUTOS_TOTALES") * 60
		stay_ss = D2.GetString("SEGUNDOS_TOTALES")
	
		
		STEYOUT = stay_hh + stay_mi + stay_ss - STEYIN
	D2.Close
	
		
	
	l_cuantosn.Text = b.GetString("CUANTOS")
	efectiva = c.GetString("CLIENTES_DIA") / e.GetString("POR_VISITAR")
	l_efectiva.text = Round2(efectiva*100,2)
    l_ctast.Text = d.GetString("TOTAL_VISITAR")
	l_porvisitar.Text = e.GetString("POR_VISITAR")
	L_CUANTOST.Text = l_cuantosc.Text + l_cuantosn.Text
		drop = L_CUANTOST.Text / l_porvisitar.Text
	l_drop.Text = Round(drop * 100) 
		If L_CUANTOST.Text < 40 Then
	 ImageView3.Bitmap = LoadBitmap(File.DirAssets, "tache_rojo.png")
		Else If L_CUANTOST.Text > =  40  And L_CUANTOST.Text < 50 Then
	 ImageView3.bitmap = LoadBitmap(File.DirAssets, "alerta_amarilla.png")
	 Else
	 ImageView3.Bitmap = LoadBitmap(File.DirAssets, "palomita_verde.png")
	 End If
	 L_TICKPROM.Text =  Round2((c.GetString("MONTO_DIA") / c.GetString("CLIENTES_DIA")),2)
	If c.GetString("MONTO_DIA") < 4000 Then
	 ImageView5.Bitmap = LoadBitmap(File.DirAssets, "tache_rojo.png")
	 Else if c.GetString("MONTO_DIA") > =  4000  And c.GetString("MONTO_DIA") < 6250 Then
	 ImageView5.bitmap = LoadBitmap(File.DirAssets, "alerta_amarilla.png")
	 Else
	 ImageView5.Bitmap = LoadBitmap(File.DirAssets, "palomita_verde.png")
	 End If
	  
	c.Close
	b.Close
	End If
	c=starter.skmt.execQuery("select  ID_ALMACEN from CAT_ALMACEN")
	C.Position =0
	ALMACEN = C.GetString("ID_ALMACEN")
	C.Close
	'ALMACEN = 1
	bu.Initialize
	batterystatus = bu.BatteryInformation
	
	c=starter.skmt.execQuery("select usuario from usuarioa")
	c.Position = 0
	usuario = c.GetString("USUARIO")
	c.Close
	
	
	sb.Initialize
	PHONE.Shell("ping -c1 -W1 177.244.63.54",Null, sb,Null)
	
	c = starter.skmt.execQuery2("select count(CAT_VA_DESCRIPCION) as HoraIngreso from cat_variables where CAT_VA_DESCRIPCION = ? ", Array As String("HoraIngreso"))
	c.Position = 0
	DateTime.TimeFormat = "HHmmss"
	
	'Valida si ya se cuenta con hora para enviar cada 5 min-----------
	If c.GetString("HoraIngreso") > 0 Then
		D2 = starter.skmt.execQuery2("select CAT_VA_VALOR as HoraIngreso from cat_variables where CAT_VA_DESCRIPCION = ? ", Array As String("HoraIngreso"))
		D2.Position = 0
		HORAINGRESO = D2.GetString("HoraIngreso")
		D2.Close
	End If
'	If 	HORAINGRESO + 500 < DateTime.Time(DateTime.Now) Then
'		starter.skmt.execNonQuery2("Update cat_variables set CAT_VA_VALOR = ?  WHERE CAT_VA_DESCRIPCION = ?" , Array As String(DateTime.Time(DateTime.Now),"HoraIngreso"))
'		DateTime.TimeFormat = "HH:mm:ss"
	If sb.Length  > 2  And sb.ToString.SubString2(110,114) <> "smit" Then
		c=starter.skmt.execQuery("select HGDATE, HGLAT, HGLON from HIST_GPS")
	
		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
				c.Position=i
				'			s=starter.skmt.execQuery2("SELECT HIST_VI_IMAGEN FROM HIST_VISITAS WHERE HIST_VI_CREDITO =?", Array As String (c.GetString("HIST_VI_CREDITO")))
				'			s.Position =0
			 'LO DOCUMENTO PARA NO HACER TAN PESADO LA TRAN DE DATOS QUE SOLO MANDE UNO
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_gps_actual_GUNA"
'				cmd.Parameters = Array As Object(c.GetString("hglat"),c.GetString("hglon"),usuario,ALMACEN,l_ruta.Text )
'				'cmd.Parameters = Array As Object(C.GetString("HGDATE"),C.GetString("HGLAT"),C.GetString("HGLON") )
	
				'reqManager.ExecuteQuery(cmd , 0, "inst_visitas")
				
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "UPDATE_DANV_ACTUAL2_GPS"
				cmd.Parameters = Array As Object(L_MONTOD.Text, L_CUANTOST.Text, l_cuantosc.Text,l_porvisitar.TEXT,c.GetString("hglat"),c.GetString("hglon"),batterystatus(0),LPT, STEYIN, STEYOUT,ALMACEN,l_ruta.Text )
				'reqManager.ExecuteQuery(cmd , 0, "inst_visitas")
				reqManager.ExecuteCommand(cmd,"inst_visitas")
				
				
	
				'		Dim cmd As DBCommand
				'		cmd.Initialize
				'		cmd.Name = "update_gps_actual_TKM"
				'		cmd.Parameters = Array As Object(C.GetString("HGLAT"),C.GetString("HGLON"),usuario )
				'		reqManager.ExecuteQuery(cmd , 0, "inst_visitas")
				'lv.AddTwoLines(c.GetString("HIST_VI_CREDITO"),c.GetString("HIST_VI_RESULTADO"))
			Next
		End If
		c.Close
		c=starter.skmt.execQuery("select COUNT(*) AS CUANTOS from INVENT_X_ENVIAR")
		c.Position=0
		If c.GetString("CUANTOS") > 0 Then
			d=starter.skmt.execQuery("select ALMACEN , PROID , CANTIDAD  from INVENT_X_ENVIAR")
			If d.RowCount>0 Then
				For i=0 To d.RowCount -1
					d.Position=i
					cmd.Initialize
					cmd.Name = "insert_invetnario_actual_DANV"
					cmd.Parameters = Array As Object(d.GetString("ALMACEN"), d.GetString("PROID"),d.GetString("CANTIDAD"))
					reqManager.ExecuteQuery(cmd , 0,"ins_pedidos")
				Next
			End If
			starter.skmt.execNonQuery("delete from INVENT_X_ENVIAR")
		End If
		 
		
	End If
	'End If
	DateTime.TimeFormat = "HH:mm:ss"
	
End Sub

Sub Activity_Pause (UserClosed As Boolean)
cargar.Visible = False
	Subir.Visible = False
	connecta.Visible = True
    inv.Visible = False	
	
End Sub
Sub trabajar_Click
	'CallSubDelayed(gestion,"gestion")
	
	StartActivity(colonia)
	
End Sub


Sub Subir_Click
	CARGA = "SUBIR"
	P1.Visible = True
	'trabajar.Visible = False
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	cargar.Visible=False
	L_P_1.Visible = False
	S_CC.Visible = False
	L_P_3.Visible = False
	S_CH.Visible = False
	PB1.Visible = False
	Resumen.Visible= False
	
	L_P_2.Text = "Envio de Pedidos"
	L_P_3.Text = "Envio de Pedidos"
	S_CH.Text = "EN PROCESO"
	S_CP.Text = "EN PROCESO"
	PB1.Progress = 0
	PB2.Progress = 0
'c=starter.skmt.execQuery("SELECT sum(IFNULL(PE_DESC,0)) as DESCUENTO FROM PEDIDO")
'c.Position =0
'If c.GetString("DESCUENTO") > 0 And PASO = 0 Then
'P1.Visible = True
'ELSE IF c.GetString("DESCUENTO") = 0 Then
PASO = 1
'End If
If PASO =1 Then
	starter.skmt.execNonQuery("delete from pedido_cliente where PC_CLIENTE not In (select PE_CLIENTE from pedido)")
c=starter.skmt.execQuery("select usuario from usuarioa")
		c.Position = 0
		usuario = c.GetString("USUARIO")
		c.Close
		
		c=starter.skmt.execQuery("select HGDATE, HGLAT, HGLON from HIST_GPS")
	
		If c.RowCount>0 Then
		For i=0 To c.RowCount -1
		c.Position=i
		Dim cmd As DBCommand
		cmd.Initialize
		cmd.Name = "UPDATE_DANV_ACTUAL2_GPS"
		cmd.Parameters = Array As Object(L_MONTOD.Text, L_CUANTOST.Text, l_cuantosc.Text,l_porvisitar.TEXT,c.GetString("hglat"),c.GetString("hglon"),batterystatus(0),LPT, STEYIN, STEYOUT,ALMACEN,l_ruta.Text )
		reqManager.ExecuteQuery(cmd , 0, "inst_visitas")
			Next
		End If
	c.Close
' PEDIO_CLIENTE

	c=starter.skmt.execQuery("SELECT PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT, PC_COSTO_SIN, PC_RUTA, PC_ALMACEN FROM PEDIDO_CLIENTE ")
	d=starter.skmt.execQuery("SELECT COUNT(*) as CUANTOS_PEDIDOSC FROM PEDIDO_CLIENTE ")
		If c.RowCount>0 Then
	     For i=0 To c.RowCount -1
		     c.Position=i
			 
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_pedidos_DANV"
				cmd.Parameters = Array As Object(C.GetString("PC_CLIENTE"),C.GetString("PC_FECHA"),C.GetString("PC_USER"),C.GetString("PC_NOART"),C.GetString("PC_MONTO"),C.GetString("PC_LON"),C.GetString("PC_LAT"),ALMACEN,l_ruta.text,C.GetString("PC_COSTO_SIN") )
				reqManager.ExecuteQuery(cmd , 0,"ins_pedidos")

	     Next
	    c.Close
	    End If
	d.Position=0
	 cuantos_pedidosc = D.GetString("CUANTOS_PEDIDOSC")
	d.Close
	
	' ENVIO DE LOS CODIGOS QR 
		'c=starter.skmt.execQuery2("SELECT CAT_CL_NUM_SERIEFISICO,CAT_CL_CODIGO ,CAT_CL_LONG,CAT_CL_LAT, CAT_CL_FOTO FROM kmt_info where CAT_CL_NUM_SERIEFISICO = ?", Array As String("OK"))
		c=starter.skmt.execQuery("SELECT CAT_CL_NUM_SERIEFISICO,CAT_CL_CODIGO ,CAT_CL_LONG,CAT_CL_LAT, CAT_CL_FOTO FROM kmt_info where CAT_CL_NUM_SERIEFISICO IS NOT NULL")
		
		If c.RowCount>0 Then
	     For i=0 To c.RowCount -1
				c.Position=i
				's=starter.skmt.execQuery2("SELECT HIST_VI_IMAGEN FROM HIST_VISITAS WHERE HIST_VI_CREDITO =?", Array As String (c.GetString("HIST_VI_CREDITO")))
				's.Position =0
				foto1 = c.GetBlob("CAT_CL_FOTO")
			 
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_QR_DANV"
				cmd.Parameters = Array As Object(C.GetString("CAT_CL_NUM_SERIEFISICO"),C.GetString("CAT_CL_CODIGO"),C.GetString("CAT_CL_LONG"),C.GetString("CAT_CL_LAT"),ALMACEN,l_ruta.text, foto1 )
				reqManager.ExecuteQuery(cmd , 0,"ins_QR")

	     Next
	    c.Close
	    End If
	
	
	' PEDIO
'		c=starter.skmt.execQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("FOLIO"))
'		c.Position =0
'		armafolio = l_ruta.text * 1000000
'		armafolio = armafolio + c.GetString("CAT_VA_VALOR")
'		c.Close
'		c=starter.skmt.execQuery("SELECT PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO, PE_COSTO_SIN, PE_RUTA, PE_DESC FROM PEDIDO WHERE PE_FOLIO IS NULL")
'	
'	
'		If c.RowCount>0 Then
'			For i=0 To c.RowCount -1
'				c.Position=i
'				starter.skmt.execNonQuery2("update PEDIDO set PE_FOLIO = ? where PE_PROID = ? AND PE_CLIENTE =? AND PE_FECHA =? AND PE_FOLIO IS NULL ", Array As Object(armafolio, c.GetString("PE_PROID"), c.GetString("PE_CLIENTE"),c.GetString("PE_FECHA")))
'
'				armafolio = armafolio + 1
'	
'			Next
'			c.Close
'		End If
'		armafolio = armafolio - (l_ruta.Text * 1000000)
' 	'starter.skmt.execNonQuery2("update CAT_VARIABLES set CAT_VA_VALOR = ? where CAT_VA_DESCRIPCION = ? ", Array As Object(armafolio,"FOLIO"))
	
	'			Dim cmd As DBCommand
	'			cmd.Initialize
	'			cmd.Name = "update_folio"
	'			cmd.Parameters = Array As Object(armafolio,l_ruta.Text , "1")
	'			reqManager.ExecuteQuery(cmd , 0, "folio")

		' ECUESTA
	
		c=starter.skmt.execQuery("SELECT  HE_CLIE, HE_RES, HE_FECHA, HE_TIPO FROM HIST_ENCUESTA")
		
		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
				c.Position=i
			 
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_encuesta_DANV"
				cmd.Parameters = Array As Object(C.GetString("HE_CLIE"),C.GetString("HE_RES"),C.GetString("HE_FECHA"), c.GetString("HE_TIPO"))
				reqManager.ExecuteQuery(cmd , 0, "inst_noventa")

			Next
		End If
		c.Close
	
	c=starter.skmt.execQuery("SELECT PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO, PE_COSTO_SIN, PE_RUTA, PE_DESC, PE_FOLIO FROM PEDIDO")
	d=starter.skmt.execQuery("SELECT COUNT(*) as CUANTOS_PEDIDO FROM PEDIDO")
	
		If c.RowCount>0 Then
	     For i=0 To c.RowCount -1
		     c.Position=i
			 
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_pedido_DANV"
				cmd.Parameters = Array As Object(C.GetString("PE_CEDIS"),ALMACEN,C.GetString("PE_COSTO_TOT"),C.GetString("PE_COSTOU"),C.GetString("PE_CANT"),C.GetString("PE_PRONOMBRE"),C.GetString("PE_PROID"),C.GetString("PE_CLIENTE"),C.GetString("PE_FECHA"),C.GetString("PE_USUARIO"),C.GetString("PE_RUTA"), C.GetString("PE_COSTO_SIN"),C.GetString("PE_DESC"),c.GetString("PE_FOLIO"))
				reqManager.ExecuteQuery(cmd , 0, "ins_pedido")

	     Next
	    c.Close
	    End If
	d.Position=0
	 cuantos_pedido = D.GetString("CUANTOS_PEDIDO")
	d.Close
	
	' NOVENTA
	c=starter.skmt.execQuery("SELECT  NV_CLIENTE,NV_FECHA,NV_USER,NV_MOTIVO,NV_COMM,NV_LAT,NV_LON FROM NOVENTA")
	D=starter.skmt.execQuery("SELECT  COUNT(*) AS CUANTOS_NOVENTA FROM NOVENTA")
	
		If c.RowCount>0 Then
	     For i=0 To c.RowCount -1
		     c.Position=i
			 
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_noventa_DANV"
				cmd.Parameters = Array As Object(C.GetString("NV_CLIENTE"),C.GetString("NV_FECHA"),C.GetString("NV_USER"),C.GetString("NV_MOTIVO"),C.GetString("NV_COMM"),C.GetString("NV_LAT"),C.GetString("NV_LON"), ALMACEN, l_ruta.Text)
				reqManager.ExecuteQuery(cmd , 0, "inst_noventa")

	     Next
	    c.Close
	    End If
	d.Position=0
	 cuantos_noventa = D.GetString("CUANTOS_NOVENTA")
	d.Close
	
' GEO CERCA

		c=starter.skmt.execQuery("Select HGCLIENTE, HGDATE, HGLAT, HGLON from HIST_GEOCERCA")

		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
				c.Position=i
			 
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_geocerca_DANV"
				cmd.Parameters = Array As Object(C.GetString("HGCLIENTE"),C.GetString("HGDATE"),C.GetString("HGLAT"),C.GetString("HGLON"))
				reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
		
			Next
			c.Close
		End If


	' VERIFICACION
'	c=starter.skmt.execQuery("SELECT  HVE_CLIENTE, HVE_IDPROD, HVE_EXISTENCIA FROM HIST_VERIFICACION")
	
'		If c.RowCount>0 Then
'	     For i=0 To c.RowCount -1
'		     c.Position=i
'			 
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_verificacion_GV2"
'				cmd.Parameters = Array As Object(C.GetString("HVE_CLIENTE"),C.GetString("HVE_IDPROD"),C.GetString("HVE_EXISTENCIA"))
'				reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
'
'	     Next
'	    c.Close
'	    End If
'	
	
	
	
		
		' DROP

		
   t1.Initialize("T1", 30000) ' 1000 = 1 second
   t1.Enabled = True
		Dim sDate,sTime As String
		DateTime.DateFormat = "MM/dd/yyyy"
		sDate=DateTime.Date(DateTime.Now)
		sTime=DateTime.Time(DateTime.Now)
   Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name ="insert_drop_DANV_2"
		cmd.Parameters = Array As Object(usuario,l_ruta.Text,sDate & sTime, l_porvisitar.Text,l_drop.Text,l_efectiva.Text,l_cuantosc.Text,l_cuantosn.Text, L_MONTOD.Text,"ENVIO",ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
   img2.Visible =True
	
PORCENTAJE = Round(100/ (cuantos_noventa + cuantos_pedido + cuantos_pedidosc + 1)) 	
	
		ToastMessageShow("Se Actualizaran los datos, Este proceso podria tardar hasta un minuto, gracias "& l_ruta.text , True)


End If		
End Sub
Sub cargar_Click
	CARGA = "CARGAR"
    img2.Visible =True
	L_P_1.Visible = True
	S_CC.Visible = True
	Btn_Ubicar.Visible=False
	P1.Visible = True
'	trabajar.Visible = False
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	L_P_3.Visible = True
	S_CH.Visible = True
	PB1.Visible = True
	Resumen.Visible= False
	
	L_P_1.Text = "Catalogo de Clientes"
	L_P_2.Text = "Catalogos de Productos"
	L_P_3.Text = "Catalogos Historicos"
	S_CC.Text = "EN PROCESO"
	S_CH.Text = "EN PROCESO"
	S_CP.Text = "EN PROCESO"
	PB1.Progress = 0
	PB2.Progress = 0
	EJECUTANDO = 1

     'c=starter.skmt.execQuery("CREATE TABLE kmt_info (pr_cd_credito NUMERIC,pr_cd_nombre TEXT,pr_cd_calle TEXT,pr_cd_numero TEXT,pr_cd_num_int TEXT,pr_cd_entrecalle1 TEXT,pr_cd_entrecalle2 TEXT,pr_cd_colonia TEXT,pr_cd_poblacion TEXT,pr_cd_edo TEXT,pr_cd_cp TEXT,pr_cd_zona TEXT,pr_cf_credito NUMERIC,pr_cf_saldotot NUMERIC,pr_cf_saldooper NUMERIC,pr_cf_saldof1 NUMERIC, pr_cf_penalizacion NUMERIC)")
    TOPE = 0
	' NUEVOS CLIENTE
	
	starter.skmt.execNonQuery("delete from kmt_info")
	starter.skmt.execNonQuery("delete from cod_result")
	starter.skmt.execNonQuery("delete from hist_gest")
	starter.skmt.execNonQuery("delete from cat_gunaprod")
	starter.skmt.execNonQuery("delete from CAT_DETALLES_PAQ")
	starter.skmt.execNonQuery("delete from telefonos")
	starter.skmt.execNonQuery("delete from HIST_VENTAS")
	starter.skmt.execNonQuery("delete from HIST_PROMOS")
	starter.skmt.execNonQuery("delete from HIST_CLIENTE_CANT_PROMOS")
	starter.skmt.execNonQuery("delete from PROMOS_COMP")
	starter.skmt.execNonQuery("delete from CAT_VERIFICACION")
	starter.skmt.execNonQuery("DELETE FROM MARCAS_RUTAS")
	starter.skmt.execNonQuery("DELETE FROM HIST_STAY_STORE")
	starter.skmt.execNonQuery("DELETE FROM HIST_GEOCERCA")
	
	
	
	c = starter.skmt.execQuery2("select count(CAT_VA_DESCRIPCION) as HoraIngreso from cat_variables where CAT_VA_DESCRIPCION = ? ", Array As String("HoraIngreso"))
	c.Position = 0
	DateTime.TimeFormat = "HHmmss"
	
	'Valida si ya se cuenta con hora actualiza el valor si no lo inserta-----------
	If c.GetString("HoraIngreso") > 0 Then
		starter.skmt.execNonQuery2("Update cat_variables set CAT_VA_VALOR = ?  WHERE CAT_VA_DESCRIPCION = ?" , Array As String(DateTime.Time(DateTime.Now),"HoraIngreso"))
	Else
		starter.skmt.execNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_VALOR,CAT_VA_DESCRIPCION)  VALUES (?,?)" , Array As String(DateTime.Time(DateTime.Now),"HoraIngreso"))
	End If

	DateTime.TimeFormat = "HH:mm:ss"
	c=starter.skmt.execQuery("select usuario from usuarioa")
		c.Position = 0
	usuario = c.GetString("USUARIO")
	c.Close
	
	c=starter.skmt.execQuery("select HGDATE, HGLAT, HGLON from HIST_GPS")
	
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			
			Dim cmd As DBCommand
			cmd.Initialize
			cmd.Name = "UPDATE_DANV_ACTUAL2_GPS"
			cmd.Parameters = Array As Object(L_MONTOD.Text, L_CUANTOST.Text, l_cuantosc.Text,l_porvisitar.TEXT,c.GetString("hglat"),c.GetString("hglon"),batterystatus(0),0, 0, 0,ALMACEN,l_ruta.Text )
			reqManager.ExecuteQuery(cmd , 0, "inst_visitas")
	
			Next
	Else
		
		Dim cmd As DBCommand
		cmd.Initialize
		cmd.Name = "UPDATE_DANV_ACTUAL2_GPS"
		cmd.Parameters = Array As Object(L_MONTOD.Text, L_CUANTOST.Text, l_cuantosc.Text,l_porvisitar.TEXT,"19.621210","-99.079422",batterystatus(0),0, 0, 0,ALMACEN,l_ruta.Text )
		reqManager.ExecuteQuery(cmd , 0, "inst_visitas")
	End If
	c.Close
	
	
	'cmd.Initialize
	'cmd.Name = "Select_count_clie"
	'reqManager.ExecuteQuery(cmd,0,"count_cli")
	Dim sDate,sTime As String
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	
	Dim P As PhoneId
	
imei = "" 'P.GetDeviceId

c=Starter.skmt.execQuery("select HGDATE, HGLAT, HGLON from HIST_GPS")
	
If c.RowCount>0 Then
	For i=0 To c.RowCount -1
	c.Position=i

	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name = "UPDATE_DANV_ACTUAL2_GPS"
	cmd.Parameters = Array As Object(0, 0,0,0,c.GetString("hglat"),c.GetString("hglon"),batterystatus(0),0,0, 0,ALMACEN,l_ruta.Text )
	reqManager.ExecuteQuery(cmd , 0, "inst_visitas")
	Next
End If

	cmd.Initialize
	cmd.Name ="insert_drop_DANV_2"
	cmd.Parameters = Array As Object(usuario,e_ruta.text,sDate,imei,sTime,"","","","","CARGA",ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
	
	'' esto es para que pongan el codigo nuevo de carga del archivo de configuración.
'	
'	cmd.Initialize
'	cmd.Name = "select_cat_gunaprod_GV2"   ''' va el nombre de archivo de config
'	cmd.Parameters = Array As Object(ALMACEN)
'	reqManager.ExecuteQuery(cmd , 0, "gunaprod") ''' donde regresa la info ver job_done
'	
'	
	
'	cmd.Initialize
'	cmd.Name = "select_cat_gunaprod_GV2"
'	cmd.Parameters = Array As Object(ALMACEN)
'	reqManager.ExecuteQuery(cmd , 0, "gunaprod")
'	
	
	cmd.Initialize
	cmd.Name = "select_cat_gunaprod_DANV"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprod")
	
	
	cmd.Initialize
	cmd.Name = "select_resum_apk_DANV"   ''' va el nombre de archivo de config
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "resum_apk") ''' donde regresa la info ver job_done
	
		
	cmd.Initialize
	cmd.Name = "select_cat_paquetes_DANV"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodp")
	
	cmd.Initialize
	cmd.Name = "select_cat_paquetess_DANV"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodp")
	
	
	cmd.Initialize
	cmd.Name = "select_cat_detallepa_DANV"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "detallepaq")
	
	
	cmd.Initialize
	cmd.Name = "select_cat_clientes_guna_DANV"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "kmt_datos")
	
	cmd.Initialize
	cmd.Name = "select_hist_datos_DANV_2"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN,e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_datos")
	
	cmd.Initialize
	cmd.Name = "select_hist_promos_DANV"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_promos")
	
	cmd.Initialize
	cmd.Name = "select_hist_cliente_promos_DANV"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_cliente_promos")
	
	If E_RUTA2.text <> "" Then
		cmd.Initialize
		cmd.Name = "select_cat_clientes_guna_DANV"
		cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "kmt_datos")
	
		cmd.Initialize
		cmd.Name = "select_hist_datos_DANV"
		cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "hist_datos")
	
		cmd.Initialize
		cmd.Name = "select_hist_promos_DANV"
		cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "hist_promos")
	
		cmd.Initialize
		cmd.Name = "select_hist_cliente_promos_DANV"
		cmd.Parameters = Array As Object(E_RUTA2.text, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "hist_cliente_promos")
	

	End If
	
	
	cmd.Initialize
	cmd.Name = "select_promo_comp_DANV"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_comp_promos")
	
	cmd.Initialize
	cmd.Name = "select_verificacion_DANV"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "cat_verificacion")
	
	cmd.Initialize
	cmd.Name = "select_fecha"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "fecha")
	
	cmd.Initialize
	cmd.Name = "select_folio_DANV"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "folio")
	
	cmd.Initialize
	cmd.Name = "select_marcas_rutas_DANV"
	cmd.Parameters = Array As Object( ALMACEN, e_ruta.text)
	reqManager.ExecuteQuery(cmd , 0, "marcas_rutas")
	
	
	cmd.Initialize
	cmd.Name = "select_CUEST_DANV"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "CUESTIONARIO")
	
	
	cmd.Initialize
	cmd.Name = "select_HIST_CUOTAS_DANV"
	cmd.Parameters = Array As Object( ALMACEN,e_ruta.text )
	reqManager.ExecuteQuery(cmd , 0, "CUOTAS")
	

	cmd.Initialize
	cmd.Name = "select_comis_DANV"
	cmd.Parameters = Array As Object( ALMACEN,e_ruta.text )
	reqManager.ExecuteQuery(cmd , 0, "COMISIONES")
	



	
	

		
	' c=starter.skmt.execQuery("select HIST_VI_CREDITO, HIST_VI_PRODUCTO,HIST_VI_VISITADOR, HIST_VI_RESULTADO, HIST_VI_CODIGO, HIST_VI_PARENTESCO, HIST_VI_COMENTARIO, HIST_VI_DTEVISITA, HIST_VI_LONGITUD, HIST_VI_LATITUD, hist_vi_imagen, hist_vi_dprom, hist_vi_mprom from HIST_VISITAS")
	'	If c.RowCount>0 Then
	 '     For i=0 To c.RowCount -1
	'	     c.Position=i
	'		 foto1 = c.GetBlob("HIST_VI_IMAGEN")
	'		 
	'			Dim cmd As DBCommand
	'			cmd.Initialize
	'			cmd.Name = "insert_gestion_plan"
	'			cmd.Parameters = Array As Object(C.GetString("HIST_VI_CREDITO"),C.GetString("HIST_VI_PRODUCTO"),C.GetString("HIST_VI_VISITADOR"),C.GetString("HIST_VI_DTEVISITA"),C.GetString("HIST_VI_RESULTADO"),C.GetString("HIST_VI_CODIGO"),C.GetString("HIST_VI_COMENTARIO"),C.GetString("HIST_VI_PARENTESCO"),C.GetString("HIST_VI_LONGITUD"), C.GetString("HIST_VI_LATITUD"), foto1, c.GetString("HIST_VI_DPROM"),C.GetString("HIST_VI_MPROM"))
	'			reqManager.ExecuteQuery(cmd , 0, "inst_visitas")

			 'lv.AddTwoLines(c.GetString("HIST_VI_CREDITO"),c.GetString("HIST_VI_RESULTADO"))
	 '     Next
	  '  End If
	'starter.skmt.execNonQuery("DELETE FROM HIST_VISITAS")		 
	
	cargar.Visible = False
	Subir.Visible = False
'	connecta.Visible = True
	inv.Visible = False	
	
	'Dim cmd As DBCommand
	'cmd.Initialize
	'cmd.Name = "select_telefonos_riva"
	'cmd.Parameters = Array As Object(usuario)
	'reqManager.ExecuteQuery(cmd , 0, "telefonos")
	
	
	
	ToastMessageShow("Se Actualizaran los datos, Este proceso podria tardar hasta un minuto, gracias" , True)
End Sub
Sub JobDone(Job As HttpJob)
	If Job.Success = False Then
		'ToastMessageShow("Error: " & Job.ErrorMessage, True)
	If Job.ErrorMessage = "STREAM" Then
		If CARGA = "SUBIR" Then
		PB2.Progress = PB2.Progress + PORCENTAJE
			S_CP.Text = "SUBIENDO"
			If PB2.Progress > 99 Then
				S_CP.Text = "VALIDANDO"
			End If
		End If
	End If		  
		
	Else
	 If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "kmt_datos" Then 'query tag
	   	S_CC.TEXT = "CARGANDO"
         For Each records() As Object In RESULT.Rows
        Dim CAT_CL_CODIGO As String = records(RESULT.Columns.Get("CAT_CL_CODIGO"))
		Dim CAT_CL_RUTA As String = records(RESULT.Columns.Get("CAT_CL_RUTA"))
		Dim CAT_CL_NOMBRE As String = records(RESULT.Columns.Get("CAT_CL_NOMBRE"))
		Dim CAT_CL_ATIENDE1 As String = records(RESULT.Columns.Get("CAT_CL_ATIENDE1"))
		Dim CAT_CL_ATIENTE2 As String = records(RESULT.Columns.Get("CAT_CL_ATIENTE2"))
		Dim CAT_CL_TELEFONO As String = records(RESULT.Columns.Get("CAT_CL_TELEFONO"))
		Dim CAT_CL_EMAIL As String = records(RESULT.Columns.Get("CAT_CL_EMAIL"))
		Dim CAT_CL_CALLE As String = records(RESULT.Columns.Get("CAT_CL_CALLE"))
		Dim CAT_CL_NOEXT As String = records(RESULT.Columns.Get("CAT_CL_NOEXT"))
		Dim CAT_CL_NOINT As String = records(RESULT.Columns.Get("CAT_CL_NOINT"))
		Dim CAT_CL_CALLE1 As String = records(RESULT.Columns.Get("CAT_CL_CALLE1"))
		Dim CAT_CL_CALLE2 As String = records(RESULT.Columns.Get("CAT_CL_CALLE2"))
		Dim CAT_CL_COLONIA As String = records(RESULT.Columns.Get("CAT_CL_COLONIA"))
		Dim CAT_CL_MUNI As String = records(RESULT.Columns.Get("CAT_CL_MUNI"))
		Dim CAT_CL_EDO As String = records(RESULT.Columns.Get("CAT_CL_EDO"))
		Dim CAT_CL_CP As String = records(RESULT.Columns.Get("CAT_CL_CP"))
		Dim CAT_CL_LONG As String = records(RESULT.Columns.Get("CAT_CL_LONG"))
		Dim CAT_CL_LAT As String = records(RESULT.Columns.Get("CAT_CL_LAT"))
		Dim CAT_CL_MTOCOMPRA As String = records(RESULT.Columns.Get("CAT_CL_MTOCOMPRA"))
   		Dim CAT_CL_NUM_SERIEFISICO As String = records(RESULT.Columns.Get("CAT_CL_NUM_SERIEFISICO"))
		   
		   starter.skmt.execNonQuery2("INSERT INTO kmt_info(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, gestion) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0)", Array As Object (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))
  	       starter.skmt.execNonQuery2("INSERT INTO HIST_STAY_STORE(HSS_CODIGO,  HSS_IN , HSS_OUT , HSS_TOT) VALUES (?,0,0,0)", Array As Object (CAT_CL_CODIGO))
         Next
	   Listo1 = 1
	   S_CC.Text = "LISTO"
   	   ToastMessageShow("Catalogo Clientes Actualizados." , True)
	   If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
       Activity_Resume
	   img2.Visible=False
					EJECUTANDO=0
				End If
	   
			End If
	   
		End If
	
	
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "resum_apk" Then 'query tag
				For Each records() As Object In RESULT.Rows
					Dim HIST_RA_OBJMES As String = records(RESULT.Columns.Get("HIST_RA_OBJMES"))
					Dim HIST_RA_VENTA As String = records(RESULT.Columns.Get("HIST_RA_VENTA"))
					Dim HIST_RA_TENDENCIA As String = records(RESULT.Columns.Get("HIST_RA_TENDENCIA"))
					Dim HIST_RA_ALCANCE As String = records(RESULT.Columns.Get("HIST_RA_ALCANCE"))
					Dim HISR_RA_DRAOBJ As String = records(RESULT.Columns.Get("HISR_RA_DRAOBJ"))
					Dim HIST_RA_DRAVTA As String = records(RESULT.Columns.Get("HIST_RA_DRAVTA"))
					Dim HIST_RA_DSOBJ As String = records(RESULT.Columns.Get("HIST_RA_DSOBJ"))
					Dim HIST_RA_DSVTA As String = records(RESULT.Columns.Get("HIST_RA_DSVTA"))
					Dim HIST_RA_VPOOBJ As String = records(RESULT.Columns.Get("HIST_RA_VPOOBJ"))
					Dim HIST_RA_VPOVTA As String = records(RESULT.Columns.Get("HIST_RA_VPOVTA"))
					Dim HIST_RA_CTES As String = records(RESULT.Columns.Get("HIST_RA_CTES"))
					Dim HIST_RA_COBCCC As String = records(RESULT.Columns.Get("HIST_RA_COBCCC"))
					Dim HIST_RA_ECO As String = records(RESULT.Columns.Get("HIST_RA_ECO"))
					Dim HIST_RA_VISITPLAN As String = records(RESULT.Columns.Get("HIST_RA_VISITPLAN"))
					Dim HIST_RA_VISIREAL As String = records(RESULT.Columns.Get("HIST_RA_VISIREAL"))
					Dim HIST_RA_COBVISIT As String = records(RESULT.Columns.Get("HIST_RA_COBVISIT"))
					Dim HIST_RA_FRECCOMPOBJ As String = records(RESULT.Columns.Get("HIST_RA_FRECCOMPOBJ"))
					Dim HIST_RA_FRECCOMREAL As String = records(RESULT.Columns.Get("HIST_RA_FRECCOMREAL"))
					Dim HIST_RA_VENTAMES1 As String = records(RESULT.Columns.Get("HIST_RA_VENTAMES1"))
					Dim HIST_RA_VENTAMES2 As String = records(RESULT.Columns.Get("HIST_RA_VENTAMES2"))
					Dim HIST_RA_VENTAMES3 As String = records(RESULT.Columns.Get("HIST_RA_VENTAMES3"))
					Dim HIST_RA_VENTAMES4 As String = records(RESULT.Columns.Get("HIST_RA_VENTAMES4"))
					Dim HIST_RA_RECHAZO As String = records(RESULT.Columns.Get("HIST_RA_RECHAZO"))
					Dim HIST_RA_RECHAZOPORCEN As String = records(RESULT.Columns.Get("HIST_RA_RECHAZOPORCEN"))
					Dim HIST_RA_SEMANA1 As String = records(RESULT.Columns.Get("HIST_RA_SEMANA1"))
					Dim HIST_RA_SEMANA1_DIAS As String = records(RESULT.Columns.Get("HIST_RA_SEMANA1_DIAS"))
					Dim HIST_RA_SEMANA1_DRA As String = records(RESULT.Columns.Get("HIST_RA_SEMANA1_DRA"))
					Dim HIST_RA_SEMANA2 As String = records(RESULT.Columns.Get("HIST_RA_SEMANA2"))
					Dim HIST_RA_SEMANA2_DIAS As String = records(RESULT.Columns.Get("HIST_RA_SEMANA2_DIAS"))
					Dim HIST_RA_SEMANA2_DRA As String = records(RESULT.Columns.Get("HIST_RA_SEMANA2_DRA"))
					Dim HIST_RA_SEMANA3 As String = records(RESULT.Columns.Get("HIST_RA_SEMANA3"))
					Dim HIST_RA_SEMANA3_DIAS As String = records(RESULT.Columns.Get("HIST_RA_SEMANA3_DIAS"))
					Dim HIST_RA_SEMANA3_DRA As String = records(RESULT.Columns.Get("HIST_RA_SEMANA3_DRA"))
					Dim HIST_RA_SEMANA4 As String = records(RESULT.Columns.Get("HIST_RA_SEMANA4"))
					Dim HIST_RA_SEMANA4_DIAS As String = records(RESULT.Columns.Get("HIST_RA_SEMANA4_DIAS"))
					Dim HIST_RA_SEMANA4_DRA As String = records(RESULT.Columns.Get("HIST_RA_SEMANA4_DRA"))
					Dim HIST_RA_SEMANA5 As String = records(RESULT.Columns.Get("HIST_RA_SEMANA5"))
					Dim HIST_RA_SEMANA5_DIAS As String = records(RESULT.Columns.Get("HIST_RA_SEMANA5_DIAS"))
					Dim HIST_RA_SEMANA5_DRA As String = records(RESULT.Columns.Get("HIST_RA_SEMANA5_DRA"))
					Dim HIST_RA_SEMANA1_LPT As String = records(RESULT.Columns.Get("HIST_RA_SEMANA1_LPT"))
					Dim HIST_RA_SEMANA2_LPT As String = records(RESULT.Columns.Get("HIST_RA_SEMANA2_LPT"))
					Dim HIST_RA_SEMANA3_LPT As String = records(RESULT.Columns.Get("HIST_RA_SEMANA3_LPT"))
					Dim HIST_RA_SEMANA4_LPT As String = records(RESULT.Columns.Get("HIST_RA_SEMANA4_LPT"))
					Dim HIST_RA_SEMANA5_LPT As String = records(RESULT.Columns.Get("HIST_RA_SEMANA5_LPT"))
					Dim HIST_RA_RUTA As String = records(RESULT.Columns.Get("HIST_RA_RUTA"))
					Dim HIST_RA_IDALMACEN As String = records(RESULT.Columns.Get("HIST_RA_IDALMACEN"))

		   
					starter.skmt.execNonQuery2("INSERT INTO HIST_RESUM_APK(HIST_RA_OBJMES,HIST_RA_VENTA,HIST_RA_TENDENCIA,HIST_RA_ALCANCE,HISR_RA_DRAOBJ,HIST_RA_DRAVTA,HIST_RA_DSOBJ,HIST_RA_DSVTA,HIST_RA_VPOOBJ,HIST_RA_VPOVTA,HIST_RA_CTES,HIST_RA_COBCCC,HIST_RA_ECO,HIST_RA_VISITPLAN,HIST_RA_VISIREAL,HIST_RA_COBVISIT,HIST_RA_FRECCOMPOBJ,HIST_RA_FRECCOMREAL,HIST_RA_VENTAMES1,HIST_RA_VENTAMES2,HIST_RA_VENTAMES3,HIST_RA_VENTAMES4,HIST_RA_RECHAZO,HIST_RA_RECHAZOPORCEN,HIST_RA_SEMANA1,HIST_RA_SEMANA1_DIAS,HIST_RA_SEMANA1_DRA,HIST_RA_SEMANA2,HIST_RA_SEMANA2_DIAS,HIST_RA_SEMANA2_DRA,HIST_RA_SEMANA3,HIST_RA_SEMANA3_DIAS,HIST_RA_SEMANA3_DRA,HIST_RA_SEMANA4,HIST_RA_SEMANA4_DIAS,HIST_RA_SEMANA4_DRA,HIST_RA_SEMANA5,HIST_RA_SEMANA5_DIAS,HIST_RA_SEMANA5_DRA,HIST_RA_SEMANA1_LPT,HIST_RA_SEMANA2_LPT,HIST_RA_SEMANA3_LPT,HIST_RA_SEMANA4_LPT,HIST_RA_SEMANA5_LPT,HIST_RA_RUTA,HIST_RA_IDALMACEN) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (HIST_RA_OBJMES,HIST_RA_VENTA,HIST_RA_TENDENCIA,HIST_RA_ALCANCE,HISR_RA_DRAOBJ,HIST_RA_DRAVTA,HIST_RA_DSOBJ,HIST_RA_DSVTA,HIST_RA_VPOOBJ,HIST_RA_VPOVTA,HIST_RA_CTES,HIST_RA_COBCCC,HIST_RA_ECO,HIST_RA_VISITPLAN,HIST_RA_VISIREAL,HIST_RA_COBVISIT,HIST_RA_FRECCOMPOBJ,HIST_RA_FRECCOMREAL,HIST_RA_VENTAMES1,HIST_RA_VENTAMES2,HIST_RA_VENTAMES3,HIST_RA_VENTAMES4,HIST_RA_RECHAZO,HIST_RA_RECHAZOPORCEN,HIST_RA_SEMANA1,HIST_RA_SEMANA1_DIAS,HIST_RA_SEMANA1_DRA,HIST_RA_SEMANA2,HIST_RA_SEMANA2_DIAS,HIST_RA_SEMANA2_DRA,HIST_RA_SEMANA3,HIST_RA_SEMANA3_DIAS,HIST_RA_SEMANA3_DRA,HIST_RA_SEMANA4,HIST_RA_SEMANA4_DIAS,HIST_RA_SEMANA4_DRA,HIST_RA_SEMANA5,HIST_RA_SEMANA5_DIAS,HIST_RA_SEMANA5_DRA,HIST_RA_SEMANA1_LPT,HIST_RA_SEMANA2_LPT,HIST_RA_SEMANA3_LPT,HIST_RA_SEMANA4_LPT,HIST_RA_SEMANA5_LPT,HIST_RA_RUTA,HIST_RA_IDALMACEN))
	'				Msgbox("pasa","alo")
				Next
				Listo1 = 1
				S_CC.Text = "LISTO"
				ToastMessageShow("Catalogo Resumen Actualizado." , True)
				
	   
			End If
	   
		End If
	
	 
	 If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "hist_promos" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   Dim HP_CLIENTE As String = records(RESULT.Columns.Get("HP_CLIENTE"))
           Dim HP_CODIGO_PROMOCION As String = records(RESULT.Columns.Get("HP_CODIGO_PROMOCION"))

		   starter.skmt.execNonQuery2("INSERT INTO HIST_PROMOS(HP_CLIENTE, HP_CODIGO_PROMOCION) VALUES (?,?)", Array As Object (HP_CLIENTE, HP_CODIGO_PROMOCION))
	   
		   
         Next
			   ToastMessageShow("Historico Promociones Actualizado." , True)
 		If PB1.Progress = 0 Then
			PB1.Progress = 30
			S_CH.Text = "CARGANDO"
		ELSE If PB1.Progress = 30 Then
			PB1.Progress = 60
		ELSE IF PB1.Progress = 60 Then
			PB1.Progress = 100
			S_CH.Text = "LISTO"
		End If
		
       End If
	 End If  
	
	 If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "hist_cliente_promos" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   Dim HCCP_CLIENTE As String = records(RESULT.Columns.Get("HCCP_CLIENTE"))
           Dim HCCP_PROMO As String = records(RESULT.Columns.Get("HCCP_PROMO"))
		   Dim HCCP_CANT As String = records(RESULT.Columns.Get("HCCP_CANT"))

		   starter.skmt.execNonQuery2("INSERT INTO HIST_CLIENTE_CANT_PROMOS(HCCP_CLIENTE, HCCP_PROMO, HCCP_CANT) VALUES (?,?,?)", Array As Object (HCCP_CLIENTE, HCCP_PROMO,HCCP_CANT))
	   
		   
         Next
		 			   ToastMessageShow(" Historico Clientes Promociones Actualizado." , True)

       End If
	 End If  
	
	
	If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "hist_comp_promos" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   Dim CAT_PA_ID As String = records(RESULT.Columns.Get("CAT_PA_ID"))
           Dim CAT_PA_MAXPROM As String = records(RESULT.Columns.Get("CAT_PA_MAXPROM"))
		   Dim CAT_PA_MAXPROMREC As String = records(RESULT.Columns.Get("CAT_PA_MAXPROMREC"))
		   Dim CAT_PA_MAXPROMCLIE As String = records(RESULT.Columns.Get("CAT_PA_MAXPROMCLIE"))
		   

		   starter.skmt.execNonQuery2("INSERT INTO PROMOS_COMP(CAT_PA_ID, CAT_PA_MAXPROM, CAT_PA_MAXPROMREC, CAT_PA_MAXPROMCLIE) VALUES (?,?,?,?)", Array As Object (CAT_PA_ID, CAT_PA_MAXPROM,CAT_PA_MAXPROMREC,CAT_PA_MAXPROMCLIE))
	   
		   
         Next
        
		If PB1.Progress = 0 Then
			PB1.Progress = 30
			S_CH.Text = "CARGANDO"
		ELSE If PB1.Progress = 30 Then
			PB1.Progress = 60
		ELSE IF PB1.Progress = 60 Then
			PB1.Progress = 100
			S_CH.Text = "LISTO"
		End If
		
		
		
       End If
	 End If  
	
	If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "cat_verificacion" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   Dim CAT_VE_IDPROD As String = records(RESULT.Columns.Get("CAT_VE_IDPROD"))
           Dim CAT_VE_NOMBRE As String = records(RESULT.Columns.Get("CAT_VE_NOMBRE"))
           Dim CAT_VE_ORDEN As String = records(RESULT.Columns.Get("CAT_VE_ORDEN"))
           

		   starter.skmt.execNonQuery2("INSERT INTO CAT_VERIFICACION(CAT_VE_IDPROD, CAT_VE_NOMBRE,CAT_VE_ORDEN) VALUES (?,?,?)", Array As Object (CAT_VE_IDPROD, CAT_VE_NOMBRE,CAT_VE_ORDEN))
	   
		   
         Next
		 
			End If
		End If
	
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "marcas_rutas" Then 'query tag
				For Each records() As Object In RESULT.Rows
           
					Dim HVD_MARCA As String = records(RESULT.Columns.Get("HVD_MARCA"))
					Dim CLIENTES As String = records(RESULT.Columns.Get("CLIENTES"))
					

					starter.skmt.execNonQuery2("INSERT INTO MARCAS_RUTAS(HVD_MARCA, CLIENTES) VALUES (?,?)", Array As Object (HVD_MARCA, CLIENTES))
	   
					
				Next
		
			End If
		End If
	
	
		'CUOTAS
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "CUOTAS" Then 'query tag
				For Each records() As Object In RESULT.Rows
           
					Dim HC_RUTA As String = records(RESULT.Columns.Get("HC_RUTA"))
					Dim HC_CUOTA1 As String = records(RESULT.Columns.Get("HC_CUOTA1"))
					Dim HC_CUOTA2 As String = records(RESULT.Columns.Get("HC_CUOTA2"))
					Dim HC_CUOTA3 As String = records(RESULT.Columns.Get("HC_CUOTA3"))
					Dim HC_CUOTA4 As String = records(RESULT.Columns.Get("HC_CUOTA4"))
					Dim HC_CUOTA5 As String = records(RESULT.Columns.Get("HC_CUOTA5"))
					Dim HC_CUOTA6 As String = records(RESULT.Columns.Get("HC_CUOTA6"))
					Dim HC_META1 As String = records(RESULT.Columns.Get("HC_META1"))
					Dim HC_META2 As String = records(RESULT.Columns.Get("HC_META2"))
					Dim HC_META3 As String = records(RESULT.Columns.Get("HC_META3"))
					Dim HC_META4 As String = records(RESULT.Columns.Get("HC_META4"))
					Dim HC_META5 As String = records(RESULT.Columns.Get("HC_META5"))
					Dim HC_META6 As String = records(RESULT.Columns.Get("HC_META6"))
					
					
					
					starter.skmt.execNonQuery2("INSERT INTO HIST_CUOTAS(HC_RUTA, HC_CUOTA1,HC_CUOTA2,HC_CUOTA3,HC_CUOTA4,HC_CUOTA5,HC_CUOTA6,HC_META1,HC_META2,HC_META3,HC_META4,HC_META5,HC_META6) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (HC_RUTA, HC_CUOTA1,HC_CUOTA2,HC_CUOTA3,HC_CUOTA4,HC_CUOTA5,HC_CUOTA6,HC_META1,HC_META2,HC_META3,HC_META4,HC_META5,HC_META6))
	      
				Next
        
			End If
		End If
	'COMISIONES
		
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "COMISIONES" Then 'query tag
				For Each records() As Object In RESULT.Rows
           
					Dim HCM_TOTAL_V As String = records(RESULT.Columns.Get("HCM_TOTAL_V"))
					Dim HCM_TOTAL_VIVE As String = records(RESULT.Columns.Get("HCM_TOTAL_VIVE"))
					Dim HCM_TOTAL_GUNA As String = records(RESULT.Columns.Get("HCM_TOTAL_GUNA"))
					Dim HCM_TOTAL_BEB As String = records(RESULT.Columns.Get("HCM_TOTAL_BEB"))
					
					
					
					
					starter.skmt.execNonQuery2("INSERT INTO HIST_COMISIONES_MOVIL (HCM_TOTAL_V , HCM_TOTAL_VIVE , HCM_TOTAL_GUNA ,	HCM_TOTAL_BEB) VALUES (?,?,?,?)", Array As Object (HCM_TOTAL_V , HCM_TOTAL_VIVE , HCM_TOTAL_GUNA ,	HCM_TOTAL_BEB))
	      
				Next
        
			End If
		End If
		
	If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "gunaprod" Then 'query tag
	   	S_CP.Text = "CARGANDO"
         For Each records() As Object In RESULT.Rows
           
		   	Dim CAT_GP_ID As String = records(RESULT.Columns.Get("CAT_GP_ID"))
			Dim CAT_GP_NOMBRE As String = records(RESULT.Columns.Get("CAT_GP_NOMBRE"))
			Dim CAT_GP_IMP1 As String = records(RESULT.Columns.Get("CAT_GP_IMP1"))
			Dim CAT_GP_IMP2 As String = records(RESULT.Columns.Get("CAT_GP_IMP2"))
			Dim CAT_GP_PRECIO As String = records(RESULT.Columns.Get("CAT_GP_PRECIO"))
			Dim CAT_GP_CLASIF As String = records(RESULT.Columns.Get("CAT_GP_CLASIF"))
			Dim CAT_GP_STS As String = records(RESULT.Columns.Get("CAT_GP_STS"))
			Dim CAT_GP_TIPO As String = records(RESULT.Columns.Get("CAT_GP_TIPO"))
			Dim CAT_GP_SUBTIPO As String = records(RESULT.Columns.Get("CAT_GP_SUBTIPO"))
			Dim CAT_GP_IMG() As Byte = records(RESULT.Columns.Get("CAT_GP_IMG"))
			Dim CAT_GP_ALMACEN As Int = records(RESULT.Columns.Get("CAT_GP_ALMACEN"))
		'	Dim CAT_GP_DEV As String = records(RESULT.Columns.Get("CAT_GP_DEV"))
			Dim CAT_GP_TIPOPROD As Int = records(RESULT.Columns.Get("CAT_GP_TIPOPROD"))
			Dim CAT_GP_INICIATIVA As Int = records(RESULT.Columns.Get("CAT_GP_INICIATIVA"))
			'CAT_GP_INICIATIVA = 5
		'	
		 '  starter.skmt.execNonQuery2("INSERT INTO CAT_GUNAPROD(CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_DEV) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_DEV))
	      		   starter.skmt.execNonQuery2("INSERT INTO CAT_GUNAPROD(CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD,CAT_GP_INICIATIVA) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD, CAT_GP_INICIATIVA))

		   
         Next
       Listo2=1
	   
	   
	   If PB2.Progress = 0 Then
			PB2.Progress = 30
			S_CP.Text = "CARGANDO"
		ELSE If PB2.Progress = 30 Then
			PB2.Progress = 60
		ELSE IF PB2.Progress = 60 Then
			PB2.Progress = 100
			S_CP.Text = "LISTO"
		End If
		
		
	   ToastMessageShow("Productos Actualizados." , True)

	   If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
       Activity_Resume
	   img2.Visible=False
	   EJECUTANDO=0
	   
	   End If
	      
	   End If
	 End If

	If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "gunaprodp" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   	Dim CAT_GP_ID As String = records(RESULT.Columns.Get("CAT_GP_ID"))
			Dim CAT_GP_NOMBRE As String = records(RESULT.Columns.Get("CAT_GP_NOMBRE"))
			Dim CAT_GP_IMP1 As String = records(RESULT.Columns.Get("CAT_GP_IMP1"))
			Dim CAT_GP_IMP2 As String = records(RESULT.Columns.Get("CAT_GP_IMP2"))
			Dim CAT_GP_PRECIO As String = records(RESULT.Columns.Get("CAT_GP_PRECIO"))
			Dim CAT_GP_CLASIF As String = records(RESULT.Columns.Get("CAT_GP_CLASIF"))
			Dim CAT_GP_STS As String = records(RESULT.Columns.Get("CAT_GP_STS"))
			Dim CAT_GP_TIPO As String = records(RESULT.Columns.Get("CAT_GP_TIPO"))
			Dim CAT_GP_SUBTIPO As String = records(RESULT.Columns.Get("CAT_GP_SUBTIPO"))
			Dim CAT_GP_IMG() As Byte = records(RESULT.Columns.Get("CAT_GP_IMG"))
			Dim CAT_GP_ALMACEN As Int = records(RESULT.Columns.Get("CAT_GP_ALMACEN"))
			Dim CAT_GP_TIPOPROD As Int = records(RESULT.Columns.Get("CAT_GP_TIPOPROD"))
			CAT_GP_TIPOPROD = "5"
					If CAT_GP_ID = "PAQUNI003" Then
						CAT_GP_ALMACEN = 60
					End If
		   starter.skmt.execNonQuery2("INSERT INTO CAT_GUNAPROD(CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD))
	      
		   
				Next
				If PB2.Progress = 0 Then
					PB2.Progress = 30
					S_CP.Text = "CARGANDO"
				ELSE If PB2.Progress = 30 Then
					PB2.Progress = 60
				ELSE IF PB2.Progress = 60 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
	   ToastMessageShow("Promociones  Actualizados." , True)

       Listo4=1
	   If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
       Activity_Resume
	   img2.Visible=False
	   EJECUTANDO=0
	   Else If Listo4 = 1 And Listo3 = 1 And inve = 1 Then
       Activity_Resume
	   img2.Visible=False
	   EJECUTANDO=0
       End If
	      
	   End If
	 End If

If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "gunaprodps" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   	Dim CAT_GP_ID As String = records(RESULT.Columns.Get("CAT_GP_ID"))
			Dim CAT_GP_NOMBRE As String = records(RESULT.Columns.Get("CAT_GP_NOMBRE"))
			Dim CAT_GP_IMP1 As String = records(RESULT.Columns.Get("CAT_GP_IMP1"))
			Dim CAT_GP_IMP2 As String = records(RESULT.Columns.Get("CAT_GP_IMP2"))
			Dim CAT_GP_PRECIO As String = records(RESULT.Columns.Get("CAT_GP_PRECIO"))
			Dim CAT_GP_CLASIF As String = records(RESULT.Columns.Get("CAT_GP_CLASIF"))
			Dim CAT_GP_STS As String = records(RESULT.Columns.Get("CAT_GP_STS"))
			Dim CAT_GP_TIPO As String = records(RESULT.Columns.Get("CAT_GP_TIPO"))
			Dim CAT_GP_SUBTIPO As String = records(RESULT.Columns.Get("CAT_GP_SUBTIPO"))
			Dim CAT_GP_IMG() As Byte = records(RESULT.Columns.Get("CAT_GP_IMG"))
			Dim CAT_GP_ALMACEN As Int = records(RESULT.Columns.Get("CAT_GP_ALMACEN"))
			Dim CAT_GP_TIPOPROD As Int = records(RESULT.Columns.Get("CAT_GP_TIPOPROD"))
		'	
		   starter.skmt.execNonQuery2("INSERT INTO CAT_GUNAPROD(CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG,CAT_GP_ALMACEN,CAT_GP_TIPOPROD) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_IMP1,CAT_GP_IMP2,CAT_GP_PRECIO,CAT_GP_CLASIF,CAT_GP_STS,CAT_GP_TIPO,CAT_GP_SUBTIPO,CAT_GP_IMG, CAT_GP_ALMACEN,CAT_GP_TIPOPROD))
	      
		   
				Next
				If PB2.Progress = 0 Then
					PB2.Progress = 30
					S_CP.Text = "CARGANDO"
				ELSE If PB2.Progress = 30 Then
					PB2.Progress = 60
				ELSE IF PB2.Progress = 60 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
	   ToastMessageShow("Promociones especiales  Actualizados." , True)

       Listo4=1
	   If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
       Activity_Resume
	   img2.Visible=False
	   EJECUTANDO=0
	   Else If Listo4 = 1 And Listo3 = 1 And inve = 1 Then
       Activity_Resume
	   img2.Visible=False
	   EJECUTANDO=0
       End If
	      
	   End If
	 End If



    If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "detallepaq" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   	Dim CAT_DP_ALMACEN  As String = records(RESULT.Columns.Get("CAT_DP_ALMACEN"))
			Dim CAT_DP_ID As String = records(RESULT.Columns.Get("CAT_DP_ID"))
			Dim CAT_DP_IDPROD As String = records(RESULT.Columns.Get("CAT_DP_IDPROD"))
			Dim CAT_DP_TIPO As String = records(RESULT.Columns.Get("CAT_DP_TIPO"))
			Dim CAT_DP_PZAS As String = records(RESULT.Columns.Get("CAT_DP_PZAS"))
			Dim CAT_DP_USUARIO  As String = records(RESULT.Columns.Get("CAT_DP_USUARIO"))
			Dim CAT_DP_FECHA As String = records(RESULT.Columns.Get("CAT_DP_FECHA"))
			Dim CAT_DP_REGALO  As String = records(RESULT.Columns.Get("CAT_DP_REGALO"))
			Dim CAT_DP_CLASIF  As String = records(RESULT.Columns.Get("CAT_DP_CLASIF"))
			Dim CAT_DP_PRECIO As String = records(RESULT.Columns.Get("CAT_DP_PRECIO"))
			Dim CAT_DP_PRECIO_SIMPTOS As String = records(RESULT.Columns.Get("CAT_DP_PRECIO_SIMPTOS"))

			
			

		   starter.skmt.execNonQuery2("INSERT INTO CAT_DETALLES_PAQ(CAT_DP_ALMACEN,CAT_DP_ID,CAT_DP_IDPROD,CAT_DP_TIPO,CAT_DP_PZAS,CAT_DP_USUARIO,CAT_DP_FECHA,CAT_DP_REGALO,CAT_DP_CLASIF,CAT_DP_PRECIO,CAT_DP_PRECIO_SIMPTOS) VALUES (?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_DP_ALMACEN,CAT_DP_ID,CAT_DP_IDPROD,CAT_DP_TIPO,CAT_DP_PZAS,CAT_DP_USUARIO,CAT_DP_FECHA,CAT_DP_REGALO,CAT_DP_CLASIF,CAT_DP_PRECIO,CAT_DP_PRECIO_SIMPTOS))
	      
		   
				Next
		 
				If PB2.Progress = 0 Then
					PB2.Progress = 30
					S_CP.Text = "CARGANDO"
				ELSE If PB2.Progress = 30 Then
					PB2.Progress = 60
				ELSE IF PB2.Progress = 60 Then
					PB2.Progress = 100
					S_CP.Text = "LISTO"
				End If
        Listo3 =1
	   If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
       Activity_Resume
	   img2.Visible=False
	   EJECUTANDO=0
       Else If Listo4 = 1 And Listo3 = 1 And inve = 1 Then
       Activity_Resume
	   img2.Visible=False
	   EJECUTANDO=0
       End If
	   
	   End If
	 End If

   If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "hist_datos" Then 'query tag
	   	
         For Each records() As Object In RESULT.Rows
           
		   	Dim HVD_CLIENTE As String = records(RESULT.Columns.Get("HVD_CLIENTE"))
			Dim HVD_PRONOMBRE As String = records(RESULT.Columns.Get("HVD_PRONOMBRE"))
			Dim HVD_CANT As String = records(RESULT.Columns.Get("HVD_CANT"))
			Dim HVD_COSTO_TOT As String = records(RESULT.Columns.Get("HVD_COSTO_TOT"))

		   starter.skmt.execNonQuery2("INSERT INTO HIST_VENTAS(HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT) VALUES (?,?,?,?)", Array As Object (HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT))
	      
		   
         Next
        Listo3 =1
		
		If PB1.Progress = 0 Then
			PB1.Progress = 30
			S_CH.Text = "CARGANDO"
		ELSE If PB1.Progress = 30 Then
			PB1.Progress = 60
		ELSE IF PB1.Progress = 60 Then
			PB1.Progress = 100
			S_CH.Text = "LISTO"
		End If
		
	   ToastMessageShow("Venta historico Actualizado." , True)

	   If Listo1 =1 And Listo2 =1 And Listo3 = 1 And Listo4 = 1 Then
       Activity_Resume
	   img2.Visible=False
	   EJECUTANDO=0

	   End If
	   
	   End If
	 End If




     If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "variables" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   Dim Cat_Va_Descripcion As String = records(RESULT.Columns.Get("CAT_VA_DESCRIPCION"))
           Dim Cat_Va_Valor As String = records(RESULT.Columns.Get("CAT_VA_VALOR"))

		   starter.skmt.execNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object (Cat_Va_Descripcion, Cat_Va_Valor))
	   
		   
         Next
       End If
		End If
    
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "CUESTIONARIO" Then 'query tag
				For Each records() As Object In RESULT.Rows
           
					Dim Cat_Va_Valor As String = records(RESULT.Columns.Get("CAT_VALOR"))

					starter.skmt.execNonQuery2("DELETE FROM CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As Object ("CUESTIONARIO"))
	   
					starter.skmt.execNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("CUESTIONARIO", Cat_Va_Valor))
	   
		   
				Next
			End If
		End If
    
If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "valida_pedido" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   Dim CUANTOSP As Int = records(RESULT.Columns.Get("CUANTOSP"))
           
           If cuantos_pedido < = CUANTOSP Then
        	  ' ToastMessageShow("rojo val ok 1 cuantosp." , True)
		      datos_iguales = "ok"
			  S_CP.Text = "INFO OK"
		   Else
        	   ToastMessageShow("No se cargo bien la info P. Sync Nuevamente" & CUANTOSP & " " & cuantos_pedido, True)
		      S_CP.Text = "ENVIAR DATOS (K-2)"
		   End If
		   
		   
         Next
       End If
	 End If 
    
If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "valida_pedidoc" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   Dim CUANTOSC As Int = records(RESULT.Columns.Get("CUANTOSC"))
           
           If cuantos_pedidosc = CUANTOSC Then
        	  ' ToastMessageShow("rojo val ok 1 cuantosp." , True)
		      datos_iguales = "ok"
		   Else
        	   ToastMessageShow("No se cargo bien la info C. Sync Nuevamente"  & CUANTOSC & " " & cuantos_pedidosc, True)
		   
		   End If
		   
		   
         Next
       End If
	 End If 

If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "valida_noventa" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   Dim CUANTOSN As Int = records(RESULT.Columns.Get("CUANTOSN"))
           
           If cuantos_noventa = CUANTOSN Then
          ' ToastMessageShow("rojo val ok 1 cuantosp." , True)
		      datos_iguales = "ok"
		   Else
        	   ToastMessageShow("No se cargo bien la info N. Sync Nuevamente"  & CUANTOSN & " " & cuantos_noventa, True)
		      
		   End If
		   
		   
         Next
       End If
	 End If 

	 If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "ins_pedido" Then 'query tag
       	    For Each records() As Object In RESULT.Rows
		
		PB2.Progress = PB2.Progress + 5
			S_CP.Text = "SUBIENDO"
			  
		Next
		PB2.Progress = 100
			S_CP.Text = "LISTO"
		
       End If
	 End If 
	 
	 If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "version" Then 'query tag
         For Each records() As Object In RESULT.Rows
           starter.skmt.execNonQuery("delete from VERSION")
		   Dim CAT_VE_VERSION As String = records(RESULT.Columns.Get("CAT_VE_VERSION"))
           
		  starter.skmt.execNonQuery2("INSERT INTO VERSION(NOVERSION) VALUES (?)", Array As Object (CAT_VE_VERSION))
	     				   
         Next
       End If
	 End If 
	 
	If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "count_cli" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   COUNT_CLIE = records(RESULT.Columns.Get("COUNT_CLIE"))
        
		   
						   
		   
         Next
       End If
	 End If  
	
	If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "ruta" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   Dim VALIDO As String = records(RESULT.Columns.Get("VALIDO"))
		              
		   If VALIDO = "OK" Then
		                   cargar.Visible = True
			      		   Subir.Visible = True
						   inv.Visible = True 
						   connecta.Visible = False
			      		   If conn = "1" Then
			      		   ToastMessageShow("Existe Conexión con el Servidor." , True)
		   				   End If
		   Else
						   cargar.Visible = False
			      		   Subir.Visible = False
						   inv.Visible = False 
						   connecta.Visible = False
			      		   
		   End If
         Next
       End If
	 End If  
	
	 If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "usuario" Then 'query tag
	   
         For Each records() As Object In RESULT.Rows
           Dim name2 As String = records(RESULT.Columns.Get("VALIDO"))
           

         Next
		 If name2 = "OK" Then
		 PASO = 1
		 End If
		 P1.Visible = False
       End If
	 End If

	 
	 If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "fecha" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   	Dim FECHA_HOY As String = records(RESULT.Columns.Get("FECHA"))
		  starter.skmt.execNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("FECHA"))
		  starter.skmt.execNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("FECHA",FECHA_HOY))
	      
        Next
        
	   End If
	 End If

	 If Job.JobName = "DBRequest" Then
       Dim RESULT As DBResult = reqManager.HandleJob(Job)
       If RESULT.Tag = "folio" Then 'query tag
         For Each records() As Object In RESULT.Rows
           
		   	Dim FOLIO As String = records(RESULT.Columns.Get("FOLIO"))
		  starter.skmt.execNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("FOLIO"))
		  starter.skmt.execNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("FOLIO",FOLIO))
	      
        Next
        
	   End If
	 End If
	
	 
   Job.Release
     
End If	
	 
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(Main)
            'Return True
    End If
    ' Returning False signals the system to handle the key
    Return False
End Sub

Sub connecta_Click
	connecta1 = connecta1 + 1
    imei = "" 'p.GetDeviceId
	conn = "1"
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name = "select_version_DANV"
	reqManager.ExecuteQuery(cmd , 0, "version")
	
	If imei = "" Then
		
	cmd.Initialize
	cmd.Name = "select_ruta_DANV_4"
	cmd.Parameters = Array As Object(ALMACEN,e_ruta.text,imei)
	reqManager.ExecuteQuery(cmd , 0, "ruta")
	Else
		Dim cmd As DBCommand
		cmd.Initialize
		cmd.Name = "select_ruta_DANV_4"
		cmd.Parameters = Array As Object(ALMACEN,e_ruta.text,imei)
		reqManager.ExecuteQuery(cmd , 0, "ruta")
	
	End If
	
	If e_ruta.Text = "KMTS1" Then
		cargar.Visible = True
		Subir.Visible = True
		e_ruta.Text = ""
	End If
	
	If e_ruta.Text = "BERNA1" Then
		cargar.Visible = True
		Subir.Visible = True
		e_ruta.Text = ""
	End If
	
	
	
	ToastMessageShow("Validando Conexión." , True)
	
	
	If connecta1 / 2  = 1 Then
		'SERVER = "http://177.244.63.54:1782"
		'SERVER = "http://keymon.com.mx:1782"
		'SERVER = "http://201.99.139.28:1782"
		SERVER = "http://187.189.244.154:1782"
		reqManager.Initialize(Me, SERVER)
	Else
		'SERVER = "http://keymon.com.mx:1782"
		'SERVER = "http://201.99.139.28:1782"
		'SERVER = "http://177.244.63.54:1782"
		SERVER = "http://187.189.244.154:1782"
		reqManager.Initialize(Me, SERVER)
			
	End If
End Sub
Sub BUSCA_Click
	StartActivity(BUSCAR)
End Sub

Sub b_mapa_Click
	StartActivity(mapas)
	
End Sub
Sub e_ruta_EnterPressed
	If e_ruta.Text = "FIN DIA" Then
	RES =  Msgbox2("Seguro que desa hacer el cierre todos los datos se borraran?","Cierre", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
	If RES = DialogResponse.POSITIVE Then

	   e_ruta.Text = ""
	   	starter.skmt.execNonQuery("delete from pedido_cliente")
	   	starter.skmt.execNonQuery("delete from pedido")
	   	starter.skmt.execNonQuery("delete from noventa")
	   	starter.skmt.execNonQuery("delete from clie_act")
  		starter.skmt.execNonQuery("delete from kmt_info")
    	starter.skmt.execNonQuery("delete from cat_gunaprod")
    	starter.skmt.execNonQuery("delete from CAT_DETALLES_PAQ")
		starter.skmt.execNonQuery("delete from HIST_VENTAS")
		starter.skmt.execNonQuery("delete from HIST_VERIFICACION")
		starter.skmt.execNonQuery("DELETE FROM HIST_ENCUESTA")
		starter.skmt.execNonQuery("DELETE FROM HIST_STAY_OUT")
		starter.skmt.execNonQuery("DELETE FROM HIST_GPS")
			
			
		
		starter.skmt.execNonQuery("INSERT INTO HIST_STAY_OUT(HSO_INI, HSO_FIN) VALUES (0,0)")
			

		Activity_Resume
	End If
    End If
	If e_ruta.Text = "IWL" Then
	'	trabajar.Visible = False
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
		img3.Visible =True
		Resumen.Visible= False
		   
	End If
	If e_ruta.Text = "SUPLENCIA" Then
	E_RUTA2.Visible = True	   
	ImageView9.Visible = True
	End If
	
End Sub
Sub inv_Click
	img2.Visible =True
	EJECUTANDO = 1
    inve = 1
	starter.skmt.execNonQuery("delete from cat_gunaprod")
	starter.skmt.execNonQuery("delete from CAT_DETALLES_PAQ")

	c=starter.skmt.execQuery("select usuario from usuarioa")
		c.Position = 0
		usuario = c.GetString("USUARIO")
	

	
	cmd.Initialize
	cmd.Name = "select_cat_gunaprod_DANV"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprod")
	
		
	cmd.Initialize
	cmd.Name = "select_cat_paquetes_DANV"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodp")
	
	
	cmd.Initialize
	cmd.Name = "select_cat_detallepa_DANV"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "detallepaq")
	

	
	cargar.Visible = False
	Subir.Visible = False
	connecta.Visible = True
    inv.Visible = False	
	ToastMessageShow("Se Actualizaran los datos, Este proceso podria tardar hasta un minuto, gracias" , True)
	
End Sub
Sub t1_tick 
	
	cmd.Initialize
	cmd.Name = "select_cuantos_pedido_DANV"
	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
	reqManager.ExecuteQuery(cmd , 0, "valida_pedido")
	
	cmd.Initialize
	cmd.Name = "select_cuantos_noventa_DANV"
	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
	reqManager.ExecuteQuery(cmd , 0, "valida_noventa")
	
	cmd.Initialize
	cmd.Name = "select_cuantos_pedidoc_DANV"
	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
	reqManager.ExecuteQuery(cmd , 0, "valida_pedidoc")
	
	If PB2.Progress = 0 Then
		S_CP.Text = "ENVIAR DATOS (K-1)"
	End If
	   img2.Visible=False
    t1.Enabled = False
End Sub
Sub B_OK_PAS_Click

If CARGA = "SUBIR" And S_CP.Text = "INFO OK" Then
	
P1.Visible = False
Btn_Ubicar.Visible=True
'trabajar.Visible = True
	NUEVO.Visible =True
	BUSCA.Visible=True
	connecta.Visible=True
	Resumen.Visible= True
	img2.Visible=False
Else If CARGA = "SUBIR" And S_CP.Text = "ERROR" Then
	 Msgbox("Tiene que subir de nuevo la información","Atención")
		P1.Visible = False
	'	trabajar.Visible = True
		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		img2.Visible=False

Else if CARGA = "SUBIR" And S_CP.Text <> "INFO OK" Then
	RES =  Msgbox2("Seguro que desa abortar el proceso","Cierre", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
	If RES = DialogResponse.POSITIVE Then
		P1.Visible = False
	'	trabajar.Visible = True
		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		img2.Visible=False
		ExitApplication
	End If
		
End If

If CARGA = "CARGAR" And S_CP.Text = "LISTO" And S_CC.Text = "LISTO" And S_CH.Text = "LISTO" Then
	
P1.Visible = False
		Btn_Ubicar.Visible=True
'trabajar.Visible = True
	NUEVO.Visible =True
	BUSCA.Visible=True
	connecta.Visible=True
	Resumen.Visible= True
	img2.Visible=False
Else if CARGA = "CARGAR" And (S_CP.Text <> "LISTO" Or S_CC.Text <> "LISTO" Or S_CH.Text <> "LISTO") Then
	RES =  Msgbox2("Seguro que desa abortar el proceso","Cierre", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
	If RES = DialogResponse.POSITIVE Then
		P1.Visible = False
'		trabajar.Visible = True
		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		img2.Visible=False
		starter.skmt.execNonQuery("delete from kmt_info")
	starter.skmt.execNonQuery("delete from cod_result")
	starter.skmt.execNonQuery("delete from hist_gest")
	starter.skmt.execNonQuery("delete from cat_gunaprod")
	starter.skmt.execNonQuery("delete from CAT_DETALLES_PAQ")
	starter.skmt.execNonQuery("delete from telefonos")
	starter.skmt.execNonQuery("delete from HIST_VENTAS")
	starter.skmt.execNonQuery("delete from HIST_PROMOS")
	starter.skmt.execNonQuery("delete from HIST_CLIENTE_CANT_PROMOS")
	starter.skmt.execNonQuery("delete from PROMOS_COMP")
	starter.skmt.execNonQuery("delete from CAT_VERIFICACION")
		ExitApplication
	End If
	
End If


'-------------
'------------- TODO ESTE CODIGO ES PARA CUANDO APLICAN DESUCENTOS.
'
'    Dim cmd As DBCommand'
'	cmd.Initialize
'	cmd.Name = "select_usuario_guna_super_GV2"
'	cmd.Parameters = Array As Object(USUARIO1.Text, CLAVE.Text)
'	reqManager.ExecuteQuery(cmd , 0, "usuario")
 'If PASO = 1 Then
'c=starter.skmt.execQuery("select usuario from usuarioa")
''		c.Position = 0
'		usuario = c.GetString("USUARIO")
'	c.Close
' PEDIO_CLIENTE
'	c=starter.skmt.execQuery("SELECT PC_CLIENTE, PC_FECHA, PC_USER, PC_NOART, PC_MONTO,PC_LON, PC_LAT, PC_COSTO_SIN, PC_RUTA, PC_ALMACEN FROM PEDIDO_CLIENTE ")
'	d=starter.skmt.execQuery("SELECT COUNT(*) as CUANTOS_PEDIDOSC FROM PEDIDO_CLIENTE ")
'		If c.RowCount>0 Then
'	     For i=0 To c.RowCount -1
'		     c.Position=i
'			 
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_pedidos_GV2"
'				cmd.Parameters = Array As Object(C.GetString("PC_CLIENTE"),C.GetString("PC_FECHA"),C.GetString("PC_USER"),C.GetString("PC_NOART"),C.GetString("PC_MONTO"),C.GetString("PC_LON"),C.GetString("PC_LAT"),ALMACEN,l_ruta.text,C.GetString("PC_COSTO_SIN") )
'				reqManager.ExecuteQuery(cmd , 0,"inst_pedidos")
'
'	     Next
'	    c.Close
'	    End If
'	d.Position=0
'	 cuantos_pedidosc = D.GetString("CUANTOS_PEDIDOSC")
'	d.Close
'	
'	' PEDIO
'	c=starter.skmt.execQuery("SELECT PE_CEDIS,PE_COSTO_TOT,PE_COSTOU,PE_CANT,PE_PRONOMBRE,PE_PROID,PE_CLIENTE,PE_FECHA,PE_USUARIO, PE_COSTO_SIN, PE_RUTA, PE_DESC FROM PEDIDO")
'	d=starter.skmt.execQuery("SELECT COUNT(*) as CUANTOS_PEDIDO FROM PEDIDO")
'	
'		If c.RowCount>0 Then
'	     For i=0 To c.RowCount -1
'		     c.Position=i
'			 
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_pedido_GV2"
'				cmd.Parameters = Array As Object(C.GetString("PE_CEDIS"),ALMACEN,C.GetString("PE_COSTO_TOT"),C.GetString("PE_COSTOU"),C.GetString("PE_CANT"),C.GetString("PE_PRONOMBRE"),C.GetString("PE_PROID"),C.GetString("PE_CLIENTE"),C.GetString("PE_FECHA"),C.GetString("PE_USUARIO"),C.GetString("PE_RUTA"), C.GetString("PE_COSTO_SIN"),C.GetString("PE_DESC"))
'				reqManager.ExecuteQuery(cmd , 0, "ins_pedido")
'
'	     Next
'	    c.Close
'	    End If
'	d.Position=0
'	 cuantos_pedido = D.GetString("CUANTOS_PEDIDO")
'	d.Close
'	
'	' NOVENTA
'	c=starter.skmt.execQuery("SELECT  NV_CLIENTE,NV_FECHA,NV_USER,NV_MOTIVO,NV_COMM,NV_LAT,NV_LON FROM NOVENTA")
'	D=starter.skmt.execQuery("SELECT  COUNT(*) AS CUANTOS_NOVENTA FROM NOVENTA")
'	
'		If c.RowCount>0 Then
'	     For i=0 To c.RowCount -1
'		     c.Position=i
'			 
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_noventa_GV2"
'				cmd.Parameters = Array As Object(C.GetString("NV_CLIENTE"),C.GetString("NV_FECHA"),C.GetString("NV_USER"),C.GetString("NV_MOTIVO"),C.GetString("NV_COMM"),C.GetString("NV_LAT"),C.GetString("NV_LON"), ALMACEN, l_ruta.Text)
'				reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
'
'	     Next
'	    c.Close
'	    End If
'	d.Position=0
'	 cuantos_noventa = D.GetString("CUANTOS_NOVENTA")
'	d.Close
'		
'	' DROP
'
 '  t1.Initialize("T1", 60000) ' 1000 = 1 second
  ' t1.Enabled = True
   'Dim cmd As DBCommand
	'cmd.Initialize
'	cmd.Name ="insert_drop_GV2"
'	cmd.Parameters = Array As Object(usuario,l_ruta.Text,fecha, l_porvisitar.Text,l_drop.Text,l_efectiva.Text,l_cuantosc.Text,l_cuantosn.Text, L_MONTOD.Text)
'	reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
 '  img2.Visible =True
'	
'	
'	
'		ToastMessageShow("Se Actualizaran los datos, Este proceso podria tardar hasta un minuto, gracias "& l_ruta.text , True)
'
 'USUARIO1.Text = ""
 'CLAVE.Text = ""
' End If
 '
End Sub

Sub NUEVO_Click
	StartActivity(nuevocliente)
End Sub

Sub B_OK_RES_Click
'	trabajar.Visible = True
		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		P_RESUMEN.Visible=False
		Panel4.Visible = False
	SCROLL_RESDIA.Visible = False
	Btn_Ubicar.Visible=True
End Sub

Sub Resumen_Click
	P_RESUMEN.Visible = True
'	trabajar.Visible = False
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	cargar.Visible=False
	Resumen.Visible= False

'	d=starter.skmt.execQuery("select distinct CAT_GP_CLASIF AS CAT_GP_CLASIF FROM cat_gunaprod")
'	If D.RowCount>0 Then
'		For i=0 To D.RowCount -1
'			D.Position=i
'			c=starter.skmt.execQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where pe_proid in (Select CAT_GP_ID from cat_gunaprod where CAT_GP_CLASIF = ? )", Array As String(d.GetString("CAT_GP_CLASIF")))
'			c.Position = 0
'			
'			
'			Dim label1 As Label
'			label1 = L_MARCAS.TwoLinesLayout.Label
'			label1.TextSize = 13
'			label1.TextColor = Colors.Black
'			Dim label2 As Label
'			label2 = L_MARCAS.TwoLinesLayout.SecondLabel
'			label2.TextSize = 13
'			label2.TextColor = Colors.Black
'			L_MARCAS.AddTwoLines(d.GetString("CAT_GP_CLASIF"),"VENTA :"  & c.GetString("MONTO_DIA")  )
'		Next
'	End If
'	
'	
'	c.Close
	
	
	
'	c=starter.skmt.execQuery("SELECT HVD_MARCA, CLIENTES FROM MARCAS_RUTAS ORDER BY CLIENTES")
'	L_MARCAS.Clear
'	If c.RowCount>0 Then
'		For i=0 To c.RowCount -1
'			c.Position=i
'			Dim label1 As Label
'			label1 = L_MARCAS.TwoLinesLayout.Label
'			label1.TextSize = 13
'			label1.TextColor = Colors.Black
'			Dim label2 As Label
'			label2 = L_MARCAS.TwoLinesLayout.SecondLabel
'			label2.TextSize = 13
'			label2.TextColor = Colors.Black
'			L_MARCAS.AddTwoLines(c.GetString("HVD_MARCA"), c.GetString("CLIENTES") & "NECESITAS : 250")
'		Next
'	End If
'	
	
End Sub

Sub CARGA_Click
	StartActivity(colonia2)
End Sub

Sub resdia_Click
'	P_RESUMEN.Visible = True
	Btn_Ubicar.Visible=False
	SCROLL_RESDIA.Visible = True
	SCROLL_RESDIA.Panel.LoadLayout("RESDIA")
	SCROLL_RESDIA.Panel.Height = Panel4.Height
	Panel4.Visible = True
	
'	trabajar.Visible = False
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	cargar.Visible=False
	Resumen.Visible= False
'	
'	d=starter.skmt.execQuery("select distinct CAT_GP_CLASIF AS CAT_GP_CLASIF FROM cat_gunaprod")
'	If D.RowCount>0 Then
'		For i=0 To D.RowCount -1
'			D.Position=i
'			c=starter.skmt.execQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where pe_proid in (Select CAT_GP_ID from cat_gunaprod where CAT_GP_CLASIF = ? )", Array As String(d.GetString("CAT_GP_CLASIF")))
'			c.Position = 0
'			
'			
'			Dim label1 As Label
'			label1 = L_MARCAS.TwoLinesLayout.Label
'			label1.TextSize = 13
'			label1.TextColor = Colors.Black
'			Dim label2 As Label
'			label2 = L_MARCAS.TwoLinesLayout.SecondLabel
'			label2.TextSize = 13
'			label2.TextColor = Colors.Black
'			L_MARCAS.AddTwoLines(d.GetString("CAT_GP_CLASIF"),"VENTA :"  & c.GetString("MONTO_DIA")  )
'		Next
'	End If
'	
'	
'	c.Close
	
	d=starter.skmt.execQuery2("select COUNT(*) AS CUANTOS FROM HIST_ENCUESTA WHERE  HE_TIPO = ?", Array As String("TELEFONO"))
	d.Position = 0
	 l_encuesta.Text = d.GetString("CUANTOS") 
	d.Close
	
	
	L_MARCAS.CLEAR
	d=starter.skmt.execQuery2("select distinct HE_CLIE AS CLIENTE FROM HIST_ENCUESTA WHERE  HE_TIPO = ?", Array As String("TELEFONO"))
	If D.RowCount>0 Then
		For i=0 To D.RowCount -1
			D.Position=i
			c=starter.skmt.execQuery2("Select  HE_RES from HIST_ENCUESTA where  HE_CLIE = ?  AND HE_TIPO = ?", Array As String(d.GetString("CLIENTE"), "TELEFONO"))
			c.Position = 0
			
			
			Dim label1 As Label
			label1 = L_MARCAS.TwoLinesLayout.Label
			label1.TextSize = 13
			label1.TextColor = Colors.Black
			Dim label2 As Label
			label2 = L_MARCAS.TwoLinesLayout.SecondLabel
			label2.TextSize = 13
			label2.TextColor = Colors.Black
			L_MARCAS.AddTwoLines(d.GetString("CLIENTE"),"TELEFONO :"  & c.GetString("HE_RES")  )
		Next
	End If
	
	
	c.Close
	
	

	c=starter.skmt.execQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_CLIENTE <> 0 and pe_proid in (Select CAT_GP_ID from cat_gunaprod where CAT_GP_TIPO = ? )", Array As String("RTEC"))
	c.Position = 0
	l_monto_k.Text = c.GetString("MONTO_DIA")
	If l_monto_k.Text = "null" Then
		l_monto_k.Text = "0"
	End If
	c.Close
	
	c=starter.skmt.execQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_CLIENTE <> 0 and pe_proid in (Select CAT_GP_ID from cat_gunaprod where CAT_GP_TIPO = ? )", Array As String("PING"))
	c.Position = 0
	l_monto_kp.Text = c.GetString("MONTO_DIA")
	If l_monto_kp.Text = "null" Then
		l_monto_kp.Text = "0"
	End If
	c.Close
			
	
'	c=starter.skmt.execQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_CLIENTE <> 0 and pe_proid in (Select CAT_GP_ID from cat_gunaprod where CAT_GP_TIPO = ? )", Array As String("SALTY SNACKS"))
'	c.Position = 0
'	l_monto_ks.Text = c.GetString("MONTO_DIA")
'	If l_monto_ks.Text = "null" Then
'		l_monto_ks.Text = "0"
'	End If
'
'	c.Close
	c=starter.skmt.execQuery("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_CLIENTE <> 0 ")
	c.Position = 0
	l_monto_ks.Text = c.GetString("MONTO_DIA")
	If l_monto_ks.Text = "null" Then
		l_monto_ks.Text = "0"
	End If

	c.Close
	
	L_REAL.Text = l_monto_ks.Text
	L_ALCANCE.Text = Round2((L_NES.Text / L_REAL.Text + 1),2)
	L_VPLAN.Text = l_porvisitar.Text
	L_VREAL.Text = L_CUANTOST.text
	L_EFEC_VIS.Text = Round2(L_VREAL.text / L_VPLAN.Text,2)
	L_VISITCC.Text = l_cuantosc.text
	L_EFEC_PV.Text = Round2(L_VISITCC.Text / L_VREAL.Text,2)
	L_EFEC_PURA.Text = Round2(L_VISITCC.Text / L_VPLAN.Text,2)
	L_LIN_TICK.Text = LPT
	
	If l_monto_ks.Text <> "0" Then
		
		c=starter.skmt.execQuery2("Select  COUNT(DISTINCT(PE_CLIENTE)) AS CUANTOS FROM PEDIDO WHERE PE_CEDIS =  ? ", Array As String(ALMACEN))
		c.Position = 0
		L_CTE_PROMO.Text = c.GetString("CUANTOS")
		c.Close
		d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_TIPOPROD = ?) ", Array As String("PRIORITARIO"))
		d.Position = 0
		L_PRIO.Text =NumberFormat(d.GetString("MONTO_DIA"),0,2)
		d.Close
		
		d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_TIPOPROD = ?) ", Array As String("ESTRATEGICO"))
		d.Position = 0
		L_SECUND.Text =d.GetString("MONTO_DIA")
		d.Close

		d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_TIPOPROD = ?) ", Array As String("COMPLEMETARIO"))
		d.Position = 0
		L_COMP.Text =d.GetString("MONTO_DIA")
		d.Close
	
	Else
		L_PRIO.Text = "0"
		L_SECUND.Text = "0"
		L_COMP.Text = "0"
		
		
	End If
	
	
	'Private L_CTE_PROMO As Label
	'Private L_REDEN_PROMO As Label
	'Private L_LIN_TICK As Label
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("UNILEVER"))
	If d.RowCount > 0 Then
	d.Position = 0
	L_UNILEVER.Text =d.GetString("MONTO_DIA")
	d.Close
	End If
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("QUALA"))
	d.Position = 0
	L_QUALA.Text =d.GetString("MONTO_DIA")
	d.Close
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("FERRERO"))
	d.Position = 0
	L_FERRERO.Text =d.GetString("MONTO_DIA")
	d.Close
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("EMPACADORA SAN MARCOS"))
	d.Position = 0
	L_SANMARCOS.Text =d.GetString("MONTO_DIA")
	d.Close
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("CAMPARI"))
	d.Position = 0
	L_CAMPARI.Text =d.GetString("MONTO_DIA")
	d.Close
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("UPFIELD"))
	d.Position = 0
	L_IBERIA.Text =d.GetString("MONTO_DIA")
	d.Close
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("BEPENSA"))
	d.Position = 0
	L_BEPENSA.Text =d.GetString("MONTO_DIA")
	d.Close
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("SC JOHNSON"))
	d.Position = 0
	L_SCJ.Text =d.GetString("MONTO_DIA")
	d.Close
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("MEAD JOHNSON"))
	d.Position = 0
	L_MEDJ.Text =d.GetString("MONTO_DIA")
	d.Close
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("DURACELL"))
	d.Position = 0
	L_DURACELL.Text =d.GetString("MONTO_DIA")
	d.Close
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("GUNA"))
	d.Position = 0
	L_GUNA.Text =d.GetString("MONTO_DIA")
	d.Close
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("KIMBERLY CLARK"))
	d.Position = 0
	L_KIMB.Text =d.GetString("MONTO_DIA")
	d.Close
	
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("TRES MONTES"))
	If d.RowCount > 0 Then
	d.Position = 0
	L_TRESM.Text =d.GetString("MONTO_DIA")
	End If
	d.Close
		
	d=starter.skmt.execQuery2("Select sum(PE_COSTO_TOT) AS MONTO_DIA FROM PEDIDO WHERE PE_PROID IN (select CAT_GP_ID from cat_gunaprod where  CAT_GP_CLASIF = ?) ", Array As String("RED BULL"))
	d.Position = 0
	L_REDB.Text =d.GetString("MONTO_DIA")
	d.Close
	
	
'	L_UNILEVER.Text  = L_REAL.Text
	L_ACUMULADO.Text = L_REAL.Text
	
	c=starter.skmt.execQuery("Select  COUNT(*) AS CUANTOS FROM PEDIDO WHERE PE_CEDIS = PE_PROID ")
	c.Position = 0
	If c.GetString("CUANTOS") > 0 Then
		d=starter.skmt.execQuery("Select  sum(pe_cant) AS CUANTOS FROM PEDIDO WHERE PE_CEDIS = PE_PROID ")
		d.Position = 0
		L_CTE_PROMO.Text = d.GetString("CUANTOS")
		d.Close
		L_REDEN_PROMO.TEXT = Round2(L_VISITCC.Text / L_CTE_PROMO.Text,2)
	Else
		L_CTE_PROMO.Text = 0
		L_REDEN_PROMO.Text = 0
	End If
	c.Close
	d=starter.skmt.execQuery("Select  COUNT(*) AS CUANTOS FROM PEDIDO ")
	d.Position = 0
	L_LIN_TICK.Text = Round2(d.GetString("CUANTOS") / L_VISITCC.Text,2)
	d.Close
	
	
	d=starter.skmt.execQuery("Select  count(*) as CUANTOS  from HIST_CUOTAS ")
	d.Position = 0
	
	If d.GetString("CUANTOS") > 0 Then
	
	
'	c=starter.skmt.execQuery("Select  HC_CUOTA1,HC_CUOTA2,HC_CUOTA3 from HIST_CUOTAS ")
'	c.Position = 0
'	l_monto_c1.Text = Round( c.GetString("HC_CUOTA1") / 6)
'	l_monto_c2.Text = Round(c.GetString("HC_CUOTA2") / 6)
'	l_monto_c3.Text = Round(c.GetString("HC_CUOTA3") / 6)
''		
'		
'	c.Close
	Else
		l_monto_c1.Text = 4000
		l_monto_c2.Text = 2000
		l_monto_c3.Text = 1000
	End If
'
	
	
'	
'	c=starter.skmt.execQuery("SELECT HVD_MARCA, CLIENTES FROM MARCAS_RUTAS ORDER BY CLIENTES")
'	L_MARCAS.Clear
'	If c.RowCount>0 Then
'		For i=0 To c.RowCount -1
'			c.Position=i
'			Dim label1 As Label
'			label1 = L_MARCAS.TwoLinesLayout.Label
'			label1.TextSize = 13
'			label1.TextColor = Colors.Black
'			Dim label2 As Label
'			label2 = L_MARCAS.TwoLinesLayout.SecondLabel
'			label2.TextSize = 13
'			label2.TextColor = Colors.Black
'			L_MARCAS.AddTwoLines(c.GetString("HVD_MARCA"), c.GetString("CLIENTES") & "NECESITAS : 250")
'		Next
'	End If
'	
	
End Sub

Sub hacer_ped_Click
	StartActivity(colonia)
End Sub

Sub nvo_cliente_Click
	StartActivity(nuevocliente)
End Sub

Sub tickets_dia_Click
	StartActivity(BUSCAR)
End Sub

Sub GPS_LocationChanged (Location1 As Location)
	lat_gps=Location1.Latitude
	lon_gps=Location1.Longitude
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	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))

'	DateTime.TimeFormat = "HHmmss"
'	sTime=DateTime.Time(DateTime.Now)
'	starter.skmt.execNonQuery2("UPDATE HIST_STAY_STORE set HSS_IN = ?  where HSS_CODIGO In (select cuenta from cuentaa)", Array As Object(sTime))
'	starter.skmt.execNonQuery2("UPDATE HIST_STAY_OUT set HSO_INI = ?  where HSO_INI = 0 ", Array As Object(sTime))
'	DateTime.TimeFormat = "HH:mm:ss"


End Sub

Sub Btn_Ubicar_Click
	StartActivity(MAPA_RUTAS)
End Sub

'''''''''''''''''''''''''''''''''''' VALIDAR CARACTERES
Sub e_ruta_TextChanged (Old As String, New As String)
	Dim validChars As String ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
  
	Try
		If validChars.Contains(New.SubString(New.Length-1)) = False Then
			e_ruta.Text = New.SubString2(0, New.Length-1)
			e_ruta.SelectionStart = e_ruta.Text.Length
		End If

	Catch
		Log(LastException)
	End Try
End Sub

Sub B_COMM_Click
	Btn_Ubicar.Visible=False
	SCROLL_RESDIA.Visible = True
	SCROLL_RESDIA.Panel.LoadLayout("COMIS")
	SCROLL_RESDIA.Panel.Height = Panel_C.Height
	Panel4.Visible = False
	Panel_C.Visible = True
	
'	trabajar.Visible = False
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	cargar.Visible=False
	Resumen.Visible= False
'	
	If l_ruta.Text <> 0 Then
	c=starter.skmt.execQuery("Select  HCM_TOTAL_V , HCM_TOTAL_VIVE , HCM_TOTAL_GUNA ,	HCM_TOTAL_BEB   from HIST_COMISIONES_MOVIL ")
	c.Position = 0
		L_TOTAL_BA.Text = c.GetString("HCM_TOTAL_BEB")
		L_TOTAL_GUNA.Text = c.GetString("HCM_TOTAL_GUNA")
		L_TOTAL_MM.Text = c.GetString("HCM_TOTAL_V")
		L_TOTAL_VIVE.Text = c.GetString("HCM_TOTAL_VIVE")
	
	c.Close
	
		L_TOTAL_COMIS.Text = 0
	Else
		L_TOTAL_BA.Text = 0
		L_TOTAL_GUNA.Text = 0
		L_TOTAL_MM.Text = 0
		L_TOTAL_VIVE.Text = 0
		L_TOTAL_COMIS.Text = 0
		
	End If
	

End Sub

Sub B_OK_COMISS_Click
	NUEVO.Visible =True
	BUSCA.Visible=True
	connecta.Visible=True
	Resumen.Visible= True
	P_RESUMEN.Visible=False
	Panel_C.Visible = False
	SCROLL_RESDIA.Visible = False
	Btn_Ubicar.Visible=True
End Sub