Source code of file oscpmwin_v0.1.2.189/currencyman.pas from the
osCommerce Product Manager for Windows.


0000:   {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001:   osCommerce Product Manager for Windows (oscpmwin).
0002:   Copyright �2003,2004,2005 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:     Windows, Messages, SysUtils, Variants, Classes, Graphics, 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:     XchangeList : TStringList;
0218:     TmpRate : CURRENCY;
0219:   BEGIN
0220:     CurList := opm_CurrentCurrency.Code;
0221:     FOR CurCurr := 0 TO (opm_TotalCurrencies - 1) DO
0222:       CurList := CurList + ',' + opmG_CurrencyList[CurCurr].Code;
0223:     opm_Form_Progress.PRopm_PDShow (FALSE, TRUE);
0224:     opm_Form_Progress.PRopm_PDUpdate_Progress (50, 1, _('Getting exchange rates...'));
0225:     PRopm_Prepare_HTTPClient (opm_Form_Progress.opm_ProgressBar_Progress2, opm_Form_Progress.opm_Label_ProgressMsg2, ((opmG_UseProxy > 0) AND (opmG_ProxyApply IN [0, 1])));
0226:     FNopm_Send_Command (opmG_WBUploadURL, 'xchgrates', CurList, ResStr);
0227:     opm_Form_Progress.PRopm_PDClose;
0228:     XchangeList := TStringList.Create;
0229:     XchangeList.Text := ResStr;
0230:     FOR CurCurr := 0 TO (opm_TotalCurrencies - 1) DO
0231:       IF (opmG_CurrencyList[CurCurr].Default = FALSE) THEN
0232:         FOR CurXchg := 0 TO (XchangeList.Count - 1) DO
0233:           BEGIN
0234:             IF (ANSIPOS (opmG_CurrencyList[CurCurr].Code, XchangeList.Strings[CurXchg]) > 0) THEN
0235:               BEGIN
0236:                 TmpRate := STRTOCURR (FNopm_CleanNumber (COPY (XchangeList.Strings[CurXchg], ANSIPOS (',', XchangeList.Strings[CurXchg]), opmC_CurrValue_MaxLen), opmC_ValIsCurrency));
0237:                 opmG_CurrencyList[CurCurr].NewValue := TmpRate;
0238:                 BREAK;
0239:               END;
0240:             opmG_CurrencyList[CurCurr].NewValue := -1;
0241:           END;
0242:     FreeAndNIL (XchangeList);
0243:     IF (opm_Form_Currupd.ShowModal = mrOk) THEN
0244:       BEGIN
0245:         FOR CurCurr := 0 TO (opm_TotalCurrencies - 1) DO
0246:           IF ((opmG_CurrencyList[CurCurr].Default = FALSE) AND
0247:               (opmG_CurrencyList[CurCurr].NewValue > 0) AND
0248:               (opmG_CurrencyList[CurCurr].Value <> opmG_CurrencyList[CurCurr].NewValue)) THEN
0249:             BEGIN
0250:               opmG_CurrencyList[CurCurr].Value := opmG_CurrencyList[CurCurr].NewValue;
0251:               opm_Form_Main.PRopm_UpdateCurrency (opmG_CurrencyList[CurCurr], TRUE);
0252:             END;
0253:         opm_Form_Progress.PRopm_PDShow (FALSE, TRUE);
0254:         opm_Form_Progress.PRopm_PDUpdate_Progress (50, 1, _('Loading currency list...'));
0255:         opm_CurrentCurrency := opm_Form_Main.FNopm_LoadCurrencyList (opmG_CurrencyList, opmG_CurrencyBoxList);
0256:         opm_Form_Progress.PRopm_PDClose;
0257:       END;
0258:     PRopm_Reload_CurrList;
0259:   end;
0260:   
0261:   
0262:   {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0263:   {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
0264:   procedure Topm_Form_CurrencyMan.opm_BitBtn_CurrencySetDefClick(Sender: TObject);
0265:   VAR
0266:     CurCurr : opmR_Currency;
0267:   begin
0268:     IF (opm_ListBox_CurrencyCurrs.ItemIndex >= 0) THEN
0269:       BEGIN
0270:         CurCurr := opm_Form_Main.FNopm_GetCurrency (opmG_CurrencyList, opm_ListBox_CurrencyCurrs.ItemIndex, opmC_FindByIndex);
0271:         IF ((CurCurr.ID >= 0) AND (CurCurr.Default = FALSE)) THEN
0272:           BEGIN
0273:               IF ((opmG_UIConfirmMods = 0) OR ((opmG_UIConfirmMods > 0) AND (FNopm_Message (_('Are you sure you want to set this currency as the default?'),
0274:                                                                                             mtConfirmation, [mbYes, mbNo], opmG_UISilent) = mrYes))) THEN
0275:                 BEGIN
0276:                   opm_Form_Main.PRopm_SetDefault_Currency (CurCurr.Code);
0277:                   PRopm_Reload_CurrList;
0278:                 END;
0279:           END;
0280:       END;
0281:   end;
0282:   
0283:   end.
 
 
NA fum/lmd: 2007.07.15
Copyright ©1994-2024 by Mario A. Valdez-Ramírez.
no siga este enlace / do not follow this link