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;
            Object           ChildrenValue, ChildrenLabel;
            ShowData         DetailDataSave;
            IList <ShowData> DetailDataList;
            string           XmlData;

            WpfFront.WMSBusinessService.Label LabelAux;
            DataDefinitionByBin DataDefinitionControlIsRequired;
            bool ControlIsRequired;

            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)
                {
                    //Obtengo el DataInformation asociado al registro
                    DataInformationSerial = View.Model.ListDataInformation.Where
                                                (f => f.Entity.ClassEntityID == EntityID.Label &&
                                                f.EntityRowID == Int32.Parse(DataRow[0].ToString())).ToList().First();

                    //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;
                        }
                    }

                    //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;
                    DataInformationSerial.ModDate    = DateTime.Now;
                    DataInformationSerial.ModifiedBy = App.curUser.UserName;

                    //Actualizo el DataInformation
                    service.UpdateDataInformation(DataInformationSerial);
                }

                LabelAux = service.GetLabel(new WpfFront.WMSBusinessService.Label
                {
                    Bin = new Bin {
                        BinCode = "MAIN", Location = LocationDespachos
                    },
                    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.");
            }
            catch (Exception Ex) { Util.ShowError("Hubo un error guardando los datos, por favor vuelva a intentarlo: " + Ex.Message); }
        }
