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

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
     Dim reqManager As DBRequestManager
	 Dim conectado As String
	 Dim skmt As SQL
	 Dim t1 As Timer
	 Dim t2 As Timer
	Dim Printer1 As EscPosPrinter
	Dim SERIAL11 As Serial

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 c As Cursor
	Dim d As Cursor
	Dim b As Cursor
	Dim e As Cursor
	Dim f 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 MARCASQ As String
	Private B_PROXIMA As Button
	Private l_monto_a As Label
	Private ImageView9 As ImageView
	Private L_MONTO_R As Label
	Dim PERFIL As String
	Dim NUMERO_PEDIDO As String
	Private l_cambios As Label
	Private l_monto_ks As Label
	Private l_monto_kp As Label
	Private l_monto_k As Label
	Private Cuantos As String
	Dim btAdmin As BluetoothAdmin
	Dim cmp20 As Serial
	Dim printer As TextWriter
	Dim PairedDevices As Map
	Dim TAMANO As Int
	Dim ESPACIO As Int
	Dim BLANCO As String
	Dim sDate,sTime As String
	Dim PASA_IMP As String
	Dim s As Cursor
	Private B_IMP As Button
	Private l_monto_c1 As Label
	Private l_monto_c2 As Label
	Private l_monto_c3 As Label
	Private TIEMPO As String
	Private t3 As Timer
End Sub

Sub Activity_Create(FirstTime As Boolean)
    EJECUTANDO=1
	'SERVER = "http://177.244.63.54:1782"
	'SERVER = "http://201.99.139.28:1782"
	SERVER = "http://keymon.lat:1781"
	
	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
	
	' 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=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=skmt.ExecQuery("Select count(*) as CUANTOS from pedido_cliente")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
	d=skmt.ExecQuery("select count(*) as TOTAL_VISITAR from kmt_info where gestion = 0")
	D.Position=0
    b.Close
	e=skmt.ExecQuery("select count(*) as POR_VISITAR from kmt_info")
	e.Position=0
	f=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=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=skmt.ExecQuery("select  sum(pc_monto) as MONTO_DIA, count(pc_cliente) AS CLIENTES_DIA  from pedido_cliente ") 
	b=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
	
	
	If FirstTime Then
		Printer1.Initialize(Me, "Printer1")
	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://keymon.lat:1781"
	'SERVER = "http://201.99.139.28:1782"
	'SERVER = "http://177.244.63.54:1782"
	'SERVER = "http://38.123.201.97:1782"
	c=skmt.ExecQuery2("select count(*) as CUANTOS from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("SERVER"))
	c.Position =0
	If c.GetString("CUANTOS") = 0 Then
		skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("SERVER",SERVER))
	Else
		c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("SERVER"))
		c.Position =0
		SERVER = c.GetString("CAT_VA_VALOR")
	End If
	
		reqManager.Initialize(Me, SERVER)
	
	PASO =0
'    c=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
	c=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=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
	
	
	
	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=skmt.ExecQuery("Select count(*) as CUANTOS from pedido_cliente where pc_cliente <> 0")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")
	ToastMessageShow(Cuantos , True)

	d=skmt.ExecQuery("select count(*) as TOTAL_VISITAR from kmt_info where gestion = 0 and  cat_cl_codigo <> 0")
	D.Position=0
    b.Close
	e=skmt.ExecQuery("select count(*) as POR_VISITAR from kmt_info where cat_cl_codigo <> 0")
	e.Position=0
	f=skmt.ExecQuery("select count(*) as CAT_CL_RUTA from kmt_info where cat_cl_codigo <> 0")
	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=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")
	d.Close
	e.Close
	Else
	
		c=skmt.ExecQuery2("select  sum(pe_cant) as CAMBIOS from pedido where substr(pe_pronombre,1,6) = ?", Array As String("CAMBIO"))
		c.Position = 0
		l_cambios.Text = c.GetString("CAMBIOS")
		c.Close
		
		c=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 = ? Or CAT_GP_TIPO = ?)", Array As String("HEALTHY DRINKS", "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=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("SNACKS"))
		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=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		
		
		s=skmt.ExecQuery("Select COUNT(*) AS CUANTOS from HIST_CUOTAS ")
		s.Position = 0
		If s.GetString("CUANTOS") > 0 Then
			
		c=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
		End If
		

		
	c=skmt.ExecQuery("select  sum(pc_monto) as MONTO_DIA, count(pc_cliente) AS CLIENTES_DIA  from pedido_cliente where pc_cliente <> 0") 
	b=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")
	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 = (c.GetString("CLIENTES_DIA") + b.GetString("CUANTOS"))/ d.GetString("TOTAL_VISITAR")
	l_drop.Text = Round(drop * 100) 
	 If l_drop.Text  + l_efectiva.Text < 100 Then
	 ImageView3.Bitmap = LoadBitmap(File.DirAssets, "tache_rojo.png")
	 Else If l_drop.Text  + l_efectiva.Text > =  100  And l_drop.Text  + l_efectiva.Text < 130 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") < 2500 Then
	 ImageView5.Bitmap = LoadBitmap(File.DirAssets, "tache_rojo.png")
	 Else if c.GetString("MONTO_DIA") > =  2500  And c.GetString("MONTO_DIA") < 4000 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=skmt.ExecQuery("select usuario from usuarioa")
	c.Position = 0
	usuario = c.GetString("USUARIO")
	c.Close

	c=skmt.ExecQuery("select  ID_ALMACEN from CAT_ALMACEN")
	C.Position =0
	ALMACEN = C.GetString("ID_ALMACEN")
	C.Close
	'ALMACEN = 1
	
	
	
	'If IsConnectedToInternet Then
	'	c=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=skmt.ExecQuery2("SELECT HIST_VI_IMAGEN FROM HIST_VISITAS WHERE HIST_VI_CREDITO =?", Array As String (c.GetString("HIST_VI_CREDITO")))
	'			'			s.Position =0
	'		 
	'			Dim cmd As DBCommand
	'			cmd.Initialize
	'			cmd.Name = "insert_gps_actual_PRO"
	'			cmd.Parameters = Array As Object(c.GetString("hgdate"),c.GetString("hglat"),c.GetString("hglon"),usuario )
	'			'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_gps_actual_PRO"
