upload many - sql table structure

upload many - sql table structure

montoyammontoyam Posts: 568Questions: 136Answers: 5

I have been working on an asp.net datatable project. Now I am wanting to let users attach multiple files to a record. I see this is possible:
https://editor.datatables.net/reference/field/uploadMany

but, I am not clear on what tables are needed. One of the samples I came across look like I need a "files" table, and parent/child table that links the parent record with the files table. Is that correct? If so, why don't the other examples seem to use this structure (or they all show the same and I am missing it??)

Answers

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406
  • montoyammontoyam Posts: 568Questions: 136Answers: 5
    edited March 2020

    all the examples I find are imbedding images. I want to attach pdfs and eml files, so your's is a perfect example. however, can you include the code for your two file render functions, renderFilesEditor and renderFilesDataTable

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406
    edited March 2020

    ok, there is lots of specific stuff in there and not the best piece of sw I've written so far. I wrote this when I had just learned JS after many years of not writing a single line of code a few years ago... I didn't even know that you can return things when they are ready ... always did it at the very end ... You'll have to filter this yourself, I am afraid. I use moment.js with locale specific settings and font awesome icons, too.

    Forgot to mention: This renders a lot more than just the uploaded files. I generate files on the server and save them like uploaded files. They also need to be rendered for the data table but are mostly omitted for Editor.

    function renderFilesDataTable(rowFile, reportEndDate, externalId, serial) {
        //reportEndDate is only filled for reports, i.e. fileName.substr(0, 7) === '__rpt__'
        
        var ix=0;
        var returnString = '';
        var fileName;
        var saveFileName;
        var fileExtension;
        var n; var m;
        var iconField;
        var fileDate;
        var skipThisRecord = false;
        
        while (rowFile[ix]) {
            if ( ( ix !== 0 ) && ( ! skipThisRecord ) ) {
                returnString = returnString.concat('<br>');
            }
            skipThisRecord = false;
            n = rowFile[ix].name.lastIndexOf("."); 
            fileExtension = rowFile[ix].name.substr(n+1);
            iconField = getIconFieldforFiles(fileExtension, '');
            fileName = rowFile[ix].name.substr(0, n);
        //generated rfp xls files aren't shown!
            if ( ( fileName.substr(0, 21) === '__rpt__Bieteranfrage_' || 
                   fileName.substr(0, 11) === '__rpt__RfP_'              ) &&
                  ( fileExtension === 'xlsx'                             )     ) {
                skipThisRecord = true;
                ix++; 
                continue; //break out of the while loop and process next record
            } else {
                if ( usrType !== 'G' ) { //only govs may see the rpf recipient list
                    if ( fileName.substr(0, 17) === '__rpt__Empfänger_' ) {
                        skipThisRecord = true;
                        ix++; 
                        continue; //break out of the while loop and process next record
                    }
                }
            }
        //if it is a generated reporting file there is a special rendering    
            if ( fileName.substr(0, 7) === '__rpt__' ) {
                fileName = fileName.substr(7);
                m = fileName.lastIndexOf("_");
                fileName = fileName.substr(0, m);
                if ( reportEndDate.length < 18 ) {
                    saveFileName = fileName + '_' + moment(reportEndDate, 'L').format('YYYY-MM-DD');
                } else { //we have a timestamp from update_time
                    saveFileName = fileName + '_' + reportEndDate;
                }
            } else {
                saveFileName = rowFile[ix].name;
                if (fileName.length > 11) {
                    fileName = fileName.substr(0, 35) + '...';
                }
            }
        //interface files infoma, Sap, Datev are displayed differently!    
            if ( rowFile[ix].name.substr(0,9) === 'interface' ) {
                var fileNameRest = rowFile[ix].name.substr(9);
                var fileNameRestNoExt = fileNameRest.substr(0, fileNameRest.lastIndexOf(".")); 
                var fileNamePrefix = '';
                
                fileExtension = rowFile[ix].name.substr(n+1);
                iconField = getIconFieldforFiles(fileExtension, '');
                fileName = rowFile[ix].name.substr(0, n);
                
                if ( fileName === "interface_KRED_civitec") {
                    fileNamePrefix = "KRED.";
                    fileNameRest = ".csv";
                } else if ( fileName === "interface_SAKO_civitec") {
                    fileNamePrefix = "SAKO.";
                    fileNameRest = ".csv";
                }           
                if ( typeof externalId !== 'undefined') {
                    if ( externalId !== null ) {
                        if ( externalId === '___Datev') {
                            fileNamePrefix = 'EXTF_'; //datev files wants a prefix
                        }
                    }
                }
                if (lang == 'de') {
                    returnString = returnString.concat
                        (iconField + ' ' + "<a href="+rowFile[ix].web_path+
                            " download="+"'"+fileNamePrefix+"Schnittstelle" + fileNameRest +"'"+">Download Schnittstelle"+fileNameRestNoExt+"</a>");
                } else {
                    returnString = returnString.concat
                        (iconField + ' ' + "<a href="+rowFile[ix].web_path+
                            " download="+"'"+fileNamePrefix+"interface" + fileNameRest +"'"+">Download Interface"+fileNameRestNoExt+"</a>");
                }
            } else if ( rowFile[ix].name.substr(0,8) === 'ctr_docs' ) {
                iconField = getIconFieldforFiles("zip", '');
                if (lang == 'de') {
                    returnString = returnString.concat
                        (iconField + ' ' + "<a href="+rowFile[ix].web_path+
                            " download="+serial+".zip>Download als Zip-Archiv</a>");
                } else {
                    returnString = returnString.concat
                        (iconField + ' ' + "<a href="+rowFile[ix].web_path+
                            " download="+serial+".zip>Download as zip-archive</a>");
                }
            } else {         
    //            returnString = returnString.concat
    //                    (iconField + ' ' + fileName.link(rowFile[ix].web_path));
                
                returnString = returnString.concat
                        (iconField + ' ' + "<a href="+rowFile[ix].web_path+
                            " download="+"'"+saveFileName+"'"+">"+fileName+"</a>");
            }
            ix++; 
        }
        return returnString;
    }
    
    function renderFilesEditor(fileNameExt) {    
        //interface files infoma, Sap, Datev are NOT displayed in Editor
        if ( fileNameExt.substr(0,9) === 'interface' ||
             fileNameExt.substr(0,8) === 'ctr_docs'      ) {
            return '';
        }
        //find the last period in the filename
        var n = fileNameExt.lastIndexOf(".");
        var fileExtension = fileNameExt.substr(n+1);
        var fileName = fileNameExt.substr(0, n);
        //generated rfp xls files aren't shown!
        if ( ( fileName.substr(0, 21) === '__rpt__Bieteranfrage_' || 
               fileName.substr(0, 11) === '__rpt__RfP_'              ) &&
              ( fileExtension === 'xlsx'                             )     ) {
            return '';
        }
        //if it is a generated reporting file there is a special rendering
        if ( fileName.substr(0, 7) === '__rpt__' ) {
            fileName = fileName.substr(7);
            var m = fileName.lastIndexOf("_");
            fileName = fileName.substr(0, m);
        } else {
            if (fileName.length > 35) {
                fileName = fileName.substr(0, 35) + '...';
            }
        }
        var iconField = getIconFieldforFiles(fileExtension, 'fa-lg');    
        return iconField + '  ' + fileName;
    }
    
    function getIconFieldforFiles(fileExtension, size) {
        fileExtension = fileExtension.toLowerCase();
        var iconField = '';
        if ( fileExtension == 'pdf' ) {
            iconField = "<i class='fa fa-file-pdf-o " + size + "' aria-hidden='true'></i>";                   
        } else if ( fileExtension == 'xls'     || 
                    fileExtension == 'xlsx'    ||
                    fileExtension == 'ods'     ||
                    fileExtension == 'csv'      ) {
                    iconField = "<i class='fa fa-file-excel-o " + size + "' aria-hidden='true'></i>";
        } else if ( fileExtension == 'doc'     ||
                    fileExtension == 'docx'    ||
                    fileExtension == 'rtf'     ||
                    fileExtension == 'odt'     ) {
                    iconField = "<i class='fa fa-file-word-o " + size + "' aria-hidden='true'></i>";
        } else if ( fileExtension == 'ppt'     ||
                    fileExtension == 'pptx'    ||
                    fileExtension == 'odp'    ) {
                    iconField = "<i class='fa fa-file-powerpoint-o " + size + "' aria-hidden='true'></i>";    
        } else if ( fileExtension == 'txt' ) {
                    iconField = "<i class='fa fa-cloud-download " + size + "' aria-hidden='true'></i>";
        } else if ( fileExtension == 'zip' ) {
                    iconField = "<i class='fa fa-cloud-download " + size + "' aria-hidden='true'></i>";
                    //iconField = "<i class='fa fa-file-archive- " + size + "' aria-hidden='true'></i>";
        } else if ( fileExtension == 'xlsm' ) {
                    iconField = "<i class='fa fa-file-excel-o " + size + "' aria-hidden='true'></i>\n\
                                 <i class='fa fa-file-code-o " + size + "' aria-hidden='true'></i>";
        }    
        return iconField;
    }
    
This discussion has been closed.