This is a migrated thread and some comments may be shown as answers.

RadAjaxLaodingPanel randomly not hide after postback

11 Answers 250 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Gustavo
Top achievements
Rank 1
Gustavo asked on 10 Feb 2014, 01:41 AM
I have a web site and one page with some panels that be updated throught radajaxmanager and the image is showing radajaxloadingpanel.
Every things works ok, but randomly the radajaxloadingpanel is not hidding after postback, no return any error jscript, on the server every things is ok.
The only way to continue is refreshing IE with F5.
I don't know how detect the error or how reproduce or what can i do to fixed

11 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 12 Feb 2014, 11:36 AM
Hello Custavo,

Most commonly the described behavior is caused by e js error that appear and prevents the ResponseEnd Ajax event to fire. However as in your case no js errors appear on the page it would be rather difficult to directly determine what the root cause of the issue is.
In order to further investigate you problem it will be best if you could send us you page markup as well as the related code behind. Thus we will be able tot revise it locally and do our best to provide proper solution.

Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Gustavo
Top achievements
Rank 1
answered on 13 Feb 2014, 03:06 AM
Thanks for your answer. Yes it is dificult because the error is randomly and no errors are returned. And if the user press F5 refresh the page and do the same process, the page run ok.
I'm sending the page source IngresoBultos.asx
thanks


 <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.master"
CodeFile="IngresoBultos.aspx.cs" Trace="false" Buffer="true" Inherits="IngresoBultos" title ="Ingreso de Bultos"%>

<%@ Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" TagPrefix="ajax"%>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Charting" Assembly="Telerik.Web.UI" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>


<asp:Content ID="ContentPage" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<%--<script src="/CalidadCertificada/Scripts/Etiquetas.js" language="javascript" type="text/javascript"></script>
<applet id="qz" name="QZ Print Plugin" code="qz.PrintApplet.class" archive="/CalidadCertificada/Scripts/qz-print.jar" width="1" height="1">
<param name="jnlp_href" value="/CalidadCertificada/Scripts/qz-print_jnlp.jnlp"/>
<param name="cache_option" value="plugin" />
<param name="initial_focus" value="false" />
</applet>--%>

<telerik:RadCodeBlock runat="server" ID="RadScriptBlock1">
<script src="/CalidadCertificada/Scripts/PrintLabels.js" language="javascript" type="text/javascript"></script>

<script language="javascript">
var buscando = 0;


function OpenNotificationPedido(Distribucion, ProductosTrazables) {
var notification = $find("<%=RadNotification1.ClientID %>");
var texto = '';

if (parseBool(ProductosTrazables) == true)
texto = "Pedido con productos trazables";

if (parseBool(Distribucion) == true) {
if(texto == '')
texto = "Pedido de Distribución";
else
texto += "<BR/>Pedido de Distribución";
}


if (texto != '') {
notification.set_text(texto);
notification.show();
}
}

function CancelarCerrar()
{

var menu = $find("<%= SubMenu.ClientID%>");
menu.findItemByValue('CerrarBulto').enable();
menu.findItemByValue('CerrarPedido').enable();
menu.findItemByValue('CerrarCarro').enable();
}

function ErrorCantidad()
{
var combolote = $find("<%= cboLotes.ClientID %>");
var comboproducto = $find("<%= cboProductos.ClientID %>");

FilterProductos(comboproducto);
combolote.findItemByValue(combolote.get_text()).select();
combolote.hideDropDown();
$find("<%=txtCantidad.ClientID %>").focus();
document.getElementById("<%= warningProductos.ClientID %>").innerHTML = "La cantidad ingresada supera a la cantidad disponible para el producto.";
}


function onItemsRequesting(sender, eventArgs)
{
if (buscando == 0)
{
sender.hideDropDown();
buscando = 1;

var combo = $find("<%=cboLotes.ClientID %>");
combo.clearItems();
combo.clearSelection();

FilterProductos(sender);
eventArgs.set_cancel(true);

if (sender.get_items().get_count() > 1)
sender.showDropDown();

buscando = 0;
}
}

function FilterProductos(combo)
{
var Productos = CargarListaProductos();
var text = combo.get_text()
var comboItem;
var desc;

combo.clearItems();

if (text.length > 0 && text.toUpperCase() != 'SELECCIONAR')
{
for (i = 0; i < Productos.length; i++)
{
desc = Productos[i].codproducto + ' ' + Productos[i].descproducto;

if (desc.toUpperCase().indexOf(text.toUpperCase()) > -1) {
if (combo.findItemByValue(Productos[i].codproductocliente) == null) {
comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_text(desc);
comboItem.set_value(Productos[i].codproductocliente);

//combo.trackChanges();
combo.get_items().add(comboItem);
//combo.commitChanges();
}
}
}
}
else
{
for (i = 0; i < Productos.length; i++)
{
desc = Productos[i].codproducto + ' ' + Productos[i].descproducto;

if (combo.findItemByValue(Productos[i].codproductocliente) == null)
{
comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_text(desc);
comboItem.set_value(Productos[i].codproductocliente);

//combo.trackChanges();
combo.get_items().add(comboItem);
//combo.commitChanges();
}
}
}

if (combo.get_items().get_count() == 1)
combo.get_items().getItem(0).select();

}

function CerrarCarro() {
$find("<%=cboCarros.ClientID %>").clearSelection();
$find("<%=cboCarros.ClientID %>").clearItems();
$find("<%=cboCarros.ClientID %>").enable();
}

function CambiarLote(nuevolote)
{
document.getElementById("<%= lblNuevoLote.ClientID%>").innerHTML = nuevolote;
$('input#' + "<%= hdNuevoLote.ClientID%>").val(nuevolote);
}

function imgCambiarLote_Click()
{
combolote = $find("<%= cboLotes.ClientID %>");

try{
if (combolote.get_selectedItem() == null)
{
document.getElementById("<%= warningProductos.ClientID %>").innerHTML = "Debe indicar el lote original.";
}
else
{
AbrirIncidencia('Cambio de Lote','proc_cambiar_lote', 'ErrCambioLote',
$find("<%=txtPedido.ClientID %>").get_value(),
$('input#' + "<%= hdIdBultoSel.ClientID%>").val(),
$('input#' + "<%= hdIdSubBultoSel.ClientID%>").val(),
combolote.get_selectedItem().get_value(),
$find("<%=cboProductos.ClientID %>").get_selectedItem().get_value());

}
}
catch(ex)
{
alert('Funcion: imgCambiarLote_Click Error:' + ex.message);
throw ex;
}
}

function AbrirIngresoPeso()
{
try {
var titulo

if ($('input#' + "<%= hdIdSubBultoSel.ClientID%>").val() != '')
titulo = 'Cerrar Subbulto';
else
titulo = 'Cerrar Bulto';

var Url = "IngresoPeso.aspx?codref=proc_cerrar_bulto" +
"&interno=" + $find("<%= txtPedido.ClientID %>").get_value() +
"&idbulto=" + $('input#' + "<%= hdIdBultoSel.ClientID%>").val() +
"&idsubbulto=" + $('input#' + "<%= hdIdSubBultoSel.ClientID%>").val() ;


var oWnd = radopen(Url, titulo);
oWnd.set_title(titulo);
oWnd.setSize(350, 200);
oWnd.set_enableShadow(true);
oWnd.set_showContentDuringLoad(false);
oWnd.set_visibleStatusbar(false);
oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close);
oWnd.set_modal(true);
}
catch (ex)
{
alert('Funcion: AbrirIngresoPeso Error:' + ex.message);
throw ex;
}
}

function AbrirIncidencia(titulo, codref, error,interno, idbulto, idsubbulto,lote, codproductocliente,nrocarro)
{
try{
var Url = "IngresoIncidencia.aspx?codref=" + codref +
"&error=" + error +
"&interno=" + interno +
"&idbulto=" + idbulto +
"&idsubbulto=" + idsubbulto +
"&lote=" + lote +
"&codproductocliente=" + codproductocliente +
"&nrocarro=" + nrocarro;


var oWnd = radopen(Url);
oWnd.set_title(titulo);
oWnd.set_enableShadow(true);
oWnd.setSize(500, 400);
oWnd.set_showContentDuringLoad(false);
oWnd.set_visibleStatusbar(false);
oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close);
oWnd.set_modal(true);
}
catch(ex)
{
alert('Funcion: AbrirIncidencia Error:' + ex.message);
throw ex;
}
}

function AbrirReetiquetar(interno)
{
try
{
var Url = "Reetiquetado.aspx?interno=" + interno;


var oWnd = radopen(Url);
oWnd.set_title('Reetiquetado');
oWnd.set_enableShadow(true);
oWnd.setSize(500, 400);
oWnd.set_showContentDuringLoad(false);
oWnd.set_visibleStatusbar(false);
oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close);
oWnd.set_modal(true);
}
catch (ex)
{
alert('Funcion: AbrirIncidencia Error:' + ex.message);
throw ex;
}
}

function ValidarCerrarSubBulto()
{
try
{
var idsubbulto = $('input#' + "<%= hdIdSubBultoSel.ClientID%>").val();
var idbulto = $('input#' + "<%= hdIdBultoSel.ClientID%>").val();

if (idsubbulto == '')
{
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "No hay un subbulto seleccionado para cerrar.";
return;
}

if (idbulto == '')
{
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "No hay un bulto padre seleccionado para el subbulto que quiere cerrar.";
return;
}

var grid = $find("<%=RadGrid1.ClientID %>");
var MasterTable = grid.get_masterTableView();
var Rows = MasterTable.get_dataItems();

if (Rows.length == 0)
{
document.getElementById("<%= warningPedido.ClientID%>").innerHTML = "No se puede cerrar el subbulto debido a que no tiene productos embalados.";
return false;
}

if ($find("<%=txtPesoSubBulto.ClientID %>").get_value() == '')
{
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "Debe indicar el peso del tipo de Subbulto."
return;
}


var TipoBulto = BuscarTipoBulto($find("<%= cboTipoSubBulto.ClientID%>").get_selectedItem().get_value());


if (EsEmbalajeOriginal(TipoBulto.idtipoembalaje) == true)
{
$('input#' + "<%= hdPesoBalanza.ClientID%>").val($find("<%=txtPesoSubBulto.ClientID %>").get_value());

CallCerrarBulto();
}
else
{
AbrirIngresoPeso();
}

return ;
}
catch(ex)
{
alert('Funcion: CerrarSubBulto Error:' + ex.message);
throw ex;
}
}


function ValidarCerrarPedido()
{
try
{
if ($find("<%= txtPedido.ClientID %>").get_value() == '' || $find("<%= txtRemito.ClientID %>").get_value() == '')
{
$find("<%= SubMenu.ClientID%>").findItemByValue('CerrarPedido').enable();
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "Debe seleccionar un pedido para cerrar.";
return;
}

var tree = $find("<%= twContenedores.ClientID %>");
var rootnode = tree.findNodeByValue('ba');

if(rootnode.get_nodes().get_count()>0)
{
$find("<%= SubMenu.ClientID%>").findItemByValue('CerrarPedido').enable();
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "No se puede cerrar el pedido debido a que aún hay bultos abiertos.";
return;
}

rootnode = tree.findNodeByValue('ca');

if (rootnode.get_nodes().get_count() > 0)
{
$find("<%= SubMenu.ClientID%>").findItemByValue('CerrarPedido').enable();
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "No se puede cerrar el pedido debido a que aún hay carros abiertos.";
return;
}

CallCerrarPedido();
}
catch (ex)
{
alert('Funcion: ValidarCerrarPedido Error:' + ex.message);
throw ex;
}
}

function ValidarCerrarCarro()
{
try {

if ($find("<%= cboCarros.ClientID%>").get_selectedItem() == null)
{
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "Debe seleccionar un carro para cerrar.";
return;
}

if ($find("<%= cboCarros.ClientID%>").get_selectedItem().get_value() == '')
{
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "Debe seleccionar un carro para cerrar.";
return;
}

var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
ajaxManager.ajaxRequestWithTarget('<%= hdBotonCerrarCarro.UniqueID %>', '');
}
catch (ex)
{
alert('Funcion: ValidarCerrarCarro Error:' + ex.message);
throw ex;
}
}

//Devuelve true si hay al menos un bulto cerrado
function TieneSubBultosCerrados()
{
var tree = $find("<%= twContenedores.ClientID %>");
var rootnode = tree.findNodeByValue('bc');

for (var i = 0; i < rootnode.get_nodes().get_count(); i++) {
if (rootnode.get_nodes().getNode(i).get_value().split('|')[0] == 'SB') {
var idbultopadre = (rootnode.get_nodes().getNode(i).get_value().split('|')[3])

if (idbultopadre == $('input#' + "<%= hdIdBultoSel.ClientID%>").val()) {
return true;
}
}
}

return false;
}

function TieneProductosCargados()
{
var grid = $find("<%=RadGrid1.ClientID %>");
var MasterTable = grid.get_masterTableView();

if (MasterTable.get_dataItems().length == 0) {

return false;
}
else{
return true;
}
}

function ValidarCerrarBulto()
{
try
{
var idbulto = $('input#' + "<%= hdIdBultoSel.ClientID%>").val();

if (idbulto == '')
{
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "Debe seleccionar un bulto para cerrar.";
return false;
}


var TipoBulto = BuscarTipoBulto($find("<%= cboTipoBulto.ClientID%>").get_selectedItem().get_value());

if ($('input#' + "<%= txtCantidadBultos.ClientID%>").val() <= 0)
{
document.getElementById("<%= warningPedido.ClientID%>").innerHTML = "Debe indicar la cantidad de bultos.";
return false;
}

//valida que no tenga subbultos abiertos
var tree = $find("<%= twContenedores.ClientID %>");
var rootnode = tree.findNodeByValue('ba');

for (var i = 0; i < rootnode.get_nodes().get_count(); i++)
{
var idbulto2 = (rootnode.get_nodes().getNode(i).get_value().split('|')[2])

if (idbulto2 == idbulto)
{
if (rootnode.get_nodes().getNode(i).get_nodes().get_count() > 0)
{
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "No se puede cerrar el bulto debido a que hay subbultos que aun no fueron cerrados.";
return false;
}
}
}

//valida que tenga algun producto cargadoe
if (!TieneSubBultosCerrados() && !TieneProductosCargados()) {
document.getElementById("<%= warningPedido.ClientID%>").innerHTML = "No se puede cerrar el bulto debido a que no tiene productos embalados.";
return false;
}




var pesobulto = $find("<%=txtPesoBulto.ClientID %>").get_value();

if (pesobulto == 0)
{
if (EsEmbalajeOriginal(TipoBulto.idtipoembalaje) == true)
document.getElementById("<%= warningPedido.ClientID%>").innerHTML = "Debe indicar el peso de la caja completa.";
else
document.getElementById("<%= warningPedido.ClientID%>").innerHTML = "Debe indicar el peso del insumo";

return false;
}

if (EsEmbalajeOriginal(TipoBulto.idtipoembalaje) == true)
{
// $('input#' + "<%= hdPesoBalanza.ClientID%>").val($find("<%=txtPesoBulto.ClientID %>").get_value());

CallCerrarBulto();
}
else
{
AbrirIngresoPeso();
}

return true;
}
catch(ex)
{

alert('Funcion: ValidarCerrarBulto Error:' + ex.message);
throw ex;
}

}


function ValidarKilos(PesoBalanza)
{

try
{
var TipoBulto;
var titulo;
// var idbulto;

$('input#' + "<%= hdPesoBalanza.ClientID%>").val(PesoBalanza);

var valPesoBalanza = Globalize.parseFloat(PesoBalanza) ;

if ($('input#' + "<%= hdIdSubBultoSel.ClientID%>").val() != '')
{
titulo = 'Cerrar Subbulto';
// idbulto = $('input#' + "<%= hdIdSubBultoSel.ClientID%>").val();
TipoBulto = BuscarTipoBulto($find("<%= cboTipoSubBulto.ClientID%>").get_selectedItem().get_value());
}
else
{
titulo = 'Cerrar Bulto';
// idbulto = $('input#' + "<%= hdIdBultoSel.ClientID%>").val();
TipoBulto = BuscarTipoBulto($find("<%= cboTipoBulto.ClientID%>").get_selectedItem().get_value());
}


if(parseBool(TipoBulto.controlapeso) == true)
{
var KilosReales = valPesoBalanza;
var i;
var KilosTeoricos = $find('<%= txtPesoBulto.ClientID%>').get_value();
var idbultopadre;

// var Cantidad = 0;
// var PesoUnitario = 0;

if (EsEmbalajeOriginal(TipoBulto.idtipoembalaje) == false)
{
if (parseBool(TipoBulto.admitesubbultos) == true)
{
//suma el peso de todos los subbultos abiertos
var tree = $find("<%= twContenedores.ClientID %>");
var rootnode = tree.findNodeByValue('ba');

for (i = 0; i < rootnode.get_nodes().get_count(); i++)
{
if (rootnode.get_nodes().getNode(i).get_value().split('|')[0] == 'SB')
{
idbultopadre = (rootnode.get_nodes().getNode(i).get_value().split('|')[3])

if (idbultopadre == $('input#' + "<%= hdIdBultoSel.ClientID%>").val())
{
for (var x = 0; x < rootnode.get_nodes().getNode(i).get_nodes().get_count(); x++)
{
KilosTeoricos += Globalize.parseFloat(rootnode.get_nodes().getNode(i).get_nodes().getNode(x).get_text().split('-')[3]);
}
}
}
}

//suma el peso de todos los subbultos cerrados
tree = $find("<%= twContenedores.ClientID %>");
rootnode = tree.findNodeByValue('bc');

for (i = 0; i < rootnode.get_nodes().get_count(); i++)
{
if (rootnode.get_nodes().getNode(i).get_value().split('|')[0] == 'SB')
{
idbultopadre = (rootnode.get_nodes().getNode(i).get_value().split('|')[3])

if (idbultopadre == $('input#' + "<%= hdIdBultoSel.ClientID%>").val())
{
KilosTeoricos += Globalize.parseFloat(rootnode.get_nodes().getNode(i).get_text().split('-')[3]);
}
}
}
}

//suma el peso de los productos
var grid = $find("<%=RadGrid1.ClientID %>");
var MasterTable = grid.get_masterTableView();
var gridItems = MasterTable.get_dataItems();
var cantidad;
var pesounitario;

for (i = 0; i < gridItems.length; ++i)
{
cantidad = Globalize.parseFloat(MasterTable.getCellByColumnUniqueName(MasterTable.get_dataItems()[i], "cantidad").innerHTML);
pesounitario = Globalize.parseFloat(gridItems[i].getDataKeyValue("pesounitario"));

KilosTeoricos += pesounitario * cantidad;
}

//suma el peso del relleno
grid = $find("<%=RadGrid2.ClientID %>");
MasterTable = grid.get_masterTableView();
gridItems = MasterTable.get_dataItems();

for (i = 0; i < gridItems.length; ++i)
{
cantidad = Globalize.parseFloat(MasterTable.getCellByColumnUniqueName(MasterTable.get_dataItems()[i], "cantidad").innerHTML);
pesounitario = Globalize.parseFloat(MasterTable.getCellByColumnUniqueName(MasterTable.get_dataItems()[i], "kilos").innerHTML);

KilosTeoricos += pesounitario * cantidad;
}

var PorcentajeDif = 1 - KilosReales / KilosTeoricos;

if (isNaN(PorcentajeDif))
{
alert('Error convirtiendo a numero. Verique el simbolo decimal y separador de miles de la configuracion Español (Argentina).');
return
}
else
{
PorcentajeDif = Math.abs(PorcentajeDif) * 100;

if (PorcentajeDif > Globalize.parseFloat(TipoBulto.tolerancia.toString()))
{
var error = "ErrTolerancia1"; //Constantes.ErrToleranciaPeso
AbrirIncidencia(titulo, 'proc_cerrar_bulto', error, $find("<%=txtPedido.ClientID %>").get_value(), $('input#' + "<%= hdIdBultoSel.ClientID%>").val(), $('input#' + "<%= hdIdSubBultoSel.ClientID%>").val(), '', '');
return;
}
}
}
}

CallCerrarBulto();
}
catch(ex)
{
alert('Funcion: ValidarKilos Error:' + ex.message);
throw ex;
}
}


function CallCerrarPedido()
{
var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
ajaxManager.ajaxRequestWithTarget('<%= hdBotonCerrarPedido.UniqueID %>', '');
}

function CallCerrarPedidoIncidentado()
{
var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
ajaxManager.ajaxRequestWithTarget('<%= hdBotonCerrarPedidoIncidentado.UniqueID %>', '');
}

function CallCerrarBulto()
{
var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
ajaxManager.ajaxRequestWithTarget('<%= hdBotonCerrarBulto.UniqueID %>', '');
}

function ValidarCerrarPedidoServer()
{
var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
ajaxManager.ajaxRequest('ValidarCerrarPedido');
}


function ValidarCambiarTipoBulto(sender, eventArgs)
{
try
{
var tree = $find("<%= twContenedores.ClientID %>");
var rootnode = tree.findNodeByValue('ba');

for (var i = 0; i < rootnode.get_nodes().get_count(); i++)
{
var idbulto = (rootnode.get_nodes().getNode(i).get_value().split('|')[2])

if (idbulto == $('input#' + "<%= hdIdBultoSel.ClientID%>").val())
{
if (rootnode.get_nodes().getNode(i).get_nodes().get_count() > 0)
{
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "No se puede cambiar el tipo de bulto debido a que hay subbultos asociados al mismo. Elimine los subbultos para poder cambiar el tipo de bulto.";
eventArgs.set_cancel(true);
}
}

}

}
catch(ex)
{
alert('Funcion: ValidarCambiarTipoBulto Error:' + ex.message);
throw ex;
}
}

function OcultarModal()
{
$find('IngresoPesoBehavior').hide();
}