'				'		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
'		
	'	End If

'	cmp20.Initialize("Printer")


	
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")
	c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("MARCAS"))
	c.Position =0
	MARCASQ = c.GetString("CAT_VA_VALOR")
	c.Close
	skmt.ExecNonQuery("delete from CAT_GUNAPROD WHERE CAT_GP_CLASIF NOT IN (" & MARCASQ &")" )
	skmt.ExecNonQuery("delete from CAT_GUNAPROD WHERE CAT_GP_ID IN (SELECT CAT_DP_ID FROM CAT_DETALLES_PAQ WHERE CAT_DP_IDPROD NOT IN (SELECT CAT_GP_ID FROM CAT_GUNAPROD))")
	StartActivity(colonia)
	
End Sub


Sub Subir_Click
	CARGA = "SUBIR"
	P1.Visible = True
	trabajar.Visible = False
	B_PROXIMA.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


PASO = 1
'End If
	If PASO =1 Then
	
	
	
		c=skmt.ExecQuery2("select count(*) AS CUANTOS from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("PERFIL"))
		c.Position =0
		PERFIL = c.GetString("CUANTOS")
		c.Close
	
		If PERFIL > 0 Then
			c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("PERFIL"))
			c.Position =0
			PERFIL = c.GetString("CAT_VA_VALOR")
			c.Close
		End If

		c=skmt.ExecQuery2("select  count(*) AS CUANTOS  from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("NUMERO_PEDIDO"))
		c.Position =0
		Cuantos =  c.GetString("CUANTOS")
		c.Close		
  		If Cuantos > 0 Then
		c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("NUMERO_PEDIDO"))
		c.Position =0
		NUMERO_PEDIDO = c.GetString("CAT_VA_VALOR")
		c.Close
		End If
	skmt.ExecNonQuery("delete from pedido_cliente where PC_CLIENTE not In (select PE_CLIENTE from pedido)")
c=skmt.ExecQuery("select usuario from usuarioa")
		c.Position = 0
		usuario = c.GetString("USUARIO")
	c.Close
	
		'DROP
	
		Dim cmd As DBCommand
		cmd.Initialize
		cmd.Name ="insert_drop_PRO"
		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,"ENVIO")
		reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
		
' PEDIO_CLIENTE
	c=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=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_PRO"
				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 EXIBIDOR
	'	c=skmt.ExecQuery("SELECT CAT_CL_CLIENTE,CAT_CL_EXHIBIDOR,CAT_CL_BEXHIBIDOR FROM HIST_EXIBIDORES")
	'	If c.RowCount>0 Then
	'		For i=0 To c.RowCount -1
	'			c.Position=i
	'		 
	'			Dim cmd As DBCommand
	'			cmd.Initialize
	'			cmd.Name = "insert_EXIBIDOR_PRO"
	'			cmd.Parameters = Array As Object(C.GetString("CAT_LO_CUENTA"),C.GetString("CAT_CL_EXHIBIDOR"),C.GetString("CAT_CL_BEXHIBIDOR"),ALMACEN,l_ruta.text )
	'			reqManager.ExecuteQuery(cmd , 0,"ins_QR")
