{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 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 currencyedit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Spin, Buttons, oscpmdata; type Topm_Form_CurrencyEdit = class(TForm) opm_Label_CurrencyName: TLabel; opm_Edit_CurrencyName: TEdit; opm_Label_CurrencyCode: TLabel; opm_Label_CurrencyLSymbol: TLabel; opm_Edit_CurrencyLSymbol: TEdit; opm_Label_CurrencyRSymbol: TLabel; opm_Edit_CurrencyRSymbol: TEdit; opm_Edit_CurrencyDecimalP: TEdit; opm_Label_CurrencyDecimalP: TLabel; opm_Label_CurrencyThousandP: TLabel; opm_Edit_CurrencyThousandP: TEdit; opm_SpinEdit_CurrencyPrecision: TSpinEdit; opm_Label_CurrencyPrecision: TLabel; opm_Edit_CurrencyValue: TEdit; opm_Label_CurrencyValue: TLabel; opm_BitBtn_CurrencyOk: TBitBtn; opm_BitBtn_CurrencyCancel: TBitBtn; opm_Edit_CurrencyExample: TEdit; opm_ComboBox_CurrencyCode: TComboBox; procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); procedure opm_BitBtn_CurrencyOkClick(Sender: TObject); procedure opm_Edit_CurrencyLSymbolExit(Sender: TObject); procedure opm_SpinEdit_CurrencyPrecisionChange(Sender: TObject); procedure opm_ComboBox_CurrencyCodeExit(Sender: TObject); private PROCEDURE PRopm_Update_CurrExample; public CU_AddEdit : BOOLEAN; CU_Currency : opmR_Currency; end; CONST opm_Currency_Example = '149-999-999=999999999'; var opm_Form_CurrencyEdit: Topm_Form_CurrencyEdit; opm_Currency_ISOCodes : STRING; implementation {$R *.dfm} USES gnugettext, dataman, attention; {$R iso4217_codes.RES} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyEdit.FormCreate(Sender: TObject); begin CU_AddEdit := FALSE; CU_Currency.ID := -1; opm_Edit_CurrencyName.MaxLength := opmC_CurrName_MaxLen; opm_ComboBox_CurrencyCode.MaxLength := opmC_CurrCode_MaxLen; opm_Edit_CurrencyLSymbol.MaxLength := opmC_CurrLSymbol_MaxLen; opm_Edit_CurrencyRSymbol.MaxLength := opmC_CurrRSymbol_MaxLen; opm_Edit_CurrencyDecimalP.MaxLength := opmC_CurrDecSep_MaxLen; opm_Edit_CurrencyThousandP.MaxLength := opmC_CurrThoSep_MaxLen; opm_SpinEdit_CurrencyPrecision.MinValue := opmC_CurrPrecision_Min; opm_SpinEdit_CurrencyPrecision.MaxValue := opmC_CurrPrecision_Max; opm_Edit_CurrencyValue.MaxLength := opmC_CurrValue_MaxLen; opm_Edit_CurrencyExample.BorderStyle := bsNone; opm_Currency_ISOCodes := FNopm_StringFromResource ('iso4217_codes'); opm_ComboBox_CurrencyCode.Items.Text := opm_Currency_ISOCodes; TranslateComponent (self); end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyEdit.FormShow(Sender: TObject); begin IF (CU_AddEdit = TRUE) THEN BEGIN opm_Form_CurrencyEdit.Caption := _('Currency configuration'); CU_Currency.ID := -1; opm_Edit_CurrencyName.Text := ''; opm_ComboBox_CurrencyCode.Text := opmC_Def_CurrCode; opm_Edit_CurrencyLSymbol.Text := opmC_Def_CurrLSymbol; opm_Edit_CurrencyRSymbol.Text := opmC_Def_CurrRSymbol; opm_Edit_CurrencyDecimalP.Text := opmC_Def_CurrDecSep; opm_Edit_CurrencyThousandP.Text := opmC_Def_CurrThoSep; opm_SpinEdit_CurrencyPrecision.Value := opmC_Def_CurrPrecision; opm_Edit_CurrencyValue.Text := INTTOSTR (opmC_Def_CurrValue); END ELSE BEGIN opm_Form_CurrencyEdit.Caption := _('Currency configuration') + ' (' + INTTOSTR (CU_Currency.ID) + ' - ' + CU_Currency.Name + ', ' + CU_Currency.Code + ')'; opm_Edit_CurrencyName.Text := CU_Currency.Name; opm_ComboBox_CurrencyCode.Text := CU_Currency.Code; opm_Edit_CurrencyLSymbol.Text := CU_Currency.Left; opm_Edit_CurrencyRSymbol.Text := CU_Currency.Right; opm_Edit_CurrencyDecimalP.Text := CU_Currency.DecimalSep; opm_Edit_CurrencyThousandP.Text := CU_Currency.ThousandSep; opm_SpinEdit_CurrencyPrecision.Value := CU_Currency.Precision; opm_Edit_CurrencyValue.Text := CURRTOSTR (CU_Currency.Value); END; PRopm_Update_CurrExample; end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyEdit.opm_BitBtn_CurrencyOkClick(Sender: TObject); begin CU_Currency.Name := FNopm_CleanString (opm_Edit_CurrencyName.Text); CU_Currency.Code := ANSIUPPERCASE (FNopm_CleanString (opm_ComboBox_CurrencyCode.Text)); CU_Currency.Left := FNopm_CleanString (opm_Edit_CurrencyLSymbol.Text); CU_Currency.Right := FNopm_CleanString (opm_Edit_CurrencyRSymbol.Text); CU_Currency.DecimalSep := FNopm_CleanString (opm_Edit_CurrencyDecimalP.Text); CU_Currency.ThousandSep := FNopm_CleanString (opm_Edit_CurrencyThousandP.Text); CU_Currency.Precision := ABS (opm_SpinEdit_CurrencyPrecision.Value); CU_Currency.Value := ABS (STRTOCURR (FNopm_CleanNumber (opm_Edit_CurrencyValue.Text, opmC_ValIsCurrency))); IF (CU_Currency.Value = 0) THEN BEGIN opm_Edit_CurrencyValue.Text := CURRTOSTR (CU_Currency.Value); opm_Form_CurrencyEdit.FocusControl (opm_Edit_CurrencyValue); FNopm_Message (_('The currency value cannot be zero.'), mtWarning, [mbOk], opmG_UISilent); ModalResult := mrNone; END ELSE IF (CU_Currency.Name = '') THEN BEGIN opm_Edit_CurrencyName.Text := CU_Currency.Name; opm_Form_CurrencyEdit.FocusControl (opm_Edit_CurrencyName); FNopm_Message (_('The currency name cannot be empty.'), mtWarning, [mbOk], opmG_UISilent); ModalResult := mrNone; END ELSE IF (CU_Currency.Code = '') THEN BEGIN opm_ComboBox_CurrencyCode.Text := CU_Currency.Code; opm_Form_CurrencyEdit.FocusControl (opm_ComboBox_CurrencyCode); FNopm_Message (_('The currency code cannot be empty.'), mtWarning, [mbOk], opmG_UISilent); ModalResult := mrNone; END ELSE ModalResult := mrOk; end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} PROCEDURE Topm_Form_CurrencyEdit.PRopm_Update_CurrExample; VAR ExampleStr : STRING; IntPart, DecPart : STRING; BEGIN ExampleStr := opm_Currency_Example; IntPart := COPY (ExampleStr, 1, (ANSIPOS ('=', ExampleStr) - 1)); IntPart := COPY (IntPart, 1, LENGTH (ExampleStr)); DecPart := COPY (ExampleStr, (ANSIPOS ('=', ExampleStr) + 1), opm_SpinEdit_CurrencyPrecision.Value); ExampleStr := IntPart + '=' + DecPart; ExampleStr := STRINGREPLACE (ExampleStr, '-', opm_Edit_CurrencyThousandP.Text, [rfReplaceAll]); ExampleStr := STRINGREPLACE (ExampleStr, '=', opm_Edit_CurrencyDecimalP.Text, []); opm_Edit_CurrencyExample.Text := opm_Edit_CurrencyLSymbol.Text + ' ' + ExampleStr + ' ' + opm_Edit_CurrencyRSymbol.Text; END; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyEdit.opm_Edit_CurrencyLSymbolExit(Sender: TObject); begin PRopm_Update_CurrExample; end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyEdit.opm_SpinEdit_CurrencyPrecisionChange(Sender: TObject); begin PRopm_Update_CurrExample; end; {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%} procedure Topm_Form_CurrencyEdit.opm_ComboBox_CurrencyCodeExit(Sender: TObject); begin opm_ComboBox_CurrencyCode.Text := COPY (opm_ComboBox_CurrencyCode.Text, 1, 3); end; end.