$(document).ready(
function () {

$('#<%= imgAddSubBulto.ClientID%>').live("click",
function () {
if ($('#<%= trTipoSubBulto.ClientID %>').is(':hidden')) {
$('#<%= trTipoSubBulto.ClientID %>').show();
$('#<%= cboTipoSubBulto.ClientID %>').focus();

$('#<%= imgCancelarBulto.ClientID %>').hide();
}
else {
$('#<%= trTipoSubBulto.ClientID %>').hide();

$('#<%= imgCancelarBulto.ClientID %>').show();
}
});
});


function MenuCuentaClientItemClick(sender, args)
{

var itemValue = args.get_item().get_value();

if (itemValue == "CerrarPedido")
{
args.get_item().disable();

if (ValidarCerrarPedido() == false)
{
args.get_item().enable();
}
}
else if (itemValue == "CerrarCarro")
{
args.get_item().disable();

if (ValidarCerrarCarro() == false)
{
args.get_item().enable();
}
}
else if(itemValue == "CerrarBulto")
{
args.get_item().disable();

if (ValidarCerrarBulto() == false)
{
args.get_item().enable();
}
}
else if (itemValue == 'ConsRemito' ||
itemValue == 'ConsProductosEmbalados' ||
itemValue == 'ConsProductosPendientes' ||
itemValue == 'ConsRemitoDistribucion' ||
itemValue == 'ConsProductosPendientesCarro')
{
AbrirConsulta(itemValue);
}

}





function CargarListaProductos()
{
var json = $('input#' + "<%= hdJson.ClientID%>").val();

if (json != '')
return JSON.parse(json);
else
return '';
}

function CargarListaparametros()
{
var json = $('input#' + "<%= hdparametrosConfig.ClientID%>").val();

return JSON.parse(json);
}

function CargarListaTiposBulto()
{
var json = $('input#' + "<%= hdTiposBulto.ClientID%>").val() ;

return JSON.parse(json);
}

function ValidarLote(codproductocliente)
{
try{
var Productos = CargarListaProductos();
var lote = $find("<%=cboLotes.ClientID %>").get_text();

for (i = 0; i < Productos.length; i++)
{
if (Productos[i].codproductocliente == codproductocliente && Productos[i].nrolote == lote)
{
$find("<%=txtCantidad.ClientID %>").enable();
$find("<%=txtCantidad.ClientID %>").focus();
document.getElementById("imgCambiarLote").style.display = '';
return true;
}
}

// $find("<%=txtCantidad.ClientID %>").disable();
// $find("<%=txtCantidad.ClientID %>").set_value(0);

document.getElementById("imgCambiarLote").style.display = 'none';
return false;

}
catch(ex)
{
alert('Funcion: ValidarLote Error:' + ex.message);
throw ex;
}
}


function cboLotes_SelectedIndexChanged(sender, eventArgs)
{
var combolote = $find("<%= cboLotes.ClientID %>");
var codproductocliente = $find("<%=cboProductos.ClientID %>").get_selectedItem().get_value();

document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "";

try
{

if (ValidarLote(codproductocliente))
{
var Productos = CargarListaProductos();

for (i = 0; i < Productos.length; i++)
{
if (Productos[i].codproductocliente == codproductocliente)
{
var serializado = Productos[i].serializado;
codproductocliente = Productos[i].codproductocliente;
var cantidad = Productos[i].cantidad;
var descproducto = Productos[i].descproducto;
var parametros = CargarListaparametros();

var controlaseries = parseBool(parametros.ControlSeries);

if (serializado == true && controlaseries == true)
{
var win = $find("<%= VentanaSeries.ClientID %>");
var txtpedido = $find("<%= txtPedido.ClientID %>");
var txtnrobulto = $find("<%= txtNroBulto.ClientID %>");


win.NavigateUrl = "IngresoSeries.aspx?interno=" + txtpedido.get_value() +
"&idbulto=" + txtnrobulto.get_value() +
"&nrolote=" + combolote.get_selectedItem().get_value() +
"&descproducto=" + descproducto +
"&cantidadproducto=" + cantidad +
"&codproducto=" + codproductocliente;

radopen(win);
}
else
{

// var TiposBulto = BuscarTipoBulto($find("<%= cboTipoBulto.ClientID%>").get_selectedItem().get_value());

//focused("<%= txtCantidad.ClientID%>");

var radInput = $telerik.findControl(document.forms[0], "<%= txtCantidad.ClientID %>");

if (radInput) {
radInput.focus();
}
}

break;
}
}
}
else
{

document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "El lote seleccionado es incorrecto.";
combolote.clearSelection();
CargarLotes(codproductocliente);
}
}
catch(ex)
{
alert('Funcion: cboLotes_SelectedIndexChanged Error:' + ex.message);
}
}

function AbrirConsulta(tipoconsulta)
{

var txtpedido = $find("<%= txtPedido.ClientID %>");
var txtremito = $find("<%= txtRemito.ClientID %>");
var nrocarro = "";

if ($find("<%= cboCarros.ClientID%>").get_selectedItem() != null)
nrocarro = $find("<%= cboCarros.ClientID%>").get_selectedItem().get_value();

if (txtpedido.get_value() == '' || txtremito.get_value() == '')
{
radalert('Debe indicar el pedido.',300,100,'Atención');
return;
}

if (tipoconsulta == 'ConsRemito') {
Title = "Consulta de remito";
Url = "ConsRemito.aspx?interno=" + txtpedido.get_value() +
"&idcliente=" + '<%=Session["idcliente"] %>';
}
else if (tipoconsulta == 'ConsProductosPendientes') {
Title = "Consulta de productos pendientes";
Url = "ConsProductosPendientes.aspx?interno=" + txtpedido.get_value() +
"&idcliente=" + '<%=Session["idcliente"] %>';
}
else if (tipoconsulta == 'ConsProductosEmbalados') {
Title = "Consulta de productos embalados";
Url = "ConsProductosEmbalados.aspx?interno=" + txtpedido.get_value() +
"&idcliente=" + '<%=Session["idcliente"] %>';
}
else if (tipoconsulta == 'ConsRemitoDistribucion') {
Title = "Consulta de Remito de Distribución";
Url = "ConsPedidosDistribucion.aspx?remito=" + txtremito.get_value() +
"&idcliente=" + '<%=Session["idcliente"] %>';
}
else if (tipoconsulta == 'ConsProductosPendientesCarro') {
if (nrocarro == "") {
document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "Debe seleccionar un carro para ver los pendientes del mismo.";
return;
}
else {
Title = "Consulta de productos pendientes del carro nro.: " + nrocarro;
Url = "ConsProductosPendientesCarro.aspx?interno=" + txtpedido.get_value() +
"&idcliente=" + '<%=Session["idcliente"] %>' +
"&nrocarro=" + nrocarro;
}
}

var oWnd = radopen(Url, Title);
oWnd.set_title(Title);
oWnd.setSize(700, 450);
oWnd.set_modal(true);
}

function cboProductos_OnClientSelectedIndexChanged(sender, eventArgs) {
try
{
if (sender.get_selectedItem() == null)
{
return;
}

document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "";

var codproductocliente = eventArgs.get_item().get_value();
var idtipobulto;
var ctrlPeso;
var ctrlCantidad = $find("<%= txtCantidad.ClientID%>");

if ($('input#' + "<%= hdIdSubBultoSel.ClientID%>").val() != '')
{
idtipobulto = $find("<%= cboTipoSubBulto.ClientID%>").get_selectedItem().get_value();
ctrlPeso = $find("<%= txtPesoSubBulto.ClientID%>")

}
else if ($('input#' + "<%= hdIdBultoSel.ClientID%>").val() != '')
{
idtipobulto = $find("<%= cboTipoBulto.ClientID%>").get_selectedItem().get_value();
ctrlPeso = $find("<%= txtPesoBulto.ClientID%>")
}

var TipoBulto = BuscarTipoBulto(idtipobulto);

if (EsEmbalajeOriginal(TipoBulto.idtipoembalaje))
{
var Productos = CargarListaProductos();


for (i = 0; i < Productos.length; i++)
{
if (Productos[i].codproductocliente == codproductocliente)
{
if (TipoBulto.idtipoembalaje == 2)
{
//CajaOriginal
ctrlPeso.set_value(Productos[i].kiloscaja);
ctrlCantidad.set_value(Productos[i].cantcaja);
}
else
{
if (TipoBulto.idtipoembalaje == 3)
{
//PackOriginal
ctrlPeso.set_value(Productos[i].kilospack);
ctrlCantidad.set_value(Productos[i].cantpack);
}
else
{
//PalletOriginal
ctrlPeso.set_value(Productos[i].kilospallet);
ctrlCantidad.set_value(Productos[i].cantpallet);
}
}

break;
}
}

}

CargarLotes(codproductocliente);
}
catch (ex)
{
alert('Funcion: cboProductos_Change Error:' + ex.message);
}
}

function ValidarProductoDemora(sender, args)
{
try
{
var item = eventArgs.get_item();
var codproductocliente = item.get_value();
var Productos = CargarListaProductos();

for (i = 0; i < Productos.length; i++)
{
if (Productos[i].codproductocliente == codproductocliente)
{
args.IsValid = true;
return;
}
}

args.IsValid = false;
}
catch(ex)
{
args.IsValid = false;
alert('Funcion: ValidarProductoDemora Error:' + ex.message);
}
}

function CargarLotes(codproductocliente)
{
try {
var lotes = new Array()
var x = 0;
var Productos = CargarListaProductos();

//crea array con los lotes del producto
for (i = 0; i < Productos.length; i++) {
if (Productos[i].codproductocliente == codproductocliente) {
lotes[x] = Productos[i].nrolote;
x += 1;
}
}

var CantLotes = x;

var Posicion = CargarArrayPosicionLote(CantLotes);



var combo = $find("<%=cboLotes.ClientID %>");

if (CantLotes < 6)
CantLotes = 6;

do {
var loteNew = CalcularNroLote(lotes[0]);

var Existe = false;

for (var y = 0; y < lotes.length; y++)
{
if (lotes[y] == loteNew)
{
Existe = true;
break;
}
}
if (!Existe)
lotes[lotes.length] = loteNew;
}
while (lotes.length < CantLotes)

combo.clearItems();

for (var i = 0; i < Posicion.length; i++)
{
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_text(lotes[Posicion[i]-1]);
comboItem.set_value(lotes[Posicion[i]-1]);

combo.trackChanges();
combo.get_items().add(comboItem);
combo.commitChanges();
}

combo.showDropDown();
focusCombo("<%= cboLotes.ClientID%>");

}
catch (ex)
{
alert('Funcion: CargarLotes Error:' + ex.message);
}
}

// function CargarSubBultos()
// {
// var TiposBulto = CargarListaTiposBulto();
// var combo = $find("<%= cboTipoSubBulto.ClientID %>");

// combo.clearItems();

// for (i = 0; i < TiposBulto.length; i++)
// {
// //carga combo con todos los bultos que no pueden tener subbultos y que no sean pallets
// if (parseBool(TiposBulto[i].admitesubbultos) == false &&
// TiposBulto[i].idtipoembalaje != 4 &&
// TiposBulto[i].idtipoembalaje != 5 &&
// TiposBulto[i].idtipobulto != $find("<%= cboTipoBulto.ClientID%>").get_selectedItem().get_value())
// {
//
// var comboItem = new Telerik.Web.UI.RadComboBoxItem();
// comboItem.set_text(TiposBulto[i].descripcion);
// comboItem.set_value(TiposBulto[i].idtipobulto);
// combo.trackChanges();
// combo.get_items().add(comboItem);
// combo.commitChanges();

//
// }
// }
// }

function CalcularNroLote(NroLote)
{
try {
var NroLoteNew = "";

for (var i = 0, len = NroLote.length; i < len; i++) {

if (isNaN(NroLote[i])) {
NroLoteNew += NroLote[i];
}
else {
NroLoteNew += Math.floor(Math.random() * 9).toString();
}
}

return NroLoteNew;
}
catch (ex) {
alert('Funcion: CalcularNroLote Error:' + ex.message);
}
}

function CargarArrayPosicionLote(cantItems)
{
try {
if (cantItems < 6)
cantItems = 6;

var Posicion = new Array(cantItems);
var Pos = 0;
var I = 0;
var Fin = false;
var Existe = false;

do
{

Pos = Math.floor(Math.random() * cantItems+1);

if(Pos>0)
{
Existe = false;

for (var x = 0; x < cantItems+1; x++)
{
if(Posicion[x] == Pos)
Existe = true;
}

if (!Existe)
{
Posicion[I] = Pos;
I += 1;
}
if (I == cantItems)
{
Fin = true;
}
}
}
while (Fin == false);

return Posicion;
}
catch (ex)
{
alert(ex.Message);
}
}

function ValidarCantidadBultos()
{
try
{
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "";

var cantidadbultos = $('input#' + "<%= txtCantidadBultos.ClientID%>").val();

if (cantidadbultos <= 0)
{
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "Debe indicar la cantidad de bultos.";
return false;
}
else
return true;
}
catch (ex)
{
alert('Funcion: ValidarCantidadBultos Error:' + ex.message);
return false;

}
}

function ValidarMonoproducto()
{
try
{
var TiposBulto = BuscarTipoBulto($find("<%= cboTipoBulto.ClientID%>").get_selectedItem().get_value());

document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "";

var grid = $find("<%=RadGrid1.ClientID %>");
var MasterTable = grid.get_masterTableView();
var Rows = MasterTable.get_dataItems();

if (EsEmbalajeOriginal(TiposBulto.idtipoembalaje) != "" && Rows.length > 0)
{
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "El bulto original debe ser monoproducto.";
return false;
}
else
return true;
}
catch (ex)
{
alert('Funcion: ValidarMonoProducto Error:' + ex.message);
return false;
}
}



function ValidarBultoSel()
{
try
{
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "";

var idbultosel = $('input#' + "<%= hdIdBultoSel.ClientID%>").val();
var idsubbultosel = $('input#' + "<%= hdIdSubBultoSel.ClientID%>").val();

if (idbultosel == "" && idsubbultosel == "")
{
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "No hay ningun contenedor asignado.";
return false;
}
else
return true;
}
catch (ex)
{
alert('Funcion: ValidarBultoSel Error:' + ex.message);
return false;
}
}

function ValidarTipoBultoSel()
{
try
{
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "";

var idbultosel = $('input#' + "<%= hdIdBultoSel.ClientID%>").val();
var idsubbultosel = $('input#' + "<%= hdIdSubBultoSel.ClientID%>").val();

if (idbultosel != "" && $find("<%=cboTipoBulto.ClientID %>").get_value() == "" ||
idsubbultosel != "" && $find("<%=cboTipoSubBulto.ClientID %>").get_value() == "")
{
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "Debe indicar el tipo de contenedor asignado.";
return false;
}
else
return true;
}
catch (ex)
{
alert('Funcion: ValidarTipoBultoSel Error:' + ex.message);
return false;
}
}

function ValidarAgregarProducto()
{
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "";

try
{
if ($find("<%=cboProductos.ClientID %>").get_selectedItem() == null)
{
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "Debe indicar el producto.";
$find("<%=cboProductos.ClientID %>").get_inputDomElement().focus()
return false;
}

if ($find("<%=cboLotes.ClientID %>").get_selectedItem() == null)
{
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "Debe indicar el lote del producto.";
$find("<%=cboLotes.ClientID %>").get_inputDomElement().focus();
return false;
}

if ($find("<%= txtCantidad.ClientID %>").get_value() == 0)
{
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "Debe indicar la cantidad del producto.";
$find("<%= txtCantidad.ClientID %>").focus();
return false;
}

if (ValidarCantidadBultos())
{
if (ValidarMonoproducto())
{
if (ValidarBultoSel())
{

document.getElementById("<%=imgAgregarProducto.ClientID%>").click();
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
catch (ex)
{
alert('Funcion: imgAgregarProducto_Click Error:' + ex.message);
return false;
}
}


function ValidarAgregarDemora()
{
document.getElementById("<%= warningDemora.ClientID%>").innerHTML = "";

try
{
if ($find("<%=cboIncidenciasDemoras.ClientID %>").get_selectedItem() == null)
{
document.getElementById("<%= warningDemora.ClientID%>").innerHTML = "Debe indicar la incidencia de la demora.";
$find("<%=cboIncidenciasDemoras.ClientID %>").get_inputDomElement().focus()
return false;
}


document.getElementById("<%=imgAgregarDemora.ClientID%>").click();

return true;
}
catch (ex)
{
alert('Funcion: ValidarAgregarDemora Error:' + ex.message);
return false;
}
}

function ValidarAgregarRelleno()
{
document.getElementById("<%= warningRelleno.ClientID%>").innerHTML = "";

try
{
if ($find("<%=cboTipoRelleno.ClientID %>").get_selectedItem() == null)
{
document.getElementById("<%= warningRelleno.ClientID%>").innerHTML = "Debe indicar el tipo de relleno.";
$find("<%=cboTipoRelleno.ClientID %>").get_inputDomElement().focus()
return false;
}


if ($find("<%= txtPesoRelleno.ClientID %>").get_value() == 0)
{
document.getElementById("<%= warningRelleno.ClientID%>").innerHTML = "Debe indicar el peso del relleno.";
$find("<%= txtPesoRelleno.ClientID %>").focus();
return false;
}

if ($find("<%= txtCantidadRelleno.ClientID %>").get_value() == 0)
{
document.getElementById("<%= warningRelleno.ClientID%>").innerHTML = "Debe indicar la cantidad del relleno.";
$find("<%= txtCantidadRelleno.ClientID %>").focus();
return false;
}

document.getElementById("<%=imgAgregarRelleno.ClientID%>").click();


return true;
}
catch (ex)
{
alert('Funcion: ValidarAgregarRelleno Error:' + ex.message);
return false;
}
}

function imgLimpiarProductos_Click()
{

$find("<%=cboProductos.ClientID %>").clearSelection();
$find("<%=cboLotes.ClientID %>").clearSelection();
$find("<%=txtCantidad.ClientID %>").set_value(0);
document.getElementById("<%= warningProductos.ClientID%>").innerHTML = "";
document.getElementById("imgCambiarLote").style.display = 'none';
document.getElementById("<%= lblNuevoLote.ClientID%>").innerHTML = "";
$('input#' + "<%= hdNuevoLote.ClientID%>").val('');
EnablePanelProductos(true);

focusCombo("<%=cboProductos.ClientID %>");

}

function imgLimpiarRelleno_Click()
{
$find("<%=cboTipoRelleno.ClientID %>").clearSelection();
$find("<%=cboTipoRelleno.ClientID %>").get_inputDomElement().focus();
$find("<%= txtPesoRelleno.ClientID %>").set_value(0);
$find("<%= txtCantidadRelleno.ClientID %>").set_value(1);
EnablePanelRelleno(true);

focusCombo("<%=cboTipoRelleno.ClientID %>");
}



function imgLimpiarDemora_Click()
{
$find("<%=cboIncidenciasDemoras.ClientID %>").clearSelection();
$find("<%=cboIncidenciasDemoras.ClientID %>").get_inputDomElement().focus();
$find("<%=cboProductoDemora.ClientID %>").clearSelection();
$find("<%=txtObservacionDemora.ClientID %>").set_value("");
$find("<%=cboProductoDemora.ClientID %>").clearSelection();
EnablePanelDemoras(true);
}

function txtRemito_OnValueChanged()
{
if ($find("<%=txtRemito.ClientID %>").get_value() != "")
{
var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
ajaxManager.ajaxRequestWithTarget('<%= hdBotonBuscarPedido.UniqueID %>','');
}
}

function txtPedido_OnValueChanged()
{
if ($find("<%=txtPedido.ClientID %>").get_value() != "")
{
var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
ajaxManager.ajaxRequestWithTarget('<%= hdBotonBuscarPedido.UniqueID %>', '');
}
}

function EsEmbalajeOriginal(idtipoembalaje)
{
if(idtipoembalaje == 2 || idtipoembalaje == 3 || idtipoembalaje == 5)
return true;
else
return false;
}

function BuscarTipoBulto(idtipobulto)
{
var TiposBulto = CargarListaTiposBulto();

for (i = 0; i < TiposBulto.length; i++)
{
if (TiposBulto[i].idtipobulto == idtipobulto)
{
return TiposBulto[i];
}
}
}



function RemitoValidado()
{
if($find("<%= txtPedido.ClientID %>").get_value() != '' && $find("<%= txtRemito.ClientID %>").get_value() != '')
return true;
else
return false;
}





function focusCombo(controlid) {
var comboBox = $find(controlid);
var input = comboBox.get_inputDomElement();
input.focus();
}

function ReiniciarPagina() {
$find("<%=RadNotification1.ClientID %>").hide();

$find("<%=txtRemito.ClientID %>").enable();
$find("<%=txtRemito.ClientID %>").focus();
$find("<%=txtRemito.ClientID %>").clear();
$find("<%=txtPedido.ClientID %>").enable();
$find("<%=txtPedido.ClientID %>").clear();
$find("<%=cboCarros.ClientID %>").clearSelection();
$find("<%=cboCarros.ClientID %>").clearItems();
$find("<%=cboCarros.ClientID %>").enable();


if (document.getElementById("<%=trTipoSubBulto.ClientID %>") != null)
{
document.getElementById("<%=trTipoSubBulto.ClientID %>").style.display = 'none';

$find("<%=txtPesoSubBulto.ClientID %>").set_value(0);
$find("<%=cboTipoSubBulto.ClientID %>").clearSelection();
}

$find("<%=txtPesoBulto.ClientID %>").set_value(0);

if(document.getElementById("<%=imgCancelarBulto.ClientID %>") != null)
document.getElementById("<%=imgCancelarBulto.ClientID %>").style.display = 'none';

if (document.getElementById("<%=imgAddSubBulto.ClientID %>")!=null)
document.getElementById("<%=imgAddSubBulto.ClientID %>").style.display = 'none';
$find("<%=txtNroBulto.ClientID %>").set_value("");
$find("<%=cboTipoBulto.ClientID %>").clearSelection();
$find("<%=cboTipoBulto.ClientID %>").disable();

if ($find("<%=txtCantidadBultos.ClientID %>") != null)
$find("<%=txtCantidadBultos.ClientID %>").set_visible(false);





document.getElementById("<%= ajaxChart.ClientID %>").style.display = 'none';

$('input#' + "<%= hdJson.ClientID%>").val('');
$('input#' + "<%= hdIdBultoSel.ClientID%>").val('');
$('input#' + "<%= hdIdSubBultoSel.ClientID%>").val('');
$('input#' + "<%= hdIdTipoBultoSel.ClientID%>").val('');
$('input#' + "<%= hdPesoBalanza.ClientID%>").val('');
$('input#' + "<%= hdBultosToPrint.ClientID%>").val('');

$find("<%=lblSubBulto.ClientID %>").set_value("");

var tree = $find("<%= twContenedores.ClientID %>");

for (var i = 0; i < tree.get_nodes().get_count(); i++)
{
var rootnode = tree.get_nodes().getNode(i);

tree.trackChanges();
do
{
rootnode.get_nodes().removeAt(0);
}
while (rootnode.get_nodes().get_count() > 0)

tree.commitChanges();
}


document.getElementById("<%= lblDir.ClientID%>").innerHTML = "";
document.getElementById("<%= lblRazSoc.ClientID%>").innerHTML = "";
document.getElementById("<%= lblCuenta.ClientID%>").innerHTML = "";
document.getElementById("<%= lblLocalidad.ClientID%>").innerHTML = "";
document.getElementById("<%= lblCodPostal.ClientID%>").innerHTML = "";
document.getElementById("<%= lblAnulacionTroquel.ClientID%>").innerHTML = "";

imgLimpiarProductos_Click();
imgLimpiarRelleno_Click();
imgLimpiarDemora_Click();

$find("<%=cboProductos.ClientID %>").clearItems();

$find("<%= RadGrid1.ClientID %>").get_masterTableView().set_dataSource([]);
$find("<%= RadGrid1.ClientID %>").get_masterTableView().dataBind();
$find("<%= RadGrid2.ClientID %>").get_masterTableView().set_dataSource([]);
$find("<%= RadGrid2.ClientID %>").get_masterTableView().dataBind();
$find("<%= RadGrid3.ClientID %>").get_masterTableView().set_dataSource([]);
$find("<%= RadGrid3.ClientID %>").get_masterTableView().dataBind();

document.getElementById("<%= warningPedido.ClientID %>").innerHTML = "";

EnablePanelProductos(false);
EnablePanelRelleno(false);
EnablePanelDemoras(false);

var menu = $find("<%= SubMenu.ClientID%>");
menu.findItemByValue('CerrarBulto').enable();
menu.findItemByValue('CerrarPedido').enable();
menu.findItemByValue('CerrarCarro').enable();

var tabstrip = $find("<%= RadTabStrip1.ClientID %>");
tabstrip.get_allTabs()[0].set_selected(true);
}

function EnablePanelProductos(enable)
{

if (parseBool(enable) == true)
{
$find("<%= cboProductos.ClientID %>").enable();
$find("<%= cboLotes.ClientID %>").enable();
$find("<%= txtCantidad.ClientID %>").enable();
}
else
{
$find("<%= cboProductos.ClientID %>").disable();
$find("<%= cboLotes.ClientID %>").disable();
$find("<%= txtCantidad.ClientID %>").disable();
}

document.getElementById("<% = imgAgregarProducto.ClientID %>").disabled = !enable;
document.getElementById("imgLimpiarProductos").disabled = !enable;

}

function EnablePanelRelleno(enable)
{
if (parseBool(enable) == true)
{
$find("<%= cboTipoRelleno.ClientID %>").enable();
$find("<%= txtPesoRelleno.ClientID %>").enable();
$find("<%= txtCantidadRelleno.ClientID %>").enable();
}
else
{
$find("<%= cboTipoRelleno.ClientID %>").disable();
$find("<%= txtPesoRelleno.ClientID %>").disable();
$find("<%= txtCantidadRelleno.ClientID %>").disable();
}

document.getElementById("<% = imgAgregarRelleno.ClientID %>").disabled = !enable;
document.getElementById("imgLimpiarRelleno").disabled = !enable;
}

function EnablePanelDemoras(enable)
{
if (parseBool(enable) == true)
{
$find("<%= cboIncidenciasDemoras.ClientID %>").enable();
$find("<%= cboProductoDemora.ClientID %>").enable();
$find("<%= txtObservacionDemora.ClientID %>").enable();
}
else
{
$find("<%= cboIncidenciasDemoras.ClientID %>").disable();
$find("<%= cboProductoDemora.ClientID %>").disable();
$find("<%= txtObservacionDemora.ClientID %>").disable();
}

document.getElementById("<% = imgAgregarDemora.ClientID %>").disabled = !enable;
document.getElementById("imgLimpiarDemora").disabled = !enable;

}

function cboTipoRelleno_OnClientSelectedIndexChanged(sender, eventArgs)
{
try
{

var idtiporellenoSel = eventArgs.get_item().get_value();
var json = $('input#' + "<%= hdTiposRelleno.ClientID%>").val();
var tiposrelleno = JSON.parse(json);

//crea array con los lotes del producto
for (i = 0; i < tiposrelleno.length; i++)
{
if (tiposrelleno[i].idtiporelleno == idtiporellenoSel)
{
if(tiposrelleno[i].requierepeso == false)
{
$find("<%=txtPesoRelleno.ClientID %>").set_value(tiposrelleno[i].kilos);
$find("<%=txtPesoRelleno.ClientID %>").disable();
$find("<%=txtCantidadRelleno.ClientID %>").enable();
$find("<%=txtCantidadRelleno.ClientID %>").focus();
}
else{
$find("<%=txtCantidadRelleno.ClientID %>").set_value(1);
$find("<%=txtCantidadRelleno.ClientID %>").disable();
$find("<%=txtPesoRelleno.ClientID %>").enable();
$find("<%=txtPesoRelleno.ClientID %>").set_value(0);
$find("<%=txtPesoRelleno.ClientID %>").focus();
}
}
}
}
catch (ex)
{
alert('Funcion: cboTipoRelleno_OnClientSelectedIndexChanged Error:' + ex.message);
}
}

function MyPress(sender, args) {

if (args.get_keyCode() == 13) {

args.set_cancel(true);

}

}
</script>
</telerik:RadCodeBlock>

<telerik:RadScriptManager ID="scManager" runat="server"></telerik:RadScriptManager>
<telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="false" />
<telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />

<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>

<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
<AjaxSettings>

<telerik:AjaxSetting AjaxControlID="hdBotonCerrarCarro">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1"/>
<telerik:AjaxUpdatedControl ControlID="upVisorBultos" />
<telerik:AjaxUpdatedControl ControlID="warningPedido" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos" />
<telerik:AjaxUpdatedControl ControlID="ajaxMenu" />
</UpdatedControls>
</telerik:AjaxSetting>

<telerik:AjaxSetting AjaxControlID="hdBotonCerrarBulto">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1"/>
<telerik:AjaxUpdatedControl ControlID="upVisorBultos" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos" />
<telerik:AjaxUpdatedControl ControlID="ajaxRelleno" />
<telerik:AjaxUpdatedControl ControlID="ajaxMenu" />
<telerik:AjaxUpdatedControl ControlID="warningPedido" />
<telerik:AjaxUpdatedControl ControlID="ajaxChart" />
</UpdatedControls>
</telerik:AjaxSetting>

<telerik:AjaxSetting AjaxControlID="hdBotonBuscarPedido">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1"/>
<telerik:AjaxUpdatedControl ControlID="upVisorBultos" />
<telerik:AjaxUpdatedControl ControlID="ajaxCabecera" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos"/>
<telerik:AjaxUpdatedControl ControlID="ajaxRelleno"/>
<telerik:AjaxUpdatedControl ControlID="ajaxDemoras"/>
<telerik:AjaxUpdatedControl ControlID="ajaxChart" />
<telerik:AjaxUpdatedControl ControlID="ajaxMenu" />
<telerik:AjaxUpdatedControl ControlID="warningPedido" />
</UpdatedControls>
</telerik:AjaxSetting>

<telerik:AjaxSetting AjaxControlID="hdBotonCerrarPedido">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1"/>
<telerik:AjaxUpdatedControl ControlID="upVisorBultos" />
<telerik:AjaxUpdatedControl ControlID="ajaxCabecera" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos"/>
<telerik:AjaxUpdatedControl ControlID="ajaxRelleno"/>
<telerik:AjaxUpdatedControl ControlID="ajaxDemoras"/>
<telerik:AjaxUpdatedControl ControlID="ajaxChart" />
<telerik:AjaxUpdatedControl ControlID="warningPedido" />
<telerik:AjaxUpdatedControl ControlID="ajaxMenu" />
</UpdatedControls>
</telerik:AjaxSetting>

<telerik:AjaxSetting AjaxControlID="hdBotonCerrarPedidoIncidentado">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1"/>
<telerik:AjaxUpdatedControl ControlID="upVisorBultos" />
<telerik:AjaxUpdatedControl ControlID="ajaxCabecera" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos"/>
<telerik:AjaxUpdatedControl ControlID="ajaxRelleno"/>
<telerik:AjaxUpdatedControl ControlID="ajaxDemoras"/>
<telerik:AjaxUpdatedControl ControlID="ajaxChart" />
<telerik:AjaxUpdatedControl ControlID="warningPedido" />
<telerik:AjaxUpdatedControl ControlID="ajaxMenu" />
</UpdatedControls>
</telerik:AjaxSetting>

<telerik:AjaxSetting AjaxControlID="cboTipoBulto">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos"/>
<telerik:AjaxUpdatedControl ControlID="ajaxRelleno"/>
<telerik:AjaxUpdatedControl ControlID="upVisorBultos"/>
<telerik:AjaxUpdatedControl ControlID="ajaxMenu" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="cboTipoSubBulto">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos"/>
<telerik:AjaxUpdatedControl ControlID="ajaxRelleno"/>
<telerik:AjaxUpdatedControl ControlID="upVisorBultos"/>
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="imgAgregarProducto">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="ajaxChart" />
<telerik:AjaxUpdatedControl ControlID="warningProductos" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos" LoadingPanelID="RadAjaxLoadingPanel1"/>

</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="imgAgregarRelleno">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="ajaxRelleno" LoadingPanelID="RadAjaxLoadingPanel1"/>
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="imgAgregarDemora">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="ajaxDemoras" LoadingPanelID="RadAjaxLoadingPanel1"/>
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="imgCancelarBulto">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos" />
<telerik:AjaxUpdatedControl ControlID="ajaxChart" />
<telerik:AjaxUpdatedControl ControlID="ajaxRelleno" />
<telerik:AjaxUpdatedControl ControlID="upVisorBultos"/>
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="imgCancelarSubBulto">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos" />
<telerik:AjaxUpdatedControl ControlID="ajaxRelleno" />
<telerik:AjaxUpdatedControl ControlID="upVisorBultos"/>
<telerik:AjaxUpdatedControl ControlID="ajaxChart" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="twContenedores">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos" />
<telerik:AjaxUpdatedControl ControlID="ajaxRelleno" />
<telerik:AjaxUpdatedControl ControlID="ajaxCabecera" />
<telerik:AjaxUpdatedControl ControlID="ajaxChart" />

</UpdatedControls>
</telerik:AjaxSetting>

<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="ajaxChart" />
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="RadGrid2">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>

<telerik:AjaxSetting AjaxControlID="RadGrid3">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid3" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="SubMenu">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="SubMenu" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="btnAceptarIncidencia">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="upVisorBultos"/>
</UpdatedControls>
</telerik:AjaxSetting>

<telerik:AjaxSetting AjaxControlID="cboCarros">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="updPedido" LoadingPanelID="RadAjaxLoadingPanel1"/>
<telerik:AjaxUpdatedControl ControlID="upVisorBultos" />
<telerik:AjaxUpdatedControl ControlID="ajaxCabecera" />
<telerik:AjaxUpdatedControl ControlID="ajaxProductos"/>
<telerik:AjaxUpdatedControl ControlID="ajaxRelleno"/>
<telerik:AjaxUpdatedControl ControlID="ajaxDemoras"/>
<telerik:AjaxUpdatedControl ControlID="ajaxChart" />
<telerik:AjaxUpdatedControl ControlID="ajaxMenu" />
<telerik:AjaxUpdatedControl ControlID="warningPedido" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>


</telerik:RadAjaxManager>

<telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true" Style="z-index: 7500">
<Windows>
<telerik:RadWindow ID="VentanaSeries" runat="server" Title="Ingreso de series" Height="810px"
Width="600px" Left="150px" ShowContentDuringLoad="false"
VisibleStatusbar="false" Animation="Fade" DestroyOnClose="True" Modal="True"/>
</Windows>
</telerik:RadWindowManager>



<div style="vertical-align:top; text-align:center; border:0px 0px 0px 0px; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px; ">
<telerik:RadSplitter ID="RadSplitter1" runat="server" Width="100%" Height="600px" VisibleDuringInit="false">
<telerik:RadPane runat="server" ID="RadPaneCabecera" Width="22px">
<telerik:RadSlidingZone Width="22px" ID="RadSlidingZone1" runat="server" ClickToOpen="true">
<telerik:RadSlidingPane runat="server" ID="RadSlidingPane1" Title="Datos del Cliente" Width="300px">
<asp:Panel ID="ajaxCabecera" runat="server">
<table>
<tr>
<td class="inputLabel">Razón&nbsp;Social:</td>
<td><asp:Label ID="lblRazSoc" runat="server" CssClass="inputField"></asp:Label></td>
</tr>
<tr>
<td class="inputLabel">Direccion:</td>
<td><asp:Label ID="lblDir" runat="server" CssClass="inputField"></asp:Label></td>
</tr>
<tr>
<td class="inputLabel">Localidad:</td>
<td><asp:Label ID="lblLocalidad" runat="server" CssClass="inputField"></asp:Label></td>
</tr>
<tr>
<td class="inputLabel">Codigo&nbsp;Postal:</td>
<td><asp:Label ID="lblCodPostal" runat="server" CssClass="inputField"></asp:Label></td>
</tr>
<tr>
<td class="inputLabel">Cuenta:</td>
<td><asp:Label ID="lblCuenta" runat="server" CssClass="inputField"></asp:Label></td>
</tr>
<tr>
<td><asp:Label ID="lblAnulacionTroquel" runat="server" Font-Bold="True"
Font-Italic="False" Font-Size="Small" ForeColor="Red"></asp:Label></td>
</tr>
</table>
</asp:Panel>

</telerik:RadSlidingPane>
<telerik:RadSlidingPane runat="server" ID="RadSlidingPane2" Title="Contenedores" Width="250px">
<asp:Panel ID="upVisorBultos" runat="server">
<telerik:RadTreeView ID="twContenedores" runat="server"
CssClass="RadTreeView" LoadingMessage="Cargando contenedores..." LoadingStatusPosition="BelowNodeText"
OnContextMenuItemClick="twContenedores_ContextMenuItemClick">
<Nodes>
<telerik:RadTreeNode runat="server" AllowEdit="False" Category="bultosabiertos" Value="BA"
EnableContextMenu="False" Expanded="True" Font-Bold="True" Font-Size="X-Small"
PostBack="False" Text="Bultos Abiertos">
</telerik:RadTreeNode>
<telerik:RadTreeNode runat="server" AllowEdit="False" Category="bultoscerrados" Value="BC"
EnableContextMenu="False" Expanded="True" Font-Bold="True" Font-Size="X-Small"
PostBack="False" Text="Bultos Cerrados">
</telerik:RadTreeNode>

<telerik:RadTreeNode runat="server" AllowEdit="False" Category="carrosabiertos" Value="CA"
EnableContextMenu="False" Expanded="True" Font-Bold="True" Font-Size="X-Small"
PostBack="False" Text="Carros Abiertos">
</telerik:RadTreeNode>

<telerik:RadTreeNode runat="server" AllowEdit="False" Category="carroscerrados" Value="CC"
EnableContextMenu="False" Expanded="True" Font-Bold="True" Font-Size="X-Small"
PostBack="False" Text="Carros Cerrados">
</telerik:RadTreeNode>

</Nodes>
<ContextMenus>
<telerik:RadTreeViewContextMenu ID="MainContextMenu" runat="server">
<Items>
<telerik:RadMenuItem Value="abrir" Text="Abrir..." ></telerik:RadMenuItem>
</Items>
</telerik:RadTreeViewContextMenu>
</ContextMenus>

</telerik:RadTreeView>
</asp:Panel>
</telerik:RadSlidingPane></telerik:RadSlidingZone>
</telerik:RadPane>
<telerik:RadPane runat="server" ID="pnlMain" Width="90%" BackColor="White">
<telerik:RadSplitter ID="RadSplitter2" runat="server" Orientation="Horizontal">
<telerik:RadPane runat="server" ID="RadPane2" Width="100%" BorderColor="White" CssClass="menuPane">
<asp:Panel ID="ajaxMenu" runat="server">
<telerik:RadMenu ID="SubMenu" runat="server" style="z-index:1" Height="70" Width="100%"
onitemclick="SubMenu_ItemClick" OnClientItemClicked="MenuCuentaClientItemClick">
<Items>
<telerik:RadMenuItem Value="CerrarBulto" ImageUrl="~/Images/cerrarbulto_small.png" Text="&nbsp;Cerrar Bulto" PostBack="false"/>
<telerik:RadMenuItem Value="CerrarCarro" ImageUrl="~/Images/CerrarCarro_small.png" Text="&nbsp;Cerrar Carro" PostBack="false"/>
<telerik:RadMenuItem Value="CerrarPedido" ImageUrl="~/Images/cerrarpedido_small.png" Text="&nbsp;Cerrar Pedido" PostBack="false"/>
<telerik:RadMenuItem Value="Consultas" Text="&nbsp;Consultas" ImageUrl="~/Images/reports.png" PostBack="false">
<Items>
<telerik:RadMenuItem Value="ConsRemito" Text="Ver Remito" PostBack="false"/>
<telerik:RadMenuItem Value="ConsProductosEmbalados" Text="Productos Embalados" PostBack="false"/>
<telerik:RadMenuItem Value="ConsProductosPendientes" Text="Productos Pendientes" PostBack="false"/>
<telerik:RadMenuItem Value="ConsProductosPendientesCarro" Text="Productos Pendientes por Carro" PostBack="false"/>
<telerik:RadMenuItem Value="ConsRemitoDistribucion" Text="Remito Distribución" PostBack="false"/>
</Items>
</telerik:RadMenuItem>
</Items>
</telerik:RadMenu>
</asp:Panel>

<table width="100%" >
<tr>
<td align="center">
<asp:Panel ID="updPedido" runat="server">
<div style="display:none;">
<asp:Button runat="server" ID="hdBotonBuscarPedido" OnClick="hdBotonBuscarPedido_Click"/>
<asp:Button runat="server" ID="hdBotonCerrarCarro" OnClick="hdBotonCerrarCarro_Click"/>
<asp:Button runat="server" ID="hdBotonCerrarBulto" OnClick="hdBotonCerrarBulto_Click"/>
<asp:Button runat="server" ID="hdBotonCerrarPedido" OnClick="hdBotonCerrarPedido_Click"/>
<asp:Button runat="server" ID="hdBotonCerrarPedidoIncidentado" OnClick="hdBotonCerrarPedidoIncidentado_Click"/>
<%--<asp:Button runat="server" ID="hdBuscarDatosLogisticos" OnClick="hdBuscarDatosLogisticos_Click"/>--%>
</div>
<asp:HiddenField runat="server" ID="hdTiposBulto"/>
<asp:HiddenField runat="server" ID="hdJson"/>
<asp:HiddenField runat="server" ID="hdJsonProductosEmbalados"/>
<asp:HiddenField runat="server" ID="hdTiposRelleno"/>
<asp:HiddenField ID="hdparametrosConfig" runat="server" />
<asp:HiddenField ID="btnCallPopUpPeso" runat="server" />
<asp:HiddenField ID="hdIdBultoSel" runat="server" />
<asp:HiddenField ID="hdIdSubBultoSel" runat="server" />
<asp:HiddenField ID="hdIdTipoBultoSel" runat="server" />
<asp:HiddenField ID="hdPesoBalanza" runat="server" />
<asp:HiddenField ID="hdNuevoLote" runat="server" />
<asp:HiddenField ID="hdBultosToPrint" runat="server" />


<table border="0" cellpadding="3" cellspacing="5" style="height:100%;text-align:center;" width="500" >
<tr>
<td colspan="6" valign="top" align="center">
<asp:Label ID="warningPedido" ForeColor="Red" runat="server"/>
</td>
</tr>

<tr>
<td colspan="6" align="left" valign="middle">
<telerik:RadNotification ID="RadNotification1" runat="server" EnableRoundedCorners="true"
EnableShadow="true" Title="Atención" CloseButtonToolTip="Ocultar"
ContentIcon="warning" TitleIcon=""
Width="300" Height="100" AutoCloseDelay="0">
</telerik:RadNotification>
</td>
</tr>

<tr>

<td align="right" valign="middle">
<asp:Label ID="Label7" runat="server" Text="Remito"></asp:Label>
</td>
<td align="left" valign="middle">
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<telerik:RadTextBox ID="txtRemito" runat="server" AutoPostBack="false"
CausesValidation="false"
ClientEvents-OnValueChanged="txtRemito_OnValueChanged" ShowButton="true"></telerik:RadTextBox>
</td>
<td>
<img id="imgReiniciar" onmouseover="this.style.cursor='pointer';"
src="Images/clear_small.png" onclick="ReiniciarPagina();"
alt="Limpiar campos" />
</td>
</tr>

</table>
</td>

<td align="right" valign="middle">

<asp:Label ID="Label1" runat="server" Text="Nro.&nbsp;Pedido"></asp:Label>
</td>
<td align="left" valign="middle">

<telerik:RadTextBox ID="txtPedido" runat="server" ClientEvents-OnValueChanged="txtPedido_OnValueChanged"
AutoPostBack="false" ShowButton="true"></telerik:RadTextBox>

</td>
<td align="right" valign="middle">
<asp:Label ID="Label10" runat="server" Text="Contenedor"></asp:Label>
</td>
<td align="left" valign="top">
<telerik:RadComboBox ID="cboCarros" runat="server"
AutoPostBack="true" CausesValidation="false"
CloseDropDownOnBlur="true"
EmptyMessage="Seleccionar"
Width="100px" AllowCustomText="true"
MarkFirstMatch="true" RenderingMode="Full"
ShowDropDownOnTextboxClick="true"
EnableTextSelection ="true"

OnSelectedIndexChanged="cboCarros_SelectedIndexChanged"/>
</td>
</tr>
<tr>
<td align="right" valign="middle">
<asp:Label ID="Label2" runat="server" Text="Tipo de Bulto"></asp:Label>
</td>
<td align="left" valign="top">
<telerik:RadComboBox ID="cboTipoBulto" runat="server" AutoPostBack="true" CausesValidation="false"
CssClass="inputField" CloseDropDownOnBlur="true" EmptyMessage="Seleccionar" Width="150px" MarkFirstMatch="true" RenderingMode="Full"
ZIndex="9000" ShowDropDownOnTextboxClick="true" EnableTextSelection ="true" OnClientSelectedIndexChanging="ValidarCambiarTipoBulto" OnSelectedIndexChanged="cboTipoBulto_SelectedIndexChanged"/>
</td>
<td align="right">
<asp:Label ID="lblPesoBulto" runat="server" Text="Peso&nbsp;insumo"></asp:Label>
</td>
<td align="left">
<telerik:RadNumericTextBox ID="txtPesoBulto" ClientEvents-OnKeyPress="MyPress" runat="server" Width="60px" Enabled="true" AutoPostBack="false" MinValue="0"/>
</td>
<td align="right" >
<asp:Label ID="Label12" runat="server" Text="Nro.&nbsp;Bulto"></asp:Label>
</td>
<td align="left" valign="middle">
<table>
<tr>
<td style="text-align:center;">
<telerik:RadTextBox ID="txtNroBulto" runat="server" CssClass="inputField" ReadOnly="true"
ClientEvents-OnKeyPress="MyPress" TextMode="SingleLine" Width="50px"></telerik:RadTextBox>
</td>
<td>
<asp:ImageButton ID="imgCancelarBulto" runat="server" AlternateText="Anular Bulto"
Visible="false" OnClick="imgCancelarBulto_Click"
ImageUrl="~/Images/delete.png" ToolTip="Anular bulto" />
<ajax:ConfirmButtonExtender ID="confirmDeleteBulto" runat="server" TargetControlID="imgCancelarBulto" >
</ajax:ConfirmButtonExtender>
</td>
<td valign="middle">
<img src="Images/AddSubBulto.png" style="display:none;" runat="server"
onmouseover="style.cursor='pointer';" id="imgAddSubBulto" alt="Agregar SubBulto"/>
</td>
</tr>
</table>

</td>
</tr>
<tr valign="middle">
<td colspan="6" align="center" valign="middle">
<asp:Panel ID="trTipoSubBulto" runat="server" style="display:none;" CssClass="ColorDetalle">
<table cellpadding="4" cellspacing="0" border="0">
<tr>

<td align="right" valign="middle">
<asp:Label ID="Label25" runat="server" Text="Tipo&nbsp;Sub&nbsp;Bulto"></asp:Label>
</td>
<td align="left" valign="middle">
<telerik:RadComboBox ID="cboTipoSubBulto" runat="server"
AutoPostBack="true" CloseDropDownOnBlur="true"
EmptyMessage="Seleccionar"
Width="100px"
MarkFirstMatch="true" RenderingMode="Full"
ShowDropDownOnTextboxClick="true"
EnableTextSelection ="true"
OnSelectedIndexChanged="cboTipoSubBulto_SelectedIndexChanged"/>
</td>
<td align="right" >
<asp:Label ID="lblPesoSubBulto" runat="server" Text="Peso insumo"></asp:Label>
</td>
<td align="left">
<telerik:RadNumericTextBox ID="txtPesoSubBulto" runat="server" Width="60px" Enabled="true" MinValue="0"
CssClass="inputField" Culture="es-AR" ClientEvents-OnKeyPress="DisabledEnterKey"/>

</td>
<td align="right" >
<asp:Label ID="Label6" runat="server" Text="Nro.SubBulto"></asp:Label>
</td>
<td align="left" valign="middle">
<table>

<tr>
<td>
<telerik:RadTextBox ID="lblSubBulto" ClientEvents-OnKeyPress="DisabledEnterKey" runat="server" CssClass="inputField" ReadOnly="true" Width="50px"></telerik:RadTextBox>
</td>
<td>
<asp:ImageButton ID="imgCancelarSubBulto" runat="server" AlternateText="Anular SubBulto"
ImageUrl="~/Images/delete.png" OnClick="ImgCancelarSubBulto_Click" ToolTip="Anular Subbulto" />
<ajax:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="imgCancelarSubBulto" ConfirmText="Realmente desea anular el subbulto?">
</ajax:ConfirmButtonExtender>
</td>
<td>
<img id="imgCerrarSubBulto" onmouseover="style.cursor='pointer';" runat="server" alt="Cerrar SubBulto" src="Images/CloseSubBulto.png" onclick="ValidarCerrarSubBulto();">
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
<tr>
<td colspan="6">
<table>
<tr>
<td>
<asp:Label ID="Label15" runat="server" Text="Tipo&nbsp;de&nbsp;Etiqueta"></asp:Label>
</td>
<td>
<asp:RadioButtonList id="rdTipoEtiqueta" runat="server" AutoPostBack="false"
CssClass="inputField" CellPadding="1" CellSpacing="1"
RepeatDirection="Horizontal" TextAlign="Right">
<asp:ListItem Text="10 x 6" Value="small"></asp:ListItem>
<asp:ListItem Text="10 x 8" Value="big" Selected="True"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
&nbsp;<telerik:RadNumericTextBox ID="txtCantidadBultos" Label="Cantidad Bultos" MinValue="0" runat="server" LabelWidth="80" Width="160px" Enabled="True" Culture="es-AR" NumberFormat-DecimalDigits="0"
visible="false"/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
<tr>
<td align="center">
<asp:Panel ID="ajaxChart" runat="server" style="display:none;">
<telerik:RadChart ID="RadChart1" runat="server" Height="55px" SeriesOrientation="Horizontal"
SkinsOverrideStyles="false" Skin="GreenStripes"
BorderWidth="0" Legend-Visible="false" PlotArea-Appearance-Dimensions-AutoSize="false"
PlotArea-Appearance-Border-Visible="False"
PlotArea-DataTable-Visible="false" PlotArea-EmptySeriesMessage-TextBlock-Visible="false"
PlotArea-XAxis-Appearance-Visible="false" Width="300px">

<Appearance Border-Visible="false" >
<FillStyle FillType="Solid" MainColor="Transparent" SecondColor="Transparent"></FillStyle>
</Appearance>
<ChartTitle>
<TextBlock Visible="true" Appearance-TextProperties-Font="Verdana,7" Appearance-Position-AlignedPosition="TopLeft" Appearance-TextProperties-Color="Black" Text="Estado del Embalaje">
</TextBlock>
<Appearance>
<FillStyle FillType="Solid" MainColor="Transparent" SecondColor="Transparent"></FillStyle>
</Appearance>
</ChartTitle>
<PlotArea>
<Appearance>

<FillStyle FillType="Solid" MainColor="Transparent" SecondColor="Transparent"></FillStyle>
</Appearance>
</PlotArea>
<Series>

<telerik:ChartSeries Name="Series 1" Type="StackedBar100" DefaultLabelValue="#%"
ActiveRegionToolTip="Procentaje Embalado" >

<Appearance BarWidthPercent="40" TextAppearance-TextProperties-Color="Black">
<Shadow Blur="2" Distance="2" Color="Silver" Position="Bottom" />
</Appearance>

</telerik:ChartSeries>
<telerik:ChartSeries Name="Series 2" Type="StackedBar100" ActiveRegionToolTip="Procentaje Pendiente">
<Appearance LabelAppearance-Visible="false" BarWidthPercent="40">
<Shadow Blur="2" Distance="2" Color="Silver" Position="Bottom" />
</Appearance>
</telerik:ChartSeries>
</Series>
</telerik:RadChart>
</asp:Panel>
</td>
</tr>
</table>

<div style="margin:0 auto;width:50%;" >
<telerik:RadTabStrip ID="RadTabStrip1" runat="server" Width="600px" SelectedIndex="0" MultiPageID="RadMultiPage1" Orientation="HorizontalTop">
<Tabs>
<telerik:RadTab Text="Productos"></telerik:RadTab>
<telerik:RadTab Text="Relleno"></telerik:RadTab>
<telerik:RadTab Text="Demoras"></telerik:RadTab>
</Tabs>
</telerik:RadTabStrip>
<telerik:RadMultiPage runat="server" CssClass="multiPage" ID="RadMultiPage1" Width="600px" SelectedIndex="0" BorderColor="GrayText" BorderStyle="Solid" BorderWidth="1px">
<telerik:RadPageView runat="server" ID="PageView1">
<asp:Panel runat="server" ID="ajaxProductos" CssClass="BorderTabs">
<table border="0" cellpadding="0" cellspacing="0" style="width:100%;">
<tr>
<td style="width: 100%; " align="center">
<asp:Label ID="warningProductos" ForeColor="Red" runat="server" Font-Size="Medium"/>
</td>
</tr>

<tr>
<td align="center">
<asp:panel runat="server" id="pnls" defaultbutton="imgAgregarProducto">
<table border ="0">
<tr>
<td align="right">
<asp:Label ID="lblProducto" runat="server" Text="Producto"></asp:Label>
</td>
<td colspan="3" align="left">
<telerik:RadComboBox ID="cboProductos" runat="server" OpenDropDownOnLoad="false" ShowDropDownOnTextboxClick="false"
EmptyMessage="Seleccionar" Enabled="true" Width="450px" HighlightTemplatedItems="true" CloseDropDownOnBlur="true"
EnableLoadOnDemand="true" AllowCustomText="true" ShowWhileLoading="false"
OnClientSelectedIndexChanged="cboProductos_OnClientSelectedIndexChanged"
ZIndex="9000" OnClientItemsRequesting="onItemsRequesting"/>
</td>
</tr>
<tr>
<td align="right" valign="middle">
<asp:Label ID="lblLote" runat="server" Text="Lote"></asp:Label>
</td>
<td align="left" valign="middle">
<table>
<tr>
<td>
<telerik:RadComboBox ID="cboLotes" runat="server" AutoPostBack="false" CloseDropDownOnBlur="true"
EmptyMessage="Seleccionar" AllowCustomText="true"
Width="100px" HighlightTemplatedItems="true" ChangeTextOnKeyBoardNavigation="true"
RenderingMode="Full" ShowDropDownOnTextboxClick="true"
EnableTextSelection ="true"
OnClientSelectedIndexChanged="cboLotes_SelectedIndexChanged"/>


</td>
<td>
<img id="imgCambiarLote" style="display:none;" src="Images/CambiarLote.png" onclick="imgCambiarLote_Click();"alt="Cambiar lote">
</td>
<td>
<asp:label runat="server" ID="lblNuevoLote"></asp:label>
</td>
</tr>
</table>
</td>
<td align="right">
<asp:Label ID="lblCantidad" runat="server" Text="Cantidad"></asp:Label>
</td>
<td align="left">

<table>
<tr>
<td>
<telerik:RadNumericTextBox ID="txtCantidad" runat="server" TabIndex="9" CssClass="inputField"
Width="70px" Culture="es-AR" NumberFormat-DecimalDigits="0" MinValue="0">
</telerik:RadNumericTextBox>

</td>
<td valign="top" align="center">
<asp:ImageButton ID="imgAgregarProducto" runat="server" OnClick="imgAgregarProducto_Click"
ImageUrl="~/Images/Flecha.png" TabIndex="10"
OnClientClick="return ValidarAgregarProducto();" ToolTip="Agregar producto" />
</td>
<td align="left" colspan="1" valign="top">
<img id="imgLimpiarProductos" src="Images/clear_small.png" onclick="imgLimpiarProductos_Click();" alt="Limpiar campos" onmouseover="style.cursor='pointer';" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</asp:panel>
</td>
</tr>
<tr>
<td>
<telerik:RadGrid runat="server" ID="RadGrid1" DataSourceID="sqlProductosBulto" Visible="true" ShowHeader="true" ShowStatusBar="false" AutoGenerateColumns="false"
OnItemCommand="RadGrid1_ItemCommand" OnItemDataBound="RadGrid1_ItemDataBound">

<MasterTableView CommandItemSettings-ShowAddNewRecordButton="false" CommandItemSettings-RefreshText="Refrescar"
DataKeyNames="idbulto,codproductocliente,idbultoitem,pesounitario" ClientDataKeyNames="idbulto,codproductocliente,idbultoitem,pesounitario" AllowAutomaticDeletes="true" ShowHeadersWhenNoRecords="true" CommandItemDisplay="Top" >
<NoRecordsTemplate>
<h5>No hay productos embalados</h5>
</NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn UniqueName="codproducto" DataField="codproducto" HeaderText="Código"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="descproducto" DataField="descproducto" HeaderText="Descripción"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="nrolote" DataField="nrolote" HeaderText="Lote"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="nuevolote" DataField="nuevolote" HeaderText="Cambio Lote"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="cantidad" DataField="cantidad" HeaderText="Cant."></telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"
ButtonType="ImageButton" ConfirmText="Se eliminará el producto seleccionado del contenedor. Desea continuar?" >
</telerik:GridButtonColumn>
</Columns>

</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource runat="server" ID="sqlProductosBulto" SelectCommandType="StoredProcedure" SelectCommand="GetBultosItems">
<SelectParameters>
<asp:ControlParameter Name="interno" ControlID="txtPedido" PropertyName="Text" DefaultValue="*"/>
<asp:SessionParameter ConvertEmptyStringToNull="true" DbType="String" DefaultValue="*" Name="idcliente" SessionField="idcliente" />
<asp:Parameter Name="idbulto" DefaultValue="0"/>
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</asp:Panel>
</telerik:RadPageView>
<telerik:RadPageView runat="server" ID="RadPageView1">
<asp:Panel runat="server" ID="ajaxRelleno" CssClass="BorderTabs">
<asp:Panel runat="server" ID="pnlRelleno" HorizontalAlign="Center" DefaultButton="imgAgregarRelleno">
<table border="0" width="100%">
<tr>
<td style="width: 100%; " align="center" colspan="7">
<asp:Label ID="warningRelleno" ForeColor="Red" runat="server"/>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="Label8" runat="server" Text="Tipo&nbsp;"></asp:Label>
</td>
<td align="left">
<telerik:RadComboBox ID="cboTipoRelleno" runat="server"
AutoPostBack="false" CloseDropDownOnBlur="true"
EmptyMessage="Seleccionar" Enabled="true" Width="140px"
MarkFirstMatch="true" RenderingMode="Full"
ShowDropDownOnTextboxClick="true" EnableTextSelection ="true"
OnClientSelectedIndexChanged="cboTipoRelleno_OnClientSelectedIndexChanged"/>

</td>
<td align="right">
<asp:Label ID="Label9" runat="server" Text="Peso"></asp:Label>
</td>
<td align="left">
<telerik:RadNumericTextBox ID="txtPesoRelleno" runat="server" CausesValidation="True" Value="0"
Enabled="False" Width="80px" CssClass="inputField" Culture="es-AR" DbValueFactor="1" LabelCssClass=""
MinValue="0">
<numberformat zeropattern="n" />
</telerik:RadNumericTextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidatorPesoRelleno"
runat="server" InitialValue="0"
Display="None" ErrorMessage="Debe indicar el peso del relleno" ControlToValidate="txtPesoRelleno" ValidationGroup="ValRellenos"></asp:RequiredFieldValidator>
</td>
<td align="right">
<asp:Label ID="Label11" runat="server" Text="Cantidad"></asp:Label>
</td>
<td align="left">
<telerik:RadNumericTextBox Width="80px" ID="txtCantidadRelleno" Enabled="false"
runat="server" CausesValidation="True" Culture="es-AR" CssClass="inputField"
DbValueFactor="1" LabelCssClass="" Value="0" MinValue="0">
<numberformat zeropattern="n" DecimalDigits="0" />
</telerik:RadNumericTextBox>
</td>
<td align="center">
<table>
<tr>
<td align="left">
<asp:ImageButton ID="imgAgregarRelleno" runat="server" OnClientClick="return ValidarAgregarRelleno();"
ImageUrl="~/Images/Flecha.png"
OnClick="imgAgregarRelleno_Click" ToolTip="Agregar relleno"
/>
</td>
<td>
<img id="imgLimpiarRelleno" src="Images/clear_small.png" onclick="imgLimpiarRelleno_Click();" alt="Limpiar campos" onmouseover="style.cursor='pointer';" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" align="center" colspan="7">
<telerik:RadGrid runat="server" ID="RadGrid2" DataSourceID="sqlDataRelleno" Visible="true" ShowFooter="true" ShowHeader="true" ShowStatusBar="false" AutoGenerateColumns="false" OnItemCommand="RadGrid2_ItemCommand">
<MasterTableView CommandItemSettings-ShowAddNewRecordButton="false" CommandItemSettings-RefreshText="Refrescar" DataKeyNames="idtiporelleno" ClientDataKeyNames="idtiporelleno" AllowAutomaticDeletes="true" ShowHeadersWhenNoRecords="true" CommandItemDisplay="Top" >
<NoRecordsTemplate>
<h5>No hay registros de relleno cargados.</h5>
</NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn UniqueName="descripcion" DataField="descripcion" HeaderText="Tipo"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="kilos" DataField="kilos" HeaderText="Peso (kg.)"></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="cantidad" DataField="cantidad" HeaderText="Cantidad"></telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"
ButtonType="ImageButton" ConfirmText="Se eliminará el relleno seleccionado. Desea continuar?">
</telerik:GridButtonColumn>
</Columns>

</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource runat="server" ID="sqlDataRelleno" SelectCommandType="StoredProcedure" SelectCommand="GetBultosRelleno">
<SelectParameters>
<asp:Parameter Name="interno" DefaultValue="*"/>
<asp:SessionParameter ConvertEmptyStringToNull="true" DbType="String" DefaultValue="*" Name="idcliente" SessionField="idcliente" />
<asp:Parameter Name="idbulto" DefaultValue="0"/>
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</asp:Panel>
</asp:Panel>
</telerik:RadPageView>
<telerik:RadPageView runat="server" ID="RadPageView2">
<asp:Panel runat="server" ID="ajaxDemoras">
<asp:Panel runat="server" ID="pnlDemoras" CssClass="BorderTabs">
<table cellspacing="1" cellpadding="3" border="0" width="1" style="width:1%;">
<tr>
<td style="width: 100%; " align="center" colspan="3">
<asp:Label ID="warningDemora" ForeColor="Red" runat="server"/>
</td>
</tr>
<tr>
<td align="right" valign="middle">
<asp:Label ID="Label20" runat="server" Text="Tipo de Incidencia"></asp:Label>
</td>
<td align="left" valign="middle">
<telerik:RadComboBox ID="cboIncidenciasDemoras" runat="server"
AutoPostBack="false"
CssClass="inputField" CloseDropDownOnBlur="true"
EmptyMessage="Seleccionar"
Width="300px"
MarkFirstMatch="true" RenderingMode="Full"
ShowDropDownOnTextboxClick="true"
EnableTextSelection ="true"/>


</td>
<td align="center" colspan="1" rowspan="2">
<table>
<tr>
<td align="left">
<asp:ImageButton ID="imgAgregarDemora" runat="server" ImageUrl="~/Images/Flecha.png"
onclick="imgAgregarDemora_Click" AlternateText="Agregar demora" OnClientClick="return ValidarAgregarDemora();"
ToolTip="Agregar demora" />
</td>
<td>
<img id="imgLimpiarDemora" src="Images/clear_small.png" onclick="imgLimpiarDemora_Click();" alt="Limpiar campos" onmouseover="style.cursor='pointer';" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="Label27" runat="server" Text="Producto"></asp:Label>
</td>
<td align="left" >
<telerik:RadComboBox ID="cboProductoDemora" runat="server" OpenDropDownOnLoad="false" ShowDropDownOnTextboxClick="false"
EmptyMessage="Seleccionar" Enabled="true" Width="450px" HighlightTemplatedItems="true" CloseDropDownOnBlur="true"
EnableLoadOnDemand="true" AllowCustomText="true" ShowWhileLoading="false"
OnClientItemsRequesting="onItemsRequesting"/>


<%--<telerik:RadComboBox ID="cboProductoDemora" runat="server" AutoPostBack="false" CloseDropDownOnBlur="true" EmptyMessage="Seleccionar" Enabled="true" Width="450px"
MarkFirstMatch="true" ShowDropDownOnTextboxClick="true" HighlightTemplatedItems="true" EnableTextSelection ="true"
Filter="Contains" DataTextField="descproducto" DataValueField="codproductocliente">
<HeaderTemplate>
<ul>
<li class="col1">Código</li>
<li class="col2">Descripción</li>
</ul>
</HeaderTemplate>
<ItemTemplate>
<ul>
<li class="col1">
<%# DataBinder.Eval(Container.DataItem, "codproducto") %></li>
<li class="col2">
<%# DataBinder.Eval(Container.DataItem, "descproducto") %></li>
</ul>
</ItemTemplate>
</telerik:RadComboBox>--%>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="Label24" runat="server" Text="Observación"></asp:Label>
</td>
<td align="left">
<telerik:RadTextBox ID="txtObservacionDemora" runat="server" CssClass="inputField"
TextMode="MultiLine" Width="400px" Height="40px" ></telerik:RadTextBox>

</td>

</tr>
<tr>
<td valign="top" align="center" colspan="3">

<telerik:RadGrid runat="server" ID="RadGrid3" DataSourceID="sqlDataDemoras" Visible="true" ShowFooter="true" ShowHeader="true" ShowStatusBar="false" AutoGenerateColumns="false" OnItemCommand="RadGrid3_ItemCommand">
<MasterTableView CommandItemSettings-ShowAddNewRecordButton="false" CommandItemSettings-RefreshText="Refrescar" DataKeyNames="iddemora" AllowAutomaticDeletes="true" ShowHeadersWhenNoRecords="true" CommandItemDisplay="Top" >
<NoRecordsTemplate>
<h5>No hay demoras cargadas.</h5>
</NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn DataField="fecha" ItemStyle-Width="50px" HeaderStyle-Width="50px" HeaderText="Fecha"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="descjustificacion" HeaderText="Justificación"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="tiempo" ItemStyle-Width="50px" HeaderStyle-Width="50px" HeaderText="Minutos"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CodProducto" ItemStyle-Width="60px" HeaderStyle-Width="60px" HeaderText="Producto"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="observacion" ItemStyle-Width="100px" HeaderStyle-Width="100px" HeaderText="Observación"></telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ConfirmText="Se eliminará la demora seleccionada. Desea continuar?"
ButtonType="ImageButton">
</telerik:GridButtonColumn>
</Columns>

</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource runat="server" ID="sqlDataDemoras" SelectCommandType="StoredProcedure" SelectCommand="GetPedidosDemoras">
<SelectParameters>
<asp:Parameter Name="interno" DefaultValue="*"/>
<asp:SessionParameter ConvertEmptyStringToNull="true" DbType="String" DefaultValue="*" Name="idcliente" SessionField="idcliente" />
<asp:Parameter Name="idusuario" DefaultValue="Anonymous" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</asp:Panel>
</asp:Panel>
</telerik:RadPageView>
</telerik:RadMultiPage>

</div>
</telerik:RadPane>
</telerik:RadSplitter>
</telerik:RadPane>
</telerik:RadSplitter>
</div>
</asp:Content>

0
Gustavo
Top achievements
Rank 1
answered on 13 Feb 2014, 03:09 AM
And IngresoBultos.aspx.cs with code behind

/*
* falta procedure Cargarparametros si va o no el cliente
* Ver cuando graba incidencia: Funciones.RegistrarLog(null, txtPedido.Text.Trim(), Seguridad.IdClienteSeleccionado, Seguridad.IdUsuario, IdBultoX, Convert.ToInt32(cboIncidencia.SelectedValue.ToString()),
txtObservaciones.Text.Trim(), string.Empty, string.Empty, (vs_ErrorTolerancia1 == true ? Constantes.ErrTolerancia1 : Constantes.ErrTolerancia2), cboProductos.SelectedValue, txtLote.Text.Trim());

*/

using System;
using System.Data;
using System.Web.UI;
using System.Collections.Generic;
using ClassBultos;
using System.Linq;
using Telerik.Web.UI;
using Newtonsoft.Json;
public partial class IngresoBultos : CalidadCertificada.Web.PaginaBase
{
#region clases
public class OParametroConfig
{
public bool EnviaBultosAlertran { get; set; }
public bool ControlCarros { get; set; }
public bool CapturaPesoBalanza { get; set; }
public bool ImprimeEtiquetas { get; set; }
public bool ControlSeries{ get; set; }
public bool ImprimeCodigoBarras { get; set; }
public bool PrevisualizacionEtiqueta { get; set; }
public bool ImprimeEtiquetaSubbulto { get; set; }
public bool MostrarGraficoEmbalaje { get; set; }
public bool CambioDocumentacion{ get; set; }
public bool ControlProductosPorCarro { get; set; }
public bool ImpresionesFinPedido { get; set; }
}

public class oRelleno
{
public int idtiporelleno { get; set; }
public bool requierepeso { get; set; }
public decimal kilos { get; set; }
}

public class oProducto
{
public string codproductocliente { get; set; }
public string nrolote { get; set; }
public bool serializado { get; set; }
public int cantidad { get; set; }
public string descproducto { get; set; }
public decimal kilos { get; set; }
public string codproducto { get; set; }
public decimal kilospack { get; set; }
public decimal kiloscaja { get; set; }
public decimal kilospallet { get; set; }
public decimal cantpack { get; set; }
public decimal cantcaja { get; set; }
public decimal cantpallet { get; set; }
}

public class oTipoBulto
{
public int idtipobulto { get; set; }
public double kilos { get; set; }
public int idtiporelleno { get; set; }
public bool controlapeso { get; set; }
public int idtipoembalaje { get; set; }
public bool admitesubbultos { get; set; }
public double tolerancia { get; set; }
public string descripcion { get; set; }
}


#endregion
#region Propiedades

Boolean RemitoValidado
{
get{
return !string.IsNullOrEmpty(txtRemito.Text.Trim()) && !string.IsNullOrEmpty(txtPedido.Text.Trim());
}

}

Boolean EsSubBulto
{
get
{
return !string.IsNullOrEmpty(hdIdSubBultoSel.Value);
}
}

Boolean EsEmbalajeOriginal(oTipoBulto obj)
{
if ((obj.idtipoembalaje == (int)Constantes.enumTiposEmbalaje.CajaOriginal ||
obj.idtipoembalaje == (int)Constantes.enumTiposEmbalaje.PackOriginal ||
obj.idtipoembalaje == (int)Constantes.enumTiposEmbalaje.PalletOriginal))
return true;
else
return false;
}


protected bool vs_reetiquetar
{
get
{
if (ViewState[Constantes.VS_REETIQUETAR] != null)
{
return Boolean.Parse(ViewState[Constantes.VS_REETIQUETAR].ToString());
}
else
{
return false;
}
}
set
{
ViewState[Constantes.VS_REETIQUETAR] = value;
}
}

public double vs_CantidadTotalUnidades
{
get
{
if (ViewState[Constantes.VS_CANTIDADTOTALUNIDADES] != null)
{
return Convert.ToDouble(ViewState[Constantes.VS_CANTIDADTOTALUNIDADES].ToString());
}
else
{
return 0;
}
}

set { ViewState[Constantes.VS_CANTIDADTOTALUNIDADES] = value; }
}


#endregion


Boolean CerrarCarro()
{
try
{
clsPedidosCarros objCarro = new clsPedidosCarros(txtPedido.Text.Trim(), Seguridad.IdCliente, cboCarros.SelectedValue);
objCarro.idusuario = Seguridad.IdUsuario;
objCarro.CerrarCarro(null);

ActualizarVisorBultos();

if (GetListaparametros().ControlProductosPorCarro == true)
{
RadAjaxManager1.ResponseScripts.Add("imgLimpiarProductos_Click();");
ajaxChart.Style.Add("display", "none");

hdJson.Value = string.Empty;

}



return true;
}
catch (Exception ex)
{
throw ex;
}
}

OParametroConfig GetListaparametros()
{
try
{
OParametroConfig listaparametros = (OParametroConfig)JsonConvert.DeserializeObject(hdparametrosConfig.Value, typeof(OParametroConfig));
return listaparametros;
}
catch (Exception ex)
{
throw ex;
}
}



void CerrarBulto()
{

try
{
List<ClassBultos.clsBultos> Bultos = new List<ClassBultos.clsBultos>();

ClassBultos.clsBultos objBulto = new ClassBultos.clsBultos();
objBulto.interno = txtPedido.Text.Trim();
objBulto.idcliente = Seguridad.IdCliente;



if (EsSubBulto)
{
objBulto.idbulto = Convert.ToDecimal(hdIdSubBultoSel.Value);
objBulto.idtipobulto = Convert.ToInt32(cboTipoSubBulto.SelectedValue);
objBulto.idbultopadre = Convert.ToDecimal(hdIdBultoSel.Value);
}
else
{
objBulto.idbulto = Convert.ToDecimal(hdIdBultoSel.Value);
objBulto.idtipobulto = Convert.ToInt32(cboTipoBulto.SelectedValue);
objBulto.idbultopadre = null;

if (!Funciones.TieneProductosFaltantes(objBulto.interno, Seguridad.IdCliente) && Funciones.GetUltimoBulto(objBulto.interno, objBulto.idcliente).idbulto == objBulto.idbulto)
objBulto.EsUltimoBulto = true;
else
objBulto.EsUltimoBulto = false;

Bultos.Add(objBulto);
}

oTipoBulto oTipoBulto = BuscarTipoBulto(objBulto.idtipobulto);

if (EsEmbalajeOriginal(oTipoBulto))
objBulto.kilos = Convert.ToDecimal(txtPesoBulto.Value);
else
objBulto.kilos = Convert.ToDecimal(hdPesoBalanza.Value);

objBulto.CerrarBulto();

if (EsSubBulto)
{
hdIdSubBultoSel.Value = string.Empty;
cboTipoSubBulto.ClearSelection();
lblSubBulto.Text = string.Empty;
txtPesoSubBulto.Value = 0;
imgCancelarSubBulto.Visible = false;
imgCerrarSubBulto.Visible = false;
sqlProductosBulto.SelectParameters["idbulto"].DefaultValue = hdIdBultoSel.Value;
sqlDataRelleno.SelectParameters["idbulto"].DefaultValue = hdIdBultoSel.Value;
}
else
{

hdIdBultoSel.Value = String.Empty;
hdIdSubBultoSel.Value = String.Empty;
cboTipoBulto.ClearSelection();
txtNroBulto.Text = string.Empty;
txtPesoBulto.Value = 0;
imgCancelarBulto.Visible = false;
sqlProductosBulto.SelectParameters["idbulto"].DefaultValue = "0";
sqlDataRelleno.SelectParameters["idbulto"].DefaultValue = "0";


if (Convert.ToInt32(txtCantidadBultos.Value) > 1)
{
clsBultos oCopy = new clsBultos(txtPedido.Text.Trim(), Seguridad.IdCliente);
oCopy.idbulto = objBulto.idbulto;
DataTable oDt = oCopy.CopiarBultos(Convert.ToInt32(txtCantidadBultos.Value) - 1);

if (!oCopy.idbultopadre.HasValue ||
(oCopy.idbultopadre.HasValue && GetListaparametros().ImprimeEtiquetaSubbulto == true))
{
int x = 1;

oCopy.EsUltimoBulto = false;

foreach (DataRow rw in oDt.Rows)
{
ClassBultos.clsBultos Bulto = new ClassBultos.clsBultos();
Bulto.idbulto = Convert.ToDecimal(rw["idbulto"].ToString());
Bulto.nrobulto = Convert.ToInt32(rw["nrobulto"].ToString());

if (x == oDt.Rows.Count)
{
Bulto.EsUltimoBulto = !Funciones.TieneProductosFaltantes(objBulto.interno, Seguridad.IdCliente);
}

Bultos.Add(Bulto);

x += 1;
}
}
}
}

if (Bultos.Count > 0)
Funciones.ImprimirEtiquetaBulto(Bultos, this.Page, rdTipoEtiqueta.SelectedValue, RadAjaxManager1, hdBultosToPrint, Seguridad.IdCliente);

RadGrid1.DataBind();
RadGrid2.DataBind();

ActualizarVisorBultos();
ActualizarGrafico();

txtCantidadBultos.Value = 1;
txtCantidadBultos.Visible = false;
EnablePanelProductos(!string.IsNullOrEmpty(hdIdBultoSel.Value));
EnablePanelRelleno(!string.IsNullOrEmpty(hdIdBultoSel.Value));
warningProductos.Text = string.Empty;
warningPedido.Text = string.Empty;
cboTipoBulto.Focus();

}
catch (Exception ex)
{
warningPedido.Text = ex.Message;
}
}






void CerrarPedido(bool TieneFaltantes)
{
string CodBarra = "";
string Expedicion = "";
clsPedidosCab objPed = new clsPedidosCab();

try
{
#region Codigo de barra

//if(GetListaparametros().ImprimeEtiquetas==true)
//{
objPed = new clsPedidosCab();
objPed.remitente = lblCuenta.Text.Trim();
objPed.remito = txtRemito.Text.Trim();
DataRow oRowAlertran = objPed.GetDatosEtiquetaAlertran();

Expedicion = oRowAlertran["expedicion"].ToString().PadLeft(10, '0');

CodBarra = "2" +
oRowAlertran["keytsv"].ToString().PadLeft(2, '0') + /*length 2*/
oRowAlertran["delegacion"].ToString().PadLeft(3, '0') + /*length 3*/
oRowAlertran["zonareparto"].ToString().PadLeft(3, '0') + /*length 3*/
oRowAlertran["codpostaldestino"].ToString().PadLeft(4, '0') + /*length 4*/
oRowAlertran["expedicion"].ToString().PadLeft(10, '0');
//}
#endregion

objPed = new clsPedidosCab(txtPedido.Text.Trim(), Seguridad.IdCliente);
objPed.CerrarPedido(null, CodBarra, Expedicion);

/* imprime etiqueta del ultimo bulto si esta incidentado porque esto
quiere decir que no se imprimió la ultima al cerrar el ultimo bulto*/
if(TieneFaltantes)
{
ClassBultos.clsBultos Bulto = Funciones.GetUltimoBulto(objPed.interno, objPed.idcliente);
Bulto.EsUltimoBulto = true;

List<ClassBultos.clsBultos> Bultos = new List<clsBultos>();
Bultos.Add(Bulto);

Funciones.ImprimirEtiquetaBulto(Bultos, this.Page, rdTipoEtiqueta.SelectedValue, RadAjaxManager1, hdBultosToPrint, Seguridad.IdCliente);
}


if (GetListaparametros().ImpresionesFinPedido== true)
{
Funciones.ImprimirEtiquetaPedido(RadAjaxManager1, txtPedido.Text.Trim(), this.Page, rdTipoEtiqueta.SelectedValue, Seguridad.IdCliente);
/*Imprimir Packing List*/
Funciones.CargarReporteProductosEmpacados(this.Page, txtPedido.Text.Trim(), true, null, false, Seguridad.IdCliente);
}

RadAjaxManager1.ResponseScripts.Add("ReiniciarPagina();");
}
catch (Exception ex)
{
if(ex is ApplicationException)
warningPedido.Text = ex.Message;
else
throw ex;
}
}

private clsPedidosCarros BuscarCarroAbierto()
{

try
{
clsPedidosCarros objCarro = new clsPedidosCarros(txtPedido.Text.Trim(), Seguridad.IdCliente);
objCarro.idusuario = Seguridad.IdUsuario;
DataView objDv = objCarro.GetUsuarioCarros();

objDv.RowFilter = "idestado=" + Convert.ToInt32(Constantes.enmEstados.Abierto).ToString();

if (objDv.Count > 0)
{
objCarro.nrocarro = objDv[0]["nrocarro"].ToString();

return objCarro;
}
else
{
return null;
}
}
catch (Exception ex)
{
throw ex;
}
}

private Boolean CancelarBulto(Decimal idbulto)
{
try
{

ClassBultos.clsBultos objBul = new ClassBultos.clsBultos(txtPedido.Text.Trim(), Seguridad.IdCliente);
objBul.idbulto = idbulto;

if (EsSubBulto)
objBul.idbultopadre = Convert.ToDecimal(hdIdBultoSel.Value);

objBul.AnularBulto();

ActualizarVisorBultos();
return true;
}
catch (Exception ex)
{
throw ex;
}
}
private void Cargarparametros()
{
try
{
OParametroConfig oParam = new OParametroConfig();
clsClientesparametros obj = new clsClientesparametros();
obj.IdCliente = Seguridad.IdCliente;
DataTable dt = obj.GetClienteparametros();

foreach(DataRow rw in dt.Rows)
{
switch(Convert.ToInt32(rw["idparam"].ToString()))
{
case (int)Constantes.parametros.ImprimeEtiquetas:
oParam.ImprimeEtiquetas = Boolean.Parse(rw["valor"].ToString());
break;
case (int)Constantes.parametros.ControlCarros:
oParam.ControlCarros = Boolean.Parse(rw["valor"].ToString());
break;
case (int)Constantes.parametros.ControlSeries:
oParam.ControlSeries = Boolean.Parse(rw["valor"].ToString());
break;
case (int)Constantes.parametros.MostrarGraficoEmbalaje:
oParam.MostrarGraficoEmbalaje = Boolean.Parse(rw["valor"].ToString());
break;
case (int)Constantes.parametros.ImprimeEtiquetaSubbulto:
oParam.ImprimeEtiquetaSubbulto = Boolean.Parse(rw["valor"].ToString());
break;
case (int)Constantes.parametros.CambioDocumentacion:
oParam.CambioDocumentacion = Boolean.Parse(rw["valor"].ToString());
break;
case (int)Constantes.parametros.ControlProductosPorCarro:
oParam.ControlProductosPorCarro = Boolean.Parse(rw["valor"].ToString());
break;
case (int)Constantes.parametros.ImpresionesFinPedido:
oParam.ImpresionesFinPedido = Boolean.Parse(rw["valor"].ToString());
break;
}

}

hdparametrosConfig.Value = JsonConvert.SerializeObject(oParam);


}
catch (Exception ex)
{
throw ex;
}
}

//public void txtRemito_OnTextChanged(object sender, EventArgs e)
//{
// try
// {
// ValidarPedido();
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}


#region Botones Hidden
public void hdBotonCerrarCarro_Click(object sender, EventArgs e)
{
try
{
if(Funciones.GetParam<bool>(Convert.ToInt32(Constantes.parametros.ControlProductosPorCarro)) == true)
{
if(Convert.ToDecimal(ViewState["PorcentajeEmbalado"].ToString()) != 100)
{
RadAjaxManager1.ResponseScripts.Add("AbrirIncidencia('Cerrar Contenedor Parcial','" + Constantes.PROC_CERRAR_CONTENEDOR_PARCIAL + "','" + Constantes.ErrProductosFaltantesCarro + "','" + txtPedido.Text.Trim() + "','','','','','" + cboCarros.Text + "');");
return;
}
}

CerrarCarro();

CargarCarros();

cboCarros.Enabled = true;
}
catch (Exception ex)
{
throw ex;
}
}
public void hdBotonBuscarPedido_Click(object sender, EventArgs e)
{
try
{
ValidarPedido();
}
catch (Exception ex)
{
throw ex;
}
}

public void hdBotonCerrarPedidoIncidentado_Click(object sender, EventArgs e)
{
CerrarPedido(true);
}

public void hdBotonCerrarPedido_Click(object sender, EventArgs e)
{
try
{
if (ValidarReetiquetar())
{
if (!Funciones.TieneProductosFaltantes(txtPedido.Text.Trim(), Seguridad.IdCliente))
{
CerrarPedido(false);

RadAjaxManager1.ResponseScripts.Add("ReiniciarPagina();");
}
else
{
RadAjaxManager1.ResponseScripts.Add("AbrirIncidencia('Incidencia','" + Constantes.PROC_CERRAR_PEDIDO + "','" + Constantes.ErrProductosFaltantes + "','" + txtPedido.Text.Trim() + "','','','','');");
}
}
else
{
RadAjaxManager1.ResponseScripts.Add("AbrirReetiquetar('" + txtPedido.Text.Trim()+ "');");
}
}
catch (Exception ex)
{
warningPedido.Text = ex.Message;
}
}
public void hdBotonCerrarBulto_Click(object sender, EventArgs e)
{
try
{
CerrarBulto();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion

void ActualizarGrafico()
{

if (GetListaparametros().MostrarGraficoEmbalaje == true)
{
ajaxChart.Style.Add("display", "''");

clsBultosItems obj = new clsBultosItems(txtPedido.Text.Trim(), Seguridad.IdCliente);
obj.nrocarro = ((GetListaparametros().ControlProductosPorCarro == true && !string.IsNullOrEmpty(cboCarros.Text))?cboCarros.Text:string.Empty);
double CantidadUnidadesEmbaladas = Convert.ToDouble(obj.GetBultosItemsCantidad());
double PorcentEmbalado = System.Math.Truncate((CantidadUnidadesEmbaladas / vs_CantidadTotalUnidades) * 100);

if (double.IsNaN(PorcentEmbalado))
PorcentEmbalado = 0;

RadChart1.Series[0].SetValues(PorcentEmbalado);
RadChart1.Series[1].SetValues(100 - PorcentEmbalado);

RadChart1.Series[0].ActiveRegionToolTip = CantidadUnidadesEmbaladas.ToString() + " Unidades Embaladas";
RadChart1.Series[1].ActiveRegionToolTip = (vs_CantidadTotalUnidades - CantidadUnidadesEmbaladas).ToString() + " Unidades Pendientes";


ViewState["PorcentajeEmbalado"] = PorcentEmbalado;
}
}

protected void Page_Load(object sender, EventArgs e)
{
try
{
string cadena= ClassConnection.clsConnection.GetConnectionString(ClassConnection.clsConnection.TipoConn.sql);
sqlProductosBulto.ConnectionString = cadena;
sqlDataRelleno.ConnectionString = cadena;
sqlDataDemoras.ConnectionString = cadena;

if (!RemitoValidado)
sqlProductosBulto.SelectParameters["idbulto"].DefaultValue = string.Empty;

sqlDataDemoras.SelectParameters["idusuario"].DefaultValue = User.Identity.Name;

if (!IsPostBack)
{

CargarTiposBulto();

Funciones.CargarIncidencias(cboIncidenciasDemoras, true, true);

if (cboIncidenciasDemoras.Items.Count > 0)
cboIncidenciasDemoras.ClearSelection();

CargarTiposRelleno();

txtRemito.Focus();


Cargarparametros();

SubMenu.FindItemByValue("ConsProductosPendientesCarro").Visible = GetListaparametros().ControlProductosPorCarro;


txtPesoBulto.Value = 0;

if (Request.QueryString[Constantes.VS_INTERNO] != null)
{
txtPedido.Text = Request.QueryString[Constantes.VS_INTERNO].ToString();

ValidarPedido();
}

cboTipoBulto.Enabled = false;
txtPesoBulto.Enabled = false;

EnablePanelProductos(false);
EnablePanelRelleno(false);
EnablePanelDemoras(false);

confirmDeleteBulto.ConfirmText = string.Format("Realmente desea anular el bulto?{0} ATENCION: serán eliminados tambien los subbultos que contuviese.", Environment.NewLine);
}

}
catch (Exception ex)
{
throw ex;
}

}

void EnablePanelDemoras(bool enable)
{
cboIncidenciasDemoras.Enabled = enable;
cboProductoDemora.Enabled = enable;
txtObservacionDemora.Enabled = enable;
imgAgregarDemora.Enabled = enable;
RadAjaxManager1.ResponseScripts.Add("document.getElementById('imgLimpiarDemora').disabled = " + (!enable).ToString().ToLower() + ";");
RadGrid3.Enabled = enable;
}

void EnablePanelRelleno(bool enable)
{
cboTipoRelleno.Enabled = enable;
txtCantidadRelleno.Enabled = enable;
txtPesoRelleno.Enabled = enable;
imgAgregarRelleno.Enabled = enable;
RadAjaxManager1.ResponseScripts.Add("document.getElementById('imgLimpiarRelleno').disabled = " + (!enable).ToString().ToLower() + ";");
RadGrid2.Enabled = enable;
}

void EnablePanelProductos(bool enable)
{
cboProductos.Enabled= enable;
cboLotes.Enabled= enable;
txtCantidad.Enabled = enable;
imgAgregarProducto.Enabled = enable;
RadAjaxManager1.ResponseScripts.Add("document.getElementById('imgLimpiarProductos').disabled = " + (!enable).ToString().ToLower() + ";");
RadGrid1.Enabled = enable;
}

void CargarTiposBulto()
{

try
{
clsTiposBulto obj = new clsTiposBulto();
obj.idcliente = Seguridad.IdCliente;
DataTable dt = obj.GetTiposBulto();
List<oTipoBulto> Lista = new List<oTipoBulto>();

foreach (DataRow rw in dt.Rows)
{
cboTipoBulto.Items.Add(new RadComboBoxItem(rw["Descripcion"].ToString(), rw["idtipobulto"].ToString()));

//if (Boolean.Parse(rw["admitesubbultos"].ToString()) == false &&
// Convert.ToInt32(rw["idtipoembalaje"].ToString()) != (int)Constantes.enumTiposEmbalaje.PalletOriginal)

//if (Convert.ToInt32(rw["idtipoembalaje"].ToString()) != (int)Constantes.enumTiposEmbalaje.PalletOriginal
// && Convert.ToInt32(rw["idtipoembalaje"].ToString()) != (int)Constantes.enumTiposEmbalaje.Pallet)
//{
// cboTipoSubBulto.Items.Add(new RadComboBoxItem(rw["Descripcion"].ToString(), rw["idtipobulto"].ToString()));
//}

oTipoBulto item = new oTipoBulto();
item.idtipobulto = Convert.ToInt32(rw["idtipobulto"].ToString());
item.descripcion = rw["Descripcion"].ToString();
double kilos;
double.TryParse(rw["kilos"].ToString(), out kilos);
item.kilos = kilos;
item.controlapeso = Boolean.Parse(rw["controlapeso"].ToString());
item.idtipoembalaje = Convert.ToInt32(rw["idtipoembalaje"].ToString());
item.admitesubbultos = Boolean.Parse(rw["admitesubbultos"].ToString());
item.tolerancia = Convert.ToDouble(rw["tolerancia"].ToString());
Lista.Add(item);
}

hdTiposBulto.Value = JsonConvert.SerializeObject(Lista);
}
catch (Exception ex)
{
throw ex;
}
}

void CargarTiposRelleno()
{
try
{
clsTiposRelleno obj = new clsTiposRelleno();
obj.idcliente = Seguridad.IdCliente;
DataTable dt = obj.GetTiposRelleno();

cboTipoRelleno.DataTextField = "descripcion";
cboTipoRelleno.DataValueField = "idtiporelleno";
cboTipoRelleno.DataSource = dt;
cboTipoRelleno.DataBind();

List<oRelleno> Lista = new List<oRelleno>();

foreach(DataRow rw in dt.Rows)
{
oRelleno item = new oRelleno();
item.idtiporelleno = Convert.ToInt32(rw["idtiporelleno"].ToString());
item.requierepeso = Boolean.Parse(rw["requierepeso"].ToString());

if (!string.IsNullOrEmpty(rw["kilos"].ToString()))
item.kilos = Convert.ToDecimal(rw["kilos"].ToString());
else
item.kilos = 0;

Lista.Add(item);
}

hdTiposRelleno.Value = JsonConvert.SerializeObject(Lista);

}
catch (Exception ex)
{
throw ex;
}

}

private DataRow BuscarPedido(string interno, string remito, string nrocarro, bool historico)
{
try{

if (!string.IsNullOrEmpty(nrocarro))
{
clsPedidosCarros obj = new clsPedidosCarros();
obj.idcliente = Seguridad.IdCliente;
obj.nrocarro = nrocarro;

DataRow rw = (!historico?obj.GetPedidoCarro():obj.GetHisPedidoCarro());

if (rw != null)
return rw;
else
throw new ApplicationException(Funciones.GetMensaje("MsgCarroPedidoInexistente"));
}
else
{
clsPedidosCab obj = new clsPedidosCab();
obj.interno = interno;
obj.remito = remito;
obj.idcliente = Seguridad.IdCliente;
DataRow rw = (!historico ? obj.GetPedidoCab() : obj.GetHisPedidoCab());

if (rw == null)
throw new ApplicationException(Funciones.GetMensaje("MsgPedidoInexistente").ToString());
else
return rw;
}
}
catch(Exception ex)
{
throw ex;
}
}

//private DataRow BuscarEnPedidoDistribucionCab(string remitocliente)
//{
// try{

// clsPedidosDistribucion obj = new clsPedidosDistribucion();
// obj.RemitoCliente = remitocliente;
// DataRow rw = obj.GetPedidosDistribucionCab();

// return rw;
// }
// catch(Exception ex)
// {
// throw ex;
// }
//}

//private DataRow BuscarEnPedidoDistribucionDet(string remitocliente, string remito)
//{
// try{

// clsPedidosDistribucion obj = new clsPedidosDistribucion();
// obj.RemitoCliente = remitocliente;
// obj.Remito = remito;
// DataTable dt = obj.GetPedidosDistribucionDet();

// if (dt.Rows.Count > 0)
// return dt.Rows[0];
// else
// return null;
// }
// catch(Exception ex)
// {
// throw ex;
// }
//}

private DataRow BuscarEnHisPedidoCab(string interno, string remito, string nrocarro)
{
try{

if (!string.IsNullOrEmpty(nrocarro))
{
clsPedidosCarros obj = new clsPedidosCarros();
obj.idcliente = Seguridad.IdCliente;
obj.nrocarro = nrocarro;

return obj.GetHisPedidoCarro();
}
else
{
clsPedidosCab obj = new clsPedidosCab();
obj.interno = interno;
obj.remito = remito;
return obj.GetHisPedidoCab();
}
}
catch(Exception ex)
{
throw ex;
}
}

private void CargarJsonProductosEmbalados()
{
try
{
clsBultosItems obj = new clsBultosItems(txtPedido.Text.Trim(), Seguridad.IdCliente);
obj.nrocarro = ((GetListaparametros().ControlProductosPorCarro == true && !string.IsNullOrEmpty(cboCarros.Text)) ? cboCarros.Text : string.Empty);

DataTable odt = obj.GetBultosItemsEmbalados();

List<oProducto> ListaProductos = new List<oProducto>();
foreach (DataRow rw2 in odt.Rows)
{
oProducto item = new oProducto();
item.codproductocliente = rw2["codproductocliente"].ToString();
item.nrolote = rw2["nrolote"].ToString();
item.cantidad = Convert.ToInt32(rw2["cantidad"].ToString());

ListaProductos.Add(item);
}

hdJsonProductosEmbalados.Value = JsonConvert.SerializeObject(ListaProductos);

}
catch (Exception ex)
{
throw ex;
}
}

private void CargarJsonProductos(DataTable odt)
{
try
{
List<oProducto> ListaProductos = new List<oProducto>();

Boolean ProductosTrazables = false;

foreach (DataRow rw2 in odt.Rows)
{
oProducto item = new oProducto();
item.codproductocliente = rw2["codproductocliente"].ToString();
item.nrolote = rw2["nrolote"].ToString();
item.cantidad = Convert.ToInt32(rw2["cantidad"].ToString());
item.serializado = bool.Parse(rw2["serializado"].ToString());

if (!ProductosTrazables)
ProductosTrazables = item.serializado;

item.descproducto = rw2["descproducto"].ToString();
item.kilos = Convert.ToDecimal(rw2["kilos"].ToString());
item.codproducto = rw2["codproducto"].ToString();

decimal val;
decimal.TryParse(rw2["kilospack"].ToString(), out val);
item.kilospack = val;

decimal.TryParse(rw2["kiloscaja"].ToString(), out val);
item.kiloscaja = val;

decimal.TryParse(rw2["kilospallet"].ToString(), out val);
item.kilospallet = val;

decimal.TryParse(rw2["cantpack"].ToString(), out val);
item.cantpack = val;

decimal.TryParse(rw2["cantcaja"].ToString(), out val);
item.cantcaja = val;

decimal.TryParse(rw2["cantpallet"].ToString(), out val);
item.cantpallet = val;

SubMenu.FindItemByValue("ConsRemitoDistribucion").Enabled = !string.IsNullOrEmpty(rw2["pedidohijo"].ToString());

ListaProductos.Add(item);

RadAjaxManager1.ResponseScripts.Add("OpenNotificationPedido('" + !string.IsNullOrEmpty(rw2["pedidohijo"].ToString()) + "','" + ProductosTrazables + "');");
}

hdJson.Value = JsonConvert.SerializeObject(ListaProductos);

}
catch (Exception ex)
{
throw ex;
}
}

public void ValidarPedido()
{

clsPedidosCab obj = new clsPedidosCab();
DataRow objDr = null;

try
{


warningPedido.Text = string.Empty;
warningProductos.Text = string.Empty;
warningRelleno.Text = string.Empty;

if (!RemitoValidado)
{
if (string.IsNullOrEmpty(txtRemito.Text.Trim()) && string.IsNullOrEmpty(txtPedido.Text.Trim())
&& string.IsNullOrEmpty(cboCarros.Text))
{
RadAjaxManager1.FocusControl(txtRemito);
throw new ApplicationException(Funciones.GetMensaje("MsgPedidoNoSel").ToString());
}

if (!string.IsNullOrEmpty(cboCarros.Text))
{
clsPedidosCarros obj2 = new clsPedidosCarros();
obj2.idcliente = Seguridad.IdCliente;
obj2.nrocarro = cboCarros.Text;
objDr = obj2.GetPedidoCarro();

if (objDr == null)
{
objDr = obj2.GetHisPedidoCarro();
}
//if (dt.Select("idestado=" + Convert.ToInt32(Constantes.enmEstados.Abierto) + " or idestado=" +
// Convert.ToInt32(Constantes.enmEstados.Disponible)).Length > 1)
//{
// RadAjaxManager1.ResponseScripts.Add("AbrirPedidosCarro();");
// return;
//}
}
else
{
objDr = BuscarPedido(txtPedido.Text.Trim(), txtRemito.Text.Trim(), string.Empty, false);

if (objDr == null)
{
//Si no lo encontró lo busca en el historico
objDr = BuscarPedido(txtPedido.Text.Trim(), txtRemito.Text.Trim(), string.Empty, true);
}
}


#region Pedido encontrado

if(objDr == null)
throw new ApplicationException(Funciones.GetMensaje("MsgPedidoInexistente").ToString());

if (string.IsNullOrEmpty(objDr["remito"].ToString()) || string.IsNullOrEmpty(objDr["interno"].ToString()))
throw new ApplicationException(Funciones.GetMensaje("MsgPedidoInexistente").ToString());

if (Convert.ToInt32(objDr["idestado"].ToString()) != Convert.ToInt32(Constantes.enmEstados.Disponible)
&& Convert.ToInt32(objDr["idestado"].ToString()) != Convert.ToInt32(Constantes.enmEstados.Abierto))
throw new ApplicationException(Funciones.GetMensaje("MsgPedidoYaCerrado").ToString());
else if (Convert.ToInt32(objDr["idestado"].ToString()) == Convert.ToInt32(Constantes.enmEstados.Disponible))
{
if (GetListaparametros().CambioDocumentacion == true)
{
if(string.IsNullOrEmpty(txtRemito.Text.Trim()))
throw new ApplicationException(Funciones.GetMensaje("MsgRemitoIngresoInicial").ToString());
else if (Boolean.Parse(objDr["CambioDocumentacion"].ToString()) == false)
throw new ApplicationException(Funciones.GetMensaje("MsgCambioDocNoSel").ToString());
}
}

txtRemito.Text = objDr["remito"].ToString();
txtPedido.Text = objDr["pedido"].ToString();
lblRazSoc.Text = objDr["razonsocial"].ToString();
lblDir.Text = objDr["direccion"].ToString();
lblCuenta.Text = objDr["cuenta"].ToString();
lblAnulacionTroquel.Text = ((Boolean.Parse(objDr["anulaciontroquel"].ToString()) == true ? Funciones.GetMensaje("MsgAnulacionTroquel") : string.Empty));
//txtRemito.Enabled = false;
//txtPedido.Enabled = false;
lblCodPostal.Text = objDr["codpostaldestino"].ToString();
lblLocalidad.Text = objDr["localidaddestino"].ToString();



//string CarroInput = cboCarros.Text;

CargarCarros();

#region Abre el pedido
if (string.IsNullOrEmpty(objDr["fechaini"].ToString()))
{
obj = new clsPedidosCab(txtPedido.Text.Trim(), Seguridad.IdCliente);
obj.AbrirPedido();
}
#endregion

//Registra el proceso Abrir Pedido
Funciones.RegistrarLog(null, (Int32)Constantes.Acciones.AbrirPedido, txtPedido.Text.Trim(), Seguridad.IdCliente, Seguridad.IdUsuario);

#region Si esta habilitado que controle carros, busca los carros del pedido para saber si tiene o no
AbrirCarro(cboCarros.Text);
#endregion




if (GetListaparametros().ControlProductosPorCarro == false || String.IsNullOrEmpty(cboCarros.Text))
{
DataTable odt = Funciones.CargarPedidoProductos(txtPedido.Text.Trim(), Seguridad.IdCliente);

if (odt.Rows.Count == 0)
throw new ApplicationException("No se pudo encontrar el detalle del pedido.");

CargarJsonProductos(odt);

vs_CantidadTotalUnidades = (double)(from n in odt.AsEnumerable()
select n.Field<decimal>("cantidad")).Sum();

}


#region busca si hay un bulto abierto y lo carga
AbrirBulto(null);
#endregion

ActualizarVisorBultos();

CargarListaDemoras();
#endregion

ActualizarGrafico();

OParametroConfig param = GetListaparametros();

cboTipoBulto.Enabled = true;

if (!string.IsNullOrEmpty(cboCarros.SelectedValue))
{
if (!string.IsNullOrEmpty(cboTipoBulto.SelectedValue))
{
cboProductos.Focus();
RadAjaxManager1.ResponseScripts.Add("focusCombo('" + cboProductos.ClientID + "');");
}
else
{
cboTipoBulto.Focus();
RadAjaxManager1.FocusControl(cboTipoBulto.ClientID + "_Input");
}
}
else
{
if (param.ControlCarros == true)
{
cboCarros.Enabled = true;
cboCarros.Focus();
RadAjaxManager1.FocusControl(cboCarros.ClientID + "_Input");
}
}



ajaxChart.Visible = param.MostrarGraficoEmbalaje;
txtPesoBulto.Enabled = (!string.IsNullOrEmpty(hdIdBultoSel.Value));
EnablePanelDemoras(true);
EnablePanelProductos(!string.IsNullOrEmpty(hdIdBultoSel.Value));
EnablePanelRelleno(!string.IsNullOrEmpty(hdIdBultoSel.Value));
txtRemito.Enabled = false;
txtPedido.Enabled = false;
cboTipoBulto.Enabled = true;
cboCarros.Enabled = true;

imgCancelarBulto.Visible = !string.IsNullOrEmpty(cboTipoBulto.SelectedValue);

}
}
catch (Exception ex)
{

if (ex is ApplicationException)
{
RadAjaxManager1.ResponseScripts.Add("ReiniciarPagina();");
RadAjaxManager1.ResponseScripts.Add("document.getElementById('" + warningPedido.ClientID + "').innerHTML = '" + ex.Message + "';");
}
else
{
throw ex;
}
}
}

private void CargarCarros()
{
try
{
cboCarros.ClearSelection();
cboCarros.Items.Clear();
if (GetListaparametros().ControlCarros == true)
{
clsPedidosCarros oCarros = new clsPedidosCarros(txtPedido.Text.Trim(), Seguridad.IdCliente);
DataTable dt = oCarros.GetPedidosCarros();
dt.Select( "idestado=" + Convert.ToInt32(Constantes.enmEstados.Disponible).ToString() +
" or (idestado=" + Convert.ToInt32(Constantes.enmEstados.Abierto).ToString() +
" and idusuariomodif='" + Seguridad.IdUsuario + "')");

cboCarros.DataSource = dt;
cboCarros.DataValueField = "nrocarro";
cboCarros.DataTextField = "nrocarro";
cboCarros.DataBind();
}
}
catch (Exception ex)
{
throw ex;
}
}

private void CambiarTipoBulto(decimal idbulto, Int32 idTipoBulto, bool EsSubbulto)
{
try
{

ClassBultos.clsBultos obj = null;

obj = new ClassBultos.clsBultos(txtPedido.Text.Trim(), Seguridad.IdCliente);
obj.idusuario = Seguridad.IdUsuario;
obj.idestado = Convert.ToInt32(Constantes.enmEstados.Abierto);
obj.idbulto = idbulto;
obj.idtipobulto = idTipoBulto;

//esto se usa solo para saber en auditoria si grabar ModificarBulto o ModificarSubBulto
if(EsSubbulto)
obj.idbultopadre = -1;

obj.ActualizarBulto();

if (!EsSubbulto)
{
txtPesoBulto.Value = BuscarTipoBulto(Convert.ToInt32(cboTipoBulto.SelectedValue)).kilos;
hdIdTipoBultoSel.Value = idTipoBulto.ToString();
hdIdSubBultoSel.Value = string.Empty;
}
else
{
txtPesoSubBulto.Value = BuscarTipoBulto(Convert.ToInt32(cboTipoSubBulto.SelectedValue)).kilos;
}



}
catch (Exception ex)
{
throw ex;
}
}

protected void cboTipoSubBulto_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrEmpty(cboTipoSubBulto.SelectedValue))
{
oTipoBulto item = BuscarTipoBulto(Convert.ToInt32(cboTipoSubBulto.SelectedValue));

if (EsSubBulto)
{
CambiarTipoBulto(Convert.ToDecimal(hdIdSubBultoSel.Value), item.idtipobulto, true);
}
else
{
AgregarBulto(item, Convert.ToDecimal(hdIdBultoSel.Value), true);
}

txtCantidadBultos.Visible = EsEmbalajeOriginal(item);
lblPesoSubBulto.Text = (EsEmbalajeOriginal(item) ? "Peso caja completa" : "Peso insumo");

imgCancelarSubBulto.Visible = (!string.IsNullOrEmpty(hdIdSubBultoSel.Value));
imgCerrarSubBulto.Visible = false;
txtCantidadBultos.Value = 1;
warningPedido.Text = string.Empty;
warningProductos.Text = string.Empty;
cboTipoSubBulto.Enabled = true;
txtPesoSubBulto.Enabled = true;
EnablePanelProductos(true);
EnablePanelRelleno(true);
cboProductos.ClearSelection();
cboLotes.Items.Clear();
cboLotes.ClearSelection();
txtCantidad.Value = 0;
cboProductos.Focus();
CargarListaProductos();
RadAjaxManager1.FocusControl(cboProductos.ClientID + "_Input");

ActualizarVisorBultos();
}

}
catch (Exception ex)
{
throw ex;
}
finally
{
imgCancelarSubBulto.Visible = (EsSubBulto);
imgCerrarSubBulto.Visible = (EsSubBulto);
//**EstadoControles();
//**updProductos.Update();
}
}

private void AgregarBulto(oTipoBulto TipoBulto, decimal? idbultopadre, bool EsSubbulto)
{
try
{
clsBultos obj = new clsBultos();
obj.interno = txtPedido.Text.Trim();
obj.idcliente = Seguridad.IdCliente;
obj.kilos = Convert.ToDecimal(TipoBulto.kilos);
obj.idtipobulto = Convert.ToInt32(TipoBulto.idtipobulto);
obj.idbultopadre = ((EsSubbulto == true) ? idbultopadre : null);

obj.AgregarBulto();

if (!EsSubbulto)
{
hdIdBultoSel.Value = obj.idbulto.ToString();
txtNroBulto.Text = obj.nrobulto.ToString();
txtPesoBulto.Value = TipoBulto.kilos;
}
else
{
hdIdSubBultoSel.Value = obj.idbulto.ToString();
lblSubBulto.Text = obj.nrobulto.ToString();
txtPesoSubBulto.Value = TipoBulto.kilos;
trTipoSubBulto.Style.Add("display", "''");
}

RadGrid1.DataSource = null;

//SubMenu.FindItemByValue("CerrarBulto").Enabled = (!String.IsNullOrEmpty(hdIdBultoSel.Value));
}
catch (Exception ex)
{
throw ex;
}
}

protected void CargarTiposSubBulto(int idtipobulto_sel)
{
try
{
cboTipoSubBulto.ClearSelection();

cboTipoSubBulto.Items.Clear();

List<oTipoBulto> Lista = (List<oTipoBulto>)JsonConvert.DeserializeObject(hdTiposBulto.Value, typeof(List<oTipoBulto>));

foreach (oTipoBulto item in Lista)
{

if (Convert.ToInt32(item.idtipoembalaje) != (int)Constantes.enumTiposEmbalaje.PalletOriginal
&& Convert.ToInt32(item.idtipoembalaje) != (int)Constantes.enumTiposEmbalaje.Pallet
&& item.idtipobulto != idtipobulto_sel)
{
cboTipoSubBulto.Items.Add(new RadComboBoxItem(item.descripcion, item.idtipobulto.ToString()));
}
}
}
catch(Exception ex)
{
throw ex;
}
}

protected void cboTipoBulto_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrEmpty(cboTipoBulto.SelectedValue))
{


CargarTiposSubBulto(Convert.ToInt32(cboTipoBulto.SelectedValue));

oTipoBulto item = BuscarTipoBulto(Convert.ToInt32(cboTipoBulto.SelectedValue));


if (hdIdBultoSel.Value != "")
{
CambiarTipoBulto(Convert.ToDecimal(hdIdBultoSel.Value), Convert.ToInt32(cboTipoBulto.SelectedValue), false);
}
else
{
if (hdIdBultoSel.Value == "" && !string.IsNullOrEmpty(cboTipoBulto.SelectedValue))
{
AgregarBulto(item, null, false);

CargarListaProductos();
CargarListaRelleno();
}
}

ActualizarVisorBultos();



imgAddSubBulto.Style.Add("display",(item.admitesubbultos==true?"''":"none"));
trTipoSubBulto.Style.Add("display", "none");
imgCancelarBulto.Visible = (!string.IsNullOrEmpty(hdIdBultoSel.Value));
imgCancelarSubBulto.Visible = false;
imgCerrarSubBulto.Visible = false;
txtCantidadBultos.Value = 1;
warningPedido.Text = string.Empty;
warningProductos.Text = string.Empty;
cboTipoBulto.Enabled = true;
txtPesoBulto.Enabled = true;
EnablePanelProductos(true);
EnablePanelRelleno(true);
cboProductos.ClearSelection();
cboLotes.Items.Clear();
cboLotes.ClearSelection();
txtCantidad.Value = 0;

cboProductos.Focus();
RadAjaxManager1.ResponseScripts.Add("focusCombo('" + cboProductos.ClientID + "');");

txtCantidadBultos.Visible = EsEmbalajeOriginal(item);
lblPesoBulto.Text = (EsEmbalajeOriginal(item) ? "Peso caja completa" : "Peso insumo");

}
}
catch (Exception ex)
{
throw ex;
}
}

