在上一篇文章中,使用了 OleVariant;
本文將介紹使用JSON方式來傳遞。。。
經測試在 windows下、Android 下都沒有問題。。蘋果則未測試。。。
服務端:
function TServerMethods1.CheckUsernameAndPassword3(U, P: string): TJSONObject;
var
JO:TJSONObject;
UserInfo :TLoginUserInfo;
begin
UserInfo.LoginState := 255 ; //Defautl: Unknown error
UserInfo.IsSuperUser := false;
UserInfo.UserCode := '';
UserInfo.UserCode := '';
UserInfo.UserName := '';
UserInfo.Password := '';
UserInfo.Deportment := '';
UserInfo.MachineCode := ''; //設備編號
UserInfo.AutoPromptMsg :='';
UserInfo.UserClass :=0 ;
UserInfo.ProductionWorkShop :='' ;
with QRY do begin
Close;
SQL.Text :=''; //略過
Open;
if not IsEmpty then begin
if P <> FieldByName('MM').AsString then begin
UserInfo.LoginState :=1;
end else
if FieldByName('SFJY').AsBoolean then begin
UserInfo.LoginState :=3;
end else begin
UserInfo.LoginState :=0;
UserInfo.IsSuperUser := FieldByName('CJYH').AsBoolean;
UserInfo.UserCode := U;
UserInfo.UserCode := FieldByName('XH').AsString;
UserInfo.UserName := FieldByName('MC').AsString;
UserInfo.Password := FieldByName('MM').AsString;
UserInfo.Deportment := FieldByName('BMBH').AsString;
UserInfo.MachineCode := FieldByName('SBBH').AsString; //設備編號
UserInfo.AutoPromptMsg :='';
UserInfo.UserClass :=FieldByName('jtsclx').AsInteger ;
UserInfo.ProductionWorkShop :=FieldByName('SCCJ').AsString ;
end;
end else UserInfo.LoginState :=2;
Close;
//讀是否是驗廠
SQL.Text :=<span style="font-family: Arial, Helvetica, sans-serif;">''; //略過</span>
Open;
UserInfo.FactoryEvaluation := FieldByName('FE').AsBoolean;
Close;
end;
JO:=TJSONObject.Create;
JO.AddPair('LoginState',TJSONNumber.Create(UserInfo.LoginState));
if UserInfo.IsSuperUser then
JO.AddPair('IsSuperUser',TJSONTrue.Create)
else
JO.AddPair('IsSuperUser',TJSONFalse.Create);
JO.AddPair('UserCode',TJSONString.Create(UserInfo.UserCode));
JO.AddPair('UserName',TJSONString.Create(UserInfo.UserName));
JO.AddPair('Password',TJSONString.Create(UserInfo.Password));
JO.AddPair('Deportment',TJSONString.Create(UserInfo.Deportment));
JO.AddPair('MachineCode',TJSONString.Create(UserInfo.MachineCode));
JO.AddPair('AutoPromptMsg',TJSONString.Create(UserInfo.AutoPromptMsg));
JO.AddPair('ProductionWorkShop',TJSONString.Create(UserInfo.ProductionWorkShop) );
JO.AddPair('UserClass',TJSONNumber.Create(UserInfo.UserClass));
Result := JO;
客戶端:
function Tdm.PubF_CheckLoginUsername3(U, P: string): TLoginUserInfo;
var
JO:TJSONObject;
begin
JO := dm.CheckUsernameAndPassword3(U,P);
Result.LoginState := StrToIntDef(JO.GetValue('LoginState').Value,255) ;
Result.IsSuperUser := JO.GetValue('IsSuperUser').Value='True' ;
Result.UserCode := JO.GetValue('UserCode').Value ;
Result.UserName := JO.GetValue('UserName').Value ;
Result.Password := JO.GetValue('Password').Value ;
Result.Deportment := JO.GetValue('Deportment').Value ;
Result.MachineCode := JO.GetValue('MachineCode').Value ;
Result.AutoPromptMsg := JO.GetValue('AutoPromptMsg').Value ;
Result.ProductionWorkShop := JO.GetValue('ProductionWorkShop').Value ;
Result.UserClass := StrToIntDef(JO.GetValue('UserClass').Value,0);
end;
|