//#region OnSaveDetails Actualizada
        //private void OnSaveDetails(object sender, EventArgs e)
        //{
        //    //Validacion si no existen datos para guardar
        //    if (View.Model.ListRecords.Rows.Count == 0)
        //        return;



        //    IList<DataInformation> DataInformationSerialList = null;
        //    //IList<DataInformation> DataInformationLabelList;
        //    //DataInformation DataInformationLabel;
        //    IList<WpfFront.WMSBusinessService.Label> EvalSerialLabelList;
        //    DataInformation DataInformationSerial = null;
        //    Object ChildrenValue, ChildrenLabel;
        //    ShowData DetailDataSave;
        //    IList<ShowData> DetailDataList;
        //    string XmlData;
        //    WpfFront.WMSBusinessService.Label LabelAux;
        //    DataDefinitionByBin DataDefinitionControlIsRequired;
        //    bool ControlIsRequired, EvalSerial1 = true, EvalSerial2 = true, EvalSerial3 = true, Res = true;
        //    DataTable Dt_Res = new DataTable("Resultados");

        //    //Agrego Columnas
        //    Dt_Res.Columns.Add("SERIAL");
        //    Dt_Res.Columns.Add("# SERIAL");
        //    Dt_Res.Columns.Add("DESCRIPCION");

        //    try
        //    {
        //        //Recorro los registros de la lista para obtener los datos y hacer un join con los anteriores y guardarlos
        //        foreach (DataRow DataRow in View.Model.ListRecords.Rows)
        //        {
        //            //Variables Auxiliares
        //            EvalSerialLabel = new WpfFront.WMSBusinessService.Label { Bin = new Bin { Location = service.GetLocation(new Location { LocationID = View.Model.LocationFrom.LocationID }).First() } };
        //            #region Nuevo Codigo

        //            foreach (DataDefinitionByBin DataDefinitionByBin in View.Model.CamposSeriales)
        //            {
        //                switch (DataDefinitionByBin.DataDefinition.Code)
        //                {
        //                    case "SERIAL1":
        //                        //Asigno el serial para evaluar si existe en el sistema
        //                        EvalSerialLabel.LabelCode = DataRow["SERIAL1"].ToString();
        //                        //Evaluo si existe la columna para validar el serial existente en el listado actual
        //                        if (View.Model.ListRecords.Columns.Contains(DataDefinitionByBin.DataDefinition.Code))
        //                        {
        //                            EvalSerial1 = Validar_serial_Lista_actual(DataDefinitionByBin.DataDefinition.Code, DataRow["SERIAL1"].ToString());
        //                        }
        //                        break;
        //                    case "SERIAL2":
        //                        //Asigno el serial para evaluar si existe en el sistema
        //                        EvalSerialLabel.PrintingLot = DataRow["SERIAL2"].ToString();
        //                        //Evaluo si existe la columna para validar el serial existente en el listado actual
        //                        if (View.Model.ListRecords.Columns.Contains(DataDefinitionByBin.DataDefinition.Code))
        //                        {
        //                            EvalSerial2 = Validar_serial_Lista_actual(DataDefinitionByBin.DataDefinition.Code, DataRow["SERIAL2"].ToString());
        //                        }
        //                        break;
        //                    case "SERIAL3":
        //                        //Asigno el serial para evaluar si existe en el sistema
        //                        EvalSerialLabel.PrintingLot = DataRow["SERIAL3"].ToString();
        //                        //Evaluo si existe la columna para validar el serial existente en el listado actual
        //                        if (View.Model.ListRecords.Columns.Contains(DataDefinitionByBin.DataDefinition.Code))
        //                        {
        //                            EvalSerial3 = Validar_serial_Lista_actual(DataDefinitionByBin.DataDefinition.Code, DataRow["SERIAL3"].ToString());
        //                        }
        //                        break;
        //                }
        //            }
        //            //Analizo si el serial ya esta en la lista y el listado a lo sumo tiene un elemento
        //            if (EvalSerial1 && EvalSerial2 && EvalSerial3 && View.Model.ListRecords.Rows.Count > 0)
        //            {
        //                Dt_Res.Rows.Add(new object[] { "SERIAL1", EvalSerialLabel.LabelCode, "El serial ya existe en el listado de ingresos" });
        //                Res = false;
        //                break;
        //            }

        //            //Analizo si el serial esta en el sistema
        //            if (service.GetLabel(EvalSerialLabel).Count() == 0)
        //            {
        //                Dt_Res.Rows.Add(new object[] { "SERIAL1", EvalSerialLabel.LabelCode, "El serial no existe en el sistema" });
        //                Res = false;
        //                break;
        //            }

        //            ////Analizo si el serial esta en el sistema y esta en el Bin actual
        //            EvalSerialLabel.Bin = View.Model.BinFrom;

        //            if (View.Model.LocationFrom.AddressLine3 == "1")
        //            {
        //                //Obtengo los equipos con el label
        //                EvalSerialLabelList = service.GetLabel(EvalSerialLabel);

        //                //Evaluo si obtuve registros para continuar
        //                if (EvalSerialLabelList.Count == 0)
        //                {
        //                    Dt_Res.Rows.Add(new object[] { "SERIAL1", EvalSerialLabel.LabelCode, "El serial no se encuentra en el estado " + View.Model.BinFrom.BinCode });
        //                    Res = false;
        //                    break;
        //                }
        //            }
        //            else
        //            {
        //                try
        //                {
        //                    //Obtengo el Label
        //                    EvalSerialLabel = service.GetLabel(EvalSerialLabel).First();
        //                    //Obtengo el DataInformation asociado al Label, si es un producto pickeado, coloco la variable en vacio
        //                    DataInformationSerialList = service.GetDataInformation(new DataInformation
        //                    {
        //                        Entity = new ClassEntity { ClassEntityID = 20 },
        //                        EntityRowID = Int32.Parse(EvalSerialLabel.LabelID.ToString())
        //                    });
        //                    /*if (DataInformationLabelList.Count > 0)*/
        //                    DataInformationSerial = DataInformationSerialList.First();
        //                    /*else
        //                        DataInformationLabel = new DataInformation { Entity = new ClassEntity { ClassEntityID = EntityID.Label } };*/
        //                }
        //                catch
        //                {
        //                    Dt_Res.Rows.Add(new object[] { "SERIAL1", EvalSerialLabel.LabelCode, "El serial no se encuentra en el estado " + View.Model.BinFrom.BinCode });
        //                    Res = false;
        //                    DataInformationSerialList = null;
        //                    DataInformationSerial = null;

        //                }
        //            }

        //            #endregion

        //            if (Res)
        //            {
        //                //Validacion si hay errores leyendo las cadenas XML
        //                try
        //                {
        //                    //Evaluo si el registro viene de un picking o si ya esta en el sistema
        //                    DataInformationSerialList = View.Model.ListDataInformation.Where
        //                        (f => f.Entity.ClassEntityID == EntityID.Label &&
        //                              f.EntityRowID == Int32.Parse(DataRow[0].ToString())).ToList();

        //                    //Si el registro tiene datainformation, lo obtengo, en caso contrario creo uno nuevo
        //                    //if (DataInformationSerialList.Count > 0)
        //                    //Obtengo el DataInformation asociado al registro
        //                    DataInformationSerial = View.Model.ListDataInformation.Where
        //                        (f => f.Entity.ClassEntityID == EntityID.Label &&
        //                              f.EntityRowID == Int32.Parse(DataRow[0].ToString())).First();
        //                    /*else
        //                        //Creo un nuevo DataInformation
        //                        DataInformationSerial = new DataInformation
        //                        {
        //                            Entity = new ClassEntity { ClassEntityID = 20 },
        //                            EntityRowID = Int32.Parse(DataRow[0].ToString()),
        //                            CreationDate = DateTime.Now,
        //                            CreatedBy = App.curUser.UserName
        //                        };*/
        //                }
        //                catch
        //                {
        //                    Util.ShowError("Hubo un error durante el proceso de grabacion. Por favor intentar nuevamente.");
        //                    return;
        //                }




        //                //Deserializo el Xml para obtener el Showdata
        //                DetailDataList = Util.DeserializeMetaDataWF(DataInformationSerial.XmlData);

        //                //Inicializo la lista de los datos a convertir en Xml
        //                View.Model.ListDetailsDataSave = new List<ShowData>();

        //                //Obtengo los datos de cada campo con su nombre
        //                foreach (DataColumn c in View.Model.ListRecords.Columns)
        //                {
        //                    //Obtengo el label y el valor digitado
        //                    ChildrenLabel = c.ColumnName;
        //                    ChildrenValue = DataRow[c.ColumnName].ToString();

        //                    //Evaluo si el campo es obligatorio
        //                    ControlIsRequired = true;
        //                    DataDefinitionControlIsRequired = (View.Model.CamposDetails.Where(f => f.DataDefinition.Code == ChildrenLabel).Count() > 0) ? View.Model.CamposDetails.Where(f => f.DataDefinition.Code == ChildrenLabel).First() : null;
        //                    if (DataDefinitionControlIsRequired != null)
        //                    {
        //                        if (DataDefinitionControlIsRequired.DataDefinition.IsRequired == true && String.IsNullOrEmpty(ChildrenValue.ToString()))
        //                            ControlIsRequired = false;
        //                        else
        //                            ControlIsRequired = true;
        //                    }

        //                    //Evaluo si puedo continuar dependiendo de si el dato era requerido y fue digitado o no
        //                    if (ControlIsRequired)
        //                    {
        //                        //Evaluo si existe el dato que estoy leyendo para quitarlo del listado anterior
        //                        try
        //                        {
        //                            DetailDataSave = DetailDataList.Where(f => f.DataKey == c.ColumnName).First();
        //                            DetailDataList.Remove(DetailDataSave);
        //                        }
        //                        //En caso de no existir no quito nada
        //                        catch { }

        //                        //Creo el ShowData con el dato
        //                        DetailDataSave = new ShowData
        //                        {
        //                            DataKey = ChildrenLabel.ToString(),
        //                            DataValue = ChildrenValue.ToString()
        //                        };

        //                        //Adiciono cada dato a la lista
        //                        View.Model.ListDetailsDataSave.Add(DetailDataSave);
        //                    }
        //                    else
        //                    {
        //                        Util.ShowError("El campo " + ChildrenLabel.ToString() + " no puede ser vacio.");
        //                        return;
        //                    }

        //                    //Cargo el dato para la variable de ultimos procesados
        //                    View.Model.UltimosProcesadosMP = View.Model.UltimosProcesadosMP + ChildrenValue.ToString() + " \t ";
        //                }
        //                //Concateno las listas de ShowData, la que estaba guardada y la nueva
        //                View.Model.ListDetailsDataSave = View.Model.ListDetailsDataSave.Concat(DetailDataList).ToList();

        //                //Convierto el listado de datos a un Xml
        //                XmlData = Util.XmlSerializerWF(View.Model.ListDetailsDataSave);

        //                //Modifico el DataInformation con el nuevo Xml
        //                DataInformationSerial.XmlData = XmlData;

        //                //Actualizo el DataInformation o creo uno nuevo en el caso de que sea un producto de picking
        //                if (DataInformationSerialList.Count > 0)
        //                {
        //                    DataInformationSerial.ModDate = DateTime.Now;
        //                    DataInformationSerial.ModifiedBy = App.curUser.UserName;
        //                    service.UpdateDataInformation(DataInformationSerial);
        //                }
        //                else
        //                    service.SaveDataInformation(DataInformationSerial);

        //                //Paso #2.
        //                View.Model.UltimosProcesadosMP = View.Model.UltimosProcesadosMP + "\n";
        //            }
        //        }//cierre datarow

        //        if (Res)
        //        {
        //            LabelAux = service.GetLabel(new WpfFront.WMSBusinessService.Label
        //       {
        //           Bin = View.Model.BinTo,
        //           LabelType = new DocumentType { DocTypeID = LabelType.BinLocation }
        //       }).First();

        //            //Recorro el listado de Labels para actualizar sus datos
        //            foreach (WpfFront.WMSBusinessService.Label Label in View.Model.ListLabelScann)
        //            {
        //                Label.Notes += (View.Model.IsCheckedCommentsSerial) ? (" " + View.Model.HeaderDocument.Comment) : "";
        //                try { service.ChangeLabelLocationV2(Label, LabelAux, View.Model.HeaderDocument); }
        //                catch { }
        //            }

        //            //Reinicio las variables
        //            View.Model.ListRecords.Rows.Clear();
        //            View.Model.ListLabelScann = new List<WpfFront.WMSBusinessService.Label>();
        //            View.Model.ListDataInformation = new List<DataInformation>();

        //            //Muestro el mensaje de guardado 
        //            Util.ShowMessage("Datos Guardados exitosamente.");
        //        }

        //        if (!Res)
        //        {
        //            Util.ShowMsgGrilla(Dt_Res);
        //        }
        //    }

        //    catch (Exception Ex) { Util.ShowError("Hubo un error guardando los datos, por favor vuelva a intentarlo: " + Ex.Message); }
        //}


        //private bool Validar_serial_Lista_actual(string Code, string Serial)
        //{
        //    bool result = false;
        //    int Con = 0;
        //    //Recorro el listado de seriales adicionados para validar que no este ingresando un serial repetido
        //    foreach (DataRow DataRow in View.Model.ListRecords.Rows)
        //    {
        //        //Recorro el listado de seriales adicionados para validar que no este ingresando un serial repetido
        //        Con = DataRow[Code].ToString() == Serial ? Con++ : 0;
        //        result = Con > 1 ? true : false;
        //    }
        //    return result;
        //}

        //#endregion


        /// <summary>
        /// Mostrar la informacion de la lista del modulo de "Mover Producto" en una ventana emergente.
        /// OK.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnMostrarInformacion(object sender, EventArgs e)
        {
            WindowInfo confirm = new WindowInfo();
            confirm.Txt_Mensaje.Text = View.Model.UltimosProcesadosMP;
            confirm.ShowDialog();
        }
        private void OnSaveDetails(object sender, EventArgs e)
        {
            //Validacion si no existen datos para guardar
            if (View.Model.ListRecords.Rows.Count == 0)
                return;

            //Variables Auxiliares
            DataInformation DataInformationSerial;
            DataDefinitionByBin DataDefinitionControlIsRequired;
            Object ChildrenValue, ChildrenLabel;
            ShowData DetailDataSave;
            string XmlData;
            bool ControlIsRequired;

            try
            {
                try
                {
                    foreach (DataRow DataRow in View.Model.ListRecords.Rows)
                    {
                        //Inicializo la lista de los datos a convertir en Xml
                        View.Model.ListDetailsDataSave = new List<ShowData>();
                        //Obtengo los datos de cada campo con su nombre
                        foreach (DataColumn c in View.Model.ListRecords.Columns)
                        {
                            //Obtengo el label y el valor digitado
                            ChildrenLabel = c.ColumnName;
                            ChildrenValue = DataRow[c.ColumnName].ToString();

                            //Evaluo si el campo es obligatorio
                            ControlIsRequired = true;
                            DataDefinitionControlIsRequired = (View.Model.CamposDetails.Where(f => f.DataDefinition.Code == ChildrenLabel).Count() > 0) ? View.Model.CamposDetails.Where(f => f.DataDefinition.Code == ChildrenLabel).First() : null;
                            if (DataDefinitionControlIsRequired != null)
                            {
                                if (DataDefinitionControlIsRequired.DataDefinition.IsRequired == true && String.IsNullOrEmpty(ChildrenValue.ToString()))
                                    ControlIsRequired = false;
                                else
                                    ControlIsRequired = true;
                            }
                            //Evaluo si puedo continuar dependiendo de si el dato era requerido y fue digitado o no
                            if (ControlIsRequired)
                            {
                                //Creo el ShowData con los datos de ChildrenLabel y ChildrenValue
                                DetailDataSave = new ShowData
                                {
                                    DataKey = ChildrenLabel.ToString(),
                                    DataValue = ChildrenValue.ToString()
                                };
                                //Adiciono cada dato a la lista
                                View.Model.ListDetailsDataSave.Add(DetailDataSave);
                            }
                            else
                            {
                                Util.ShowError("El campo " + ChildrenLabel.ToString() + " no puede ser vacio.");
                                return;
                            }

                            //Cargo el dato para la variable de ultimos procesados
                            View.Model.UltimosProcesados = View.Model.UltimosProcesados + ChildrenValue.ToString() + " \t ";

                        }
                        //Convierto el listado de datos a un Xml
                        XmlData = Util.XmlSerializerWF(View.Model.ListDetailsDataSave);
                        //Creo el DataInformation del Serial para el Xml
                        DataInformationSerial = new DataInformation
                        {
                            Entity = new ClassEntity { ClassEntityID = 20 },
                            EntityRowID = Int32.Parse(DataRow[0].ToString()),
                            XmlData = XmlData,
                            CreationDate = DateTime.Now,
                            CreatedBy = App.curUser.UserName,
                            ModDate = DateTime.Now
                        };
                        //Guardo el Xml en la tabla DataInformation
                        DataInformationSerial = service.SaveDataInformation(DataInformationSerial);

                        //Ejecuto el proceso para cargar los datos a las tablas
                        CargarDatosXML(DataInformationSerial);

                        View.Model.UltimosProcesados = View.Model.UltimosProcesados + "\n";
                    }
                }
                catch (Exception ex)
                { Util.ShowError(ex.Message); }


                //COMPLETAR DOCUMENTO
                service.CreatePurchaseReceipt(View.Model.HeaderDocument);

                WindowInfo confirm = new WindowInfo();
                confirm.Txt_Mensaje.Text = View.Model.UltimosProcesados;
                confirm.ShowDialog();

                //Mensaje de confirmacion
                Util.ShowMessage("Datos Guardados exitosamente.");

                #region Nuevo Codigo

                DocumentoConsultado = service.GetDocument(new Document { DocNumber = View.NumeroDelDocumento.Text }).Where(f => f.DocNumber == View.NumeroDelDocumento.Text).ToList().First();
                View.Model.ListaSerialesNoCargados = service.GetLabel(new WMSBusinessService.Label
                {
                    Node = new Node { NodeID = NodeType.PreLabeled },
                    CreTerminal = View.Model.RecordCliente.LocationID.ToString(),
                    ReceivingDocument = DocumentoConsultado
                }).Where(f => f.Node.NodeID == 1 && f.ReceivingDocument == DocumentoConsultado).ToList();

                Util.ShowMessage("Los equipos cargados fueron guardados satisfactoriamente. \n"
                    + "Equipos cargados: " + View.Model.ListRecords.Rows.Count + " \n"
                    + "Equipos No cargador por error en la comunicacion con el servidor principal: " + View.Model.ListaSerialesNoCargados.Count);

                #endregion
                //Inicializo los campos de ingreso
                LimpiarDatosIngresoSeriales();
            }
            catch (Exception Ex) { Util.ShowError("Hubo un error guardando los datos, por favor vuelva a intentarlo: " + Ex.Message); }
        }