示例#1
0
        //insertar

        public static string InsertarProducto(ProductoModel producto)
        {
            OdbcConnection conn = Conexion.obtenerConexion();

            try
            {
                byte[] Imagen = Convert.FromBase64String(producto.Imagen);

                string ruta = @"C:\inetpub\wwwroot\Produx\Imagenes";
                if (!Directory.Exists(ruta))
                {
                    Directory.CreateDirectory(ruta);
                }
                File.WriteAllBytes(ruta + @"\" + producto.Descripcion + ".jpg", Imagen);


                OdbcCommand command = new OdbcCommand();
                string      Sql     = "{call [dbo].[sp_Insertar_Producto](?,?,?,?,?,?,?,?)}";

                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = Sql;
                command.Connection  = conn;

                command.Parameters.Add("@Id_Producto", OdbcType.VarChar);
                command.Parameters["@Id_Producto"].Value = producto.Codigo;
                command.Parameters.Add("@Descripcion", OdbcType.VarChar);
                command.Parameters["@Descripcion"].Value = producto.Descripcion;
                command.Parameters.Add("@Precio", OdbcType.Decimal);
                command.Parameters["@Precio"].Value = producto.Precio;
                command.Parameters.Add("@Cant_Inventario", OdbcType.Int);
                command.Parameters["@Cant_Inventario"].Value = producto.CantidadInventario;//Usuario Logueado
                command.Parameters.Add("@Observaciones", OdbcType.VarChar);
                command.Parameters["@Observaciones"].Value = producto.Observaciones;
                command.Parameters.Add("@Imagen", OdbcType.VarChar);
                command.Parameters["@Imagen"].Value = @"/" + producto.Descripcion + ".jpg";
                command.Parameters.Add("@Estado", OdbcType.Int);
                command.Parameters["@Estado"].Value = producto.Estado;
                command.Parameters.Add("@Usuario_Creacion", OdbcType.VarChar);
                command.Parameters["@Usuario_Creacion"].Value = producto.Usuario_Creacion;
                command.ExecuteNonQuery();

                command.Dispose();
                return("true");
            }
            catch (Exception ax)
            {
                //if (!EventLog.SourceExists("MySource"))
                //{
                //    EventLog.CreateEventSource("MySource", "MyNewLog");
                //}

                //// Create an EventLog instance and assign its source.
                //EventLog myLog = new EventLog();
                //myLog.Source = "MySource";

                //myLog.WriteEntry(ax.Message);
                return(ax.Message); // "false";
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
        }