{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% osCommerce Product Manager for Windows (oscpmwin). Copyright ©2003-2006 by Mario A. Valdez-Ramirez. You can contact Mario A. Valdez-Ramirez by email at mario@mariovaldez.org or paper mail at Olmos 809, San Nicolas, NL. 66495, Mexico. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} unit currencyman; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ComCtrls; type Topm_Form_CurrencyMan = class(TForm) opm_ListBox_CurrencyCurrs: TListBox; opm_BitBtn_CurrencyAdd: TBitBtn; opm_BitBtn_CurrencyEdit: TBitBtn; opm_BitBtn_CurrencyDel: TBitBtn; opm_BitBtn_CurrencyUpdateAll: TBitBtn; opm_BitBtn_CurrencyOk: TBitBtn; opm_StatusBar_Currency: TStatusBar; opm_BitBtn_CurrencySetDef: TBitBtn; procedure FormShow(Sender: TObject); procedure FormCreate(Sender: TObject); procedure opm_ListBox_CurrencyCurrsClick(Sender: TObject); procedure opm_BitBtn_CurrencyAddClick(Sender: TObject); procedure opm_BitBtn_CurrencyDelClick(Sender: TObject); procedure opm_BitBtn_CurrencyEditClick(Sender: TObject); procedure opm_ListBox_CurrencyCurrsDblClick(Sender: TObject); procedure opm_BitBtn_CurrencyUpdateAllClick(Sender: TObject); procedure opm_BitBtn_CurrencySetDefClick(Sender: TObject); private PROCEDURE PRopm_Reload_CurrList; public { Public declarations } end; var opm_Form_CurrencyMan: Topm_Form_CurrencyMan; implementation {$R *.dfm} USES gnugettext, oscpmdata, currencyedit, attention, main, progress, network, dataman, currupd; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyMan.FormShow(Sender: TObject); BEGIN opm_Form_CurrencyMan.Caption := _('Currencies management'); PRopm_Reload_CurrList; END; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyMan.FormCreate(Sender: TObject); begin TranslateComponent (self); end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyMan.opm_ListBox_CurrencyCurrsClick(Sender: TObject); begin IF (opm_ListBox_CurrencyCurrs.ItemIndex >= 0) THEN BEGIN opm_BitBtn_CurrencyDel.Enabled := TRUE; opm_BitBtn_CurrencyEdit.Enabled := TRUE; opm_BitBtn_CurrencySetDef.Enabled := TRUE; END ELSE BEGIN opm_BitBtn_CurrencyDel.Enabled := FALSE; opm_BitBtn_CurrencyEdit.Enabled := FALSE; opm_BitBtn_CurrencySetDef.Enabled := TRUE; END; end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyMan.opm_BitBtn_CurrencyAddClick(Sender: TObject); begin opm_Form_CurrencyEdit.CU_AddEdit := TRUE; IF (opm_Form_CurrencyEdit.ShowModal = mrOk) THEN BEGIN opm_Form_Main.PRopm_AddCurrency (opm_Form_CurrencyEdit.CU_Currency); PRopm_Reload_CurrList; END; end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyMan.opm_BitBtn_CurrencyDelClick(Sender: TObject); VAR CurCurr : opmR_Currency; begin IF (opm_ListBox_CurrencyCurrs.ItemIndex >= 0) THEN IF ((opmG_UIConfirmDels = 0) OR ((opmG_UIConfirmDels > 0) AND (FNopm_Message (_('Are you sure you want to delete this currency?'), mtConfirmation, [mbYes, mbNo], opmG_UISilent) = mrYes))) THEN BEGIN CurCurr := opm_Form_Main.FNopm_GetCurrency (opmG_CurrencyList, opm_ListBox_CurrencyCurrs.ItemIndex, opmC_FindByIndex); IF (CurCurr.Default = FALSE) THEN opm_Form_Main.PRopm_DelCurrency (CurCurr) ELSE FNopm_Message (_('This currency is the default currency. It cannot be deleted.'), mtError, [mbOk], opmG_UISilent); PRopm_Reload_CurrList; END; end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyMan.opm_BitBtn_CurrencyEditClick(Sender: TObject); VAR CurCurr : opmR_Currency; begin IF (opm_ListBox_CurrencyCurrs.ItemIndex >= 0) THEN BEGIN CurCurr := opm_Form_Main.FNopm_GetCurrency (opmG_CurrencyList, opm_ListBox_CurrencyCurrs.ItemIndex, opmC_FindByIndex); IF (CurCurr.ID >= 0) THEN BEGIN opm_Form_CurrencyEdit.CU_AddEdit := FALSE; opm_Form_CurrencyEdit.CU_Currency := CurCurr; IF (opm_Form_CurrencyEdit.ShowModal = mrOk) THEN IF ((opmG_UIConfirmMods = 0) OR ((opmG_UIConfirmMods > 0) AND (FNopm_Message (_('Are you sure you want to change this currency?'), mtConfirmation, [mbYes, mbNo], opmG_UISilent) = mrYes))) THEN BEGIN opm_Form_Main.PRopm_UpdateCurrency (opm_Form_CurrencyEdit.CU_Currency, FALSE); PRopm_Reload_CurrList; END; END; END; end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyMan.opm_ListBox_CurrencyCurrsDblClick(Sender: TObject); VAR CurCurr : opmR_Currency; begin IF (opm_ListBox_CurrencyCurrs.ItemIndex >= 0) THEN BEGIN CurCurr := opm_Form_Main.FNopm_GetCurrency (opmG_CurrencyList, opm_ListBox_CurrencyCurrs.ItemIndex, opmC_FindByIndex); IF (CurCurr.ID >= 0) THEN BEGIN opm_Form_CurrencyEdit.CU_AddEdit := FALSE; opm_Form_CurrencyEdit.CU_Currency := CurCurr; IF (opm_Form_CurrencyEdit.ShowModal = mrOk) THEN IF ((opmG_UIConfirmMods = 0) OR ((opmG_UIConfirmMods > 0) AND (FNopm_Message (_('Are you sure you want to change this currency?'), mtConfirmation, [mbYes, mbNo], opmG_UISilent) = mrYes))) THEN BEGIN opm_Form_Main.PRopm_UpdateCurrency (opm_Form_CurrencyEdit.CU_Currency, FALSE); PRopm_Reload_CurrList; END; END; END; end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} PROCEDURE Topm_Form_CurrencyMan.PRopm_Reload_CurrList; VAR CurCurr : LONGINT; DefCurExist : BOOLEAN; BEGIN DefCurExist := FALSE; FOR CurCurr := 0 TO (opm_TotalCurrencies - 1) DO BEGIN opmG_CurrencyList[CurCurr].NewValue := 0; DefCurExist := (DefCurExist OR opmG_CurrencyList[CurCurr].Default); END; opm_ListBox_CurrencyCurrs.Items := opmG_CurrencyBoxList; opm_ListBox_CurrencyCurrs.ItemIndex := -1; opm_BitBtn_CurrencyDel.Enabled := FALSE; opm_BitBtn_CurrencyEdit.Enabled := FALSE; opm_BitBtn_CurrencySetDef.Enabled := FALSE; opm_BitBtn_CurrencyUpdateAll.Enabled := ((opm_TotalCurrencies > 1) AND (DefCurExist = TRUE)); END; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyMan.opm_BitBtn_CurrencyUpdateAllClick(Sender: TObject); VAR CurCurr, CurXchg : LONGINT; CurList : STRING; ResStr : STRING; ResCode : LONGINT; XchangeList : TStringList; TmpRate : CURRENCY; BEGIN CurList := opm_CurrentCurrency.Code; FOR CurCurr := 0 TO (opm_TotalCurrencies - 1) DO CurList := CurList + ',' + opmG_CurrencyList[CurCurr].Code; opm_Form_Progress.PRopm_PDShow (FALSE, TRUE); opm_Form_Progress.PRopm_PDUpdate_Progress (50, 1, _('Getting exchange rates...')); PRopm_Prepare_HTTPClient (opm_Form_Progress.opm_ProgressBar_Progress2, opm_Form_Progress.opm_Label_ProgressMsg2, ((opmG_UseProxy > 0) AND (opmG_ProxyApply IN [0, 1]))); ResCode := FNopm_Send_Command (opmG_WBUploadURL, 'xchgrates', CurList, ResStr); opm_Form_Progress.PRopm_PDClose; IF (ResCode = 0) THEN BEGIN XchangeList := TStringList.Create; XchangeList.Text := ResStr; FOR CurCurr := 0 TO (opm_TotalCurrencies - 1) DO IF (opmG_CurrencyList[CurCurr].Default = FALSE) THEN FOR CurXchg := 0 TO (XchangeList.Count - 1) DO BEGIN IF (ANSIPOS (opmG_CurrencyList[CurCurr].Code, XchangeList.Strings[CurXchg]) > 0) THEN BEGIN TmpRate := STRTOCURR (FNopm_CleanNumber (COPY (XchangeList.Strings[CurXchg], ANSIPOS (',', XchangeList.Strings[CurXchg]), opmC_CurrValue_MaxLen), opmC_ValIsCurrency)); opmG_CurrencyList[CurCurr].NewValue := TmpRate; BREAK; END; opmG_CurrencyList[CurCurr].NewValue := -1; END; FreeAndNIL (XchangeList); IF (opm_Form_Currupd.ShowModal = mrOk) THEN BEGIN FOR CurCurr := 0 TO (opm_TotalCurrencies - 1) DO IF ((opmG_CurrencyList[CurCurr].Default = FALSE) AND (opmG_CurrencyList[CurCurr].NewValue > 0) AND (opmG_CurrencyList[CurCurr].Value <> opmG_CurrencyList[CurCurr].NewValue)) THEN BEGIN opmG_CurrencyList[CurCurr].Value := opmG_CurrencyList[CurCurr].NewValue; opm_Form_Main.PRopm_UpdateCurrency (opmG_CurrencyList[CurCurr], TRUE); END; opm_Form_Progress.PRopm_PDShow (FALSE, TRUE); opm_Form_Progress.PRopm_PDUpdate_Progress (50, 1, _('Loading currency list...')); opm_CurrentCurrency := opm_Form_Main.FNopm_LoadCurrencyList (opmG_CurrencyList, opmG_CurrencyBoxList); opm_Form_Progress.PRopm_PDClose; END; PRopm_Reload_CurrList; END ELSE FNopm_Message (_('There was an error while downloading the exchange rates from the server.') + #13#10 + FNopm_FullRemoteError (ResCode), mtError, [mbOk], opmG_UISilent); end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyMan.opm_BitBtn_CurrencySetDefClick(Sender: TObject); VAR CurCurr : opmR_Currency; begin IF (opm_ListBox_CurrencyCurrs.ItemIndex >= 0) THEN BEGIN CurCurr := opm_Form_Main.FNopm_GetCurrency (opmG_CurrencyList, opm_ListBox_CurrencyCurrs.ItemIndex, opmC_FindByIndex); IF ((CurCurr.ID >= 0) AND (CurCurr.Default = FALSE)) THEN BEGIN IF ((opmG_UIConfirmMods = 0) OR ((opmG_UIConfirmMods > 0) AND (FNopm_Message (_('Are you sure you want to set this currency as the default?'), mtConfirmation, [mbYes, mbNo], opmG_UISilent) = mrYes))) THEN BEGIN opm_Form_Main.PRopm_SetDefault_Currency (CurCurr.Code); PRopm_Reload_CurrList; END; END; END; end; end.