Example #1
0
 private void btnGuardar_Click(object sender, EventArgs e)
 {
     try
     {
         if (Nuevo == true)
         {
             using (Profit_RGEntities context = new Profit_RGEntities())
             {
                 int Factura = Convert.ToInt32(context.pObtenerProximoConsecutivo("Ord_num", true).FirstOrDefault().Value);
                 context.pInsertarOrdenes(Factura, txtEmpresa.Text.Trim(), txtProv.Text.Trim(),
                                          txtProv_des.Text.Trim(), txtFecha.Value, txtObserv.Text.Trim(),
                                          0, Convert.ToDecimal(txtTotal.Value));
                 foreach (var item in detalle)
                 {
                     if (item.co_art.Trim().Length > 0)
                     {
                         context.pInsertarOrdenes_Reng(Factura, item.reng_num, item.co_art.Trim(),
                                                       item.art_des.Trim(), item.total_art,
                                                       item.precio, item.total_art);
                     }
                 }
             }
         }
         else
         {
             using (Profit_RGEntities context = new Profit_RGEntities())
             {
                 int Factura = txtFact_num.Value;
                 context.pActualizarOrdenes(Factura, txtEmpresa.Text.Trim(), txtProv.Text.Trim(),
                                            txtProv_des.Text.Trim(), txtFecha.Value, txtObserv.Text.Trim(),
                                            0, false, Convert.ToDecimal(txtTotal.Value), Validador);
                 context.pEliminarReng_Ordenes(Factura);
                 foreach (var item in detalle)
                 {
                     if (item.co_art.Trim().Length > 0)
                     {
                         context.pInsertarOrdenes_Reng(Factura, item.reng_num, item.co_art.Trim(),
                                                       item.art_des.Trim(), item.total_art,
                                                       item.precio, item.total_art);
                     }
                 }
             }
         }
         Navegar(5);
         MessageBox.Show(this, "Se ha guardado la informacion satisfactoriamente.", "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (EntityException ex)
     {
         MessageBox.Show(ex.InnerException.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (Exception ex1)
     {
         MessageBox.Show(ex1.Message, "Profit Expansion", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }