Mini Shell
using System;
using System.Threading;
using System.Web.UI;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;
using System.IO;
using System.Drawing.Imaging;
public partial class admin_editar2 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["protarteConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string id = Request.QueryString["id"];
SqlCommand select1 = new SqlCommand("SELECT * from produto where id_pro='" + id + "'", con);
SqlDataReader dr;
try
{
con.Open();
dr = select1.ExecuteReader();
while (dr.Read())
{
string num1 = dr["cat"].ToString();
int i = Convert.ToInt32(num1);
i = i - 1;
dp.SelectedIndex = i;
TextBox1.Text = dr["tit"].ToString();
TextBox2.Text = dr["url"].ToString();
img1.ImageUrl = "../_include/img/work/thumbs/" + dr["imagem"].ToString();
TextBox3.Text = dr["imagem"].ToString();
TextBox4.Text = dr["cat"].ToString();
}
con.Close();
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + ex.Message + "');", true);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
VaryQualityLevel();
VaryQualityLevel2();
string id = Request.QueryString["id"];
string cod = "<li class=''item-thumbs span3 cabeca''> <span style=''font-size:25px; display:block; text-align:center; width:100%; margin-bottom:10px''>" + TextBox1.Text + "</span> <a class=''hover-wrap fancybox'' data-fancybox-group=''gallery'' title=''" + TextBox1.Text + "'' target=''_blank'' href=''_include/img/work/ficha/" + TextBox2.Text + "''> <span class=''overlay-img''></span> <span class=''overlay-img-thumb font-icon-plus''></span> </a><img src=''_include/img/work/thumbs/" + TextBox3.Text + "'' > </li>";
string sql2 = "UPDATE produto SET tit='" + TextBox1.Text + "', url ='" + TextBox2.Text +"', imagem='"+ TextBox3.Text+"', cod='"+cod +"' ,cat='" + TextBox4.Text +"'" ;
sql2 += " WHERE id_pro='" +id + "'";
SqlCommand update5 = new SqlCommand(sql2, con);
con.Open();
int n2 = update5.ExecuteNonQuery();
con.Close();
Response.Redirect("editar2.aspx?id=" + id);
}
//funcao para crop tamnho imagem-----------------------------------------------------------
public System.Drawing.Bitmap ProportionallyResizeBitmap(System.Drawing.Bitmap src, int maxWidth, int maxHeight)
{
// original dimensions
int w = src.Width;
int h = src.Height;
// Longest and shortest dimension
int longestDimension = (w > h) ? w : h;
int shortestDimension = (w < h) ? w : h;
// propotionality
float factor = ((float)longestDimension) / shortestDimension;
// default width is greater than height
double newWidth = maxWidth;
double newHeight = maxWidth / factor;
// if height greater than width recalculate
if (w < h)
{
newWidth = maxHeight / factor;
newHeight = maxHeight;
}
// Create new Bitmap at new dimensions
System.Drawing.Bitmap result = new System.Drawing.Bitmap((int)newWidth, (int)newHeight);
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage((System.Drawing.Image)result))
g.DrawImage(src, 0, 0, (int)newWidth, (int)newHeight);
return result;
}
//funcao para crop tamnho imagem-----------------------------------------------------------
//funcao para uploadfotos comentarios-------------------------------------------------------------------------
private void VaryQualityLevel()
{
try
{
if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
{
HttpPostedFile pf = FileUpload1.PostedFile;
System.Drawing.Image bm = System.Drawing.Image.FromStream(pf.InputStream);
bm = ProportionallyResizeBitmap((System.Drawing.Bitmap)bm, 570, 400); /// new width, height
// Get a bitmap.
System.Drawing.Bitmap bmp1 = new System.Drawing.Bitmap(bm);
ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
// Create an Encoder object based on the GUID
// for the Quality parameter category.
System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one
// EncoderParameter object in the array.
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 50L);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(Path.Combine(Server.MapPath("../_include/img/work/thumbs/"), pf.FileName), jgpEncoder, myEncoderParameters);
myEncoderParameter = new EncoderParameter(myEncoder, 80L);
myEncoderParameters.Param[0] = myEncoderParameter;
bmp1.Save(Path.Combine(Server.MapPath("../_include/img/work/thumbs/"), pf.FileName), jgpEncoder, myEncoderParameters);
TextBox3.Text = pf.FileName;
}
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + ex.Message + "');", true);
}
}
//funcao para uploadfotos comentarios-------------------------------------------------------------------------
//funcao para uploadfotos publicaçoes------------------------------------------------------------------------
private void VaryQualityLevel2()
{
if( ( FileUpload2.PostedFile != null ) && ( FileUpload2.PostedFile.ContentLength > 0 ) )
{
string fn = System.IO.Path.GetFileName(FileUpload2.PostedFile.FileName);
string SaveLocation = Server.MapPath("../_include/img/work/ficha/"+ fn);
try
{
FileUpload2.PostedFile.SaveAs(SaveLocation);
TextBox2.Text = FileUpload2.FileName;
}
catch ( Exception ex )
{
Response.Write("Error: " + ex.Message);
//Note: Exception.Message returns detailed message that describes the current exception.
//For security reasons, we do not recommend you return Exception.Message to end users in
//production environments. It would be better just to put a generic error message.
}
}
else
{
Response.Write("Por favor selecionar ficha tecnica");
return;
}
}
private ImageCodecInfo GetEncoder(ImageFormat format)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.FormatID == format.Guid)
{
return codec;
}
}
return null;
}
protected void dp_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox4.Text = dp.SelectedValue.ToString();
}
}
Zerion Mini Shell 1.0