Ejemplo n.º 1
0
        private void btn_atualizar_regra_Click(object sender, EventArgs e)
        {
            try
            {
                PFC_V1.Modelo.Regra regra = this.regra;
                if (String.IsNullOrEmpty(txb_gasto_limite.Text) || String.IsNullOrEmpty(txb_periodo.Text))
                {
                    throw new System.InvalidOperationException("Necessário preencimento de todos os campos.");
                }

                if (Int32.TryParse(cmb_tipo.SelectedValue.ToString(), out int tipoaux))
                {
                    regra.tipo.id = tipoaux;
                }

                for (int i = 0; i < this.arrregratipo.Count; i++)
                {
                    if (regra.tipo.id == arrregratipo[i].id)
                    {
                        regra.tipo = arrregratipo[i];
                    }
                }

                try { regra.valor = Convert.ToDouble(txb_gasto_limite.Text); } catch (Exception ex) {
                    throw new System.InvalidOperationException("O campo \"Gasto Limite\" só aceita números");
                }

                if (!int.TryParse(txb_periodo.Text, out int periodoaux))
                {
                    throw new System.InvalidOperationException("O campo \"Periodo\" aceita apenas números inteiros (dias).");
                }
                else
                {
                    regra.periodo = periodoaux;
                }

                regra.ativo = ckb_ativo.Checked;

                IOperadorREST  op         = new OperadorJson();
                CtrlHidrometro controle   = new CtrlHidrometro();
                Hidrometro     hidrometro = new Hidrometro();
                hidrometro.id     = this.conexao.hidrometro.id;
                hidrometro.regras = new List <PFC_V1.Modelo.Regra>();
                hidrometro.regras.Add(regra);
                try
                {
                    this.conexao.hidrometro = controle.alterar <Hidrometro>(hidrometro, op, this.conexao);

                    MessageBox.Show("Regra atualizada com sucesso!");
                    this.Hide();
                }
                catch (Exception ex)
                {
                    throw new System.InvalidOperationException("Ocorreu um erro inesperado, verifique sua conexão.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
 public frm_atualizar_regra(PFC_V1.Modelo.Regra regra, Conexao conexao)
 {
     InitializeComponent();
     this.regra   = regra;
     this.conexao = conexao;
 }