private void AbrirBulto(decimal?idbulto)
{
try
{
/*Busca si ya tenia un bulto y subbulto abierto para el pedido*/
ClassBultos.clsBultos objBul = new ClassBultos.clsBultos(txtPedido.Text.Trim(), Seguridad.IdCliente);
objBul.idestado = Convert.ToInt32(Constantes.enmEstados.Abierto); /*En proceso*/
objBul.idbulto = idbulto;
objBul.idusuario = Seguridad.IdUsuario;
oTipoBulto item = null;
DataTable dt = objBul.GetBultoAbierto();

foreach (DataRow rw in dt.Rows)
{
if (string.IsNullOrEmpty(rw["idbultopadre"].ToString()))
{
hdIdBultoSel.Value = rw["idbulto"].ToString();
txtNroBulto.Text = rw["nrobulto"].ToString();

if (!string.IsNullOrEmpty(rw["idtipobulto"].ToString()))
{
item = BuscarTipoBulto(Convert.ToInt32(rw["idtipobulto"].ToString()));

txtPesoBulto.Value = item.kilos;

foreach (RadComboBoxItem objItem in cboTipoBulto.Items)
{
if (objItem.Value == item.idtipobulto.ToString())
{
cboTipoBulto.SelectedValue = objItem.Value;
hdIdTipoBultoSel.Value = objItem.Value;
CargarTiposSubBulto(Convert.ToInt32(objItem.Value));
break;
}
}


imgCancelarBulto.Style.Add("display", "");
trTipoSubBulto.Style.Add("display", "none");
cboTipoBulto.Enabled = true;
imgCancelarBulto.Visible = true;

imgAddSubBulto.Style.Add("display", (item.admitesubbultos == true ? "''" : "none"));
}
}
else
{
hdIdSubBultoSel.Value = rw["idbulto"].ToString();

lblSubBulto.Text = rw["nrobulto"].ToString();

item = BuscarTipoBulto(Convert.ToInt32(rw["idtipobulto"].ToString()));

if (item.idtipobulto > 0)
{
txtPesoSubBulto.Value = item.kilos;

foreach (RadComboBoxItem objItem in cboTipoSubBulto.Items)
{
if (objItem.Value == item.idtipobulto.ToString())
{
cboTipoSubBulto.SelectedValue = objItem.Value;
break;
}
}
}

trTipoSubBulto.Style.Add("display", "''");
imgCancelarBulto.Style.Add("display", "none");
cboTipoSubBulto.Enabled = true;
imgCancelarSubBulto.Visible = true;
}
}



txtCantidadBultos.Value = 1;





if (!string.IsNullOrEmpty(hdIdBultoSel.Value))
{
EnablePanelProductos(true);
EnablePanelRelleno(true);
CargarListaProductos();
CargarListaRelleno();


}

if (item != null)
{
txtCantidadBultos.Visible = EsEmbalajeOriginal(item);
lblPesoBulto.Text = (EsEmbalajeOriginal(item) ? "Peso caja completa" : "Peso insumo");
txtPesoBulto.Enabled = true;
}
else
{
txtCantidadBultos.Visible = false;
txtPesoBulto.Enabled = false;
}


}
catch (Exception ex)
{
throw ex;
}
}