'
'			Next
'			c.Close
'		End If
	
		' ENVIO DE LOS CODIGOS QR
	c=skmt.ExecQuery("SELECT CAT_CL_NUM_SERIEFISICO,CAT_CL_CODIGO ,CAT_CL_LONG,CAT_CL_LAT FROM kmt_info")
		If c.RowCount>0 Then
	     For i=0 To c.RowCount -1
		     c.Position=i
			 
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_QR_PRO"
				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 )
				reqManager.ExecuteQuery(cmd , 0,"ins_QR")

	     Next
	    c.Close
	    End If
	
	
		' MANDA LA INFO DE LOS CLIENTES CON LOS NUEVOS GPS
		c=skmt.ExecQuery("SELECT CLIENTE, LAT, LON  FROM CLIENTES_GPS")
		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
				c.Position=i
			 
				Dim cmd As DBCommand
				cmd.Initialize
				cmd.Name = "insert_ACT_CLIE_GPS_PRO"
				cmd.Parameters = Array As Object(C.GetString("CLIENTE"),C.GetString("LAT"),C.GetString("LON") )
				reqManager.ExecuteQuery(cmd , 0,"ins_QR")

			Next
			c.Close
		End If
	
	
	' PEDIO
	c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("FOLIO"))
	c.Position =0 
    armafolio = 0
	' l_ruta.text * 1000000
	'armafolio = armafolio + c.GetString("CAT_VA_VALOR")
	c.Close
		c=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_TIPO FROM PEDIDO WHERE PE_FOLIO IS NULL")
	
	
		If c.RowCount>0 Then
	     For i=0 To c.RowCount -1
		     c.Position=i
			 	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 = 0
	'armafolio - (l_ruta.Text * 1000000)
 	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")

	
		If PERFIL = "V-ESPECIAL" Then

		
			c=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,PE_TIPO FROM PEDIDO ORDER BY PE_CLIENTE")
	d=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_esp_PRO"
				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"), c.GetString("PE_TIPO"),NUMERO_PEDIDO )
				reqManager.ExecuteQuery(cmd , 0, "ins_pedido")

	     Next
	    c.Close
			End If
		Else
			c=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,PE_TIPO FROM PEDIDO")
			d=skmt.ExecQuery("SELECT COUNT(*) as CUANTOS_PEDIDO FROM PEDIDO")
	TIEMPO = 0
			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_PRO"
					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"), c.GetString("PE_TIPO"))
					reqManager.ExecuteQuery(cmd , 0, "ins_pedido")

					TIEMPO =  TIEMPO + 1
					
					If TIEMPO  > 20 Then
						'	Msgbox("M","A")
						If L_P_2.Text = "Envio de Pedidos" Then
							L_P_2.Text = "Envio de Pedidos --"
						else if  L_P_2.Text = "Envio de Pedidos --" Then
							L_P_2.Text = "Envio de Pedidos \"
						else if L_P_2.Text = "Envio de Pedidos \" Then
							L_P_2.Text = "Envio de Pedidos |"
						else if L_P_2.Text = "Envio de Pedidos |" Then
							L_P_2.Text = "Envio de Pedidos /"
						else if L_P_2.Text = "Envio de Pedidos /" Then
							L_P_2.Text = "Envio de Pedidos --"
						End If
						t3.Initialize("T3", 2000) ' 1000 = 1 second
						t3.Enabled = True
						Wait For  t3_tick
						TIEMPO = 0
			 	
					End If

				Next
				c.Close
			End If
		
	End If
	d.Position=0
	 cuantos_pedido = D.GetString("CUANTOS_PEDIDO")
	d.Close
	
	' NOVENTA
	c=skmt.ExecQuery("SELECT  NV_CLIENTE,NV_FECHA,NV_USER,NV_MOTIVO,NV_COMM,NV_LAT,NV_LON FROM NOVENTA")
	D=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_PRO"
				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
	
	' VERIFICACION
'	c=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_PRO"
'				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
		'
	
