📄 webservice1.pas.~1~
字号:
unit WebService1;
interface
uses
System.Collections, System.ComponentModel,
System.Data, System.Diagnostics, System.Web,
System.Web.Services, System.Data.SqlClient,
Borland.Vcl.SysUtils;
type
/// <summary>
/// Summary description for WebService1.
/// </summary>
TWebService1 = class(System.Web.Services.WebService)
{$REGION 'Designer Managed Code'}
strict private
/// <summary>
/// Required designer variable.
/// </summary>
components: IContainer;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure InitializeComponent;
{$ENDREGION}
strict protected
/// <summary>
/// Clean up any resources being used.
/// </summary>
procedure Dispose(disposing: boolean); override;
private
{ Private Declarations }
public
constructor Create;
(*
// Sample Web Service Method
[WebMethod]
function HelloWorld: string;
*)
[WebMethod]
function ContractInfo(Contract: String) : string;
[WebMethod]
function MonthlyPay(Money:integer; Period:integer; Rate:single):string;
end;
implementation
{$REGION 'Designer Managed Code'}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWebService1.InitializeComponent;
begin
end;
{$ENDREGION}
constructor TWebService1.Create;
begin
inherited;
//
// Required for Windows Form Designer support
InitializeComponent;
// TODO: Add any constructor code after InitializeComponent call
//
end;
/// <summary>
/// Clean up any resources being used.
/// </summary>
procedure TWebService1.Dispose(disposing: boolean);
begin
if disposing and (components <> nil) then
components.Dispose;
inherited Dispose(disposing);
end;
// Sample Web Service Method
// The following method is provided to allow for testing a new web service.
(*
[WebMethod]
function TWebService1.HelloWorld: string;
begin
Result := 'Hello World';
end;
*)
[WebMethod]
function TWebService1.ContractInfo(Contract: string) : string;
var
strSql :string;
Conn1: SqlConnection;
MyDataAdapter: SqlDataAdapter;
ResultStr: string;
MyDataSet : DataSet;
MyDataRow : DataRow;
begin
MyDataSet := DataSet.Create;
try
Conn1 :=SqlConnection.Create('server=localhost; uid= sa;pwd=; database=LoanContract');
strSql := 'select * from ContractInfo Where ContractNo = ''' + Contract+'''';
MyDataAdapter := SqlDataAdapter.Create(strSql,Conn1);
MyDataAdapter.Fill(MyDataSet,'ContractInfo');
MyDataRow := MyDataset.Tables[0].Rows[0];
ResultStr:= '合同号:'+ MyDataRow.Item['ContractNo'].ToString +',';
ResultStr := ResultStr + '借款人:'+ MyDataRow.Item['Debit'].ToString+',';
ResultStr := ResultStr + '贷款人:'+ MyDataRow.Item['Credit'].ToString+',';
ResultStr := ResultStr + '贷款金额:'+ MyDataRow.Item['Money'].ToString+',';
ResultStr := ResultStr + '贷款年限:'+ MyDataRow.Item['Period'].ToString+',';
ResultStr := ResultStr + '年利率:'+ MyDataRow.Item['Rate'].ToString+',';
ResultStr := ResultStr + '月还贷款:'+ MyDataRow.Item['MonthlyPay'].ToString+',';
ResultStr := ResultStr + '担保方式:'+ MyDataRow.Item['Mortgage'].ToString;
Result := ResultStr;
Except
On E: Exception do
Result:= E.Message;
end;
end;
[WebMethod]
function TWebService1.MonthlyPay(Money:integer; Period:integer; Rate:single):string;
var
Annuity : Single;
Months : Integer;
mRate : Single;
CIF : Single;
i:integer;
begin
Months := Period*12;
mRate := Rate/1200;
CIF := 1;
for i:= 1 to Months do
CIF:= CIF*(1+mRate) ;
Annuity := mRate*CIF* Money/(CIF-1);
Result := format('%8.2f', [Annuity]);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -