复制代码 代码如下:
// 涉及命名空间
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Web;
using System.Configuration;

// 方法
public void AddUser(string PersonName, string PersonEmail, string PersonSex, string PersonDOB, string PersonImage, string PersonImageType)
{
string strImageType = userImage.PostedFile.ContentType;
Stream ImageStream = userImage.PostedFile.InputStream;

// 加水印----------------->
string wImageFile = Server.MapPath("/bkwww/image/HomeSign.gif"); // 要加的水印图
Image sImage = Image.FromStream(ImageStream); // 从 Http 输入流创建 image
Image wImage = Image.FromFile(wImageFile);

// 绘图
Graphics g = Graphics.FromImage(sImage);
g.DrawImage(wImage, new Rectangle(0, 0, wImage.Width, wImage.Height), 0, 0, wImage.Width, wImage.Height, GraphicsUnit.Pixel);

// 保存,并将 image 转化为 byte[]
MemoryStream ms=new MemoryStream();
byte[] myImage=null;
sImage.Save(ms, ImageFormat.Gif);
myImage = ms.GetBuffer();
//------------------------>



// 写入数据库
string strConn = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection myConnection = new SqlConnection(strConn);
SqlCommand myCommand = new SqlCommand("sp_person_isp", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;

myCommand.Parameters.Add("@PersonEmail", SqlDbType.VarChar, 255).Value = PersonEmail;
myCommand.Parameters.Add("@PersonName", SqlDbType.VarChar, 255).Value = PersonName;
myCommand.Parameters.Add("@PersonSex", SqlDbType.Char, 1);
if(sexMale.Checked)
myCommand.Parameters["@PersonSex"].Value = "M";
else
myCommand.Parameters["@PersonSex"].Value = "F";
myCommand.Parameters.Add("@PersonDOB", SqlDbType.DateTime).Value = PersonDOB;
myCommand.Parameters.Add("@PersonImage", SqlDbType.Image).Value = myImage;
myCommand.Parameters.Add("@PersonImageType", SqlDbType.VarChar, 255).Value = ImageType;

try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
Response.Write("添加成功!");
}
catch(System.Exception SqlEx)
{
Response.Write("添加失败!"+SqlEx.ToString());
}
}
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com