'		c=skmt.ExecQuery("select HGDATE, HGLAT, HGLON from HIST_GPS")
'	
'	
'		'' HACER ESTO PARA EL FORANEO
'		If c.RowCount>0 Then
'			For i=0 To c.RowCount -1
'				c.Position=i
'				's=skmt.ExecQuery2("SELECT HIST_VI_IMAGEN FROM HIST_VISITAS WHERE HIST_VI_CREDITO =?", Array As String (c.GetString("HIST_VI_CREDITO")))
'				's.Position =0
'			 
'				Dim cmd As DBCommand
'				cmd.Initialize
'				cmd.Name = "insert_gps_actual_PRO"
'				cmd.Parameters = Array As Object(c.GetString("hgdate"),c.GetString("hglat"),c.GetString("hglon"),usuario )
'				'cmd.Parameters = Array As Object(C.GetString("HGDATE"),C.GetString("HGLAT"),C.GetString("HGLON") )
'	
'				reqManager.ExecuteQuery(cmd , 0, "")
'			
'		
'
'				'		Dim cmd As DBCommand
'				'		cmd.Initialize
'				'		cmd.Name = "update_gps_actual_PRO"
'				'		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
'	
'	
		'' PARA LA ENCUESTA
	
		
		c=skmt.ExecQuery("select HE_CUENTA, HE_MANEJA, HE_RES1, HE_RES2, HE_RES3, HE_RES4,HE_FECHA,HE_USUARIO from HIST_ENCUESTA")
	
	
		If c.RowCount>0 Then
			For i=0 To c.RowCount -1
			c.Position=i
			's=skmt.ExecQuery2("SELECT HIST_VI_IMAGEN FROM HIST_VISITAS WHERE HIST_VI_CREDITO =?", Array As String (c.GetString("HIST_VI_CREDITO")))
			's.Position =0
			 
			Dim cmd As DBCommand
			cmd.Initialize
			cmd.Name = "insert_ENCUESTA_PRO"
			cmd.Parameters = Array As Object(c.GetString("HE_CUENTA"),c.GetString("HE_MANEJA"),c.GetString("HE_RES1"),c.GetString("HE_RES2"),c.GetString("HE_RES3"),c.GetString("HE_RES4"),c.GetString("HE_FECHA"),c.GetString("HE_USUARIO"))
			'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_gps_actual_PRO"
				'		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
	
	
		
	' DROP

   t1.Initialize("T1", 20000) ' 1000 = 1 second
   t1.Enabled = True
 
   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

	P1.Visible = True
	trabajar.Visible = False
	B_PROXIMA.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=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
	
	skmt.ExecNonQuery2("delete from kmt_info where substr(CAT_CL_CODIGO,1,1) <> ?", Array As Object ("N"))
	skmt.ExecNonQuery("delete from cod_result")
	skmt.ExecNonQuery("delete from hist_gest")
	skmt.ExecNonQuery("delete from cat_gunaprod")
	skmt.ExecNonQuery("delete from cat_gunaprod2")
	
	skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")
	skmt.ExecNonQuery("delete from telefonos")
	skmt.ExecNonQuery("delete from HIST_VENTAS")
	skmt.ExecNonQuery("delete from HIST_PROMOS")
	skmt.ExecNonQuery("delete from HIST_CLIENTE_CANT_PROMOS")
	skmt.ExecNonQuery("delete from PROMOS_COMP")
	skmt.ExecNonQuery("delete from CAT_VERIFICACION")
	skmt.ExecNonQuery("delete from LISTA_PRECIOS")
	skmt.ExecNonQuery("delete from CAT_PRECIOS")
	skmt.ExecNonQuery("delete from HIST_RMI")
	skmt.ExecNonQuery("delete from TMP_PROMO_ESP_REGALO")
		
	skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("NUMERO_PEDIDO"))
	skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("NUMERO_PEDIDO",0))

	c=skmt.ExecQuery("select usuario from usuarioa")
		c.Position = 0
		usuario = c.GetString("USUARIO")
	
	
	'cmd.Initialize
	'cmd.Name = "Select_count_clie"
	'reqManager.ExecuteQuery(cmd,0,"count_cli")
	
	cmd.Initialize
	cmd.Name = "select_cat_gunaprod_PRO"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprod")
	
	cmd.Initialize
	cmd.Name = "select_cat_gunaprod2_PRO"
	cmd.Parameters = Array As Object(ALMACEN, e_ruta.Text)
	reqManager.ExecuteQuery(cmd , 0, "gunaprod2")

		
	cmd.Initialize
	cmd.Name = "select_cat_paquetes_PRO"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodp")
	
	cmd.Initialize
	cmd.Name = "select_cat_paquetess_PRO"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodps")
	
	
	cmd.Initialize
	cmd.Name = "select_cat_detallepa_PRO"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "detallepaq")
	
	
	cmd.Initialize
	cmd.Name = "select_cat_clientes_guna_PRO"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "kmt_datos")
	
	cmd.Initialize
	cmd.Name = "select_hist_datos_PRO"
	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_PRO"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_promos")
	
	cmd.Initialize
	cmd.Name = "select_hist_cliente_promos_PRO"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_cliente_promos")
	
	cmd.Initialize
	cmd.Name = "select_promo_comp_PRO"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_comp_promos")
	
	cmd.Initialize
	cmd.Name = "select_verificacion_PRO"
	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_PRO"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "folio")
	
	' esto es para sacar el perfil y marcas del usuario
	cmd.Initialize
	cmd.Name = "select_perfil_PRO"
	cmd.Parameters = Array As Object(usuario)
	reqManager.ExecuteQuery(cmd , 0, "perfil")

	cmd.Initialize
	cmd.Name = "select_marcas_PRO"
	cmd.Parameters = Array As Object(usuario)
	reqManager.ExecuteQuery(cmd , 0, "marcas")
		
	cmd.Initialize
	cmd.Name = "select_precios_PRO"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "precios")
	
	cmd.Initialize
	cmd.Name = "select_promo_esp_2021"
	cmd.Parameters = Array As Object(e_ruta.text)
	reqManager.ExecuteQuery(cmd , 0, "promo_2021")
	
	
	cmd.Initialize
	cmd.Name = "select_hist_rmi1_PRO"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN,e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_rmi")
		
	cmd.Initialize
	cmd.Name = "select_hist_rmi2_PRO"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN,e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_rmi")
	
	cmd.Initialize
	cmd.Name = "select_hist_rmi3_PRO"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN,e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_rmi")
	
	cmd.Initialize
	cmd.Name = "select_hist_rmi4_PRO"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN,e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_rmi")
	
	cmd.Initialize
	cmd.Name = "select_CAMBIOS_PRO"
	'cmd.Parameters = Array As Object( ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "cat_cambios")

	cmd.Initialize
	cmd.Name = "select_SUCURSAL_PRO"
	cmd.Parameters = Array As Object( ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "sucursal")
	
	cmd.Initialize
	cmd.Name = "select_HIST_CUOTAS_PRO"
	cmd.Parameters = Array As Object( ALMACEN,e_ruta.text )
	reqManager.ExecuteQuery(cmd , 0, "CUOTAS")
	
	cmd.Initialize
	cmd.Name = "select_HIST_CLIE_GPS_PRO"
	cmd.Parameters = Array As Object( ALMACEN,e_ruta.text )
	reqManager.ExecuteQuery(cmd , 0, "CUOTAS")
	

		
	' c=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
	'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"))
		Dim CAT_CL_BFACTURA As String = records(RESULT.Columns.Get("CAT_CL_BFACTURA"))
		Dim CAT_CL_BCREDITO As String = records(RESULT.Columns.Get("CAT_CL_BBLOQUEOCRED"))
		
		   
				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,CAT_CL_BFACTURA,CAT_CL_BCREDITO, 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,CAT_CL_BFACTURA,CAT_CL_BCREDITO))
		   
         Next
				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_BFACTURA,CAT_CL_BCREDITO,CAT_CL_MTOCOMPRA,CAT_CL_NUM_SERIEFISICO, gestion) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,0,0) ",Array As Object ("0",e_ruta.TEXT, "VENTA ABORDO","null","null","null","null","null","null","null","null","null","null","null","null","null","null","null","NULL","NULL"))
				skmt.ExecNonQuery("UPDATE kmt_info set gestion = 2  where CAT_CL_CODIGO In (select PE_CLIENTE from PEDIDO)")
	   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 = "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"))

		   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 = 70
				ELSE IF PB1.Progress = 70 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"))

		   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"))
		   

		   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 = 70
				ELSE IF PB1.Progress = 70 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"))
           

		   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 = "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
		'	
					'  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))
					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,CAT_GP_DEV,CAT_GP_CODPROMO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,0)", 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,CAT_GP_DEV))

		   
				Next
				
	'			c=skmt.ExecQuery("select CAT_GP_CLASIF, COUNT(*) AS CUANTOS from CAT_GUNAPROD GROUP BY CAT_GP_CLASIF order by CAT_GP_CLASIF asc")
	'			c.Position=0
	'			skmt.ExecNonQuery("DELETE FROM COUNT_GUNAPROD")
	'			skmt.ExecNonQuery2("INSERT INTO COUNT_GUNAPROD(CAT_GP_CLASIF, CUANTOS) VALUES (?,?)", Array As Object (c.GetString("CAT_GP_CLASIF"), c.GetString("CUANTOS")))
	'			c.Close

       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 = 80
		ELSE IF PB2.Progress = 80 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
	 
		' CARGA DEL CATALOGO ABORDO
	 
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "gunaprod2" 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_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"))
					Dim CAT_GP_CODPROMO As String = records(RESULT.Columns.Get("CAT_GP_CODPROMO"))
					'CAT_GP_INICIATIVA = 5
					'
					 ' 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))
					skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD2(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,CAT_GP_DEV,CAT_GP_CODPROMO) 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,CAT_GP_DEV,CAT_GP_CODPROMO))

		   
				Next
				
				
				c=skmt.ExecQUERY("SELECT COUNT(*) AS CUANTOS FROM PEDIDO")
				c.Position = 0
				cuantos_pedidosc = c.GetString("CUANTOS")
				c.Close
				If cuantos_pedidosc > 0 Then
					c=skmt.ExecQUERY("SELECT PE_PROID, PE_CANT FROM PEDIDO")
					If c.RowCount>0 Then
						For i=0 To c.RowCount -1
							c.Position=i
							skmt.ExecNonQuery2("update CAT_GUNAPROD2 set CAT_GP_ALMACEN = CAT_GP_ALMACEN - ? where CAT_GP_ID = ? ", Array As Object(c.GetString("PE_CANT"),c.GetString("PE_PROID")))
	
						Next
					End If
				End If
				
	'			c=skmt.ExecQuery("select CAT_GP_CLASIF, COUNT(*) AS CUANTOS from CAT_GUNAPROD2 GROUP BY CAT_GP_CLASIF order by CAT_GP_CLASIF asc")
	'			c.Position=0
	'			skmt.ExecNonQuery("DELETE FROM COUNT_GUNAPROD2")
	'			skmt.ExecNonQuery2("INSERT INTO COUNT_GUNAPROD2(CAT_GP_CLASIF, CUANTOS) VALUES (?,?)", Array As Object (c.GetString("CAT_GP_CLASIF"), c.GetString("CUANTOS")))
	'			c.Close

			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"))