public Boolean ValidarReabrirCarro()
{
try
{
warningPedido.Text = string.Empty;

string NroCarro = twContenedores.SelectedNode.Value;

/*busca que el usuario no tenga carros abiertos */
clsPedidosCarros obj = new clsPedidosCarros(txtPedido.Text.Trim(), Seguridad.IdCliente);
obj.idusuario = Seguridad.IdUsuario;
DataView odw = obj.GetUsuarioCarros();

odw.RowFilter = "idestado = " + Convert.ToInt32(Constantes.enmEstados.Abierto).ToString();

if (odw.Count > 0)
throw new ApplicationException(Funciones.GetMensaje("MsgCarroCerrarActual"));

obj = new clsPedidosCarros(txtPedido.Text.Trim(), Seguridad.IdCliente, NroCarro);
DataTable dt = obj.GetPedidosCarros();

if (dt.Rows.Count == 0 )
{
throw new ApplicationException(Funciones.GetMensaje("MsgCarroInexistente"));
}
else
{
if (dt.Rows.Count > 0)
{
DataRow[] rws = dt.Select("idestado=" + Convert.ToInt32(Constantes.enmEstados.Abierto).ToString() + " or " +
"idestado=" + Convert.ToInt32(Constantes.enmEstados.Disponible).ToString());

if (rws.Length > 0)
throw new ApplicationException(String.Format(Funciones.GetMensaje("MsgCarroAbierto").ToString(),rws[0]["idusuariomodifcarro"]));
}
}

return true;

}
catch (Exception ex)
{
if (ex is ApplicationException)
{

warningPedido.Text = ex.Message;
return false;
}
else
{
throw ex;
}
}
}

