public bool SaveSpaceAttachment(SpaceAttachmentInfo spaceattachments) { //try //{ IDataParameter[] prams = { DbHelper.MakeInParam("@aid", (DbType)SqlDbType.Int, 4,spaceattachments.AID), DbHelper.MakeInParam("@uid", (DbType)SqlDbType.Int, 4,spaceattachments.UID), DbHelper.MakeInParam("@spacepostid", (DbType)SqlDbType.Int, 4,spaceattachments.SpacePostID), DbHelper.MakeInParam("@postdatetime", (DbType)SqlDbType.DateTime, 8,spaceattachments.PostDateTime), DbHelper.MakeInParam("@filename", (DbType)SqlDbType.NChar, 100,spaceattachments.FileName), DbHelper.MakeInParam("@filetype", (DbType)SqlDbType.NChar, 50,spaceattachments.FileType), DbHelper.MakeInParam("@filesize", (DbType)SqlDbType.Float, 8,spaceattachments.FileSize), DbHelper.MakeInParam("@attachment", (DbType)SqlDbType.NChar, 100,spaceattachments.Attachment), DbHelper.MakeInParam("@attachment", (DbType)SqlDbType.Int, 4,spaceattachments.Downloads) }; string sqlstring = String.Format("UPDATE [" + BaseConfigs.GetTablePrefix + "spaceattachments] SET [uid] = @uid, [spacepostid] = @spacepostid, [postdatetime] = @postdatetime, [filename] = @filename, [filetype] = @filetype, [filesize] = @filesize, [attachment] = @attachment, [downloads] = @downloads WHERE [aid] = @aid"); DbHelper.ExecuteNonQuery(CommandType.Text, sqlstring, prams); return true; //} //catch (Exception ex) //{ // errormsg = Globals.TransferSqlErrorInfo(ex.Message); // return false; //} }
public static SpaceAttachmentInfo[] GetSpaceAttachmentInfo (DataTable dt) { if(dt == null || dt.Rows.Count == 0) return null; SpaceAttachmentInfo[] spaceattachmentinfoarray = new SpaceAttachmentInfo[dt.Rows.Count]; for(int i = 0 ; i < dt.Rows.Count ; i++) { spaceattachmentinfoarray[i] = new SpaceAttachmentInfo(); spaceattachmentinfoarray[i].AID = TypeConverter.ObjectToInt(dt.Rows[i]["aid"]); spaceattachmentinfoarray[i].UID = TypeConverter.ObjectToInt(dt.Rows[i]["uid"]); spaceattachmentinfoarray[i].SpacePostID = TypeConverter.ObjectToInt(dt.Rows[i]["spacepostid"]); spaceattachmentinfoarray[i].PostDateTime = Convert.ToDateTime(dt.Rows[i]["postdatetime"]); spaceattachmentinfoarray[i].FileName = dt.Rows[i]["filename"].ToString(); spaceattachmentinfoarray[i].FileType = dt.Rows[i]["filetype"].ToString(); spaceattachmentinfoarray[i].FileSize = TypeConverter.ObjectToInt(dt.Rows[i]["filesize"]); spaceattachmentinfoarray[i].Attachment = dt.Rows[i]["attachment"].ToString(); spaceattachmentinfoarray[i].Downloads = TypeConverter.ObjectToInt(dt.Rows[i]["downloads"]); } dt.Dispose(); return spaceattachmentinfoarray; }
public static SpaceAttachmentInfo GetSpaceAttachmentInfo(IDataReader idatareader) { if(idatareader == null) return null; if(idatareader.Read()) { SpaceAttachmentInfo spaceattachmentinfo = new SpaceAttachmentInfo(); spaceattachmentinfo.AID = TypeConverter.ObjectToInt(idatareader["aid"]); spaceattachmentinfo.UID = TypeConverter.ObjectToInt(idatareader["uid"]); spaceattachmentinfo.SpacePostID = TypeConverter.ObjectToInt(idatareader["spacepostid"]); spaceattachmentinfo.PostDateTime = Convert.ToDateTime(idatareader["postdatetime"]); spaceattachmentinfo.FileName = idatareader["filename"].ToString(); spaceattachmentinfo.FileType = idatareader["filetype"].ToString(); spaceattachmentinfo.FileSize = TypeConverter.ObjectToInt(idatareader["filesize"]); spaceattachmentinfo.Attachment = idatareader["attachment"].ToString(); spaceattachmentinfo.Downloads = TypeConverter.ObjectToInt(idatareader["downloads"]); idatareader.Close(); return spaceattachmentinfo; } else { idatareader.Close(); return null; } }
public bool AddSpaceAttachment(SpaceAttachmentInfo spaceattachments) { DbParameter[] parms = { DbHelper.MakeInParam("@aid", (DbType)SqlDbType.Int, 4,spaceattachments.AID), DbHelper.MakeInParam("@uid", (DbType)SqlDbType.Int, 4,spaceattachments.UID), DbHelper.MakeInParam("@spacepostid", (DbType)SqlDbType.Int, 4,spaceattachments.SpacePostID), DbHelper.MakeInParam("@postdatetime", (DbType)SqlDbType.DateTime, 8,spaceattachments.PostDateTime), DbHelper.MakeInParam("@filename", (DbType)SqlDbType.NChar, 100,spaceattachments.FileName), DbHelper.MakeInParam("@filetype", (DbType)SqlDbType.NChar, 50,spaceattachments.FileType), DbHelper.MakeInParam("@filesize", (DbType)SqlDbType.Float, 8,spaceattachments.FileSize), DbHelper.MakeInParam("@attachment", (DbType)SqlDbType.NChar, 100,spaceattachments.Attachment), DbHelper.MakeInParam("@downloads", (DbType)SqlDbType.Int, 4,spaceattachments.Downloads), }; string commandText = string.Format("INSERT INTO [{0}spaceattachments] ( [uid], [spacepostid], [postdatetime], [filename], [filetype], [filesize], [attachment], [downloads]) VALUES ( @uid, @spacepostid, @postdatetime, @filename, @filetype, @filesize, @attachment, @downloads)", BaseConfigs.GetTablePrefix); DbHelper.ExecuteNonQuery(CommandType.Text, commandText, parms); return true; }
/// <summary> /// 保存附件 /// </summary> /// <param name="mediaObject"></param> /// <param name="uid"></param> /// <param name="filename"></param> private static void SaveSpaceAttachment(MediaObject mediaObject, int uid, string filename) { SpaceAttachmentInfo spaceattachmentinfo = new SpaceAttachmentInfo(); spaceattachmentinfo.UID = uid; spaceattachmentinfo.SpacePostID = 0; spaceattachmentinfo.PostDateTime = DateTime.Now; spaceattachmentinfo.FileName = filename; spaceattachmentinfo.FileType = mediaObject.type; spaceattachmentinfo.FileSize = mediaObject.bits.Length; spaceattachmentinfo.Attachment = mediaObject.name; spaceattachmentinfo.Downloads = 0; DbProvider.GetInstance().AddSpaceAttachment(spaceattachmentinfo); }
private void InsertSapceAttachment(string filename, string filetype, int filesize, string attachment) { SpaceAttachmentInfo spaceattachmentinfo = new SpaceAttachmentInfo(); spaceattachmentinfo.UID = userid; spaceattachmentinfo.SpacePostID = Convert.ToInt32(ViewState["postid"].ToString()); spaceattachmentinfo.PostDateTime = DateTime.Now; spaceattachmentinfo.FileName = filename; spaceattachmentinfo.FileType = filetype; spaceattachmentinfo.FileSize = filesize; spaceattachmentinfo.Attachment = attachment; spaceattachmentinfo.Downloads = 0; Space.Data.DbProvider.GetInstance().AddSpaceAttachment(spaceattachmentinfo); }