'					Dim CAT_GP_DEV As String = records(RESULT.Columns.Get("CAT_GP_DEV"))
		'	
					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_DEV,CAT_GP_CODPROMO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,0)", 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,"0"))
					skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD2(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_DEV,CAT_GP_CODPROMO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,0)", 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,"0"))
					
	      
		   
         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 = 80
		ELSE IF PB2.Progress = 80 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"))
		'	
		   	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))
			skmt.ExecNonQuery2("INSERT INTO CAT_GUNAPROD2(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 = 80
		ELSE IF PB2.Progress = 80 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"))

			
			

		   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 = 80
		ELSE IF PB2.Progress = 80 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"))
			Dim HVD_FECHA As String = records(RESULT.Columns.Get("HVD_FECHA"))
		   skmt.ExecNonQuery2("INSERT INTO HIST_VENTAS(HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT, HVD_FECHA) VALUES (?,?,?,?,?)", Array As Object (HVD_CLIENTE,HVD_PRONOMBRE,HVD_CANT,HVD_COSTO_TOT,HVD_FECHA))
	      
		   
         Next
				Listo3 =1
		
				If PB1.Progress = 0 Then
					PB1.Progress = 30
					S_CH.Text = "CARGANDO"
				ELSE If PB1.Progress = 30 Then
					PB1.Progress = 70
				ELSE IF PB1.Progress = 70 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 = "hist_rmi" 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_PROID As String = records(RESULT.Columns.Get("HVD_PROID"))
					skmt.ExecNonQuery2("INSERT INTO HIST_RMI(HR_CLIENTE,HR_PRONOMBRE,HR_PROID, HR_CANT) VALUES (?,?,?,?)", Array As Object (HVD_CLIENTE,HVD_PRONOMBRE,HVD_PROID, HVD_CANT))
	      
		   
				Next
				Listo3 =1
		
				If PB1.Progress = 0 Then
					PB1.Progress = 30
					S_CH.Text = "CARGANDO"
				ELSE If PB1.Progress = 30 Then
					PB1.Progress = 50
				ELSE IF PB1.Progress = 50 Then
					PB1.Progress = 80
				ELSE If PB1.Progress = 80 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"))

		   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 = "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
           skmt.ExecNonQuery("delete from VERSION")
		   Dim CAT_VE_VERSION As String = records(RESULT.Columns.Get("CAT_VE_VERSION"))
           
		  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"))
		  skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("FECHA"))
		  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"))
		  skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("FOLIO"))
		  skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("FOLIO",FOLIO))
	      
        Next
        
	   End If
		End If
	'perfil
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "perfil" Then 'query tag
				For Each records() As Object In RESULT.Rows
           
					Dim PERFIL As String = records(RESULT.Columns.Get("PERFIL"))
					skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("PERFIL"))
					skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("PERFIL",PERFIL))
	      
				Next
        
			End If
		End If
	' marcas
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "marcas" Then 'query tag
				For Each records() As Object In RESULT.Rows
           
					Dim MARCAS As String = records(RESULT.Columns.Get("MARCAS"))
					skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("MARCAS"))
					skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("MARCAS",MARCAS))
	      
				Next
        
			End If
		End If
		' SUCURSAL
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "sucursal" Then 'query tag
				For Each records() As Object In RESULT.Rows
           
					Dim SUCURSAL As String = records(RESULT.Columns.Get("SUCURSAL"))
					skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("SUCURSAL"))
					skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("SUCURSAL",SUCURSAL))
	      
				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"))
					
					
					
					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
		
		
		' cambios
	
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "cat_cambios" Then 'query tag
				For Each records() As Object In RESULT.Rows
           
					Dim CAMBIOS As String = records(RESULT.Columns.Get("CAT_VA_VALOR"))
					skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("CAMBIOS"))
					skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("CAMBIOS",CAMBIOS))
					
				Next
        
			End If
		End If
	
		' promo espacial 2021
		
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "promo_2021" Then 'query tag
				For Each records() As Object In RESULT.Rows
           
					Dim CAT_ESP_CLIENTE As String = records(RESULT.Columns.Get("CLIENTE"))
					Dim CAT_ESP_MONTO As String = records(RESULT.Columns.Get("MONTO"))
					Dim CAT_ESP_REGALO As String = records(RESULT.Columns.Get("REGALO"))
					
					skmt.ExecNonQuery2("INSERT INTO TMP_PROMO_ESP_REGALO(CLIENTE , MONTO , REGALO ) VALUES (?,?,?)", Array As Object (CAT_ESP_CLIENTE,CAT_ESP_MONTO,CAT_ESP_REGALO))
					
					
					
				Next
        
			End If
		End If
	
		
		' precios
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "precios" 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_PRECIO As String = records(RESULT.Columns.Get("CAT_GP_PRECIO"))
					Dim CAT_GP_PRECIO1 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO1"))
					Dim CAT_GP_PRECIO2 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO2"))
					Dim CAT_GP_PRECIO3 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO3"))
					Dim CAT_GP_PRECIO4 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO4"))
					Dim CAT_GP_PRECIO5 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO5"))
					Dim CAT_GP_PRECIO6 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO6"))
					Dim CAT_GP_PRECIO7 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO7"))
					Dim CAT_GP_PRECIO8 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO8"))
					Dim CAT_GP_PRECIO9 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO9"))
					Dim CAT_GP_PRECIO10 As String = records(RESULT.Columns.Get("CAT_GP_PRECIO10"))
				
				
					skmt.ExecNonQuery2("INSERT INTO CAT_PRECIOS(CAT_GP_ID,CAT_GP_PRECIO, CAT_GP_PRECIO1,CAT_GP_PRECIO2,CAT_GP_PRECIO3,CAT_GP_PRECIO4,CAT_GP_PRECIO5,CAT_GP_PRECIO6,CAT_GP_PRECIO7,CAT_GP_PRECIO8,CAT_GP_PRECIO9) VALUES (?,?,?,?,?,?,?,?,?,?,?)", Array As Object (CAT_GP_ID,CAT_GP_PRECIO, CAT_GP_PRECIO1,CAT_GP_PRECIO2,CAT_GP_PRECIO3,CAT_GP_PRECIO4,CAT_GP_PRECIO5,CAT_GP_PRECIO6,CAT_GP_PRECIO7,CAT_GP_PRECIO8,CAT_GP_PRECIO9))
	      
				Next
				skmt.ExecNonQuery("delete from LISTA_PRECIOS")
				skmt.ExecNonQuery(" insert into LISTA_PRECIOS(PRECIO, CAT_GP_ID, NLISTA)  select cat_gp_precio as precio, cat_gp_id, '1' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO1 As precio, CAT_GP_ID, '2' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO2 As precio, CAT_GP_ID, '3' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO3 As precio, CAT_GP_ID, '4' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO4 As precio, CAT_GP_ID, '5' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO5 As precio, CAT_GP_ID, '6' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO6 As precio, CAT_GP_ID, '7' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO7 As precio, CAT_GP_ID, '8' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO8 As precio, CAT_GP_ID, '9' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO9 As precio, CAT_GP_ID, '10' as NLISTA from CAT_PRECIOS union Select CAT_GP_PRECIO10 As precio, CAT_GP_ID, '11' as NLISTA from CAT_PRECIOS")
				
			'	ToastMessageShow("LISTA DE PRECIOS OK LISTA DE PRECIOS OK", True)
			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