public Boolean ValidarActualizarBulto()
{
try
{
RadTreeNode oNode = twContenedores.SelectedNode;


decimal? idbultopadre = null;
string[] param = oNode.Value.Split('|');

if (param.Length > 1)
{
if (oNode.Category == "bultoscerrados")
{
bool EsSubBulto = (param[0] == "SB" ? true : false);
//string idusuario = param[1];

if (EsSubBulto)
{
if (!string.IsNullOrEmpty(param[3].ToString()))
idbultopadre = Convert.ToDecimal(param[3]);
}

if (twContenedores.SelectedNode.Text.Split('-')[2].ToString().Trim() != Seguridad.IdUsuario)
throw new ApplicationException(Funciones.GetMensaje("MsgActualizarUsuarioIncorrecto"));

if (!EsSubBulto)
{
/*es un bulto*/
if (hdIdBultoSel.Value != "")
throw new ApplicationException(Funciones.GetMensaje("MsgActualizarBultosAbiertos"));
}
else
{
/*es un subbulto*/
if (EsSubBulto && !string.IsNullOrEmpty(hdIdSubBultoSel.Value))
throw new ApplicationException(Funciones.GetMensaje("MsgActualizarSubBultosAbiertos"));
else if (hdIdBultoSel.Value!="" && Convert.ToDecimal(hdIdBultoSel.Value) != idbultopadre)
throw new ApplicationException(Funciones.GetMensaje("MsgActualizarSubbultoOtroBulto"));
else if (hdIdBultoSel.Value == "")
throw new ApplicationException(Funciones.GetMensaje("MsgActualizarSubbultoAbrirPadre"));
}
}
}

return true;
}
catch (Exception ex)
{
if (ex is ApplicationException)
{

warningPedido.Text = ex.Message;
return false;
}
else
{
throw ex;
}
}
}

public void AgregarProducto()
{
try
{

oProducto objProductoAdd = null;

warningProductos.Text = string.Empty;

//var codproducto = cboProductos.SelectedValue;

if (ValidarProductoCantidad())
{
List<oProducto> Productos = (List<oProducto>)JsonConvert.DeserializeObject(hdJson.Value, typeof(List<oProducto>));

if (Productos != null)
{
foreach (oProducto obj in Productos)
{
if (obj.codproductocliente == cboProductos.SelectedValue && obj.nrolote == cboLotes.SelectedValue)
{
if (string.IsNullOrEmpty(obj.codproducto))
throw new ApplicationException("No se puede embalar el producto ya que no tiene cargado el código de barras.");

objProductoAdd = obj;
break;
}
}

if (objProductoAdd != null)
{
clsBultosItems obj = new clsBultosItems(txtPedido.Text.Trim(), Seguridad.IdCliente);
obj.idbulto = (EsSubBulto ? Convert.ToDecimal(hdIdSubBultoSel.Value) : Convert.ToDecimal(hdIdBultoSel.Value));
obj.codproducto = objProductoAdd.codproducto;
obj.descproducto = objProductoAdd.descproducto;
obj.cantidad = Convert.ToInt32(txtCantidad.Value);
obj.nrolote = cboLotes.SelectedValue;
obj.nuevolote = hdNuevoLote.Value;
obj.codproductocliente = objProductoAdd.codproductocliente;

if(GetListaparametros().ControlProductosPorCarro == true)
obj.nrocarro = cboCarros.SelectedValue;


decimal idbultoitem = obj.AgregarBultoItem();
CargarListaProductos();


ActualizarGrafico();

RadAjaxManager1.ResponseScripts.Add("imgLimpiarProductos_Click();");

RadAjaxManager1.FocusControl(cboProductos.ClientID + "_Input");
}
}
}
else
{
RadAjaxManager1.ResponseScripts.Add("ErrorCantidad();");
}
}
catch (Exception ex)
{
if (ex is ApplicationException)
{
warningProductos.Text = ex.Message;
}
else
{
throw ex;
}
}

}

//protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
//{
// Int32 CantidadAEmbalar = 0;

// if (e.Item is GridDataItem)
// {
// GridDataItem dataItem = (GridDataItem)e.Item;

// List<oProducto> ProductosEmbalados = (List<oProducto>)JsonConvert.DeserializeObject(hdJsonProductosEmbalados.Value, typeof(List<oProducto>));

// if (Productos != null)
// {
// foreach (oProducto item in Productos)
// {
// if (item.codproductocliente == dataItem.GetDataKeyValue("codproductocliente").ToString() && item.nrolote == dataItem["nrolote"].Text)
// {
// CantidadAEmbalar += item.cantidad;
// break;
// }
// }
// }

// clsBultosItems obj = new clsBultosItems(txtPedido.Text.Trim(), Seguridad.IdCliente);
// obj.codproductocliente = dataItem.GetDataKeyValue("codproductocliente").ToString();
// obj.nrolote = dataItem["nrolote"].Text;
// obj.nrocarro = ((GetListaparametros().ControlProductosPorCarro == true && !string.IsNullOrEmpty(cboCarros.Text)) ? cboCarros.Text : string.Empty);

// Int32 CantEmbalada = Convert.ToInt32(obj.GetBultosItemsCantidad());

// if (txtCantidadBultos.Value > 1)
// CantEmbalada = CantEmbalada * Convert.ToInt32(txtCantidadBultos.Value);

// if (CantidadAEmbalar > CantEmbalada)
// {
// dataItem.BackColor = System.Drawing.Color.Red;
// dataItem.ForeColor = System.Drawing.Color.White;
// }
// }
//}

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
Int32 CantidadAEmbalar = 0;
Int32 CantidadEmabalada = 0;


if (e.Item is GridDataItem)
{
GridDataItem dataItem = (GridDataItem)e.Item;

//Carga el teorico a embalar
List<oProducto> Productos = (List<oProducto>)JsonConvert.DeserializeObject(hdJson.Value, typeof(List<oProducto>));

if (Productos != null)
{
foreach (oProducto item in Productos)
{
if (item.codproductocliente == dataItem.GetDataKeyValue("codproductocliente").ToString() && item.nrolote == dataItem["nrolote"].Text)
{
CantidadAEmbalar += item.cantidad;
break;
}
}
}

//Carga el real emb alado
List<oProducto> ProductosEmbalados = (List<oProducto>)JsonConvert.DeserializeObject(hdJsonProductosEmbalados.Value, typeof(List<oProducto>));

if (ProductosEmbalados != null)
{
foreach (oProducto item in ProductosEmbalados)
{
if (item.codproductocliente == dataItem.GetDataKeyValue("codproductocliente").ToString() && item.nrolote == dataItem["nrolote"].Text)
{
CantidadEmabalada += item.cantidad;
break;
}
}
}

if (txtCantidadBultos.Value > 1)
CantidadEmabalada = CantidadEmabalada * Convert.ToInt32(txtCantidadBultos.Value);

if (CantidadAEmbalar > CantidadEmabalada)
{
dataItem.BackColor = System.Drawing.Color.Red;
dataItem.ForeColor = System.Drawing.Color.White;
}
}
}

private void CargarListaProductos()
{
try
{
if (hdIdBultoSel.Value != "" || hdIdSubBultoSel.Value != "")
{
sqlProductosBulto.SelectParameters["interno"].DefaultValue = txtPedido.Text.Trim();
sqlProductosBulto.SelectParameters["idbulto"].DefaultValue = (EsSubBulto ? hdIdSubBultoSel.Value : hdIdBultoSel.Value);

CargarJsonProductosEmbalados();

RadGrid1.Rebind();
}
}
catch (Exception ex)
{
throw ex;
}
}

private void CargarListaRelleno()
{
try
{
if (hdIdBultoSel.Value != "" || hdIdSubBultoSel.Value != "")
{
sqlDataRelleno.SelectParameters["interno"].DefaultValue = txtPedido.Text.Trim();
sqlDataRelleno.SelectParameters["idbulto"].DefaultValue = (EsSubBulto ? hdIdSubBultoSel.Value : hdIdBultoSel.Value);
RadGrid2.Rebind();
}
}
catch (Exception ex)
{
throw ex;
}
}

private void CargarListaDemoras()
{
try
{
if (RemitoValidado)
{
sqlDataDemoras.SelectParameters["interno"].DefaultValue = txtPedido.Text.Trim();
RadGrid3.Rebind();
}
}
catch (Exception ex)
{
throw ex;
}
}

public Boolean ValidarProductoCantidad()
{
try
{
Int32 intCantidad = 0;
Int32 CantidadPedidoProducto = 0;
Int32 CantPedidoBulto = 0;

Int32.TryParse(txtCantidad.Value.ToString(), out intCantidad);

if (intCantidad == 0)
{
warningProductos.Text = "Debe indicar la cantidad.";
return false;
}


intCantidad = Convert.ToInt32(txtCantidad.Value) * Convert.ToInt32(txtCantidadBultos.Value);

CargarJsonProductosEmbalados();

List<oProducto> ProductosEmbalados = (List<oProducto>)JsonConvert.DeserializeObject(hdJsonProductosEmbalados.Value, typeof(List<oProducto>));

if (ProductosEmbalados != null)
{
foreach (oProducto item in ProductosEmbalados)
{
if (item.codproductocliente == cboProductos.SelectedValue && item.nrolote == cboLotes.SelectedValue)
{
CantPedidoBulto = item.cantidad;
break;
}
}
}




List<oProducto> Productos = (List<oProducto>)JsonConvert.DeserializeObject(hdJson.Value,typeof(List<oProducto>));

if (Productos != null)
{
foreach (oProducto item in Productos)
{
if (item.codproductocliente == cboProductos.SelectedValue && item.nrolote == cboLotes.SelectedValue)
{
CantidadPedidoProducto = Convert.ToInt32(item.cantidad);
}
}


if (CantidadPedidoProducto > 0)
{
if (CantPedidoBulto + intCantidad > CantidadPedidoProducto)
{
txtCantidad.Focus();
txtCantidad.Value = 0;
return false;
}
else
return true;
}
else
{
return false;
}
}
else
{
return false;
}


}
catch (Exception ex)
{
throw ex;
}
}
private Boolean AbrirCarro(string CarroInput)
{
try
{
clsPedidosCarros objCarro = BuscarCarroAbierto();

if (objCarro != null)
{
if (!string.IsNullOrEmpty(CarroInput) && objCarro.nrocarro.ToLower() != CarroInput.ToLower())
throw new ApplicationException(string.Format( Funciones.GetMensaje("MsgCarroOtroAbierto"),objCarro.nrocarro));

cboCarros.SelectedValue = objCarro.nrocarro;

cboTipoBulto.Focus();
RadAjaxManager1.ResponseScripts.Add("focusCombo('" + cboTipoBulto.ClientID + "');");
}
else
{
cboCarros.SelectedValue = CarroInput;

if (!string.IsNullOrWhiteSpace(cboCarros.SelectedValue))
{
objCarro = new clsPedidosCarros();
objCarro.interno = txtPedido.Text.Trim();
objCarro.idcliente = Seguridad.IdCliente;
objCarro.nrocarro = cboCarros.SelectedValue;
objCarro.AbrirCarro();

ActualizarVisorBultos();

cboTipoBulto.Focus();
RadAjaxManager1.ResponseScripts.Add("focusCombo('" + cboTipoBulto.ClientID + "');");



}
else
{
cboCarros.Focus();
RadAjaxManager1.ResponseScripts.Add("focusCombo('" + cboCarros.ClientID + "');");
}
}

//Si tiene control productos por carro, carga el json de los carros
if (cboCarros.SelectedItem != null && GetListaparametros().ControlProductosPorCarro == true)
{
clsPedidosCarrosProductos obj = new clsPedidosCarrosProductos();
obj.interno = txtPedido.Text.Trim();
obj.idcliente = Seguridad.IdCliente;
obj.nrocarro = cboCarros.SelectedValue;
DataTable odt = obj.GetPedidosCarrosProductos();

if (odt.Rows.Count == 0)
{
RadAjaxManager1.ResponseScripts.Add("document.getElementById('" + warningPedido.ClientID + "').innerHTML = 'No se pudo encontrar el detalle de los productos que se encuentran dentro del carro.';");
}
else
{
CargarJsonProductos(odt);

vs_CantidadTotalUnidades = (double)(from n in odt.AsEnumerable()
select n.Field<decimal>("cantidad")).Sum();

}


}
return true;
}
catch (Exception ex)
{
cboCarros.Focus();
cboCarros.ClearSelection();
throw ex;
}
}


//private Boolean ValidarKilos()
//{
// clsTiposBulto item = BuscarTipoBulto(Convert.ToInt32(cboTipoBulto.SelectedValue));
// Double decTolerancia1 = Convert.ToDouble(item.tolerancia);

// if (!EsEmbalajeOriginal(item))
// {
// Double KilosReales = Convert.ToDouble(txtPesoTotal.Value);
// Double KilosTeoricos = Convert.ToDouble(txtPesoBulto.Value);
// Int32 Cantidad = 0;
// Decimal PesoUnitario = 0;
// vs_ErrorTolerancia1 = false;

// try
// {
// //SUBBULTOS
// if (item.admitesubbultos == true)
// {
// clsBultos oBulto = new clsBultos(txtPedido.Text.Trim(), Seguridad.IdClienteSeleccionado);
// oBulto.idbultopadre = Convert.ToDecimal(hdIdBultoSel.Value);
// DataTable dt = oBulto.GetBultos();

// foreach (DataRow rw in dt.Rows)
// KilosTeoricos += Convert.ToDouble(Funciones.GetDecimal(rw["kilos"].ToString()));
// }

// //PRODUCTOS
// foreach (GridDataItem dataItem in RadGrid1.Items)
// {
// Cantidad = Convert.ToInt32(dataItem["cantidad"].Text);
// PesoUnitario = Convert.ToDecimal(Funciones.GetDecimal((string.IsNullOrEmpty(dataItem.GetDataKeyValue("kilos").ToString()) ? "0" : dataItem.GetDataKeyValue("kilos").ToString())));

