Beispiel #1
0
        //METODO ADD,EDIT, DELETE
        public string SaveChanges()
        {
            string message;

            try
            {
                Dcargo dc = new Dcargo();
                dc.Idcargo      = idcargo;
                dc.Nombre_cargo = nombre_cargo;
                dc.Descripcion  = descripcion;

                switch (state)
                {
                case EntityState.Guardar:
                    cargo_repository.Add(dc);
                    message = "¡Registrado!";
                    break;

                case EntityState.Modificar:
                    cargo_repository.Edit(dc);
                    message = "¡Modificado!";
                    break;

                case EntityState.Remover:
                    cargo_repository.Delete(dc);
                    message = dc.Message;
                    break;

                default:
                    message = "Error in Transaction!";
                    break;
                }
            }
            catch (Exception ex)
            {
                message = ex.ToString();
            }
            finally { }

            return(message);
        }
Beispiel #2
0
        public int Delete(Dcargo entiti)
        {
            result = 0;
            using (SqlConnection conect = RConexion.Getconectar())
            {
                conect.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conect;
                    cmd.CommandText = "SP_DELETE_CARGO";
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@idcargo", SqlDbType.Int).Value = entiti.Idcargo;
                    cmd.Parameters.Add("@message", SqlDbType.VarChar, 100).Direction = ParameterDirection.Output;
                    result         = cmd.ExecuteNonQuery();
                    entiti.Message = cmd.Parameters["@message"].Value.ToString();
                    cmd.Parameters.Clear();
                    return(result);
                }
            }
        }
Beispiel #3
0
        public int Add(Dcargo entiti)
        {
            result = 0;
            using (SqlConnection conect = RConexion.Getconectar())
            {
                conect.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conect;
                    cmd.CommandText = "SP_REGISTRAR_CARGO";
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@nom", entiti.Nombre_cargo);
                    cmd.Parameters.AddWithValue("@descripcion", entiti.Descripcion);
                    result = cmd.ExecuteNonQuery();

                    cmd.Parameters.Clear();
                    return(result);
                }
            }
        }
Beispiel #4
0
        public int Edit(Dcargo entiti)
        {
            result = 0;
            using (SqlConnection conect = RConexion.Getconectar())
            {
                conect.Open();
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conect;
                    cmd.CommandText = "SP_UPDATE_CARGO";
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@nom", SqlDbType.VarChar, 40).Value           = entiti.Nombre_cargo;
                    cmd.Parameters.Add("@descripcion", SqlDbType.NVarChar, 100).Value = entiti.Descripcion;
                    cmd.Parameters.Add("@idcargo", SqlDbType.Int).Value = entiti.Idcargo;
                    result = cmd.ExecuteNonQuery();

                    cmd.Parameters.Clear();
                    return(result);
                }
            }
        }
Beispiel #5
0
        //MOSTRAR
        public DataTable GetData(Dcargo entiti)
        {
            using (var conect = RConexion.Getconectar())
            {
                conect.Open();
                SqlDataAdapter da = new SqlDataAdapter();
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection  = conect;
                    cmd.CommandText = "SP_SELECT_CARGO";
                    cmd.CommandType = CommandType.StoredProcedure;

                    da.SelectCommand = cmd;

                    using (var dt = new DataTable())
                    {
                        da.Fill(dt);
                        da.Dispose();
                        return(dt);
                    }
                }
            }
        }