'	c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("RUTA"))
'	c.Position =0
'	If c.GetString("CAT_VA_VALOR") = l_ruta.Text Then
		
	
	connecta1 = connecta1 + 1
'	imei = p.GetDeviceId
	conn = "1"
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name = "select_version_PRO"
	reqManager.ExecuteQuery(cmd , 0, "version")
	
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name = "select_ruta_PRO2_224"
	cmd.Parameters = Array As Object(ALMACEN,e_ruta.text,imei)
	reqManager.ExecuteQuery(cmd , 0, "ruta")
	
	If e_ruta.Text = "ROOT" Then
		cargar.Visible = True
		Subir.Visible = True
		e_ruta.Text = ""
	End If
	ToastMessageShow("Validando Conexión." , True)
	
	

'	Else
'		Msgbox("LA RUTA NO ES CORRECTA","")
'	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 desea hacer el cierre todos los datos se borraran?","Cierre", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
	If RES = DialogResponse.POSITIVE Then

	   e_ruta.Text = ""
	   	skmt.ExecNonQuery("delete from pedido_cliente")
	   	skmt.ExecNonQuery("delete from pedido")
	   	skmt.ExecNonQuery("delete from noventa")
	   	skmt.ExecNonQuery("delete from clie_act")
  		skmt.ExecNonQuery("delete from kmt_info")
			skmt.ExecNonQuery("delete from cat_gunaprod")
			skmt.ExecNonQuery("delete from cat_gunaprod2")
		
    	skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")
		skmt.ExecNonQuery("delete from HIST_VENTAS")
		skmt.ExecNonQuery("delete from HIST_VERIFICACION")
			skmt.ExecNonQuery("delete from HIST_ENCUESTA")
			skmt.ExecNonQuery("delete from CLIENTES_GPS")
			
			
		
			skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("NUMERO_PEDIDO"))
			skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("NUMERO_PEDIDO",0))
		


		Activity_Resume
	End If
    End If
	If e_ruta.Text = "HUGO" Then
		trabajar.Visible = False
		B_PROXIMA.Visible =False
	
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
		img3.Visible =True
		Resumen.Visible= False
		   
	End If
	