Ejemplo n.º 2
0
        private void OnUpdateData(object sender, EventArgs e)
        {
            Object           ChildrenValue, ChildrenLabel;
            ShowData         HeaderDataSave;
            string           XmlData;
            string           CodigoCampo;
            DataDefinition   IsRequiredField;
            bool             ControlIsRequired;
            IList <ShowData> DetailDataList;

            //Deserializo el Xml para obtener el Showdata
            DetailDataList = Util.DeserializeMetaDataWF(View.Model.DataInformationSearch.XmlData);
            //Inicializo la lista de los datos a convertir en Xml
            View.Model.ListDataSave = new List <ShowData>();
            //Obtengo los datos de los campos
            foreach (UIElement UIElement in View.GetStackPanelDinamicos.Children)
            {
                try
                {
                    //Obtengo el label y el valor digitado
                    ChildrenLabel = UIElement.GetType().GetProperty("UcLabel").GetValue(UIElement, null);
                    ChildrenValue = UIElement.GetType().GetProperty("UcValue").GetValue(UIElement, null);
                    //Obtengo el codigo del campo
                    CodigoCampo = UIElement.GetType().GetProperty("Name").GetValue(UIElement, null).ToString();
                    CodigoCampo = CodigoCampo.Replace("f_", "");
                    //Traigo sus datos de creacion
                    IsRequiredField = service.GetDataDefinition(new DataDefinition {
                        Code = CodigoCampo
                    }).First();
                    //Evaluo si el campo es obligatorio

                    /*if (IsRequiredField.IsRequired == true && String.IsNullOrEmpty(ChildrenValue == null ? "" : 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
                        {
                            HeaderDataSave = DetailDataList.Where(f => f.DataKey == CodigoCampo.ToString()).First();
                            DetailDataList.Remove(HeaderDataSave);
                        }
                        //En caso de no existir no quito nada
                        catch { }
                        //Creo el ShowData con los datos de ChildrenLabel y ChildrenValue
                        HeaderDataSave = new ShowData
                        {
                            DataKey   = CodigoCampo.ToString(),
                            DataValue = ChildrenValue == null ? "" : ChildrenValue.ToString()
                        };
                        //Adiciono el ShowData al listado para crear el Xml
                        View.Model.ListDataSave.Add(HeaderDataSave);
                    }
                    else
                    {
                        Util.ShowError("El campo " + ChildrenLabel.ToString() + " no puede ser vacio.");
                        return;
                    }
                }
                catch { continue; }
            }
            try
            {
                //Concateno las listas de ShowData, la que estaba guardada y la nueva
                View.Model.ListDataSave = View.Model.ListDataSave.Concat(DetailDataList).ToList();
                //Convierto el listado de datos a un Xml
                XmlData = Util.XmlSerializerWF(View.Model.ListDataSave);
                //Evaluo el tipo de dato a editar(Document o Label)
                if (View.Model.DataInformationSearch.Entity.ClassEntityID == EntityID.Document)
                {
                    //Guardo los datos para el documento
                    UpdateDocumentData(XmlData);
                }
                if (View.Model.DataInformationSearch.Entity.ClassEntityID == EntityID.Label)
                {
                    //Guardo los datos para el label
                    UpdateLabelData(XmlData);
                }
                //Muestro el mensaje de confirmacion
                Util.ShowMessage("Los datos fueron editados correctamente");
            }
            catch (Exception Ex) { Util.ShowError("Hubo un error durante el proceso: " + Ex.Message); }
        }
        private void OnConfirmBasicData(object sender, EventArgs e)
        {
            Object         ChildrenValue, ChildrenLabel;
            ShowData       HeaderDataSave;
            string         XmlData;
            string         CodigoCampo;
            DataDefinition IsRequiredField;
            bool           ControlIsRequired;

            //Inicializo la lista de los datos a convertir en Xml
            View.Model.ListHeaderDataSave = new List <ShowData>();
            //Obtengo los datos de los campos
            foreach (UIElement UIElement in View.GetStackPanelHeader.Children)
            {
                try
                {
                    //Obtengo el label y el valor digitado
                    ChildrenLabel = UIElement.GetType().GetProperty("UcLabel").GetValue(UIElement, null);
                    ChildrenValue = UIElement.GetType().GetProperty("UcValue").GetValue(UIElement, null);
                    //Obtengo el codigo del campo
                    CodigoCampo = UIElement.GetType().GetProperty("Name").GetValue(UIElement, null).ToString();
                    CodigoCampo = CodigoCampo.Replace("f_", "");
                    //Traigo sus datos de creacion
                    IsRequiredField = service.GetDataDefinition(new DataDefinition {
                        Code = CodigoCampo
                    }).First();
                    //Evaluo si el campo es obligatorio
                    if (IsRequiredField.IsRequired == true && String.IsNullOrEmpty(ChildrenValue == null ? "" : 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 CodigoCampo y ChildrenValue
                        HeaderDataSave = new ShowData
                        {
                            DataKey   = CodigoCampo.ToString(),
                            DataValue = ChildrenValue == null ? "" : ChildrenValue.ToString()
                        };
                        //Adiciono el ShowData al listado para crear el Xml
                        View.Model.ListHeaderDataSave.Add(HeaderDataSave);
                    }
                    else
                    {
                        Util.ShowError("El campo " + ChildrenLabel.ToString() + " no puede ser vacio.");
                        return;
                    }
                }
                catch { continue; }
            }
            try
            {
                //Convierto el listado de datos a un Xml
                XmlData = Util.XmlSerializerWF(View.Model.ListHeaderDataSave);
                //Asigno los datos del documento para guardar
                View.Model.HeaderDocument.Location = LocationDespachos;
                View.Model.HeaderDocument.DocType  = new DocumentType {
                    DocTypeID = SDocType.SalesOrder
                };
                View.Model.HeaderDocument.IsFromErp    = false;
                View.Model.HeaderDocument.CrossDocking = false;
                View.Model.HeaderDocument.Vendor       = service.GetAccount(new Account {
                    AccountCode = WmsSetupValues.DEFAULT
                }).First();
                View.Model.HeaderDocument.Customer = service.GetAccount(new Account {
                    AccountCode = WmsSetupValues.DEFAULT
                }).First();
                View.Model.HeaderDocument.Date1     = DateTime.Now;
                View.Model.HeaderDocument.CreatedBy = App.curUser.UserName;
                View.Model.HeaderDocument.Company   = new Company {
                    CompanyID = App.curCompany.CompanyID
                };
                //Guardo el Documento
                View.Model.HeaderDocument = service.CreateNewDocument(View.Model.HeaderDocument, true);
                //Creo el DataInformation del Header para el Xml
                View.Model.DataInformationHeader = new DataInformation
                {
                    Entity = new ClassEntity {
                        ClassEntityID = 6
                    },
                    EntityRowID  = View.Model.HeaderDocument.DocID,
                    XmlData      = XmlData,
                    CreationDate = DateTime.Now,
                    CreatedBy    = App.curUser.UserName
                };
                //Guardo el Xml en la tabla DataInformation
                View.Model.DataInformationHeader = service.SaveDataInformation(View.Model.DataInformationHeader);
                //Inhabilito el boton de Guardar, muestro Cancelar y oculto Nuevo
                View.GetButtonConfirmar.IsEnabled = false;
                View.GetButtonNuevo.Visibility    = Visibility.Collapsed;
                View.GetButtonCancelar.Visibility = Visibility.Visible;
                //Inhabilito el combobox de bin de ingreso
                View.GetListBinInicio.IsEnabled = false;
                //Muestro el boton para mostrar los datos del header y oculto header
                View.GetTextHideShowHeader.Visibility = Visibility.Visible;
                View.GetBorderHeader.Visibility       = Visibility.Collapsed;
                //Cargo los datos para el detalle, los seriales y muestro
                CargarSeriales();
                CargarDatosDetails();
                View.BorderDetails.Visibility = Visibility.Visible;
                //Muestro el mensaje de confirmacion
                Util.ShowMessage("El documento se guardo satisfactoriamente");
            }
            catch (Exception Ex) { Util.ShowError("Hubo un error durante el proceso: " + Ex.Message); }
        }