public QueryReport Insert_AttributeDATA(string PathDir)
        {
            QueryReport result = new QueryReport();
            result.StartReport();

            if (_fileCsvData != null && _fileCsvData.IsValid)
            {
                result.FileSource = _fileCsvData.filename;
                QueryReport _result = ISTAT.DBDAL.DataAccess.Insert_AttributeData(_fileCsvData.filePath + @"\" + _fileCsvData.filename, this.DataSet.IDSet, PathDir);
                result.Merge(_result);
            }

            if (result.RecordCount > 0 || result.RecordOverrideCount > 0)
                ISTAT.DBDAL.DataAccess.Insert_Load(
                    this.DataSet.IDSet,
                    this.DataSet.IDFlow,
                    result.MinTime,
                    result.MaxTime,
                    result.RecordCount + result.RecordOverrideCount,
                    result.FileSource);

            result.StopReport();

            return result;
        }
        /*
        public QueryReport Insert_DATA()
        {

            QueryReport result = new QueryReport();
            result.StartReport();
            Dictionary<string, List<string>> _view = null;

            // return view of csv file
            if (_fileCsvData != null && _fileCsvData.IsValid)
            {
                result.FileSource = _fileCsvData.filename;
                string[] filesData = System.IO.Directory.GetFiles(_fileCsvData.filePath);
                using (System.IO.StreamReader streamFile = new System.IO.StreamReader(filesData[0]))
                {
                    _view = Mapping.GetView(streamFile.BaseStream, _mapping, 0, (_mapping.CSV_HASHEADER)?1:0);
                    streamFile.Close();
                }
                QueryReport _result = ISTAT.DBDAL.DataAccess.Insert_Data(this.DataSet.IDSet, _view);
                result.Merge(_result);
            }

            // return view of xml file
            if (_filesXmlData != null)
            {
                result.FileSource = _filesXmlData.filename;
                string[] filesData = System.IO.Directory.GetFiles(_filesXmlData.filePath);
                using (System.IO.StreamReader streamFile = new System.IO.StreamReader(filesData[0]))
                {

                    TranscodeTime transcode = (_mapping != null) ? (_mapping.TranscodeUse) ? _mapping.TranscodeTime : null : null;

                    _view = ISTAT.DBDAL.DataSDMX.GetView(streamFile.BaseStream, transcode, 0);
                    streamFile.Close();
                }
                QueryReport _result = ISTAT.DBDAL.DataAccess.Insert_Data(this.DataSet.IDSet, _view);
                result.Merge(_result);
            }

            // Write log on db for RSS

            if (result.RecordCount>0 || result.RecordOverrideCount>0)
                ISTAT.DBDAL.DataAccess.Insert_Load(
                    this.DataSet.IDSet,
                    this.DataSet.IDFlow,
                    result.MinTime,
                    result.MaxTime,
                    result.RecordCount+result.RecordOverrideCount,
                    result.FileSource);

            result.StopReport();

            return result;
        }*/
        public QueryReport Insert_DATA()
        {
            QueryReport result = new QueryReport();
            result.StartReport();
            Dictionary<string, List<string>> _view = null;

            try
            {

                // return view of csv file
                if (_fileCsvData != null && _fileCsvData.IsValid)
                {

                    result.FileSource = _fileCsvData.filename;
                    QueryReport _result = ISTAT.DBDAL.DataAccess.Insert_CSVData(_fileCsvData.filePath + @"\" + _fileCsvData.filename, _fileCsvData.separator, _mapping.IDSchema);
                    result.Merge(_result);

                }

                // return view of xml file
                if (_filesXmlData != null)
                {
                    result.FileSource = _filesXmlData.filename;
                    string[] filesData = System.IO.Directory.GetFiles(_filesXmlData.filePath);
                    using (System.IO.StreamReader streamFile = new System.IO.StreamReader(filesData[0]))
                    {
                        string tempCsvFilename = Path.GetTempFileName();

                        TranscodeTime transcode = (_mapping != null) ? (_mapping.TranscodeUse) ? _mapping.TranscodeTime : null : null;
                        System.IO.StreamWriter outFile = new System.IO.StreamWriter(tempCsvFilename);
                        var fieldsList = ISTAT.DBDAL.DataSDMX.WriteSDMXtoCSV(streamFile.BaseStream, outFile);
                        //var builder = SDMX_Dataloader.Engine.BuilderProcedure.Create();
                        //var mapping = builder.Create_MappingForSdmxMl(_ds.IDSet, fieldsList);

                        QueryReport _result = ISTAT.DBDAL.DataAccess.Insert_CSVData(tempCsvFilename, ';', 0, _ds.IDSet);

                        //builder.Delete_MAPPING(mapping.IDSchema);
                        if (outFile.BaseStream != null) outFile.Close();
                        System.IO.File.Delete(tempCsvFilename);

                        result.Merge(_result);

                    }

                }
            }
            catch (Exception ex)
            {
                QueryReport _report = new QueryReport();
                _report.RecordCount = 0;
                _report.RecordTargetCount = 0;
                _report.Errors.Add(ex.Message);
                result.Merge(_report);
            }

            // Write log on db for RSS

            if (result.RecordCount > 0 || result.RecordOverrideCount > 0)
                ISTAT.DBDAL.DataAccess.Insert_Load(
                    this.DataSet.IDSet,
                    this.DataSet.IDFlow,
                    result.MinTime,
                    result.MaxTime,
                    result.RecordCount + result.RecordOverrideCount,
                    result.FileSource);

            result.StopReport();

            return result;
        }
        public QueryReport Insert_DATA()
        {
            QueryReport result = new QueryReport();
            result.StartReport();
            Dictionary<string, List<string>> _view = null;

            // return view of csv file
            if (_fileCsvData != null && _fileCsvData.IsValid)
            {
                result.FileSource = _fileCsvData.filename;
                string[] filesData = System.IO.Directory.GetFiles(_fileCsvData.filePath);
                using (System.IO.StreamReader streamFile = new System.IO.StreamReader(filesData[0]))
                {
                    _view = Mapping.GetView(streamFile.BaseStream, _mapping, 0, (_mapping.CSV_HASHEADER)?1:0);
                    streamFile.Close();
                }
                QueryReport _result = ISTAT.DBDAL.DataAccess.Insert_Data(this.DataSet.IDSet, _view);
                result.Merge(_result);
            }

            // return view of xml file
            if (_filesXmlData != null)
            {
                result.FileSource = _filesXmlData.filename;
                string[] filesData = System.IO.Directory.GetFiles(_filesXmlData.filePath);
                using (System.IO.StreamReader streamFile = new System.IO.StreamReader(filesData[0]))
                {

                    TranscodeTime transcode = (_mapping != null) ? (_mapping.TranscodeUse) ? _mapping.TranscodeTime : null : null;

                    _view = ISTAT.DBDAL.DataSDMX.GetView(streamFile.BaseStream, transcode, 0);
                    streamFile.Close();
                }
                QueryReport _result = ISTAT.DBDAL.DataAccess.Insert_Data(this.DataSet.IDSet, _view);
                result.Merge(_result);
            }

            // Write log on db for RSS

            if (result.RecordCount>0 || result.RecordOverrideCount>0)
                ISTAT.DBDAL.DataAccess.Insert_Load(
                    this.DataSet.IDSet,
                    this.DataSet.IDFlow,
                    result.MinTime,
                    result.MaxTime,
                    result.RecordCount+result.RecordOverrideCount,
                    result.FileSource);

            result.StopReport();

            return result;
        }