CreatePicture和CreatePictureData

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

ContractedBlock.gif ExpandedBlockStart.gif CreatePicture
None.gif        public override void CreatePicture(Picture picture)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
using( SqlConnection myConnection = GetSqlConnection() ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                SqlCommand myCommand 
= new SqlCommand(databaseOwner + ".cs_Post_CreateUpdate", myConnection);
InBlock.gif                myCommand.CommandType 
= CommandType.StoredProcedure;
InBlock.gif
InBlock.gif                
// Add parameters
InBlock.gif                
//
InBlock.gif
                myCommand.Parameters.Add("@SectionID", SqlDbType.Int).Value = picture.SectionID;
InBlock.gif                myCommand.Parameters.Add(
"@ParentID", SqlDbType.Int).Value = picture.ParentID;
InBlock.gif                myCommand.Parameters.Add(
"@AllowDuplicatePosts", SqlDbType.Bit).Value = true;
InBlock.gif                myCommand.Parameters.Add(
"@DuplicateIntervalInMinutes", SqlDbType.Int).Value = 0;
InBlock.gif                myCommand.Parameters.Add(
"@Subject", SqlDbType.NVarChar, 256).Value = picture.Subject;
InBlock.gif                myCommand.Parameters.Add(
"@IsLocked", SqlDbType.Bit).Value = picture.IsLocked;
InBlock.gif                myCommand.Parameters.Add(
"@PostType", SqlDbType.Int).Value = picture.PostType;
InBlock.gif                myCommand.Parameters.Add(
"@EmoticonID", SqlDbType.Int).Value = picture.EmoticonID;
InBlock.gif                myCommand.Parameters.Add(
"@PostAuthor", SqlDbType.NVarChar, 64).Value = picture.Username;
InBlock.gif                myCommand.Parameters.Add(
"@UserID", SqlDbType.Int).Value = picture.AuthorID;
InBlock.gif                myCommand.Parameters.Add(
"@Body", SqlDbType.NText).Value = picture.Body;
InBlock.gif                myCommand.Parameters.Add(
"@FormattedBody", SqlDbType.NText).Value = picture.FormattedBody;
InBlock.gif                myCommand.Parameters.Add(
"@UserHostAddress", SqlDbType.NVarChar, 32).Value = picture.UserHostAddress;
InBlock.gif                myCommand.Parameters.Add(
"@IsSticky", SqlDbType.Bit).Value = picture.IsSticky;
InBlock.gif                myCommand.Parameters.Add(
"@StickyDate", SqlDbType.DateTime).Value = picture.StickyDate;
InBlock.gif
InBlock.gif                myCommand.Parameters.Add(
this.SettingsIDParameter());
InBlock.gif
InBlock.gif
InBlock.gif                SerializerData data 
= picture.GetSerializerData();
InBlock.gif
InBlock.gif                myCommand.Parameters.Add(
"@PropertyNames", SqlDbType.NText).Value = data.Keys;
InBlock.gif                myCommand.Parameters.Add(
"@PropertyValues", SqlDbType.NText).Value = data.Values;
InBlock.gif
InBlock.gif                myCommand.Parameters.Add(
"@PostID", SqlDbType.Int).Direction = ParameterDirection.Output;
InBlock.gif                myCommand.Parameters.Add(
"@ThreadID", SqlDbType.Int).Direction = ParameterDirection.Output;
InBlock.gif
InBlock.gif                myConnection.Open();
InBlock.gif                myCommand.ExecuteNonQuery();
InBlock.gif
InBlock.gif                
// LN 5/27/04: try/catch added to get rid of exceptions
InBlock.gif
                try 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    picture.PostID 
= (int) myCommand.Parameters["@PostID"].Value;
InBlock.gif                    picture.ThreadID 
= (int) myCommand.Parameters["@ThreadID"].Value;
ExpandedSubBlockEnd.gif                }
 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
catch dot.gif{}
InBlock.gif
InBlock.gif                
if (picture.PostID == -1
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    myConnection.Close();
InBlock.gif                    
throw new CSException(CSExceptionType.PostDuplicate);
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                myConnection.Close();
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

然后再将相片文件存入DB
ContractedBlock.gif ExpandedBlockStart.gif CreatePictureData
None.gif        public override void CreatePictureData(Picture picture, PostAttachment pictureData)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
using( SqlConnection connection = GetSqlConnection() ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                SqlCommand myCommand 
= new SqlCommand(databaseOwner + ".cs_PostAttachment_Add", connection);
InBlock.gif                myCommand.CommandType 
= CommandType.StoredProcedure;
InBlock.gif
InBlock.gif
InBlock.gif                
// Add parameters
InBlock.gif                
//
InBlock.gif
                myCommand.Parameters.Add("@AttachmentID", SqlDbType.UniqueIdentifier).Value = picture.PictureData.AttachmentID;
InBlock.gif                
//guid    //
InBlock.gif
                myCommand.Parameters.Add("@PostID", SqlDbType.Int).Value = picture.PostID;
InBlock.gif                
//21    //
InBlock.gif
                myCommand.Parameters.Add("@UserID", SqlDbType.Int).Value = picture.AuthorID;
InBlock.gif                
//2105    //
InBlock.gif
                myCommand.Parameters.Add("@SectionID", SqlDbType.Int).Value = picture.SectionID;
InBlock.gif                
//15    //
InBlock.gif
                myCommand.Parameters.Add("@Filename", SqlDbType.NVarChar, 256).Value = pictureData.FileName;
InBlock.gif                
//xin_410902010922890994356.jpg    //
InBlock.gif
                myCommand.Parameters.Add("@RealFilename", SqlDbType.NVarChar, 256).Value = pictureData.RealFileName;
InBlock.gif                
//1000.15.21    //1000.SectionID.PostID
InBlock.gif
                myCommand.Parameters.Add("@Content", SqlDbType.Image).Value = pictureData.Content;
InBlock.gif                
//
InBlock.gif
                myCommand.Parameters.Add("@ContentType", SqlDbType.NVarChar, 50).Value = pictureData.ContentType;
InBlock.gif                
//image/jpeg
InBlock.gif
                myCommand.Parameters.Add("@ContentSize", SqlDbType.Int).Value = pictureData.Length;
InBlock.gif                
//49790
InBlock.gif
                myCommand.Parameters.Add(this.SettingsIDParameter());
InBlock.gif
InBlock.gif                connection.Open();
InBlock.gif                myCommand.ExecuteNonQuery();
InBlock.gif                connection.Close();
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/konimeter/archive/2005/10/18/257251.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值