End Sub
Sub inv_Click
	img2.Visible =True
	EJECUTANDO = 1
    inve = 1
	skmt.ExecNonQuery("delete from cat_gunaprod")
	skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")

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

	
	cmd.Initialize
	cmd.Name = "select_cat_gunaprod_PRO"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprod")
	
		
	cmd.Initialize
	cmd.Name = "select_cat_paquetes_PRO"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodp")
	
	
	cmd.Initialize
	cmd.Name = "select_cat_detallepa_PRO"
	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_PRO"
	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
	reqManager.ExecuteQuery(cmd , 0, "valida_pedido")
	
	
	t3.Initialize("T3", 5000) ' 1000 = 1 second
	t3.Enabled = True
	Wait For  t3_tick
'	
'	cmd.Initialize
'	cmd.Name = "select_cuantos_noventa_PRO"
'	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
'	reqManager.ExecuteQuery(cmd , 0, "valida_noventa")
'	
'	cmd.Initialize
'	cmd.Name = "select_cuantos_pedidoc_PRO"
'	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
		c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("PERFIL"))
		c.Position =0
		PERFIL = c.GetString("CAT_VA_VALOR")
		c.Close
		c=skmt.ExecQuery2("select CAT_VA_VALOR from CAT_VARIABLES WHERE CAT_VA_DESCRIPCION = ?", Array As String ("NUMERO_PEDIDO"))
		c.Position =0
		NUMERO_PEDIDO = c.GetString("CAT_VA_VALOR")
		c.Close
  
		If PERFIL = "V-ESPECIAL" Then
		skmt.ExecNonQuery2("delete from CAT_VARIABLES where CAT_VA_DESCRIPCION = ?", Array As Object ("NUMERO_PEDIDO"))
		skmt.ExecNonQuery2("INSERT INTO CAT_VARIABLES(CAT_VA_DESCRIPCION, CAT_VA_VALOR) VALUES (?,?)", Array As Object ("NUMERO_PEDIDO",NUMERO_PEDIDO + 1))
	    End If  
P1.Visible = False
		trabajar.Visible = True
		B_PROXIMA.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 desea abortar el proceso","Cierre", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
	If RES = DialogResponse.POSITIVE Then
		P1.Visible = False
		trabajar.Visible = True
			B_PROXIMA.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
		trabajar.Visible = True
		B_PROXIMA.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 desea abortar el proceso","Cierre", "Si", "", "No",LoadBitmap(File.DirAssets,"alert2.png"))
	If RES = DialogResponse.POSITIVE Then
		P1.Visible = False
		trabajar.Visible = True
			B_PROXIMA.Visible =True

		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		img2.Visible=False
		skmt.ExecNonQuery("delete from kmt_info")
	skmt.ExecNonQuery("delete from cod_result")
	skmt.ExecNonQuery("delete from hist_gest")
	skmt.ExecNonQuery("delete from cat_gunaprod")
	skmt.ExecNonQuery("delete from CAT_DETALLES_PAQ")
	skmt.ExecNonQuery("delete from telefonos")
	skmt.ExecNonQuery("delete from HIST_VENTAS")
	skmt.ExecNonQuery("delete from HIST_PROMOS")
	skmt.ExecNonQuery("delete from HIST_CLIENTE_CANT_PROMOS")
	skmt.ExecNonQuery("delete from PROMOS_COMP")
	skmt.ExecNonQuery("delete from CAT_VERIFICACION")
	skmt.ExecNonQuery("delete from HIST_CUOTAS")
		ExitApplication
	End If
	
End If


End Sub

