Пример #1
0
 private void BtnRead_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         DaoContrato dc = new DaoContrato();
         Contrato    c  = dc.Read(txtNumero.Text);
         if (c != null)
         {
             LlenarContrato(c);
         }
         else
         {
             txtNumero.Focus();
             throw new Exception("Error, Ese numero de contrato no existe");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Пример #2
0
        private void BtnUpdate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Contrato   c   = new Contrato();
                DaoCliente dc  = new DaoCliente();
                Cliente    cli = dc.Read(txtRut.Text);
                c.Numero        = txtNumero.Text;
                c.FechaCreacion = DateTime.Now;

                if (cli != null)
                {
                    c.Cliente = cli;
                }
                else
                {
                    throw new Exception("El rut del cliente no esta registrado");
                }

                if (cboPlan.SelectedIndex >= 0)
                {
                    c.Plan = (Plan)cboPlan.SelectedItem;
                }
                else
                {
                    throw new Exception("Seleccione un plan");
                }
                c.FechaInicioVigencia = (DateTime)dtpFechaInicioVigencia.SelectedDate;
                c.FechaFinVigencia    = c.FechaInicioVigencia.AddYears(1);
                c.Vigente             = true;
                if (rbtSi.IsChecked == true)
                {
                    c.DeclaracionSalud = true;
                }
                else
                {
                    c.DeclaracionSalud = false;
                }
                c.Observaciones = txtObservaciones.Text;
                c.PrimaAnual    = (float)Math.Round(c.ValorPrimalAnual(), 4);
                c.PrimaMensual  = (float)Math.Round((c.PrimaAnual / 12), 4);

                DaoContrato act             = new DaoContrato();
                Contrato    contratoantiguo = act.Read(c.Numero);
                if (contratoantiguo.Vigente)
                {
                    bool resp = act.UPDATE(c);
                    MessageBox.Show(resp ? "Actualizo" : "No Actualizo, Ese numero de contrato no esta registrado");
                    if (resp)
                    {
                        limpiar();
                        txtRut.Focus();
                    }
                    else
                    {
                        txtRut.Focus();
                    }
                }
                else
                {
                    throw new Exception("No se puede actualizar un contrato NO vigente");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }