private void BuildParametroListCheckboxGenerico(
            ComandoParametroDto paramItem
            , ref TableSection paramDiv
            )
        {
            try
            {
                paramDiv.Title = paramItem.Label;
                List <String> dominio      = paramItem.Dominio.Split(';').ToList();
                List <char>   valorDefault = paramItem.Valor.ToCharArray().Reverse().ToList();

                for (Int32 i = 0; i < dominio.Count(); i++)
                {
                    CustomSwitchCell entry = new CustomSwitchCell()
                    {
                        CellLabel = dominio[i],
                        CellText  = valorDefault[i].ToString()
                    };

                    ListParametros.Add(
                        paramItem.IdParametro.ToString() + "-" + i.ToString()
                        , entry
                        );

                    entry.Tapped += Entry_Tapped;
                    paramDiv.Add(entry);
                }
            } catch
            {
            }
        }
        private void BuildParametroTextboxLivre(
            ComandoParametroDto paramItem
            , ref TableSection paramDiv
            )
        {
            try
            {
                CustomEntryCell entry = new CustomEntryCell()
                {
                    CellLabel       = paramItem.Label,
                    CellPlaceholder = paramItem.ToolTip
                };

                if (!String.IsNullOrWhiteSpace(paramItem.Valor))
                {
                    entry.CellText = paramItem.Valor;
                }

                if (paramItem.TamanhoMaximo.HasValue)
                {
                    EntryLengthValidatorBehavior maxLength = new EntryLengthValidatorBehavior();
                    maxLength.MaxLength = paramItem.TamanhoMaximo.Value;
                    entry.Behaviors.Add(maxLength);
                }

                if (!String.IsNullOrWhiteSpace(paramItem.Dominio))
                {
                    String[] minMax = paramItem.Dominio.Split('>');

                    Int32 min = 0;
                    Int32 max = 0;

                    if (minMax.Count() == 2)
                    {
                        min = Convert.ToInt32(minMax[0]);
                        max = Convert.ToInt32(minMax[1]);
                    }
                    else
                    {
                        min = 0;
                        max = Convert.ToInt32(minMax[0]);
                    }

                    entry.Keyboard = Keyboard.Numeric;

                    EntryMaxMinValidatorBehavior maxLength = new EntryMaxMinValidatorBehavior();
                    maxLength.MinNumber = min;
                    maxLength.MaxNumber = max;
                    entry.Behaviors.Add(maxLength);
                }

                ListParametros.Add(
                    paramItem.IdParametro.ToString()
                    , entry
                    );
                entry.Tapped += Entry_Tapped;
                paramDiv.Add(entry);
            } catch {  }
        }
        //TODO: Mascara IP
        private void BuildParametroTextboxIP(
            ComandoParametroDto paramItem
            , ref TableSection paramDiv
            )
        {
            try
            {
                EntryCell entry = new EntryCell();

                if (!String.IsNullOrWhiteSpace(paramItem.Valor))
                {
                    entry.Text = paramItem.Valor;
                }

                //if (paramItem.TamanhoMaximo.HasValue)
                //{
                //	EntryLengthValidatorBehavior maxLength = new EntryLengthValidatorBehavior();
                //	maxLength.MaxLength = paramItem.TamanhoMaximo.Value;
                //	entry.Behaviors.Add(maxLength);
                //}

                //if(!String.IsNullOrWhiteSpace(paramItem.Dominio))
                //{
                //	String[] minMax = paramItem.Dominio.Split('>');

                //	Int32 min = 0;
                //	Int32 max = 0;

                //	if (minMax.Count() == 2) {
                //		min = Convert.ToInt32(minMax[0]);
                //		max = Convert.ToInt32(minMax[1]);
                //	} else {
                //		min = 0;
                //		max = Convert.ToInt32(minMax[0]);
                //	}

                //	entry.Keyboard = Keyboard.Numeric;

                //	EntryMaxMinValidatorBehavior maxLength = new EntryMaxMinValidatorBehavior();
                //	maxLength.MinNumber = min;
                //	maxLength.MaxNumber = max;
                //	entry.Behaviors.Add(maxLength);
                //}

                ListParametros.Add(
                    paramItem.IdParametro.ToString()
                    , entry
                    );

                entry.Tapped += Entry_Tapped;
                paramDiv.Add(entry);
            } catch {  }
        }
 private void BuildParametroComboboxAPN(
     ComandoParametroDto paramItem
     , ref TableSection paramDiv
     )
 {
     try
     {
         BuildParametroComboboxGenerico(
             paramItem
             , ref paramDiv
             );
     } catch { }
 }
 private void BuildParametroListCheckboxSaida(
     ComandoParametroDto paramItem
     , ref TableSection paramDiv
     )
 {
     try
     {
         BuildParametroListCheckboxGenerico(
             paramItem
             , ref paramDiv
             );
     } catch { }
 }
 private void BuildParametroTextboxNumeroDecimal(
     ComandoParametroDto paramItem
     , ref TableSection paramDiv
     )
 {
     try
     {
         BuildParametroTextboxLivre(
             paramItem
             , ref paramDiv
             );
     } catch { }
 }
 private void BuildParametroTextboxNumeroInteiro(
     ComandoParametroDto paramItem
     , ref TableSection paramDiv
     )
 {
     try
     {
         //Mudar se tiver alguma diferença
         BuildParametroTextboxLivre(
             paramItem
             , ref paramDiv
             );
     } catch { }
 }
        private void BuildParametroComboboxGenerico(
            ComandoParametroDto paramItem
            , ref TableSection paramDiv
            )
        {
            try
            {
                String[] opt = paramItem.Dominio.Split(';');
                List <FormularioDinamicoElementDto> dataSource = new List <FormularioDinamicoElementDto>();

                foreach (String item in opt)
                {
                    String[] dataTemp = item.Split('|');

                    dataSource.Add(new FormularioDinamicoElementDto()
                    {
                        Id   = dataTemp[0],
                        Text = dataTemp[1]
                    });
                }

                CustomPickerCell entry = new CustomPickerCell()
                {
                    DataSource         = dataSource,
                    ItemDisplayBinding = new Binding("Text"),
                    CellLabel          = paramItem.Label
                };


                if (!String.IsNullOrWhiteSpace(paramItem.Valor))
                {
                    entry.CellText = paramItem.Valor;
                }

                ListParametros.Add(
                    paramItem.IdParametro.ToString()
                    , entry
                    );

                entry.Tapped += Entry_Tapped;
                paramDiv.Add(entry);
            } catch { }
        }
        private void BuildParametroCheckboxGenerico(
            ComandoParametroDto paramItem
            , ref TableSection paramDiv
            )
        {
            try
            {
                CustomSwitchCell entry = new CustomSwitchCell()
                {
                    CellLabel = paramItem.Label,
                    CellText  = paramItem.Valor
                };

                ListParametros.Add(
                    paramItem.IdParametro.ToString()
                    , entry
                    );

                entry.Tapped += Entry_Tapped;
                paramDiv.Add(entry);
            } catch { }
        }
        public List <ComandoParametroDto> RecuperaValor()
        {
            List <ComandoParametroDto> lstReturn = new List <ComandoParametroDto>();

            try
            {
                Dictionary <Int32, ComandoParametroDto> dic
                    = new Dictionary <int, ComandoParametroDto>();

                foreach (KeyValuePair <String, Cell> item in Form.ListParametros)
                {
                    ComandoParametroDto temp;
                    String[]            parts = item.Key.Split('-');
                    Int32 idParametro         = Convert.ToInt32(parts[0]);

                    if (dic.ContainsKey(idParametro))
                    {
                        temp = dic[idParametro];
                        dic.Remove(idParametro);
                    }
                    else
                    {
                        temp = new ComandoParametroDto()
                        {
                            IdParametro = idParametro
                        };
                    }

                    String valor = "";

                    Type tipo = item.Value.GetType();

                    Layout <View> tempView;

                    if (tipo == typeof(CustomSwitchCell))
                    {
                        CustomSwitchCell tempCell = (CustomSwitchCell)item.Value;
                        tempView = (Grid)tempCell.View;
                    }
                    else if (tipo == typeof(CustomPickerCell))
                    {
                        CustomPickerCell tempCell = (CustomPickerCell)item.Value;
                        tempView = (StackLayout)tempCell.View;
                    }
                    else
                    {
                        CustomEntryCell tempCell = (CustomEntryCell)item.Value;
                        tempView = (StackLayout)tempCell.View;
                    }

                    foreach (View itemView in tempView.Children)
                    {
                        Type tipoChildren = itemView.GetType();
                        if (tipoChildren != typeof(Label))
                        {
                            if (tipoChildren == typeof(Switch))
                            {
                                valor = Convert.ToInt32(((Switch)itemView).IsToggled).ToString();
                            }
                            else if (tipoChildren == typeof(Picker))
                            {
                                FormularioDinamicoElementDto tempPicker
                                    = ((Picker)itemView).SelectedItem as FormularioDinamicoElementDto;

                                if (tempPicker != null)
                                {
                                    valor = tempPicker.Id;
                                }
                            }
                            else
                            {
                                valor = ((Entry)itemView).Text;
                            }
                            break;
                        }
                    }

                    temp.Valor += valor;

                    dic.Add(temp.IdParametro, temp);
                }

                lstReturn = dic.Values.ToList();
            } catch { }

            return(lstReturn);
        }
Exemple #11
0
        //TODO:Tradução erros
        private void BtnSendAction(object obj)
        {
            try
            {
                _view.ExibirLoad();
                _tokensourceAction = new CancellationTokenSource();
                Task.Run(async() =>
                {
                    ServiceResult <StatusComandoDto> comando = new ServiceResult <StatusComandoDto>();
                    try
                    {
                        List <ComandoParametroDto> lst = _view.RecuperaValor();

                        ServiceResult <List <ComandoParametroDto> > result
                            = new ServiceResult <List <ComandoParametroDto> >();

                        if (lst.Count > 0)
                        {
                            foreach (ComandoParametroDto item in lst)
                            {
                                ComandoParametroDto paramDb =
                                    ParameterBoxBindingContext
                                    .FirstOrDefault(
                                        x => x.IdParametro == item.IdParametro
                                        );

                                if (paramDb != null)
                                {
                                    if (!String.IsNullOrWhiteSpace(paramDb.Dominio))
                                    {
                                        if (paramDb.TamanhoMaximo.HasValue)
                                        {
                                            if (item.Valor.Length > paramDb.TamanhoMaximo.Value)
                                            {
                                                result.MessageError += String.Format(
                                                    "{0}: {1} {2}"
                                                    , paramDb.Label
                                                    , "MuitoGrande"
                                                    , Environment.NewLine
                                                    );
                                            }
                                        }

                                        if (
                                            paramDb.IdTipoParametro == (Int32)EnumTipoParametro.TextboxLivre ||
                                            paramDb.IdTipoParametro == (Int32)EnumTipoParametro.TextboxNumeroInteiro ||
                                            paramDb.IdTipoParametro == (Int32)EnumTipoParametro.TextboxNumeroDecimal
                                            )
                                        {
                                            if (!String.IsNullOrWhiteSpace(paramDb.Dominio))
                                            {
                                                String[] minMax = paramDb.Dominio.Split('>');

                                                Int32 min = 0;
                                                Int32 max = 0;

                                                if (minMax.Count() == 2)
                                                {
                                                    min = Convert.ToInt32(minMax[0]);
                                                    max = Convert.ToInt32(minMax[1]);
                                                }
                                                else
                                                {
                                                    min = 0;
                                                    max = Convert.ToInt32(minMax[0]);
                                                }

                                                Double valor = Double.Parse(item.Valor);
                                                // if Entry text is longer then valid length
                                                if (valor < min || valor > max)
                                                {
                                                    result.MessageError += String.Format(
                                                        "{0}: {1} {2}"
                                                        , paramDb.Label
                                                        , "ForaDaFaixa"
                                                        , Environment.NewLine
                                                        );
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                }
                            }

                            if (
                                lst.Count() == 1 &&
                                lst[0].IdTipoParametro == (int)EnumTipoParametro.AtivacaoSaida
                                )
                            {
                                lst[0].Label = ComandoGlobal.ID;                                 //SAI_33 || CSP_33
                            }


                            if (!_tokensourceAction.IsCancellationRequested)
                            {
                                comando = await Model.SendCommand(
                                    PosicaoUnidadeRastreada.IdRastreador
                                    , PosicaoUnidadeRastreada.OrdemRastreador
                                    , PosicaoUnidadeRastreada.IdRastreadorUnidadeRastreada
                                    , ComandoGlobal.IdObjeto
                                    , JsonConvert.SerializeObject(lst)
                                    , _tokensourceAction.Token
                                    );
                            }
                        }
                    }
                    catch
                    {
                        comando.MessageError = "Exception";
                    }
                    finally
                    {
                        FinalizaEnvioComando(comando);
                    }
                }, _tokensourceAction.Token);
            }
            catch
            {
                _view.EscondeLoad();
                _messageService.ShowAlertAsync(
                    AppResources.Exception
                    , AppResources.Erro
                    );
            }
        }