/// <summary> /// This will get the list of all attachments based on the attachement id /// </summary> /// <param name="inItemID"></param> /// <returns></returns> public static List<Attachment> GetAttachments(int inItemID) { ScrumQueue.IOLogic.DBAccess dba = ScrumQueue.IOLogic.DBAccess.CreateConnection(); System.Data.SqlClient.SqlDataReader reader = dba.execSP("GetAllAttachmentsBasedOnItemID", new string[] { "@ItemID" }, new int[] { inItemID }); List<Attachment> listOfItems = new List<Attachment>(); while (reader.Read()) { // [AttachmentID],[ItemID],[Name],[CreateDate],[FileName],[FileType],[FileSize],[FileOriginalLocation],[FileData] int id = int.Parse(reader["AttachmentID"].ToString());// ok int iid = int.Parse(reader["ItemID"].ToString()); string name = reader["Name"].ToString();// ok DateTime createdOn = DateTime.Parse(reader["CreateDate"].ToString());//ok string fileName = reader["FileName"].ToString(); string fileType = reader["FileType"].ToString(); int fileSize = int.Parse(reader["FileSize"].ToString());//ok string fileOriginalLocation = reader["FileOriginalLocation"].ToString(); byte[] buffer = (byte[])reader["FileData"]; Attachment a = new Attachment(id, iid, name, fileName, fileType, fileSize, fileOriginalLocation, buffer); listOfItems.Add(a); } dba.CloseConn(); return listOfItems; }
private void button_Add_Click(object sender, EventArgs e) { if (this.Item.ItemID == -1) { MessageBox.Show(IOQMessages.saveFileBeforeAttachment); return; } string[] fileList = CommonLogic.Common.BrowseFile(this.openFileDialog_Browse); if (fileList != null) { foreach (string x in fileList) { ScrumQueueLoading dg = new ScrumQueueLoading(); dg.Show(); Attachment a = new Attachment(-1, this.item.ItemID, new System.IO.FileInfo(x), CommonLogic.Common.GetBytesFromFile(x)); List<Attachment> la = new List<Attachment>(); la.Add(a); Attachment.SaveAttachments(la); dg.Close(); } } this.LoadAttachement(); }
public static void DeleteAttachments(Attachment attachment) { ScrumQueue.IOLogic.DBAccess dba = ScrumQueue.IOLogic.DBAccess.CreateConnection(); // insert the item if (attachment.ItemID != -1) { System.Data.SqlClient.SqlDataReader reader = dba.execSP("DeleteAttachment", new string[] { "@AttachmentID" }, new System.Data.SqlDbType[] { System.Data.SqlDbType.Int }, new object[] { attachment.AttachmentID }); reader.Read(); // History.Insert(a, 1); } dba.CloseConn(); }