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

Sub mods
	'V3.04.17 - Se cambio en los queries de "Resumen_Click", "cat_gunaprod" por una "UNION de cat_gunaprod con cat_gunaprod2" para calcular l_monto_k, l_monto_kp, l_monto_ks y l_monto_kc (5 instancias)
End Sub

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 Timer_GIF1 As Timer
	Dim Frame1 As Int
	Dim Awake As PhoneWakeState
	Dim sb As StringBuilder
	Dim PHONE As Phone
	Timer_GIF1.Initialize("Timer1",0)
'	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 T3 As Timer
	Dim c As Cursor
	Dim d As Cursor
	Dim d3 As  Cursor
	Dim b As Cursor
	Dim e As Cursor
	Dim f As Cursor
	Dim D2 As Cursor
	Dim E1 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 HORAINGRESO As String
	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
'	Dim lat_gps, lon_gps 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
	Private TIEMPO As String
	Private i_gif As ImageView
	Dim gif1 As GifDecoder
	Dim ruta As String
	
	Private L_VENTA As Label
	Private L_PREVENTA As Label
	Private L_ABORDO As Label
	
	Dim cuantos_ped As String
	Dim conteo As String
	Private PASO_info As String
	
	Private bpv1 As BatteryProgressView
	Dim batterystatus(11) As Int
	Private bu As BatteryUtilities

	
	Private ImageView12 As ImageView
	
	Private TitleHeight As Int = 50dip
	Private Title2Height As Int = 100dip
	
	Private DividerHeight As Int = 5dip
	Private CLV1 As CustomListView
	Private pnlTitle As B4XView
	Private xui As XUI
	Type TitleData (Title As String)
	
	Private B_MARCAS As Button
	Private Panel5 As Panel
	Private lblTitle As Label
	Private B_OK_PANEL5 As Button
	Private Btn_UbicarR As Button
	Private SUBIR_P As Button
	Private b_e_resumen As Button
	Private cuantos_exib As String
	Dim ime As IME
	Private l_monto_kc As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
	EJECUTANDO=1
	SERVER = Starter.DBReqServer

	If(FirstTime) Then
'		g.Initialize("GPS")
	End If
	If FirstTime Then
		reqManager.Initialize(Me, SERVER)
		Log(SERVER)
	End If
	Activity.LoadLayout("seleccion")
	img2.Visible =False

	' valido donde escribo el archivo de la base de datos de kmt
	ruta = File.DirInternal
Log(SERVER)
	' 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

	c = 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
		skmt.ExecNonQuery2("Update cat_variables set CAT_VA_VALOR = ?  WHERE CAT_VA_DESCRIPCION = ?" , Array As String(DateTime.Time(DateTime.Now),"HoraIngreso"))
	Else
		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"

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 = Starter.DBReqServer
	HORAINGRESO ="000000"
	NUEVO.Visible = True
	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)
	Log(SERVER)
	
	If PASO = 2 Then
		Dim result As Int
		result = Msgbox2("El proceso de enviar información no a terminado, Continuar", "", "Si", "", "No", LoadBitmap(File.DirAssets, "alert2.png"))
		If result = DialogResponse.POSITIVE Then
			VALIDA_INFO
		Else
			PASO = 0
		End If
	Else
		PASO =0
	End If
	
	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
	
	'    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_fechat"
		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 = "yyyyMMddHHmm"
		sDate=DateTime.Date(DateTime.Now)
'		Msgbox("AaaaA " & " "& c.GetString("CAT_VA_VALOR") & " " & sDate & sTime ,"AVISO")

		If c.GetString("CAT_VA_VALOR") > sDate & sTime Then
			Msgbox("AJUSTAR LA FECHA YA QUE ES MENOR AL SISTEMA" ,"AVISO")
			DateTime.TimeFormat = "HH:mm:ss"
			Activity_Resume
		End If
		DateTime.TimeFormat = "MM/dd/yyyyHH:mm:ss"

	End If
	
	
	L_CUANTOST.Text = l_cuantosc.Text + l_cuantosn.Text
	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)
	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

	b=skmt.ExecQuery("Select count(*) as CUANTOS from pedido_cliente where pc_cliente <> 0")
	b.Position=0
	Cuantos = b.GetString("CUANTOS")

	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 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")
	
		L_CUANTOST.Text = l_cuantosc.Text + l_cuantosn.Text

	End If

