先新增一条新增相片的记录

CreatePicture
public override void CreatePicture(Picture picture)

{
using( SqlConnection myConnection = GetSqlConnection() )

{
SqlCommand myCommand = new SqlCommand(databaseOwner + ".cs_Post_CreateUpdate", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;

// Add parameters
//
myCommand.Parameters.Add("@SectionID", SqlDbType.Int).Value = picture.SectionID;
myCommand.Parameters.Add("@ParentID", SqlDbType.Int).Value = picture.ParentID;
myCommand.Parameters.Add("@AllowDuplicatePosts", SqlDbType.Bit).Value = true;
myCommand.Parameters.Add("@DuplicateIntervalInMinutes", SqlDbType.Int).Value = 0;
myCommand.Parameters.Add("@Subject", SqlDbType.NVarChar, 256).Value = picture.Subject;
myCommand.Parameters.Add("@IsLocked", SqlDbType.Bit).Value = picture.IsLocked;
myCommand.Parameters.Add("@PostType", SqlDbType.Int).Value = picture.PostType;
myCommand.Parameters.Add("@EmoticonID", SqlDbType.Int).Value = picture.EmoticonID;
myCommand.Parameters.Add("@PostAuthor", SqlDbType.NVarChar, 64).Value = picture.Username;
myCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = picture.AuthorID;
myCommand.Parameters.Add("@Body", SqlDbType.NText).Value = picture.Body;
myCommand.Parameters.Add("@FormattedBody", SqlDbType.NText).Value = picture.FormattedBody;
myCommand.Parameters.Add("@UserHostAddress", SqlDbType.NVarChar, 32).Value = picture.UserHostAddress;
myCommand.Parameters.Add("@IsSticky", SqlDbType.Bit).Value = picture.IsSticky;
myCommand.Parameters.Add("@StickyDate", SqlDbType.DateTime).Value = picture.StickyDate;

myCommand.Parameters.Add(this.SettingsIDParameter());


SerializerData data = picture.GetSerializerData();

myCommand.Parameters.Add("@PropertyNames", SqlDbType.NText).Value = data.Keys;
myCommand.Parameters.Add("@PropertyValues", SqlDbType.NText).Value = data.Values;

myCommand.Parameters.Add("@PostID", SqlDbType.Int).Direction = ParameterDirection.Output;
myCommand.Parameters.Add("@ThreadID", SqlDbType.Int).Direction = ParameterDirection.Output;

myConnection.Open();
myCommand.ExecuteNonQuery();

// LN 5/27/04: try/catch added to get rid of exceptions
try

{
picture.PostID = (int) myCommand.Parameters["@PostID"].Value;
picture.ThreadID = (int) myCommand.Parameters["@ThreadID"].Value;
}

catch
{}

if (picture.PostID == -1)

{
myConnection.Close();
throw new CSException(CSExceptionType.PostDuplicate);
}

myConnection.Close();
}
}
然后再将相片文件存入DB

CreatePictureData
public override void CreatePictureData(Picture picture, PostAttachment pictureData)

{
using( SqlConnection connection = GetSqlConnection() )

{
SqlCommand myCommand = new SqlCommand(databaseOwner + ".cs_PostAttachment_Add", connection);
myCommand.CommandType = CommandType.StoredProcedure;


// Add parameters
//
myCommand.Parameters.Add("@AttachmentID", SqlDbType.UniqueIdentifier).Value = picture.PictureData.AttachmentID;
//guid //
myCommand.Parameters.Add("@PostID", SqlDbType.Int).Value = picture.PostID;
//21 //
myCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = picture.AuthorID;
//2105 //
myCommand.Parameters.Add("@SectionID", SqlDbType.Int).Value = picture.SectionID;
//15 //
myCommand.Parameters.Add("@Filename", SqlDbType.NVarChar, 256).Value = pictureData.FileName;
//xin_410902010922890994356.jpg //
myCommand.Parameters.Add("@RealFilename", SqlDbType.NVarChar, 256).Value = pictureData.RealFileName;
//1000.15.21 //1000.SectionID.PostID
myCommand.Parameters.Add("@Content", SqlDbType.Image).Value = pictureData.Content;
//
myCommand.Parameters.Add("@ContentType", SqlDbType.NVarChar, 50).Value = pictureData.ContentType;
//image/jpeg
myCommand.Parameters.Add("@ContentSize", SqlDbType.Int).Value = pictureData.Length;
//49790
myCommand.Parameters.Add(this.SettingsIDParameter());

connection.Open();
myCommand.ExecuteNonQuery();
connection.Close();
}
}
posted on 2005-10-18 15:38
Konimeter 阅读(168)
评论(0) 编辑 收藏 网摘 所属分类:
CommunityServer