public bool Export(OXODoc documentToExport, string comment, string PACN)
        {
            var retVal = false;

            XLWorkbook workbook = ClosedXmlExcelGenerator.GenerateExcelOXO(documentToExport.ProgrammeId, documentToExport.Id, CDSID, true);

            OXOProgrammeFile file = new OXOProgrammeFile();
            file.ProgrammeId = documentToExport.ProgrammeId;
            file.FileCategory = ProgrammFileCategory.Publish.ToString();
            file.FileComment = comment;
            file.PACN = PACN;
            file.FileName = String.Format("{0} {1} {2} {3} v{4}.{5} {6}.xlsx", 
                documentToExport.VehicleName, 
                documentToExport.VehicleAKA, 
                documentToExport.ModelYear, 
                documentToExport.Gateway, 
                documentToExport.VersionMajor, 
                documentToExport.VersionMinor, 
                documentToExport.Status);
            file.FileType = "application/vnd.open";
            file.FileExt = "xlsx";
            file.Gateway = documentToExport.Gateway;
            MemoryStream m = new MemoryStream();
            workbook.SaveAs(m);
            file.FileContent = m.ToArray();
            file.FileSize = file.FileContent.Length;
            _programmeFileDataStore.OXOProgrammeFileSave(file);

            retVal = true;

            return retVal;
        }
        public bool OXOProgrammeFileSave(OXOProgrammeFile obj)
        {
            bool retVal = true;
            string procName = (obj.Id == 0 ? "dbo.OXO_Programme_File_New" : "dbo.OXO_Programme_File_Edit");

			using (IDbConnection conn = DbHelper.GetDBConnection())
            {
				try
				{

                    obj.Save(this.CurrentCDSID);
                    
                    var para = new DynamicParameters();

                     para.Add("@p_Programme_Id", obj.ProgrammeId, dbType: DbType.Int32);
                     para.Add("@p_File_Category", obj.FileCategory, dbType: DbType.String, size: 100);
                     para.Add("@p_File_Comment", obj.FileComment, dbType: DbType.String, size: 2000);                    
                     para.Add("@p_File_Name", obj.FileName, dbType: DbType.String, size: 100);
                     para.Add("@p_File_Ext", obj.FileExt, dbType: DbType.String, size: 4);
					 para.Add("@p_File_Type", obj.FileType, dbType: DbType.String, size: 20);
					 para.Add("@p_File_Size", obj.FileSize, dbType: DbType.Int32);
                     para.Add("@p_gateway", obj.Gateway, dbType: DbType.String, size: 100);
                     para.Add("@p_PACN", obj.PACN, dbType: DbType.String, size: 10);					
					 para.Add("@p_File_Content", obj.FileContent, dbType: DbType.Binary);
					 para.Add("@p_Created_By", obj.CreatedBy, dbType: DbType.String, size: 8);
					 para.Add("@p_Created_On", obj.CreatedOn, dbType: DbType.DateTime);
					 para.Add("@p_Updated_By", obj.UpdatedBy, dbType: DbType.String, size: 8);
					 para.Add("@p_Last_Updated", obj.LastUpdated, dbType: DbType.DateTime);
					    

					if (obj.Id == 0)
					{
						para.Add("@p_Id", dbType: DbType.Int32, direction: ParameterDirection.Output);
					}
					else
					{
						para.Add("@p_Id", obj.Id, dbType: DbType.Int32);
					}

					conn.Execute(procName, para, commandType: CommandType.StoredProcedure);

					if (obj.Id == 0)
					{
						obj.Id = para.Get<int>("@p_Id");
					}

				}
				catch (Exception ex)
				{
                    Log.Error(ex);
                    throw;
				}
			}

            return retVal;
            
        }