Ejemplo n.º 1
0
 public string FunCrearEstrategia(SoftCob_ESTRATEGIA_CABECERA _estrategia)
 {
     try
     {
         using (SoftCobEntities _db = new SoftCobEntities())
         {
             _db.SoftCob_ESTRATEGIA_CABECERA.Add(_estrategia);
             _db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         _mensaje = ex.ToString();
     }
     return(_mensaje);
 }
Ejemplo n.º 2
0
        public string FunEditEstrategia(SoftCob_ESTRATEGIA_CABECERA _estrategia)
        {
            try
            {
                using (SoftCobEntities _db = new SoftCobEntities())
                {
                    _db.SoftCob_ESTRATEGIA_CABECERA.Add(_estrategia);
                    _db.Entry(_estrategia).State = System.Data.Entity.EntityState.Modified;

                    foreach (SoftCob_ESTRATEGIA_DETALLE _deta in _estrategia.SoftCob_ESTRATEGIA_DETALLE)
                    {
                        if (_deta.ESDE_CODIGO != 0)
                        {
                            _db.Entry(_deta).State = System.Data.Entity.EntityState.Modified;
                        }
                        else
                        {
                            _db.Entry(_deta).State = System.Data.Entity.EntityState.Added;
                        }
                    }
                    _db.SaveChanges();
                }
            }
            catch (Exception ex /*DbEntityValidationException ex*/)
            {
                //foreach (var validationErrors in ex.EntityValidationErrors)
                //{
                //    foreach (var validationError in validationErrors.ValidationErrors)
                //    {
                //        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                //    }
                //}
                _mensaje = ex.ToString();
            }
            return(_mensaje);
        }
Ejemplo n.º 3
0
        protected void BtnGrabar_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(TxtEstrategia.Text.Trim()))
                {
                    new FuncionesDAO().FunShowJSMessage("Ingrese nombre de la Estrategia...!", this);
                    return;
                }

                if (string.IsNullOrEmpty(TxtDescripcion.Text.Trim()))
                {
                    new FuncionesDAO().FunShowJSMessage("Ingrese descripción de la Estrategia...!", this);
                    return;
                }

                _dtbcampos = (DataTable)ViewState["EstrategiaDetalle"];

                if (_dtbcampos.Rows.Count > 0)
                {
                    SoftCob_ESTRATEGIA_CABECERA _estcab = new SoftCob_ESTRATEGIA_CABECERA();
                    {
                        _estcab.ESCA_CODIGO      = int.Parse(ViewState["CodigoEstrategia"].ToString());
                        _estcab.esca_estrategia  = TxtEstrategia.Text.Trim().ToUpper();
                        _estcab.esca_descripcion = TxtDescripcion.Text.Trim().ToUpper();
                        _estcab.esca_estado      = ChkEstadoCab.Checked ? true : false;
                        _estcab.esca_auxv1       = "";
                        _estcab.esca_auxv2       = "";
                        _estcab.esca_auxv3       = "";
                        _estcab.esca_auxi1       = 0;
                        _estcab.esca_auxi2       = 0;
                        _estcab.esca_auxi3       = 0;
                        _estcab.esca_fum         = DateTime.Now;
                        _estcab.esca_uum         = int.Parse(Session["usuCodigo"].ToString());
                        _estcab.esca_tum         = Session["MachineName"].ToString();
                    }

                    if (int.Parse(ViewState["CodigoEstrategia"].ToString()) == 0)
                    {
                        _estcab.esca_fechacreacion    = DateTime.Now;
                        _estcab.esca_usuariocreacion  = int.Parse(Session["usuCodigo"].ToString());
                        _estcab.esca_terminalcreacion = Session["MachineName"].ToString();
                    }
                    else
                    {
                        _estcab.esca_fechacreacion    = DateTime.ParseExact(ViewState["fechacreacion"].ToString(), "MM/dd/yyyy", CultureInfo.InvariantCulture);
                        _estcab.esca_usuariocreacion  = int.Parse(ViewState["usucreacion"].ToString());
                        _estcab.esca_terminalcreacion = ViewState["terminalcreacion"].ToString();
                    }

                    _estcab.SoftCob_ESTRATEGIA_DETALLE = new List <SoftCob_ESTRATEGIA_DETALLE>();

                    List <SoftCob_ESTRATEGIA_DETALLE> _estdetalle = new List <SoftCob_ESTRATEGIA_DETALLE>();

                    foreach (DataRow _dr in _dtbcampos.Rows)
                    {
                        _estdetalle.Add(new SoftCob_ESTRATEGIA_DETALLE()
                        {
                            ESDE_CODIGO     = new EstrategiaDAO().FunGetCodigoCabEstrategia(int.Parse(ViewState["CodigoEstrategia"].ToString()), int.Parse(_dr[0].ToString())),
                            ESCA_CODIGO     = int.Parse(ViewState["CodigoEstrategia"].ToString()),
                            esde_caescodigo = int.Parse(_dr[1].ToString()),
                            esde_operacion  = _dr[3].ToString(),
                            esde_valor      = _dr[4].ToString(),
                            esde_orden      = _dr[5].ToString(),
                            esde_prioridad  = int.Parse(_dr[6].ToString()),
                            esde_estado     = _dr[7].ToString() == "Activo" ? true : false,
                            esde_auxv1      = "",
                            esde_auxv2      = "",
                            esde_auxv3      = "",
                            esde_auxi1      = 0,
                            esde_auxi2      = 0,
                            esde_auxi3      = 0
                        });
                    }

                    _estcab.SoftCob_ESTRATEGIA_DETALLE = new List <SoftCob_ESTRATEGIA_DETALLE>();

                    foreach (SoftCob_ESTRATEGIA_DETALLE _detalle in _estdetalle)
                    {
                        _estcab.SoftCob_ESTRATEGIA_DETALLE.Add(_detalle);
                    }

                    if (_estcab.ESCA_CODIGO == 0)
                    {
                        _mensaje = new EstrategiaDAO().FunCrearEstrategia(_estcab);
                    }
                    else
                    {
                        _mensaje = new EstrategiaDAO().FunEditEstrategia(_estcab);
                    }

                    if (_mensaje == "")
                    {
                        Response.Redirect("WFrm_EstrategiaAdmin.aspx?MensajeRetornado=Guardado con Éxito");
                    }
                    else
                    {
                        Lblerror.Text = _mensaje;
                    }
                }
                else
                {
                    new FuncionesDAO().FunShowJSMessage("Ingrese al menos un registro para la Estrategia..!", this);
                }
            }
            catch (Exception ex)
            {
                Lblerror.Text = ex.ToString();
            }
        }