'	bu.Initialize
'	batterystatus = bu.BatteryInformation
'	
'	sb.Initialize
'	PHONE.Shell("ping -c1 -W1 google.com",Null, sb,Null)
'
'	c = skmt.ExecQuery2("select count(CAT_VA_DESCRIPCION) as HoraIngreso from cat_variables where CAT_VA_DESCRIPCION = ? ", Array As String("HoraIngreso"))
'	c.Position = 0
'	
'	'Valida si ya se cuenta con hora para enviar cada 5 min-----------
'	If c.GetString("HoraIngreso") > 0 Then
'		D2 = 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
'	DateTime.TimeFormat = "HHmmss"
'
'	If 	HORAINGRESO + 500 < DateTime.Time(DateTime.Now) Then
'
'	
'		If sb.Length  > 2  And sb.ToString.SubString2(110,114) <> "smit" 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
'					'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")
'				
'					cmd.Initialize
'					cmd.Name = "select_fechat"
'					reqManager.ExecuteQuery(cmd , 0, "fechat")
'	
'				
'					Dim cmd As DBCommand
'					cmd.Initialize
'					cmd.Name = "UPDATE_DURK_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.ExecuteCommand(cmd,"inst_visitas")
'					skmt.ExecNonQuery2("Update cat_variables set CAT_VA_VALOR = ?  WHERE CAT_VA_DESCRIPCION = ?" , Array As String(DateTime.Time(DateTime.Now),"HoraIngreso"))
'
'	
'	
'					'		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
'		End If
'	End If

	Main.montoActual = L_MONTOD.Text
	Main.clientestotal = L_CUANTOST.Text
	Main.clientesventa =  l_cuantosc.Text
	Main.clientesvisitados = l_porvisitar.TEXT
	Main.ALMACEN = ALMACEN
	Main.rutapreventa =  l_ruta.text
	
	DateTime.TimeFormat = "HH:mm:ss"

	c=skmt.ExecQuery("select NOVERSION FROM VERSION")
	c.Position = 0
	
	If c.GetString("NOVERSION")  <> "2.6" Then
		Msgbox("VERSION INCORRECTA SOLICITAR O DESCARGAR LA NUEVA","ALERTA")
		Activity_Resume
	End If
	CallSub(Starter,"ENVIA_ULTIMA_GPS")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
	cargar.Visible = False
	Subir.Visible = False
	SUBIR_P.Visible = False
	
	connecta.Visible = True
	inv.Visible = False
	If PASO = 1 Then
		PASO = 2
	End If
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
	Awake.KeepAlive(True)
	CARGA = "SUBIR"
	P1.Visible = True
	trabajar.Visible = False
	B_PROXIMA.Visible =False
	Btn_UbicarR.Visible=False
	
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	SUBIR_P.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
	PORCENTAJE = 0
	
	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
	PB2.Visible = True
	conteo = 0
	'i_gif.Visible = True
