public static void AddAttachByTask(int ttid, string filename, string data) { int taksid = Defect.GetIDbyTT(ttid); int repid = Defect.GetRepRecByTTID(taksid); byte[] filedata = Convert.FromBase64String(data); byte[] filedata4Disk = filedata; int filesize = filedata.Length; if (filedata.Length > 1024 * 1024 * 5) { filedata = new byte[0]; } int key = DefectAttach.AddObject( _FileTabl, new string[] { "idRecord", "ProjectID", "ArchvFile", "FileData" }, new object[] { new Expression(string.Format("(SELECT MAX(IDRECORD) + 1 FROM {0} where IDRECORD < 3000000)", _FileTabl)), 1, new Expression(string.Format("(SELECT CONVERT(VARCHAR(10), MAX(IDRECORD) + 1) + '.DAT' FROM {0} where IDRECORD < 3000000)", _FileTabl)), filedata }, "IDRECORD" ); int attkey = DefectAttach.AddObject( _Tabl, new string[] { _ID, _Proj, _Entit, _AttType, _Rid, _Name, _Mac, _MacCr, _DateC, _Size, _File, _Compr, _InDB }, new object[] { new Expression(string.Format("(SELECT MAX(IDRECORD) + 1 FROM {0} where IDRECORD < 3000000)", _Tabl)), 1, 1684431732, 1, repid, filename, 1061109567, 1061109567, new Expression("GETUTCDATE()"), filesize, string.Format("{0}.DAT", key), 0, 1 }, "IDRECORD" ); if (filedata.Length < 1) { if (!Directory.Exists(Settings.CurrentSettings.DEFECTATTACHDIR)) { Directory.CreateDirectory(Settings.CurrentSettings.DEFECTATTACHDIR); } DefectAttach da = new DefectAttach(attkey); File.WriteAllBytes(da.FileOnDisk, filedata4Disk); } DefectHistory.AddHisotoryByTask(taksid, string.Format("Added attachment: {0}", filename)); }
public static List <DefectAttach> GetAttachsByTask(int ttid) { List <DefectAttach> res = new List <DefectAttach>(); int taksid = Defect.GetIDbyTT(ttid); int repid = Defect.GetRepRecByTTID(taksid); foreach (int i in EnumRecords(_Tabl, _ID, new string[] { _Rid }, new object[] { repid })) { res.Add(new DefectAttach(i)); } return(res); }