// KilosTeoricos += Convert.ToDouble(Cantidad * PesoUnitario);
// }

// //RELLENO
// foreach (GridDataItem dataItem in RadGrid2.Items)
// {
// Cantidad = Convert.ToInt32(dataItem["cantidad"].Text);
// PesoUnitario = Convert.ToDecimal(Funciones.GetDecimal(dataItem["kilos"].Text));
// KilosTeoricos += Convert.ToDouble(Cantidad * PesoUnitario);
// }


// Double PorcentajeDif = Convert.ToDouble(1 - KilosReales / KilosTeoricos);
// PorcentajeDif = Math.Abs(PorcentajeDif) * 100;

// Boolean blValTolerancia1 = false;


// if (PorcentajeDif > decTolerancia1)
// return false;
// else
// return true;

// }
// catch (Exception ex)
// {
// throw ex;
// }
// }
// else
// {
// return true;
// }
//}

protected void imgAgregarRelleno_Click(object sender, ImageClickEventArgs e)
{
try
{

if (Page.IsValid)
{



clsBultosRelleno obj = new clsBultosRelleno(txtPedido.Text.Trim(), Seguridad.IdCliente, (EsSubBulto ? Convert.ToDecimal(hdIdSubBultoSel.Value) : Convert.ToDecimal(hdIdBultoSel.Value)));
obj.idtiporelleno = Convert.ToInt32(cboTipoRelleno.SelectedValue.ToString());
obj.cantidad = Convert.ToInt32(txtCantidadRelleno.Value);
obj.kilos = Convert.ToDecimal(txtPesoRelleno.Value);

obj.AgregarBultosRelleno();


RadGrid2.Rebind();

RadAjaxManager1.ResponseScripts.Add("imgLimpiarRelleno_Click();");
RadAjaxManager1.ResponseScripts.Add("$find('" + cboTipoRelleno.ClientID + "').get_inputDomElement().focus();");

}
}
catch (Exception ex)
{
throw ex;
}
}

protected void imgAgregarDemora_Click(object sender, ImageClickEventArgs e)
{
try
{
if (Page.IsValid)
{
if (!string.IsNullOrEmpty(cboIncidenciasDemoras.SelectedValue))
{
clsPedidosDemoras obj = new clsPedidosDemoras();
obj.idcliente = Seguridad.IdCliente;
obj.interno = txtPedido.Text.Trim();
obj.idjustificacion = Convert.ToInt32(cboIncidenciasDemoras.SelectedValue.ToString());
obj.codproducto = cboProductoDemora.SelectedValue;
obj.observacion = txtObservacionDemora.Text.Trim();
obj.Insertar();

RadGrid3.Rebind();

RadAjaxManager1.ResponseScripts.Add("imgLimpiarDemora_Click();");
}
}
}
catch (Exception ex)
{
throw ex;
}
}

public void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
try
{
if (e.CommandName == "Delete")
{
GridDataItem item = (GridDataItem)e.Item;

clsBultosItems obj = new clsBultosItems();
obj.idbultoitem = Convert.ToInt32(item.GetDataKeyValue("idbultoitem").ToString());
obj.EliminarBultoItem();

CargarJsonProductosEmbalados();

RadGrid1.Rebind();

ActualizarGrafico();
}
}
catch (Exception ex)
{
throw ex;
}
}

public void RadGrid3_ItemCommand(object sender, GridCommandEventArgs e)
{
try
{
if (e.CommandName == "Delete")
{
GridDataItem item = (GridDataItem)e.Item;

clsPedidosDemoras obj = new clsPedidosDemoras();
obj.iddemora = Convert.ToInt32(item.GetDataKeyValue("iddemora").ToString());
obj.Eliminar();

RadGrid3.Rebind();
}
}
catch (Exception ex)
{
throw ex;
}
}

public void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
{
try
{
if (e.CommandName == "Delete")
{
GridDataItem item = (GridDataItem)e.Item;

clsBultosRelleno obj = new clsBultosRelleno(txtPedido.Text.Trim(), Seguridad.IdCliente, (EsSubBulto ? Convert.ToDecimal(hdIdSubBultoSel.Value) : Convert.ToDecimal(hdIdBultoSel.Value)));
obj.idtiporelleno = Convert.ToInt32(item.GetDataKeyValue("idtiporelleno").ToString());
obj.EliminarBultoRelleno();

RadGrid2.Rebind();
}
}
catch (Exception ex)
{
throw ex;
}
}



protected void imgCancelarBulto_Click(object sender, EventArgs e)
{
try
{
if (RemitoValidado && !string.IsNullOrEmpty(hdIdBultoSel.Value))
{
if (CancelarBulto(Convert.ToDecimal(hdIdBultoSel.Value)))
{
ActualizarVisorBultos();

ActualizarGrafico();

RadAjaxManager1.ResponseScripts.Add("imgLimpiarProductos_Click();");
RadAjaxManager1.ResponseScripts.Add("imgLimpiarRelleno_Click();");

imgCancelarBulto.Visible = false;
hdIdBultoSel.Value = string.Empty;
hdIdSubBultoSel.Value = string.Empty;
cboTipoBulto.ClearSelection();
cboTipoBulto.Focus();
txtNroBulto.Text = string.Empty;
txtPesoBulto.Value = 0;
warningPedido.Text = string.Empty;
cboProductos.ClearSelection();

RadGrid1.DataSource = null;
RadGrid1.DataBind();
RadGrid2.DataSource = null;
RadGrid2.DataBind();

EnablePanelProductos(false);
EnablePanelRelleno(false);
}
}
}
catch (Exception ex)
{
throw ex;
}
}

protected void imgAgregarProducto_Click(object sender, ImageClickEventArgs e)
{
AgregarProducto();
}

void CargarVisor()
{
try
{

twContenedores.Nodes.Clear();
string nodeCategory;
string nodeValue;
string nodeText;
Telerik.Web.UI.RadTreeNode childNode;
Telerik.Web.UI.RadTreeNode parentNode;
Telerik.Web.UI.RadTreeNode rootNode;


rootNode = new Telerik.Web.UI.RadTreeNode("Bultos Abiertos", "ba");
rootNode.EnableContextMenu = false;
rootNode.Font.Bold = true;
twContenedores.Nodes.Add(rootNode);

rootNode = new Telerik.Web.UI.RadTreeNode("Bultos Cerrados", "bc");
rootNode.EnableContextMenu = false;
rootNode.Font.Bold = true;
twContenedores.Nodes.Add(rootNode);

rootNode = new Telerik.Web.UI.RadTreeNode("Carros Abiertos", "ca");
rootNode.EnableContextMenu = false;
rootNode.Font.Bold = true;
twContenedores.Nodes.Add(rootNode);

rootNode = new Telerik.Web.UI.RadTreeNode("Carros Cerrados", "cc");
rootNode.EnableContextMenu = false;
rootNode.Font.Bold = true;
twContenedores.Nodes.Add(rootNode);



ClassBultos.clsBultos obj = new ClassBultos.clsBultos(txtPedido.Text.Trim(), Seguridad.IdCliente);
DataSet ds = obj.GetDatosVisor();

DataView dw = ds.Tables[0].DefaultView;
dw.RowFilter = "idestado=" + (int)Constantes.enmEstados.Abierto + " or idestado=" + (int)Constantes.enmEstados.Cerrado;
dw.Sort = "idestado,idbultopadre asc, nrobulto";

foreach (DataRowView rw in dw)
{
if (Convert.ToInt32(rw["idestado"].ToString()) == (int)Constantes.enmEstados.Abierto)
nodeCategory = "bultosabiertos";
else
nodeCategory = "bultoscerrados";

if (!string.IsNullOrEmpty(rw["idbultopadre"].ToString()))
{
nodeText = rw["nrobultopadre"].ToString() + "." + rw["nrobulto"].ToString() + " - " + rw["tipobulto"].ToString() + " - " + rw["idusuariomodif"].ToString() + " - " + rw["kilos"].ToString();
nodeValue = "SB" + "|" + rw["idusuariomodif"] + "|" + rw["idbulto"].ToString() + "|" + rw["idbultopadre"].ToString();
childNode = new Telerik.Web.UI.RadTreeNode(nodeText, nodeValue);
childNode.ImageUrl = "~/Images/visorbulto.png";
childNode.EnableContextMenu = (nodeCategory == "bultoscerrados");
childNode.Category = nodeCategory;

string parentValuePath = "B" + "|" + rw["idusuariomodif"] + "|" + rw["idbultopadre"].ToString();
parentNode = twContenedores.FindNodeByValue(parentValuePath);

if (parentNode == null || (parentNode != null && parentNode.Category != childNode.Category))
parentNode = twContenedores.FindNodeByValue((nodeCategory == "bultoscerrados" ? "bc" : "ba"));

parentNode.Nodes.Add(childNode);
}
else

{
nodeText = rw["nrobulto"].ToString() + " - " + rw["tipobulto"].ToString() + " - " + rw["idusuariomodif"].ToString() + " - " + rw["kilos"].ToString();
nodeValue = "B" + "|" + rw["idusuariomodif"] + "|" + rw["idbulto"].ToString();
childNode = new Telerik.Web.UI.RadTreeNode(nodeText, nodeValue);
childNode.ImageUrl = "~/Images/visorbulto.png";
childNode.EnableContextMenu = (nodeCategory == "bultoscerrados");
childNode.Category = nodeCategory;
twContenedores.FindNodeByValue((nodeCategory == "bultoscerrados"?"bc":"ba")).Nodes.Add(childNode);
}


}

twContenedores.ExpandAllNodes();

#region CarrosAbiertos
dw = ds.Tables[1].DefaultView;
dw.RowFilter = "idestado=" + (int)Constantes.enmEstados.Abierto + " or idestado=" + (int)Constantes.enmEstados.Cerrado;
dw.Sort = "idestado";

foreach (DataRowView rw in dw)
{
if (Convert.ToInt32(rw["idestado"].ToString()) == (int)Constantes.enmEstados.Abierto)
nodeCategory = "carrosabiertos";
else
nodeCategory = "carroscerrados";

childNode = new Telerik.Web.UI.RadTreeNode(rw["nrocarro"].ToString() + " - " + rw["idusuariomodif"].ToString(), rw["nrocarro"].ToString());
childNode.ImageUrl = "~/Images/visorcarro.png";
childNode.EnableContextMenu = (nodeCategory == "carroscerrados");
childNode.Category = nodeCategory;
twContenedores.FindNodeByValue((nodeCategory == "carroscerrados"?"cc":"ca")).Nodes.Add(childNode);
}

#endregion

}
catch (Exception ex)
{
throw ex;
}
}

protected void ActualizarVisorBultos()
{
try
{

if (RemitoValidado)
{
CargarVisor();
}
}
catch (Exception ex)
{
throw ex;
}
}

public Boolean ValidarCarro()
{
try
{
if (!string.IsNullOrWhiteSpace(cboCarros.SelectedValue))
{
clsPedidosCarros obj = new clsPedidosCarros(txtPedido.Text.Trim(), Seguridad.IdCliente, cboCarros.SelectedValue);
DataTable dt = obj.GetPedidosCarros();

if (dt.Rows.Count > 0)
{
DataRow objDr = dt.Rows[0];

switch (Convert.ToInt32(objDr["idestado"].ToString()))
{
case (int)Constantes.enmEstados.Abierto:
/*Carro abierto por el otro usuario*/
throw new ApplicationException(Funciones.GetMensaje("MsgCarroAbierto").ToString().Replace("{0}", objDr["idusuariomodif"].ToString()));
case (int)Constantes.enmEstados.Cerrado:
throw new ApplicationException(Funciones.GetMensaje("MsgCarroYaUsado"));
}
}
}

return true;

//**upVisorBultos.Update();
}
catch (Exception ex)
{

if (ex is ApplicationException)
{

warningPedido.Text = ex.Message;
cboCarros.ClearSelection();
cboCarros.Text = string.Empty;
return false;
}
else
throw ex;
}
finally
{
//**EstadoControles();
}
}

protected void cboCarros_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (RemitoValidado == false)
{
ValidarPedido();
return;
}

if (!string.IsNullOrEmpty(cboCarros.Text))
{
if (ValidarCarro())
{
if (cboCarros.SelectedItem != null)
{
AbrirCarro(cboCarros.SelectedValue);
}
}
}

}
catch (Exception ex)
{
if (ex is ApplicationException)
{

RadAjaxManager1.ResponseScripts.Add("document.getElementById('" + warningPedido.ClientID + "').innerHTML = '" + ex.Message + "';");
}
else
throw ex;
}
finally
{
cboCarros.Enabled = RemitoValidado && GetListaparametros().ControlCarros && String.IsNullOrEmpty(cboCarros.SelectedValue);
SubMenu.Items.FindItemByValue("CerrarCarro").Enabled = cboCarros.SelectedValue != null;
cboTipoBulto.Enabled = RemitoValidado && cboCarros.SelectedValue != null;
}
}

protected void SubMenu_ItemClick(object sender, RadMenuEventArgs e)
{
try
{
switch (e.Item.Value)
{
case "Reetiquetar":
Response.Redirect("~/Reetiquetado.aspx?" + Constantes.VS_INTERNO + "=" + txtPedido.Text.Trim(), false);
break;
}

}
catch (Exception ex)
{
throw ex;
}
}


public Boolean ValidarReetiquetar()
{
try
{
clsPedidosCab obj = new clsPedidosCab(txtPedido.Text.Trim(), Seguridad.IdCliente);
DataRow row = obj.GetPedidoReetiquetar();

return (row == null);

//throw new ApplicationException(Funciones.GetMensaje("MsgReetiquetarBultos"));

}
catch (Exception ex)
{
throw ex;
}
}


protected oTipoBulto BuscarTipoBulto(Int32 idtipobulto)
{
try
{
List<oTipoBulto> ListaTiposBulto = (List<oTipoBulto>)JsonConvert.DeserializeObject(hdTiposBulto.Value, typeof(List<oTipoBulto>));

foreach (oTipoBulto item in ListaTiposBulto)
{
if (item.idtipobulto == idtipobulto)
return item;
}

return null;
}
catch (Exception ex)
{
throw ex;
}
}

protected void ImgCancelarSubBulto_Click(object sender, ImageClickEventArgs e)
{
try
{
if (RemitoValidado && EsSubBulto)
{
if (CancelarBulto(Convert.ToDecimal(hdIdSubBultoSel.Value)))
{
ActualizarVisorBultos();
ActualizarGrafico();

RadAjaxManager1.ResponseScripts.Add("imgLimpiarProductos_Click();");
RadAjaxManager1.ResponseScripts.Add("imgLimpiarRelleno_Click();");

imgCancelarSubBulto.Visible = false;
imgCerrarSubBulto.Visible = false;
hdIdSubBultoSel.Value = string.Empty;
cboTipoSubBulto.ClearSelection();
cboTipoSubBulto.Focus();
lblSubBulto.Text = string.Empty;
txtPesoSubBulto.Value = 0;

RadGrid1.DataSource = null;
RadGrid1.DataBind();
RadGrid2.DataSource = null;
RadGrid2.DataBind();

EnablePanelProductos(!string.IsNullOrEmpty(hdIdBultoSel.Value));
EnablePanelRelleno(!string.IsNullOrEmpty(hdIdBultoSel.Value));

CargarListaProductos();
CargarListaRelleno();
}
}
}
catch(Exception ex)
{
throw ex;
}
}

protected void twContenedores_ContextMenuItemClick(object sender, Telerik.Web.UI.RadTreeViewContextMenuEventArgs e)
{

try
{
e.Node.Selected = true;

if (e.Node.Category == "bultoscerrados")
{

string[] param = e.Node.Value.Split('|');

if (param.Length > 1)
{
decimal idbulto = Convert.ToDecimal(param[2]);
//bool EsSubBulto = (param[0] == "SB" ? true : false);
string idusuario = param[1];
//decimal? idbultopadre;

//if (EsSubBulto)
//{
// if (!string.IsNullOrEmpty(param[3].ToString()))
// idbultopadre = Convert.ToDecimal(param[3]);
//}

if(ValidarActualizarBulto())
{
clsBultos obj = new clsBultos();
obj.idbulto = idbulto;
obj.idusuario = idusuario;
obj.idestado = (int)Constantes.enmEstados.Abierto;
obj.interno = txtPedido.Text.Trim();
obj.idcliente = Seguridad.IdCliente;
obj.ActualizarBulto();

AbrirBulto(obj.idbulto);

ActualizarVisorBultos();

RadAjaxManager1.ResponseScripts.Add("EnablePanelProductos(true);");
RadAjaxManager1.ResponseScripts.Add("EnablePanelRelleno(true);");


}

//**updPedido.Update();
}
}
else if (e.Node.Category == "carroscerrados")
{
if(ValidarReabrirCarro())
{
clsPedidosCarros obj = new clsPedidosCarros(txtPedido.Text.Trim(), Seguridad.IdCliente, e.Node.Value);
obj.AbrirCarro();

CargarCarros();

AbrirCarro(e.Node.Value);

ActualizarVisorBultos();

cboCarros.Enabled = false;

cboTipoBulto.Enabled = true;
cboTipoBulto.Focus();
}

//updPedido.Update();
}
}
catch (Exception ex)
{

throw ex;
}
}
}


0
Maria Ilieva
Telerik team
answered on 17 Feb 2014, 12:57 PM
Hello Gustavo,

I revise the provided code and noticed that you have a huge amount of Ajax settings added to the RadAjaxManager. Could you please try to reduce their number by wrapping most of the controls in a single wrapper (for example asp Panel) and use this wrappers in the RadAjaxManager settings. Also I would  suggest you to try adding the LoadingPanel manually as described in the help topic below:

http://www.telerik.com/help/aspnet-ajax/ajax-show-hide-loadingpanel.html


Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Gustavo
Top achievements
Rank 1
answered on 24 Feb 2014, 01:41 AM
Hi, sorry but i don't understand, i use all asp:panel and the radajaxmanager update asp:panel, how can i reduce? i should put a great asp:panel envolving anothers asp:panels?
About the On the sample page on the aspx code say....
<telerik:AjaxUpdatedControl ControlID="Panel1" LoadingPanelID="RadAjaxLoadingPanel1" />

if is setted the loadingpanelid, the radajaxmanager manage automatically hide and show of loading panel? other way is i put the events OnRequestStart nad OnRequestEnd is necesary set loadingpanelid on ajaxupdatedcontrol?

I think, maybe one diference on the old OK source and the new BAD source is that on the new code, i added on the combo carros change, update some asp:panels and on the old code isn't, is posible that this new ajax setting fire another ajax settings and spme times it's make recursive ajax fires and this is the javascript problem?
best regards
0
Maria Ilieva
Telerik team
answered on 26 Feb 2014, 12:16 PM
Hello Gustavo,

As the application contains a big amount of markup and server code it will be best if you could open a regular support ticket and send us sample runnable version of the presented application. Thus we will be able to debug it locally and advise you further on the best approach for setting the LoadingPanel so that the issue does not appear.

Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Gustavo
Top achievements
Rank 1
answered on 26 Feb 2014, 12:36 PM
I could get the error and know what is the message,
This error is reproducing pressing 15 to 17 times the button that go to the server. As pressing the button will on the 14 time, the page is more and more slow and on the 16 o 17 time, the loadingpanel isn't hide because the requestEnd event isn't fire because this error
    
SCRIPT28: Out of stack space

I have commented all c# and jscrit source and the only way that isn't ocurs is if a comment the RadAjaxManager but it isn't a solution because i need use partitial postback. What can i do?
0
Maria Ilieva
Telerik team
answered on 28 Feb 2014, 02:27 PM
Hi Gustavo,

I suppose that the issue might be related with terminated subsequent Ajax request which is causing an error and problems with the RadAjaxLoadingPanel hiding. Could you please try to set RequestQueueSize for the RadAjaxManager to "5" for example and verify if this makes any difference?

Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Gustavo
Top achievements
Rank 1
answered on 15 Jul 2014, 12:14 PM
Hello, sorry but the error causes for that line:
<telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />

I don't know why but after comment this line, the page run OK, no more problemas with the loadingpanel or the stack overflow. Can you tell me why this FormDecorator cause this problem in this page?
0
Gustavo
Top achievements
Rank 1
answered on 15 Jul 2014, 12:14 PM
Hello, sorry but the error causes for that line:
<telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />

I don't know why but after comment this line, the page run OK, no more problemas with the loadingpanel or the stack overflow. Can you tell me why this FormDecorator cause this problem in this page?
0
Konstantin Dikov
Telerik team
answered on 18 Jul 2014, 10:16 AM
Hello Gustavo,

As Maria mentioned in one of her posts, in order for us to be able to assist you any further on this matter, since we are not able to replicate the issues on our end with a simple scenario, please open a regular support ticket and provide a sample, runnable project replicating the problematic behavior. Thus will allow us to investigate the issue locally and easily locate the root of the problem.

On a side note, could you please elaborate if you have test the suggestion from the Maria's last post, for setting the RequestQueueSize for the RadAjaxManager to "5" for example?

Finally, following is a very simple example, demonstrating that everything is working correctly, even if a RadFormDecorator is included:
<telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />
 
<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="Panel1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Panel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
 
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default"></telerik:RadAjaxLoadingPanel>
 
<asp:Panel runat="server" ID="Panel1">
    <telerik:RadButton runat="server" ID="RadButton1" Text="Test button"></telerik:RadButton>
 
    <telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource">
    </telerik:RadGrid>
</asp:Panel>

And the code-behind:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("SortOrder", typeof(int));
    table.Columns.Add("SomeField", typeof(string));
    for (int i = 0; i < 5; i++)
    {
        table.Rows.Add(i, "Some value");
    }
 
    (sender as RadGrid).DataSource = table;
}


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Ajax
Asked by
Gustavo
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Gustavo
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or