protected void btnImportFromCsv_Click(object sender, EventArgs e)
        {
            if ( !csvFile.HasFile )
            {
                Utils.AppendScript( "openPopUp( 'importCsv' );" );
                Utils.AppendScript( "location.href='#dataconsumers';" );
                Utils.AppendScript( string.Format( "alert( '{0}' );", Resources.Messages.err_no_file_uploaded ) );
                return;
            }

            IDataConsumerSchemeMutableObject dataConsumerScheme = GetDataConsumerSchemeFromSession();
            if (dataConsumerScheme == null) return;
            List<csvDataConsumer> dataConsumers = new List<csvDataConsumer>();
            bool errorInUploading = false;

            string wrongRowsMessage = string.Empty;
            string wrongRowsMessageForUser = string.Empty;
            string wrongFileLines = string.Empty;

            try
            {
                string filenameWithoutExtension = string.Format("{0}_{1}_{2}", Path.GetFileName(csvFile.FileName).Substring(0, csvFile.FileName.Length - 4), Session.SessionID, DateTime.Now.ToString().Replace('/', '_').Replace(':', '_').Replace(' ', '_'));
                string filename = string.Format("{0}.csv", filenameWithoutExtension);
                string logFilename = string.Format("{0}.log", filenameWithoutExtension);
                csvFile.SaveAs(Server.MapPath("~/csv_dataconsumerschemes_files/") + filename);

                StreamReader reader = new StreamReader(Server.MapPath("~/csv_dataconsumerschemes_files/") + filename);
                StreamWriter logWriter = new StreamWriter(Server.MapPath("~/csv_dataconsumerschemes_import_logs/") + logFilename, true);
                logWriter.WriteLine(string.Format("LOG RELATIVO A CARICAMENTO DEL DATA CONSUMER SCHEME [ ID => \"{0}\"  AGENCY_ID => \"{1}\"  VERSION => \"{2}\" ]  |  LINGUA SELEZIONATA: {3}\n", dataConsumerScheme.Id.ToString(), dataConsumerScheme.AgencyId.ToString(), dataConsumerScheme.Version.ToString(), cmbLanguageForCsv.SelectedValue.ToString()));
                logWriter.WriteLine("-----------------------------------------------------------------------------------------------------------------------------\n");
                reader.ReadLine();
                int currentRow = 1;

                char separator = txtSeparator.Text.Trim().Equals( string.Empty ) ? ';' : txtSeparator.Text.Trim().ElementAt( 0 );

                while (!reader.EndOfStream)
                {
                    string  currentFileLine = reader.ReadLine();
                    string[] fields = currentFileLine.Split( separator );
                    if (fields.Length != 3)
                    {
                        errorInUploading = true;
                        wrongRowsMessage += string.Format(Resources.Messages.err_csv_import_line_bad_format, currentRow + 1);
                        wrongRowsMessageForUser += string.Format(Resources.Messages.err_csv_import_line_bad_format_gui, currentRow + 1);
                        wrongFileLines += string.Format( "{0}\n", currentFileLine );
                        logWriter.WriteLine(string.Format(Resources.Messages.err_csv_import_line_bad_format, currentRow + 1));
                        logWriter.Flush();
                        currentRow++;
                        continue;
                    }
                    if (fields[0].Trim().Equals("\"\"") || fields[0].Trim().Equals(string.Empty))
                    {
                        errorInUploading = true;
                        wrongRowsMessage += string.Format(Resources.Messages.err_csv_import_id_missing, currentRow + 1);
                        wrongRowsMessageForUser += string.Format(Resources.Messages.err_csv_import_id_missing_gui, currentRow + 1);
                        wrongFileLines += string.Format( "{0}\n", currentFileLine );
                        logWriter.WriteLine(string.Format(Resources.Messages.err_csv_import_id_missing, currentRow + 1));
                        logWriter.Flush();
                        currentRow++;
                        continue;
                    }
                    if (fields[1].Trim().Equals("\"\"") || fields[1].Trim().Equals(string.Empty))
                    {
                        errorInUploading = true;
                        wrongRowsMessage += string.Format(Resources.Messages.err_csv_import_name_missing, currentRow + 1);
                        wrongRowsMessageForUser += string.Format(Resources.Messages.err_csv_import_name_missing_gui, currentRow + 1);
                        wrongFileLines += string.Format( "{0}\n", currentFileLine );
                        logWriter.WriteLine(string.Format(Resources.Messages.err_csv_import_name_missing, currentRow + 1));
                        logWriter.Flush();
                        currentRow++;
                        continue;
                    }
                    dataConsumers.Add(new csvDataConsumer(fields[0].ToString().Replace( "\"", "" ), fields[1].ToString().Replace( "\"", "" ), fields[2].ToString().Replace( "\"", "" )));
                    currentRow++;
                }
                if ( !errorInUploading )
                {
                    logWriter.WriteLine("Andato tutto a buon fine con questo file!");
                }
                else
                {
                    lblImportCsvErrors.Text = wrongRowsMessageForUser;
                    lblImportCsvWrongLines.Text = wrongFileLines;
                    Utils.AppendScript("openP('importCsvErrors',500);");
                }
                logWriter.Close();
                reader.Close();
            }
            catch (Exception ex)
            {
                Utils.AppendScript(string.Format("Upload status: The file could not be uploaded. The following error occured: {0}", ex.Message));
            }

            foreach (csvDataConsumer dataConsumer in dataConsumers)
            {
                IEnumerable<IDataConsumerMutableObject> tmpDataConsumers = (from dataCons in dataConsumerScheme.Items where dataCons.Id == dataConsumer.dataConsumer select dataCons).OfType<IDataConsumerMutableObject>();

                IDataConsumerMutableObject tmpDataConsumer;

                if (!(tmpDataConsumers.Count() > 0))
                {
                    tmpDataConsumer = new DataConsumerMutableCore();
                    tmpDataConsumer.Id = dataConsumer.dataConsumer;
                    tmpDataConsumer.AddName(cmbLanguageForCsv.SelectedValue.ToString(), dataConsumer.name);
                    tmpDataConsumer.AddDescription(cmbLanguageForCsv.SelectedValue.ToString(), dataConsumer.description);

                    dataConsumerScheme.AddItem(tmpDataConsumer);

                }
                else
                {
                    tmpDataConsumer = tmpDataConsumers.First();
                    tmpDataConsumer.Id = dataConsumer.dataConsumer;
                    tmpDataConsumer.AddName(cmbLanguageForCsv.SelectedValue.ToString(), dataConsumer.name);
                    tmpDataConsumer.AddDescription(cmbLanguageForCsv.SelectedValue.ToString(), dataConsumer.description);
                }
            }

            if (!SaveInMemory(dataConsumerScheme))
                return;
            BindData();
            if ( !errorInUploading )
            {
                Utils.ShowDialog( Resources.Messages.succ_operation );
            }
            Utils.AppendScript("location.href='#dataconsumers';");
        }
        protected void btnUpdateDataConsumer_Click(object sender, EventArgs e)
        {
            // Get Input field
            string data_consumer_id = txt_id_update.Text.Trim();
            IList<ITextTypeWrapperMutableObject> data_consumer_names = AddTextName_Update.TextObjectList;
            IList<ITextTypeWrapperMutableObject> data_consumer_descs = AddTextDescription_Update.TextObjectList;
            // string code_order_str = txtUpdateCodeOrder.Text.Trim();

            // Get Current Object Session
            IDataConsumerSchemeMutableObject dataConsumerScheme = GetDataConsumerSchemeFromSession();
            IEnumerable<IDataConsumerMutableObject> _rc = (from x in dataConsumerScheme.Items where x.Id == data_consumer_id select x).OfType<IDataConsumerMutableObject>();
            if (_rc.Count() == 0) return;

            IDataConsumerMutableObject dataConsumer = _rc.First();

            IDataConsumerMutableObject _bDataConsumer = new DataConsumerMutableCore();

            int indexDataConsumer = dataConsumerScheme.Items.IndexOf(dataConsumer);
            int indexOrder = 0;
            try
            {

                #region DATACONSUMER ID
                if (!data_consumer_id.Equals(string.Empty) && ValidationUtils.CheckIdFormat(data_consumer_id))
                {
                    _bDataConsumer.Id = data_consumer_id;
                }
                else
                {
                    lblErrorOnUpdate.Text = Resources.Messages.err_id_format;
                    Utils.AppendScript( "openPopUp('df-Dimension-update', 600 );" );
                    Utils.AppendScript("location.href= '#dataconsumers';");
                    return;
                }
                #endregion

                #region DATACONSUMER NAMES
                if (data_consumer_names != null)
                {
                    foreach (var tmpName in data_consumer_names)
                    {
                        _bDataConsumer.AddName(tmpName.Locale, tmpName.Value);
                    }
                }
                else
                {
                    lblErrorOnUpdate.Text = Resources.Messages.err_list_name_format;
                    Utils.AppendScript( "openPopUp('df-Dimension-update', 600 );" );
                    Utils.AppendScript("location.href= '#dataconsumers';");
                    return;
                }
                #endregion

                #region DATACONSUMER DESCRIPTIONS
                if (data_consumer_descs != null)
                {
                    foreach (var tmpDescription in data_consumer_descs)
                    {
                        _bDataConsumer.AddDescription(tmpDescription.Locale, tmpDescription.Value);
                    }
                }
                #endregion

                dataConsumerScheme.Items.Remove(dataConsumer);
                dataConsumerScheme.Items.Insert(indexDataConsumer, _bDataConsumer);

                var canRead = dataConsumerScheme.ImmutableInstance;

            }
            catch (Exception ex) // ERRORE GENERICO!
            {
                dataConsumerScheme.Items.Remove(_bDataConsumer);
                dataConsumerScheme.Items.Insert(indexDataConsumer, dataConsumer);

                Utils.ShowDialog(Resources.Messages.err_agency_update, 300, Resources.Messages.err_title);
                Utils.AppendScript("location.href='#dataconsumers';");

            }

            if (!SaveInMemory(dataConsumerScheme))
                return;

            BindData();
            lblErrorOnUpdate.Text = string.Empty;
            Utils.AppendScript("location.href='#dataconsumers';");
        }
        private IDataConsumerSchemeMutableObject InsertDataConsumerInDataConsumerscheme(IDataConsumerSchemeMutableObject dataConsumerScheme)
        {
            if (dataConsumerScheme == null) return null;

            IDataConsumerMutableObject dataConsumer = new DataConsumerMutableCore();

            string data_consumer_id = txt_id_new.Text.Trim();

            IList<ITextTypeWrapperMutableObject> data_consumer_names = AddTextName_new.TextObjectList;
            IList<ITextTypeWrapperMutableObject> data_consumer_descs = AddTextDescription_new.TextObjectList;
            // string code_order_str = txtOrderNewCode.Text.Trim();     ----- ORDINE

            #region DATACONSUMER ID
            if (ValidationUtils.CheckIdFormat(data_consumer_id))
            {
                dataConsumer.Id = data_consumer_id;
            }
            else
            {
                lblErrorOnNewInsert.Text = Resources.Messages.err_id_format;
                Utils.AppendScript( "openPopUp('df-Dimension', 600);" );
                Utils.AppendScript("location.href= '#dataconsumers';");
                return null;
            }

            IEnumerable<IDataConsumerMutableObject> dataConsumers = (from c in dataConsumerScheme.Items where c.Id == data_consumer_id select c).OfType<IDataConsumerMutableObject>();
            if (dataConsumers.Count() > 0)
            {
                lblErrorOnNewInsert.Text = Resources.Messages.err_id_exist;
                Utils.AppendScript( "openPopUp('df-Dimension', 600);" );
                Utils.AppendScript("location.href= '#dataconsumers';");
                return null;
            }
            #endregion

            #region DATACONSUMER NAMES
            if (data_consumer_names != null)
            {
                foreach (var tmpName in data_consumer_names)
                {
                    dataConsumer.AddName(tmpName.Locale, tmpName.Value);
                }
            }
            else
            {
                lblErrorOnNewInsert.Text = Resources.Messages.err_list_name_format;
                Utils.AppendScript( "openPopUp('df-Dimension', 600);" );
                Utils.AppendScript("location.href= '#dataconsumers';");
                return null;
            }
            #endregion

            #region DATACONSUMER DESCRIPTIONS
            if (data_consumer_descs != null)
            {
                foreach (var tmpDescription in data_consumer_descs)
                {
                    dataConsumer.AddDescription(tmpDescription.Locale, tmpDescription.Value);
                }
            }
            #endregion

            dataConsumerScheme.Items.Add(dataConsumer);

            try
            {
                // Ultimo controllo se ottengo Immutable istanze validazione completa
                var canRead = dataConsumerScheme.ImmutableInstance;
            }
            catch (Exception ex)
            {
                dataConsumerScheme.Items.Remove(dataConsumer);

                return null;

            }
            return dataConsumerScheme;
        }