'	load_gif

	PASO = 1
	'End If
	If PASO =1 Then
		E1=skmt.ExecQuery2("Select  count(*) As CUANTOS from pedido where PE_TIPO = ?", Array As String("ABORDO"))
		E1.Position = 0
		If E1.GetString("CUANTOS") > 0 Then
		
			c=skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_TIPO = ?", Array As String("ABORDO"))
			c.Position = 0
			L_ABORDO.Text = c.GetString("MONTO_DIA")
			c.Close
		Else
			L_ABORDO.Text = 0
		End If
		E1.Close

	

		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
		Else
			NUMERO_PEDIDO = 0
		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
		d3=skmt.ExecQuery("SELECT SUM(PE_COSTO_TOT) as MONTO FROM PEDIDO")
		d3.Position = 0
		Dim cmd As DBCommand
		cmd.Initialize
		cmd.Name ="UPDATE_INFO_E_DURK"
		cmd.Parameters = Array As Object(d3.GetDouble("MONTO")- L_ABORDO.text, L_ABORDO.Text, d3.GetDouble("MONTO"),l_ruta.TEXT, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
		Dim cmd As DBCommand
		cmd.Initialize
		cmd.Name ="insert_drop2_DUR"
		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", ALMACEN, L_VENTA.Text, L_PREVENTA.Text, L_ABORDO.Text, l_cambios.TEXT)
		reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
		d3.Close
		' 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_DUR"
				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
	
		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_DUR"
				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
	
		c=skmt.ExecQuery("SELECT  HE_CLIE, HE_RES, HE_FECHA, HE_TIPO FROM HIST_ENCUESTA")
	'	S_CP.Text = "Envio Encuesta"
	'	PB2.Progress = 1
		
		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_DUR"
				cmd.Parameters = Array As Object(C.GetString("HE_CLIE"),C.GetString("HE_RES"),C.GetString("HE_FECHA"), c.GetString("HE_TIPO"),l_ruta.Text )
				reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
				
				
			Next
			
		End If
		c.Close
		' PEDIO
	
		skmt.ExecNonQuery("update PEDIDO set PE_FOLIO = rowid ")

		'
'	c=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=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 = 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")
			d.Position=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_esp_DUR"
					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")
			d.Position=0
			TIEMPO = 0
			If c.RowCount>0 Then
				For i=0 To c.RowCount -1
					c.Position=i
					TIEMPO =  TIEMPO + 1
					
					If TIEMPO  > 20 Then
						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
					conteo = conteo + 1
					cuantos_ped = D.GetString("CUANTOS_PEDIDO")
					PORCENTAJE = 2 'Round(100/ (D.GetString("CUANTOS_PEDIDO") + 1))
					Dim cmd As DBCommand
					cmd.Initialize
					cmd.Name = "insert_pedido_DUR"
					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")

				Next
				c.Close
			End If
		
		End If
	
		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_DUR"
				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

		' NOVENTA    HIST_EXIBIDORES(CAT_CL_CLIENTE,CAT_CL_EXHIBIDOR,CAT_CL_BEXHIBIDOR)
		c=skmt.ExecQuery("SELECT  CAT_CL_CLIENTE,CAT_CL_EXHIBIDOR,CAT_CL_BEXHIBIDOR from HIST_EXIBIDORES")
		D=skmt.ExecQuery("SELECT  COUNT(*) AS CUANTOS_NOVENTA 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_HIST_EXIBIDORES_DUR"
				cmd.Parameters = Array As Object(C.GetString("CAT_CL_CLIENTE"),C.GetString("CAT_CL_EXHIBIDOR"),C.GetString("CAT_CL_BEXHIBIDOR"),l_ruta.TEXT)
				reqManager.ExecuteQuery(cmd , 0, "inst_noventa")

			Next
			c.Close
		End If
		d.Position=0
		cuantos_exib = 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_DUR"
'				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_DUR"
'				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_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
'	
	
	
		
		' DROP

		t1.Initialize("T1", 20000) ' 1000 = 1 second
		t1.Enabled = True
  
		img2.Visible =True
	
	
		'	ToastMessageShow("Se Actualizaran los datos, Este proceso podria tardar hasta un minuto, gracias "& l_ruta.text , True)
		If S_CP.Text = "SUBIENDO" Then
			S_CP.Text = "VALIDANDO"
		End If
		

	End If
End Sub
Sub cargar_Click
	Log(SERVER)
	CARGA = "CARGAR"
	img2.Visible =True
	L_P_1.Visible = True
	S_CC.Visible = True

	P1.Visible = True
	trabajar.Visible = False
	B_PROXIMA.Visible =False
	Btn_UbicarR.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.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))
	skmt.ExecNonQuery("delete from HIST_EXIBIDORES")
	skmt.ExecNonQuery("delete from CAT_EXHIBIDORES")
	skmt.ExecNonQuery("delete from CAT_ENCUESTA_PREGUNTA")

	c=skmt.ExecQuery("select usuario from usuarioa")
	c.Position = 0
	usuario = c.GetString("USUARIO")
	
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name ="insert_drop2_DUR"
	'cmd.Name = "UPDATE_DUR_ACTUALR2_GPS"
	cmd.Parameters = Array As Object(usuario, e_ruta.Text,fecha, l_porvisitar.Text,l_drop.Text,l_efectiva.Text,l_cuantosc.Text,l_cuantosn.Text, L_MONTOD.Text,"CARGO", ALMACEN, L_VENTA.Text, L_PREVENTA.Text, L_ABORDO.Text, l_cambios.TEXT)
	reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
	'sql.UPDATE_DUR_ACTUALR2_GPS=UPDATE DURAKELO.CAT_RUTAS_REPARTO SET CAT_RR_MONTO_ACT = (?),CAT_RR_MRECH_ACT =(?),CAT_RR_VISIT_ACT =(?), CAT_RR_DEV_ACT =(?), CAT_RR_LAT_ACT =(?), CAT_RR_LONG_ACT =(?), CAT_RR_BAT_ACT =(?), CAT_RR_TT = (?), CAT_RR_MONTO = (?), CAT_RR_FECHA_ACT = SYSDATE WHERE CAT_RR_IDALMACEN = (?) And CAT_RR_RUTA = (?)

	'cmd.Initialize
	'cmd.Name = "Select_count_clie"
	'reqManager.ExecuteQuery(cmd,0,"count_cli")

	cmd.Initialize
	cmd.Name = "select_codigo_exhibidor"
	'cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "catalogo_exhibidor")

	cmd.Initialize
	cmd.Name = "select_cat_gunaprod_DUR"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprod")

	cmd.Initialize
	cmd.Name = "select_cat_gunaprod2_DUR"
	cmd.Parameters = Array As Object(ALMACEN, e_ruta.Text)
	reqManager.ExecuteQuery(cmd , 0, "gunaprod2")

	cmd.Initialize
	cmd.Name = "select_cat_paquetes_abordo_DUR"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodpa")
	
	cmd.Initialize
	cmd.Name = "select_cat_paquetes_DUR"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodp")

	cmd.Initialize
	cmd.Name = "select_cat_paquetess_DUR"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodps")

	cmd.Initialize
	cmd.Name = "select_cat_detallepa_DUR"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "detallepaq")

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

	cmd.Initialize
	cmd.Name = "select_hist_datos_DUR"
	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_DUR"
	cmd.Parameters = Array As Object(e_ruta.text, ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "hist_promos")

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

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

	''' validar para que sirve esto ya que no esta en la base de datos.

	cmd.Initialize
	cmd.Name = "select_verificacion_DUR"
	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_DUR"
	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_DUR"
	cmd.Parameters = Array As Object(usuario)
	reqManager.ExecuteQuery(cmd , 0, "perfil")

	cmd.Initialize
	cmd.Name = "select_marcas_DUR"
	cmd.Parameters = Array As Object(usuario)
	reqManager.ExecuteQuery(cmd , 0, "marcas")

	cmd.Initialize
	cmd.Name = "select_precios_DUR"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "precios")

	cmd.Initialize
	cmd.Name = "select_hist_rmi1_DUR"
	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_DUR"
	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_DUR"
	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_DUR"
	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_DUR"
	'cmd.Parameters = Array As Object( ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "cat_cambios")

	cmd.Initialize
	cmd.Name = "select_SUCURSAL_DUR"
	cmd.Parameters = Array As Object( ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "sucursal")

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

	' 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
	SUBIR_P.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
		'If 	Job.ErrorMessage <> "STREAM" Then
		'	ToastMessageShow("Error: " & Job.ErrorMessage, True)
		'End If
		If Job.ErrorMessage = "STREAM" Then
			If CARGA = "SUBIR" Then
				PB2.Progress = PB2.Progress + PORCENTAJE
		
				If S_CP.Text = "EN PROCESO" Then
					S_CP.Text = "SUBIENDO"
				End If
				'	If PB2.Progress > 99 Then
				'		S_CP.Text = "VALIDANDO"
				'	End If

				If 	cuantos_ped = conteo Then
					S_CP.Text = "VALIDANDO"
				End If
			End If
		End If
	Else
		LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green)  'Mod por CHV - 211027
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "kmt_datos" Then 'query tag
				skmt.BeginTransaction
				Try
				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.TransactionSuccessful
				Catch
					Log(LastException)
					ToastMessageShow(LastException, True)
				End Try
				skmt.EndTransaction
				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"))
				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
				skmt.BeginTransaction
				Try
					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 = 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
				Catch
					Log(LastException)
					ToastMessageShow(LastException, True)
				End Try
				skmt.EndTransaction
			End If
		End If
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "catalogo_exhibidor" Then 'query tag
				skmt.BeginTransaction
				Try
					For Each records() As Object In RESULT.Rows
						Dim CAT_EX_ID As String = records(RESULT.Columns.Get("CAT_EX_ID"))
						Dim CAT_EX_TIPO As String = records(RESULT.Columns.Get("CAT_EX_TIPO"))
						Dim CAT_EX_VALOR As String = records(RESULT.Columns.Get("CAT_EX_VALOR"))

						skmt.ExecNonQuery2("INSERT INTO CAT_EXHIBIDORES(CAT_EX_ID, CAT_EX_TIPO, CAT_EX_VALOR) VALUES (?,?,?)", Array As Object (CAT_EX_ID, CAT_EX_TIPO, CAT_EX_VALOR))
					Next
					' ToastMessageShow(" Historico Clientes Promociones Actualizado." , True)
				Catch
					Log(LastException)
					ToastMessageShow(LastException, True)
				End Try
				skmt.EndTransaction
			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 = 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

			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.ExecQUERY2("SELECT COUNT(*) AS CUANTOS FROM PEDIDO WHERE PE_TIPO = ?", Array As String ("VENTA"))
				c.Position = 0
				cuantos_pedidosc = c.GetString("CUANTOS")
				c.Close
				If cuantos_pedidosc > 0 Then
					c=skmt.ExecQUERY2("SELECT PE_PROID, PE_CANT FROM PEDIDO WHERE PE_TIPO = ?", Array As String ("VENTA"))
					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
			End If
		End If

		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "gunaprodpa" 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_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 = "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"))
				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))
				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 = "fechat" 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 = "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 = 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 = "carga_encuesta" Then 'query tag
				For Each records() As Object In RESULT.Rows
					
					Dim CAT_EP_ID  As String = records(RESULT.COLUMNS.GET("CAT_EP_ID"))
					Dim CAT_EP_IDTIPOPREGUNTA  As String = records(RESULT.COLUMNS.GET("CAT_EP_IDTIPOPREGUNTA"))
					Dim CAT_CE_DESCRIPCION  As String = records(RESULT.COLUMNS.GET("CAT_CE_DESCRIPCION"))
					Dim CAT_EP_PREGUNTA  As String = records(RESULT.COLUMNS.GET("CAT_EP_PREGUNTA"))
					Dim CAT_EP_RES1_PRED  As String = records(RESULT.COLUMNS.GET("CAT_EP_RES1_PRED"))
					Dim CAT_EP_RES2_PRED  As String = records(RESULT.COLUMNS.GET("CAT_EP_RES2_PRED"))
					Dim CAT_EP_RES3_PRED  As String = records(RESULT.COLUMNS.GET("CAT_EP_RES3_PRED"))
					Dim CAT_EP_ORDEN_PREGUNTA As String = records(RESULT.COLUMNS.GET("CAT_EP_ORDEN_PREGUNTA"))

					
					skmt.ExecNonQuery2("INSERT INTO CAT_ENCUESTA_PREGUNTA (CAT_EP_ID ,CAT_EP_IDTIPOPREGUNTA ,CAT_CE_DESCRIPCION ,CAT_EP_PREGUNTA ,CAT_EP_RES1_PRED ,CAT_EP_RES2_PRED ,CAT_EP_RES3_PRED ,CAT_EP_ORDEN_PREGUNTA ) VALUES (?,?,?,?,?,?,?,?)", Array As Object (CAT_EP_ID ,CAT_EP_IDTIPOPREGUNTA ,CAT_CE_DESCRIPCION ,CAT_EP_PREGUNTA ,CAT_EP_RES1_PRED ,CAT_EP_RES2_PRED ,CAT_EP_RES3_PRED ,CAT_EP_ORDEN_PREGUNTA))
	   	
					
		   
				Next
			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"
						i_gif.Visible = False
					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
		'' PEDIDO
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "pedido_env" Then 'query tag
				skmt.ExecNonQuery("delete from telefonos")
					
				For Each records() As Object In RESULT.Rows
           
					Dim FOLIO_PE As String = records(RESULT.Columns.Get("FOLIO"))
           
					skmt.ExecNonQuery2("INSERT INTO telefonos (PR_CD_CREDITO) VALUES (?)", Array As Object (FOLIO_PE))
	   
		   
						   
		   
				Next
				PASO_info = 1
			End If
		End If
	
		If Job.JobName = "DBRequest" Then
			Dim RESULT As DBResult = reqManager.HandleJob(Job)
			If RESULT.Tag = "ruta" Then 'query tag
				
'				cargar.Visible = True
'				Subir.Visible = True
'				SUBIR_P.Visible = True
'				inv.Visible = True
'				connecta.Visible = False
'				If conn = "1" Then
'					ToastMessageShow("Existe Conexión con el Servidor." , True)
'				End If

				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
						SUBIR_P.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
						SUBIR_P.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
		' 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
	
		' 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, CAT_GP_PRECIO10) 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,CAT_GP_PRECIO10))
	      
				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 GPS_LocationChanged (Location1 As Location)
'	lat_gps=Location1.ConvertToSeconds(Location1.Latitude)
'	lon_gps=Location1.ConvertToSeconds(Location1.Longitude)
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
	ime.HideKeyboard
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name = "UPDATE_DURK_ACTUAL2_GPS"
	cmd.Parameters = Array As Object(L_MONTOD.Text, L_CUANTOST.Text, l_cuantosc.Text,l_porvisitar.TEXT,Main.lat_gps,Main.lon_gps,batterystatus(0),0, 0, 0,ALMACEN,l_ruta.Text )
	reqManager.ExecuteCommand(cmd,"inst_visitas")

	connecta1 = connecta1 + 1
	imei = p.GetDeviceId
	conn = "1"
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name = "select_version_DUR"
	reqManager.ExecuteQuery(cmd , 0, "version")

	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name = "select_ruta_DUR2"
	cmd.Parameters = Array As Object(ALMACEN,e_ruta.text,imei)
	Log($"${ALMACEN},${e_ruta.text},${imei}"$)
	reqManager.ExecuteQuery(cmd , 0, "ruta")

	If e_ruta.Text = "ROOT" Then
		cargar.Visible = True
		Subir.Visible = True
		SUBIR_P.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 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 = ""
			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.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
		Btn_UbicarR.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_DUR"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprod")
	
	cmd.Initialize
	cmd.Name = "select_cat_paquetes_DUR"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "gunaprodp")
	
	cmd.Initialize
	cmd.Name = "select_cat_detallepa_DUR"
	cmd.Parameters = Array As Object(ALMACEN)
	reqManager.ExecuteQuery(cmd , 0, "detallepaq")
	
	cargar.Visible = False
	Subir.Visible = False
	SUBIR_P.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_DUR"
	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_DUR"
'	cmd.Parameters = Array As Object(ALMACEN,l_ruta.text)
'	reqManager.ExecuteQuery(cmd , 0, "valida_noventa")
'	
'	cmd.Initialize
'	cmd.Name = "select_cuantos_pedidoc_DUR"
'	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
		Btn_UbicarR.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
			B_PROXIMA.Visible =True
			Btn_UbicarR.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
		Btn_UbicarR.Visible=True


 	NUEVO.Visible =True
		BUSCA.Visible=True
		connecta.Visible=True
		Resumen.Visible= True
		img2.Visible=False
		Activity_Resume
	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
			B_PROXIMA.Visible =True
			Btn_UbicarR.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")
			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_DUR"
'	cmd.Parameters = Array As Object(USUARIO1.Text, CLAVE.Text)
'	reqManager.ExecuteQuery(cmd , 0, "usuario")
	'If PASO = 1 Then
	'c=skmt.ExecQuery("select usuario from usuarioa")
	''		c.Position = 0
'		usuario = c.GetString("USUARIO")
'	c.Close
	' 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_DUR"
'				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=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=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_DUR"
'				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=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_DUR"
'				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_DUR"
'	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
	'
'	Awake.KeepAlive(False)
End Sub

Sub NUEVO_Click
	StartActivity(nuevocliente)
End Sub

Sub B_OK_RES_Click
	trabajar.Visible = True
	B_PROXIMA.Visible =True
	Btn_UbicarR.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
	Btn_UbicarR.Visible=False

	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	SUBIR_P.Visible = False
	cargar.Visible=False
	Resumen.Visible= False
	
	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 count(*) as CUANTOS FROM CAT_GUNAPROD WHERE CAT_GP_CLASIF = ?   ", Array As String ("KELLOGGS"))
		c.Position = 0
		Log("Cuantos=" & Cuantos)
		If c.GetString("CUANTOS") > 0 Then
			Log("Entramos")
			ImageView12.Bitmap = LoadBitmap(File.DirAssets, "k.png")
			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.ExecQuery("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_CLASIF = 'KELLOGGS' Or CAT_GP_CLASIF = 'KELLOGGS 2' union Select CAT_GP_ID from cat_gunaprod2 where CAT_GP_CLASIF = 'KELLOGGS' Or CAT_GP_CLASIF = 'KELLOGGS 2')")
			c.Position = 0
			l_monto_k.Text = c.GetString("MONTO_DIA")
			c.Close
			c=skmt.ExecQuery("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_CLASIF = 'KELLOGGS' Or CAT_GP_CLASIF = 'KELLOGGS 2') And CAT_GP_TIPO = 'PRINGLES' union Select CAT_GP_ID from cat_gunaprod2 where (CAT_GP_CLASIF = 'KELLOGGS' Or CAT_GP_CLASIF = 'KELLOGGS 2') And CAT_GP_TIPO = 'PRINGLES')")
			c.Position = 0
			l_monto_kp.Text = c.GetString("MONTO_DIA")
			Log("Pringles=" & l_monto_kp.text)
			If l_monto_kp.Text = "null" Then
				l_monto_kp.Text = "0"
			End If
			c.Close
			c=skmt.ExecQuery("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_CLASIF = 'KELLOGGS' Or CAT_GP_CLASIF = 'KELLOGGS 2') And CAT_GP_TIPO = 'SNACK' union Select CAT_GP_ID from cat_gunaprod2 where (CAT_GP_CLASIF = 'KELLOGGS' Or CAT_GP_CLASIF = 'KELLOGGS 2') And CAT_GP_TIPO = 'SNACK')")
			c.Position = 0
			l_monto_ks.Text = c.GetString("MONTO_DIA")
			c.Close
			Log("Snacks=" & l_monto_ks.text)
			c=skmt.ExecQuery("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_CLASIF = 'KELLOGGS' Or CAT_GP_CLASIF = 'KELLOGGS 2') And CAT_GP_TIPO = 'CEREAL' union Select CAT_GP_ID from cat_gunaprod2 where (CAT_GP_CLASIF = 'KELLOGGS' Or CAT_GP_CLASIF = 'KELLOGGS 2') And CAT_GP_TIPO = 'CEREAL')")
			c.Position = 0
			l_monto_kc.Text = c.GetString("MONTO_DIA")
			c.Close
			Log("Cereal=" & l_monto_kc.text)
			
		Else
			ImageView12.Bitmap = LoadBitmap(File.DirAssets, "unilever.jpg")
			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.ExecQuery("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_CLASIF = 'UNILEVER' union Select CAT_GP_ID from cat_gunaprod2 where CAT_GP_CLASIF = 'UNILEVER')")
			c.Position = 0
			l_monto_k.Text = c.GetString("MONTO_DIA")
			c.Close
	
			l_monto_kp.Text = "0"
			l_monto_ks.Text = "0"
		End If

		Log($"${l_monto_k.text}, ${l_monto_kp.text}, ${l_monto_ks.text}"$)
	
		E1=skmt.ExecQuery2("Select count(*) As CUANTOS from pedido where PE_TIPO = ?", Array As String("VENTA"))
		E1.Position = 0
		If E1.GetString("CUANTOS") > 0 Then
		
			c=skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_TIPO = ?", Array As String("VENTA"))
			c.Position = 0
			L_VENTA.Text = c.GetString("MONTO_DIA")
			c.Close
		Else
			L_VENTA.Text = 0
		End If
		E1.Close
		
		
		E1=skmt.ExecQuery2("Select  count(*) As CUANTOS from pedido where PE_TIPO = ?", Array As String("PREVENTA"))
		E1.Position = 0
		If E1.GetString("CUANTOS") > 0 Then
		
			c=skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_TIPO = ?", Array As String("PREVENTA"))
			c.Position = 0
			L_PREVENTA.Text = c.GetString("MONTO_DIA")
			c.Close
		Else
			L_PREVENTA.Text = 0
		End If
		E1.Close
		
		
		E1=skmt.ExecQuery2("Select  count(*) As CUANTOS from pedido where PE_TIPO = ?", Array As String("ABORDO"))
		E1.Position = 0
		If E1.GetString("CUANTOS") > 0 Then
		
			c=skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_TIPO = ?", Array As String("ABORDO"))
			c.Position = 0
			L_ABORDO.Text = c.GetString("MONTO_DIA")
			c.Close
		Else
			L_ABORDO.Text = 0
		End If
		E1.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_CLASIF = ? Or CAT_GP_CLASIF = ?) And CAT_GP_TIPO = ?)", Array As String("KELLOGGS", "KELLOGGS 2","SNACK"))
'		c.Position = 0
'		l_monto_ks.Text = c.GetString("MONTO_DIA")
'		c.Close

		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
	
	
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 Timer_GIF1_Tick
	Timer_GIF1.Enabled = False
	Frame1 = Frame1 + 1
	If Frame1 >= gif1.FrameCount Then
		Frame1 = 0
	End If
	Timer_GIF1.Interval = gif1.Delay(Frame1)
	i_gif.Bitmap = gif1.Frame(Frame1)
	Timer_GIF1.Enabled = True
End Sub

Sub load_gif

	gif1.DisposeFrames
	

	gif1.Load(ruta, "espera.gif")
	Frame1 = 0
	
	
	Timer_GIF1.Interval = gif1.Delay(Frame1)
	i_gif.Bitmap = gif1.Frame(Frame1)
	
	Timer_GIF1.Initialize("TG", 40) ' 1000 = 1 second

	Timer_GIF1.Enabled = True
	
	
	
	gif1.SaveFrame(0, ruta, "frame1.png", "P", 85)
	gif1.SaveFrame(0, ruta, "frame1.jpg", "J", 85)

End Sub

Sub VALIDA_INFO

	cmd.Initialize
	cmd.Name = "select_datos_enviados_pe"
	cmd.Parameters = Array As Object(ALMACEN, e_ruta.Text)
	reqManager.ExecuteQuery(cmd , 0, "pedido_env")
	PASO_info = 0
	
	For I = 0 To 2
		T3.Initialize("T3", 8000) ' 1000 = 1 second
		T3.Enabled = True
		Wait For  t3_tick
		If PASO_info = 0 Then
			I = 0
		End If
	Next
	
End Sub


Sub B_MARCAS_Click
	Panel5.Visible = True
	
	pnlTitle.Visible = False
	pnlTitle.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, TitleHeight + DividerHeight)
	pnlTitle.LoadLayout("CellTitle")
	c=skmt.ExecQuery("Select CAT_GP_CLASIF, SUM(TOTAL) AS TOTAL FROM TOTAL_MARCAS GROUP BY CAT_GP_CLASIF")
	CLV1.Clear
	
	If c.RowCount>0 Then
		For i=0 To c.RowCount -1
			c.Position=i
			AddTitle(c.GetString("CAT_GP_CLASIF"))
			CLV1.AddTextItem("TOTAL VENTA Y PREVENTA = $" & c.GetString("TOTAL"),"1")
			
		Next
	End If
End Sub
Sub AddTitle (Title As String)
	Dim p_MARCAS As B4XView = xui.CreatePanel("")
	p_MARCAS.SetLayoutAnimated(0, 0, 0, CLV1.AsView.Width, TitleHeight)
	p_MARCAS.LoadLayout("CellTitle")
	lblTitle.Text = Title
	Dim td As TitleData
	td.Title = Title
	CLV1.Add(p_MARCAS, td)
End Sub


Sub B_OK_PANEL5_Click
	Panel5.Visible = False

End Sub

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 Btn_UbicarR_Click
	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(MAPA_RUTAS)
End Sub

Sub SUBIR_P_Click
	Awake.KeepAlive(True)
	CARGA = "SUBIR"
	P1.Visible = True
	trabajar.Visible = False
	B_PROXIMA.Visible =False
	Btn_UbicarR.Visible=False
	
	NUEVO.Visible =False
	BUSCA.Visible=False
	connecta.Visible=False
	Subir.Visible=False
	SUBIR_P.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
	PB2.Visible = True
	conteo = 0
	'i_gif.Visible = True
'	load_gif

	PASO = 1
	'End If
	If PASO =1 Then
		E1=skmt.ExecQuery2("Select  count(*) As CUANTOS from pedido where PE_TIPO = ?", Array As String("ABORDO"))
		E1.Position = 0
		If E1.GetString("CUANTOS") > 0 Then
		
			c=skmt.ExecQuery2("Select  sum(PE_COSTO_TOT) As MONTO_DIA from pedido where PE_TIPO = ?", Array As String("ABORDO"))
			c.Position = 0
			L_ABORDO.Text = c.GetString("MONTO_DIA")
			c.Close
		Else
			L_ABORDO.Text = 0
		End If
		E1.Close

	
		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
		d3=skmt.ExecQuery("SELECT SUM(PE_COSTO_TOT) as MONTO FROM PEDIDO")
		d3.Position = 0
		Dim cmd As DBCommand
		cmd.Initialize
		cmd.Name ="UPDATE_INFO_E_DURK"
		cmd.Parameters = Array As Object(d3.GetDouble("MONTO")- L_ABORDO.text, L_ABORDO.Text, d3.GetDouble("MONTO"),l_ruta.TEXT, ALMACEN)
		reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
		Dim cmd As DBCommand
		cmd.Initialize
		cmd.Name ="insert_drop2_DUR"
		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", ALMACEN, L_VENTA.Text, L_PREVENTA.Text, L_ABORDO.Text, l_cambios.TEXT)
		reqManager.ExecuteQuery(cmd , 0, "inst_noventa")
		d3.Close
		cuantos_pedidosc = 0
	
	
		' PEDIO
	
		skmt.ExecNonQuery("update PEDIDO set PE_FOLIO = rowid ")

		'
'	c=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=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 = 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")

	
		
			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 WHERE PE_CLIENTE = 0")
		d=skmt.ExecQuery("SELECT COUNT(*) as CUANTOS_PEDIDO FROM PEDIDO WHERE PE_CLIENTE = 0")
			d.Position=0
			TIEMPO = 0
			If c.RowCount>0 Then
				For i=0 To c.RowCount -1
					c.Position=i
					TIEMPO =  TIEMPO + 1
					
					If TIEMPO  > 20 Then
						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
					conteo = conteo + 1
					cuantos_ped = D.GetString("CUANTOS_PEDIDO")
					PORCENTAJE = 2 'Round(100/ (D.GetString("CUANTOS_PEDIDO") + 1))
					Dim cmd As DBCommand
					cmd.Initialize
					cmd.Name = "insert_pedido_DUR"
					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")

				Next
				c.Close
			End If
		
		
	
		cuantos_pedido = D.GetString("CUANTOS_PEDIDO")
		d.Close
	

		t1.Initialize("T1", 20000) ' 1000 = 1 second
		t1.Enabled = True
  
		img2.Visible =True
	
	
		'	ToastMessageShow("Se Actualizaran los datos, Este proceso podria tardar hasta un minuto, gracias "& l_ruta.text , True)
		If S_CP.Text = "SUBIENDO" Then
			S_CP.Text = "VALIDANDO"
		End If
		

	End If

End Sub

Sub b_e_resumen_Click
	Dim cmd As DBCommand
	cmd.Initialize
	cmd.Name = "UPDATE_DURK_ACTUAL2_GPS"
	cmd.Parameters = Array As Object(L_MONTOD.Text, L_CUANTOST.Text, l_cuantosc.Text,l_porvisitar.TEXT,Main.lat_gps,Main.lon_gps,batterystatus(0),0, 0, 0,ALMACEN,l_ruta.Text )
	reqManager.ExecuteCommand(cmd,"inst_visitas")
End Sub