Sub NUEVO_Click
	StartActivity(nuevocliente)
End Sub

Sub B_OK_RES_Click
	trabajar.Visible = True
	B_PROXIMA.Visible =True

		NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		P_RESUMEN.Visible=False
End Sub

Sub Resumen_Click
	P_RESUMEN.Visible = True
	trabajar.Visible = False
	B_PROXIMA.Visible =False

	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	cargar.Visible=False
	Resumen.Visible= False
End Sub

Sub B_PROXIMA_Click
	skmt.ExecNonQuery("delete from CUENTAA")
	skmt.ExecNonQuery2("INSERT INTO CUENTAA VALUES (?)", Array As Object("0"))
	Main.tipov = "ABORDO"
	StartActivity(colonia2)
End Sub

Sub Printer1_Connected (Success As Boolean)
	If Success Then
		ToastMessageShow("Connected successfully", False)
		B_IMP.Enabled = True
	Else
		Msgbox(Printer1.ConnectedErrorMsg, "Error connecting.")
	End If
End Sub

Sub t2_tick
	
	c=skmt.ExecQuery("select USUARIO from usuarioa")
	c.Position=0
	usuario = c.GetString("USUARIO")
	DateTime.DateFormat = "MM/dd/yyyy"
	sDate=DateTime.Date(DateTime.Now)
	sTime=DateTime.Time(DateTime.Now)
	c.Close
	
	TAMANO = 5
	ESPACIO = 21
	BLANCO = " "
	Printer1.WriteString("KELLOG COMPANY MEXICO"  & CRLF)
	Printer1.WriteString("RESUMEN DIA"  & CRLF)
	Printer1.WriteString(sDate & " " &  sTime  & CRLF)
	
	Printer1.WriteString("Vendedor:" & usuario  & CRLF)
	
	
	Printer1.WriteString("-----------INVENTARIO-----------"  & CRLF)
	' aqui es donde esta el pedo de julieta de los descuentos quitar el precio2 pero meter un if para saber si es ruta especial o es normal o que show.
'	s=skmt.ExecQuery("select CAT_GP_ID,CAT_GP_NOMBRE,CAT_GP_ALMACEN  from cat_gunaprod2 ")
'	
'	
'	If S.RowCount>0 Then
'		For i=0 To S.RowCount -1
'			S.Position=i
'	
'			Printer1.WriteString(s.GetString("CAT_GP_NOMBRE")  & CRLF)
'			
'			Printer1.WriteString("CANTIDAD: " &  s.GetString("CAT_GP_ALMACEN")  & CRLF)
'					
'	TAMANO = TAMANO + 1
'		If TAMANO > 40 Then
'			Msgbox(" PAUSA","IMP")
'			TAMANO = 0	
'		End If
'		Next
'	End If
'	s.Close
	'	s=skmt.ExecQuery("select SUM(PE_COSTO_TOT) AS TOTAL FROM PEDIDO")
	'	s.Position =0
	'	If s.GetString("TOTAL") - s.GetString("TOTAL2") <> 0 Then
	'		Printer1.WriteString("Descuento:     $" & 	 (s.GetString("TOTAL2") -  s.GetString("TOTAL")))
	'	End If
	'	Printer1.WriteString("Total Preventa:   $" & s.GetString("TOTAL"))
	'	s.Close
	

	Printer1.WriteString(CRLF)
	Printer1.WriteString("-----------RMI----------------"  & CRLF)
	Printer1.WriteString(CRLF)
	'c=skmt.ExecQuery2("select  count(*) as CUANTOS from pedido where substr(pe_pronombre,1,6) = ? GROUP BY PE_PRONOMBRE", Array As String("CAMBIO"))
	'c.Position =0
	'Cuantos = c.GETSTRING("CUANTOS")
	'c.Close
	'If Cuantos >0 Then
	c=skmt.ExecQuery2("select  SUM(PE_CANT) AS CANTIDAD,PE_PRONOMBRE from pedido where CAT_GP_CLASIF <> ? and  substr(pe_pronombre,1,6) = ? GROUP BY PE_PRONOMBRE", Array As String("PROMOS","CAMBIO"))
	
	If C.RowCount>0 Then
		For i=0 To C.RowCount -1
			C.Position=i
	
			Printer1.WriteString(C.GetString("CANTIDAD") & " " & C.GetString("PE_PRONOMBRE")  & CRLF)
			
					
	
		Next
	End If
	
	c.Close
	'End If
	
	Printer1.WriteString("------------------------------" & CRLF)
	Printer1.WriteString("Nombre y Firma"  & CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString("______________________________" & CRLF)
	Printer1.WriteString("------------------------------" & CRLF)
	Printer1.WriteString(CRLF)
	Printer1.WriteString(CRLF)
	
	
	
	
'	Printer1.Disconnect
	t2.Enabled= False
	trabajar.Visible = True
	B_PROXIMA.Visible =True

	NUEVO.Visible =True
	BUSCA.Visible=True
	connecta.Visible=True
	Resumen.Visible= True
	P_RESUMEN.Visible=False
	
	Msgbox(Main.mac_impresora, "AVISO")
	
End Sub


Sub B_IMP_Click
	Printer1.Disconnect
	t2.Initialize("T2", 4000) ' 1000 = 1 second
	t2.Enabled = True
	
	If Printer1.IsConnected = False Then
		Printer1.Connect
	End If
	
End Sub



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

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

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

	PairedDevices.Initialize

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

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

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

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

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

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

