Source code of file oscpmwin/currencyman.pas from the
osCommerce Product Manager for Windows.
0000: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001: osCommerce Product Manager for Windows (oscpmwin).
0002: Copyright �2003-2006 by Mario A. Valdez-Ramirez.
0003:
0004: You can contact Mario A. Valdez-Ramirez
0005: by email at mario@mariovaldez.org or paper mail at
0006: Olmos 809, San Nicolas, NL. 66495, Mexico.
0007:
0008: This program is free software; you can redistribute it and/or modify
0009: it under the terms of the GNU General Public License as published by
0010: the Free Software Foundation; either version 2 of the License, or (at
0011: your option) any later version.
0012:
0013: This program is distributed in the hope that it will be useful, but
0014: WITHOUT ANY WARRANTY; without even the implied warranty of
0015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0016: General Public License for more details.
0017:
0018: You should have received a copy of the GNU General Public License
0019: along with this program; if not, write to the Free Software
0020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0021: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0022: unit currencyman;
0023:
0024: interface
0025:
0026: uses
0027: SysUtils, Classes, Controls, Forms,
0028: Dialogs, StdCtrls, Buttons, ComCtrls;
0029:
0030: type
0031: Topm_Form_CurrencyMan = class(TForm)
0032: opm_ListBox_CurrencyCurrs: TListBox;
0033: opm_BitBtn_CurrencyAdd: TBitBtn;
0034: opm_BitBtn_CurrencyEdit: TBitBtn;
0035: opm_BitBtn_CurrencyDel: TBitBtn;
0036: opm_BitBtn_CurrencyUpdateAll: TBitBtn;
0037: opm_BitBtn_CurrencyOk: TBitBtn;
0038: opm_StatusBar_Currency: TStatusBar;
0039: opm_BitBtn_CurrencySetDef: TBitBtn;
0040: procedure FormShow(Sender: TObject);
0041: procedure FormCreate(Sender: TObject);
0042: procedure opm_ListBox_CurrencyCurrsClick(Sender: TObject);
0043: procedure opm_BitBtn_CurrencyAddClick(Sender: TObject);
0044: procedure opm_BitBtn_CurrencyDelClick(Sender: TObject);
0045: procedure opm_BitBtn_CurrencyEditClick(Sender: TObject);
0046: procedure opm_ListBox_CurrencyCurrsDblClick(Sender: TObject);
0047: procedure opm_BitBtn_CurrencyUpdateAllClick(Sender: TObject);
0048: procedure opm_BitBtn_CurrencySetDefClick(Sender: TObject);
0049: private
0050: PROCEDURE PRopm_Reload_CurrList;
0051: public
0052: { Public declarations }
0053: end;
0054:
0055: var
0056: opm_Form_CurrencyMan: Topm_Form_CurrencyMan;
0057:
0058: implementation
0059:
0060: {$R *.dfm}
0061:
0062: USES gnugettext, oscpmdata, currencyedit, attention, main, progress, network, dataman,
0063: currupd;
0064:
0065:
0066:
0067: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0068: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0069: procedure Topm_Form_CurrencyMan.FormShow(Sender: TObject);
0070: BEGIN
0071: opm_Form_CurrencyMan.Caption := _('Currencies management');
0072: PRopm_Reload_CurrList;
0073: END;
0074:
0075:
0076: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0077: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0078: procedure Topm_Form_CurrencyMan.FormCreate(Sender: TObject);
0079: begin
0080: TranslateComponent (self);
0081: end;
0082:
0083:
0084: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0085: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0086: procedure Topm_Form_CurrencyMan.opm_ListBox_CurrencyCurrsClick(Sender: TObject);
0087: begin
0088: IF (opm_ListBox_CurrencyCurrs.ItemIndex >= 0) THEN
0089: BEGIN
0090: opm_BitBtn_CurrencyDel.Enabled := TRUE;
0091: opm_BitBtn_CurrencyEdit.Enabled := TRUE;
0092: opm_BitBtn_CurrencySetDef.Enabled := TRUE;
0093: END
0094: ELSE
0095: BEGIN
0096: opm_BitBtn_CurrencyDel.Enabled := FALSE;
0097: opm_BitBtn_CurrencyEdit.Enabled := FALSE;
0098: opm_BitBtn_CurrencySetDef.Enabled := TRUE;
0099: END;
0100: end;
0101:
0102:
0103:
0104: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0105: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0106: procedure Topm_Form_CurrencyMan.opm_BitBtn_CurrencyAddClick(Sender: TObject);
0107: begin
0108: opm_Form_CurrencyEdit.CU_AddEdit := TRUE;
0109: IF (opm_Form_CurrencyEdit.ShowModal = mrOk) THEN
0110: BEGIN
0111: opm_Form_Main.PRopm_AddCurrency (opm_Form_CurrencyEdit.CU_Currency);
0112: PRopm_Reload_CurrList;
0113: END;
0114: end;
0115:
0116:
0117: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0118: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0119: procedure Topm_Form_CurrencyMan.opm_BitBtn_CurrencyDelClick(Sender: TObject);
0120: VAR
0121: CurCurr : opmR_Currency;
0122: begin
0123: IF (opm_ListBox_CurrencyCurrs.ItemIndex >= 0) THEN
0124: IF ((opmG_UIConfirmDels = 0) OR ((opmG_UIConfirmDels > 0) AND (FNopm_Message (_('Are you sure you want to delete this currency?'),
0125: mtConfirmation, [mbYes, mbNo], opmG_UISilent) = mrYes))) THEN
0126: BEGIN
0127: CurCurr := opm_Form_Main.FNopm_GetCurrency (opmG_CurrencyList, opm_ListBox_CurrencyCurrs.ItemIndex, opmC_FindByIndex);
0128: IF (CurCurr.Default = FALSE) THEN
0129: opm_Form_Main.PRopm_DelCurrency (CurCurr)
0130: ELSE
0131: FNopm_Message (_('This currency is the default currency. It cannot be deleted.'), mtError, [mbOk], opmG_UISilent);
0132: PRopm_Reload_CurrList;
0133: END;
0134: end;
0135:
0136:
0137: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0138: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0139: procedure Topm_Form_CurrencyMan.opm_BitBtn_CurrencyEditClick(Sender: TObject);
0140: VAR
0141: CurCurr : opmR_Currency;
0142: begin
0143: IF (opm_ListBox_CurrencyCurrs.ItemIndex >= 0) THEN
0144: BEGIN
0145: CurCurr := opm_Form_Main.FNopm_GetCurrency (opmG_CurrencyList, opm_ListBox_CurrencyCurrs.ItemIndex, opmC_FindByIndex);
0146: IF (CurCurr.ID >= 0) THEN
0147: BEGIN
0148: opm_Form_CurrencyEdit.CU_AddEdit := FALSE;
0149: opm_Form_CurrencyEdit.CU_Currency := CurCurr;
0150: IF (opm_Form_CurrencyEdit.ShowModal = mrOk) THEN
0151: IF ((opmG_UIConfirmMods = 0) OR ((opmG_UIConfirmMods > 0) AND (FNopm_Message (_('Are you sure you want to change this currency?'),
0152: mtConfirmation, [mbYes, mbNo], opmG_UISilent) = mrYes))) THEN
0153: BEGIN
0154: opm_Form_Main.PRopm_UpdateCurrency (opm_Form_CurrencyEdit.CU_Currency, FALSE);
0155: PRopm_Reload_CurrList;
0156: END;
0157: END;
0158: END;
0159: end;
0160:
0161:
0162:
0163: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0164: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0165: procedure Topm_Form_CurrencyMan.opm_ListBox_CurrencyCurrsDblClick(Sender: TObject);
0166: VAR
0167: CurCurr : opmR_Currency;
0168: begin
0169: IF (opm_ListBox_CurrencyCurrs.ItemIndex >= 0) THEN
0170: BEGIN
0171: CurCurr := opm_Form_Main.FNopm_GetCurrency (opmG_CurrencyList, opm_ListBox_CurrencyCurrs.ItemIndex, opmC_FindByIndex);
0172: IF (CurCurr.ID >= 0) THEN
0173: BEGIN
0174: opm_Form_CurrencyEdit.CU_AddEdit := FALSE;
0175: opm_Form_CurrencyEdit.CU_Currency := CurCurr;
0176: IF (opm_Form_CurrencyEdit.ShowModal = mrOk) THEN
0177: IF ((opmG_UIConfirmMods = 0) OR ((opmG_UIConfirmMods > 0) AND (FNopm_Message (_('Are you sure you want to change this currency?'),
0178: mtConfirmation, [mbYes, mbNo], opmG_UISilent) = mrYes))) THEN
0179: BEGIN
0180: opm_Form_Main.PRopm_UpdateCurrency (opm_Form_CurrencyEdit.CU_Currency, FALSE);
0181: PRopm_Reload_CurrList;
0182: END;
0183: END;
0184: END;
0185: end;
0186:
0187:
0188: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0189: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0190: PROCEDURE Topm_Form_CurrencyMan.PRopm_Reload_CurrList;
0191: VAR
0192: CurCurr : LONGINT;
0193: DefCurExist : BOOLEAN;
0194: BEGIN
0195: DefCurExist := FALSE;
0196: FOR CurCurr := 0 TO (opm_TotalCurrencies - 1) DO
0197: BEGIN
0198: opmG_CurrencyList[CurCurr].NewValue := 0;
0199: DefCurExist := (DefCurExist OR opmG_CurrencyList[CurCurr].Default);
0200: END;
0201: opm_ListBox_CurrencyCurrs.Items := opmG_CurrencyBoxList;
0202: opm_ListBox_CurrencyCurrs.ItemIndex := -1;
0203: opm_BitBtn_CurrencyDel.Enabled := FALSE;
0204: opm_BitBtn_CurrencyEdit.Enabled := FALSE;
0205: opm_BitBtn_CurrencySetDef.Enabled := FALSE;
0206: opm_BitBtn_CurrencyUpdateAll.Enabled := ((opm_TotalCurrencies > 1) AND (DefCurExist = TRUE));
0207: END;
0208:
0209:
0210: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0211: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0212: procedure Topm_Form_CurrencyMan.opm_BitBtn_CurrencyUpdateAllClick(Sender: TObject);
0213: VAR
0214: CurCurr, CurXchg : LONGINT;
0215: CurList : STRING;
0216: ResStr : STRING;
0217: ResCode : LONGINT;
0218: XchangeList : TStringList;
0219: TmpRate : CURRENCY;
0220: BEGIN
0221: CurList := opm_CurrentCurrency.Code;
0222: FOR CurCurr := 0 TO (opm_TotalCurrencies - 1) DO
0223: CurList := CurList + ',' + opmG_CurrencyList[CurCurr].Code;
0224: opm_Form_Progress.PRopm_PDShow (FALSE, TRUE);
0225: opm_Form_Progress.PRopm_PDUpdate_Progress (50, 1, _('Getting exchange rates...'));
0226: PRopm_Prepare_HTTPClient (opm_Form_Progress.opm_ProgressBar_Progress2, opm_Form_Progress.opm_Label_ProgressMsg2, ((opmG_UseProxy > 0) AND (opmG_ProxyApply IN [0, 1])));
0227: ResCode := FNopm_Send_Command (opmG_WBUploadURL, 'xchgrates', CurList, ResStr);
0228: opm_Form_Progress.PRopm_PDClose;
0229: IF (ResCode = 0) THEN
0230: BEGIN
0231: XchangeList := TStringList.Create;
0232: XchangeList.Text := ResStr;
0233: FOR CurCurr := 0 TO (opm_TotalCurrencies - 1) DO
0234: IF (opmG_CurrencyList[CurCurr].Default = FALSE) THEN
0235: FOR CurXchg := 0 TO (XchangeList.Count - 1) DO
0236: BEGIN
0237: IF (ANSIPOS (opmG_CurrencyList[CurCurr].Code, XchangeList.Strings[CurXchg]) > 0) THEN
0238: BEGIN
0239: TmpRate := STRTOCURR (FNopm_CleanNumber (COPY (XchangeList.Strings[CurXchg], ANSIPOS (',', XchangeList.Strings[CurXchg]), opmC_CurrValue_MaxLen), opmC_ValIsCurrency));
0240: opmG_CurrencyList[CurCurr].NewValue := TmpRate;
0241: BREAK;
0242: END;
0243: opmG_CurrencyList[CurCurr].NewValue := -1;
0244: END;
0245: FreeAndNIL (XchangeList);
0246: IF (opm_Form_Currupd.ShowModal = mrOk) THEN
0247: BEGIN
0248: FOR CurCurr := 0 TO (opm_TotalCurrencies - 1) DO
0249: IF ((opmG_CurrencyList[CurCurr].Default = FALSE) AND
0250: (opmG_CurrencyList[CurCurr].NewValue > 0) AND
0251: (opmG_CurrencyList[CurCurr].Value <> opmG_CurrencyList[CurCurr].NewValue)) THEN
0252: BEGIN
0253: opmG_CurrencyList[CurCurr].Value := opmG_CurrencyList[CurCurr].NewValue;
0254: opm_Form_Main.PRopm_UpdateCurrency (opmG_CurrencyList[CurCurr], TRUE);
0255: END;
0256: opm_Form_Progress.PRopm_PDShow (FALSE, TRUE);
0257: opm_Form_Progress.PRopm_PDUpdate_Progress (50, 1, _('Loading currency list...'));
0258: opm_CurrentCurrency := opm_Form_Main.FNopm_LoadCurrencyList (opmG_CurrencyList, opmG_CurrencyBoxList);
0259: opm_Form_Progress.PRopm_PDClose;
0260: END;
0261: PRopm_Reload_CurrList;
0262: END
0263: ELSE FNopm_Message (_('There was an error while downloading the exchange rates from the server.') + #13#10 + FNopm_FullRemoteError (ResCode, opmC_DefErrorDataLen), mtError, [mbOk], opmG_UISilent);
0264: end;
0265:
0266:
0267: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0268: {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0269: procedure Topm_Form_CurrencyMan.opm_BitBtn_CurrencySetDefClick(Sender: TObject);
0270: VAR
0271: CurCurr : opmR_Currency;
0272: begin
0273: IF (opm_ListBox_CurrencyCurrs.ItemIndex >= 0) THEN
0274: BEGIN
0275: CurCurr := opm_Form_Main.FNopm_GetCurrency (opmG_CurrencyList, opm_ListBox_CurrencyCurrs.ItemIndex, opmC_FindByIndex);
0276: IF ((CurCurr.ID >= 0) AND (CurCurr.Default = FALSE)) THEN
0277: BEGIN
0278: IF ((opmG_UIConfirmMods = 0) OR ((opmG_UIConfirmMods > 0) AND (FNopm_Message (_('Are you sure you want to set this currency as the default?'),
0279: mtConfirmation, [mbYes, mbNo], opmG_UISilent) = mrYes))) THEN
0280: BEGIN
0281: opm_Form_Main.PRopm_SetDefault_Currency (CurCurr.Code);
0282: PRopm_Reload_CurrList;
0283: END;
0284: END;
0285: END;
0286: end;
0287:
0288: end.