From a9a302855c0f60ddd501628f501a5eb5c5531fef Mon Sep 17 00:00:00 2001
From: Jasmin Dizdarevic <jasmin.dizdarevic@vvb.at>
Date: Sat, 27 Apr 2013 21:09:47 +0200
Subject: [PATCH 1/2] Decimal mark option added

---
 pgadmin/ctl/ctlSQLResult.cpp        | 19 +++++++++++++++----
 pgadmin/frm/frmOptions.cpp          | 10 ++++++++++
 pgadmin/include/utils/sysSettings.h | 10 ++++++++++
 pgadmin/ui/frmOptions.xrc           | 15 +++++++++++++++
 4 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/pgadmin/ctl/ctlSQLResult.cpp b/pgadmin/ctl/ctlSQLResult.cpp
index 6471890..75c5b58 100644
--- a/pgadmin/ctl/ctlSQLResult.cpp
+++ b/pgadmin/ctl/ctlSQLResult.cpp
@@ -201,7 +201,7 @@ void ctlSQLResult::DisplayData(bool single)
 		int w;
 
 		size_t hdrIndex = 0;
-		long col, nCols = thread->DataSet()->NumCols();
+		long col, nCols = thread->DataSet()->NumCols();		
 
 		for (col = 0 ; col < nCols ; col++)
 		{
@@ -327,12 +327,23 @@ wxString sqlResultTable::GetValue(int row, int col)
 				return wxT("<NULL>");
 			else
 			{
+
+				wxString decimalMark = wxT(".");
+				wxString s = wxEmptyString;
+				s = thread->DataSet()->GetVal(col);
+
+				if(thread->DataSet()->ColTypClass(col) == PGTYPCLASS_NUMERIC &&
+						settings->GetDecimalMark().Length() > 0)
+				{
+					decimalMark = settings->GetDecimalMark();
+					s.Replace(wxT("."), decimalMark);
+
+				}
 				if (thread->DataSet()->ColTypClass(col) == PGTYPCLASS_NUMERIC &&
 				        settings->GetThousandsSeparator().Length() > 0)
 				{
-					/* Add thousands separator */
-					wxString s = thread->DataSet()->GetVal(col);
-					size_t pos = s.find(wxT("."));
+					/* Add thousands separator */					
+					size_t pos = s.find(decimalMark);
 					if (pos == wxString::npos)
 						pos = s.length();
 					while (pos > 3)
diff --git a/pgadmin/frm/frmOptions.cpp b/pgadmin/frm/frmOptions.cpp
index 4bf8942..c1fcd14 100644
--- a/pgadmin/frm/frmOptions.cpp
+++ b/pgadmin/frm/frmOptions.cpp
@@ -85,6 +85,7 @@
 #define cbCopySeparator				CTRL_COMBOBOX("cbCopySeparator")
 #define chkStickySql                CTRL_CHECKBOX("chkStickySql")
 #define chkIndicateNull             CTRL_CHECKBOX("chkIndicateNull")
+#define txtDecimalMark	            CTRL_TEXT("txtDecimalMark")
 #define txtThousandsSeparator       CTRL_TEXT("txtThousandsSeparator")
 #define chkAutoRollback             CTRL_CHECKBOX("chkAutoRollback")
 #define chkDoubleClickProperties    CTRL_CHECKBOX("chkDoubleClickProperties")
@@ -302,6 +303,7 @@ frmOptions::frmOptions(frmMain *parent)
 	txtThousandsSeparator->SetValue(settings->GetThousandsSeparator());
 	chkAutoRollback->SetValue(settings->GetAutoRollback());
 	chkDoubleClickProperties->SetValue(settings->GetDoubleClickProperties());
+	txtDecimalMark->SetValue(settings->GetDecimalMark());
 	chkShowNotices->SetValue(settings->GetShowNotices());
 
 	txtPgHelpPath->SetValue(settings->GetPgHelpPath());
@@ -573,6 +575,13 @@ void frmOptions::OnOK(wxCommandEvent &ev)
 		return;
 	}
 
+	//Check decimal mark <> thousands separator
+	if(txtDecimalMark->GetValue() == txtThousandsSeparator->GetValue())
+	{
+		wxMessageBox(_("Decimal mark and thousands separator must not be equal"), _("Error"), wxICON_ERROR | wxOK);
+		return;
+	}
+
 	// Clean and check the help paths
 	txtPgHelpPath->SetValue(CleanHelpPath(txtPgHelpPath->GetValue()));
 	if (!HelpPathValid(txtPgHelpPath->GetValue()))
@@ -661,6 +670,7 @@ void frmOptions::OnOK(wxCommandEvent &ev)
 
 	settings->SetStickySql(chkStickySql->GetValue());
 	settings->SetIndicateNull(chkIndicateNull->GetValue());
+	settings->SetDecimalMark(txtDecimalMark->GetValue());
 	settings->SetThousandsSeparator(txtThousandsSeparator->GetValue());
 	settings->SetAutoRollback(chkAutoRollback->GetValue());
 	settings->SetDoubleClickProperties(chkDoubleClickProperties->GetValue());
diff --git a/pgadmin/include/utils/sysSettings.h b/pgadmin/include/utils/sysSettings.h
index 58906b2..945e537 100644
--- a/pgadmin/include/utils/sysSettings.h
+++ b/pgadmin/include/utils/sysSettings.h
@@ -369,6 +369,16 @@ public:
 	{
 		WriteBool(wxT("frmQuery/AutoRollback"), newval);
 	}
+	wxString GetDecimalMark() const
+	{
+		wxString s;
+		Read(wxT("DecimalMark"), &s, wxEmptyString);
+		return s;
+	}
+	void SetDecimalMark(const wxString &newval) 
+	{		
+		Write(wxT("DecimalMark"), newval);
+	}
 	bool GetLineNumber() const
 	{
 		bool b;
diff --git a/pgadmin/ui/frmOptions.xrc b/pgadmin/ui/frmOptions.xrc
index cf136c6..892a940 100644
--- a/pgadmin/ui/frmOptions.xrc
+++ b/pgadmin/ui/frmOptions.xrc
@@ -871,6 +871,21 @@
                   <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
                   <border>4</border>
                 </object>
+                <object class="sizeritem">
+                  <object class="wxStaticText" name="stDecimalMark">
+                    <label>Decimal mark</label>
+                  </object>
+                  <flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxTextCtrl" name="txtDecimalMark">
+                    <label></label>
+                    <checked>0</checked>
+                  </object>
+                  <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>                  
                 </object>
               </object>
               <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
-- 
1.8.0.msysgit.0

