IBE.SQL.EliteDBIO.ExportLocalizationDataToCSV C# (CSharp) Method

ExportLocalizationDataToCSV() public method

public ExportLocalizationDataToCSV ( string fileName, enLocalizationType activeSetting ) : void
fileName string
activeSetting enLocalizationType
return void
        public void ExportLocalizationDataToCSV(string fileName, enLocalizationType activeSetting)
        {
            String sqlString = "";
            DataTable data;
            Int32 counter;
            String infoString = "";
            String idString = "";

            try
            {
                switch (activeSetting)
                {
                    case enLocalizationType.Commodity:
                        sqlString = "select Lo.commodity_id As id, La.language, Lo.locname" + 
                                    "   from tbCommodityLocalization Lo, tbLanguage La" +
                                    "   where Lo.language_id = La.id" +
                                    " order by Lo.commodity_id, La.id";
                        infoString = "export commodity localization...";
                        idString = "Commodity_ID;Language;Name";
                        break;
                    case enLocalizationType.Category:
                        sqlString = "select Lo.category_id As id, La.language, Lo.locname" + 
                                    "   from tbCategoryLocalization Lo, tbLanguage La" +
                                    "   where Lo.language_id = La.id" +
                                    " order by Lo.category_id, La.id";
                        infoString = "export category localization...";
                        idString = "Category_ID;Language;Name";
                        break;
                    case enLocalizationType.Economylevel:
                        sqlString = "select Lo.economylevel_id As id, La.language, Lo.locname" + 
                                    "   from tbLevelLocalization Lo, tbLanguage La" +
                                    "   where Lo.language_id = La.id" +
                                    " order by Lo.economylevel_id, La.id";
                        infoString = "export economylevel localization...";
                        idString = "EconomyLevel_ID;Language;Name";
                        break;
                    default:
                        throw new Exception("unknown setting :  " + activeSetting);
                }

                if(System.IO.File.Exists(fileName))
                    System.IO.File.Delete(fileName);

                data        = new DataTable();
                counter     = 0;

                Program.DBCon.Execute(sqlString, data);

                sendProgressEvent(new ProgressEventArgs() { Info="export prices...", NewLine=true });

                var writer = new StreamWriter(File.OpenWrite(fileName));
                writer.WriteLine(idString);
                

                foreach (DataRow row in data.Rows)
                {
                    writer.WriteLine(row["id"] + ";" + 
                                     row["language"] + ";" + 
                                     row["locname"] );
                    counter++;
                    sendProgressEvent(new ProgressEventArgs() { Info="export prices...", CurrentValue=counter, TotalValue=data.Rows.Count });
                }

                sendProgressEvent(new ProgressEventArgs() {Info="export prices...", CurrentValue=1, TotalValue=1, ForceRefresh=true });

                writer.Close();
                writer.Dispose();
            }
            catch (Exception ex)
            {
                throw new Exception("Error while exporting localization data to csv", ex);
            }
        }