首页 > SAP > HANA > SMP3.0学习笔记之五 使用OData Native SDK修改数据
2019
08-27

SMP3.0学习笔记之五 使用OData Native SDK修改数据

获取到航班信息之后,如果有满意的航班就需要预定了。于是增加如下界面进行航班的预定:

<img src="/oldimg/50/https://www.ut163.com/wp-content/uploads/2019/08/20190827124503-12.jpg" alt="SMP3.0学习笔记之五使用ODataNativeSDK修改数据” />

点击“Book”按钮后会使用OData SDK创建POST操作所需要的对象,然后向SMP暴露的OData服务发起POST操作:

public void Book(View v)

{
this.bookFlight();

}
private void bookFlight()
{
IODataEntry newBookingEntry =
new ODataEntry();
newBookingEntry.putPropertyValue(ConnectivityConstants.AIRLINE_ID,
mAirlineID);
newBookingEntry.putPropertyValue(ConnectivityConstants.CONNECTION_ID,
mConnectionID);
newBookingEntry.putPropertyValue(ConnectivityConstants.FLIGHT_DATE,
Utils.formatDate(mFlightDate, mApplication.useJSONFormat()));
newBookingEntry.putPropertyValue(ConnectivityConstants.CUSTOMER_ID,
ConnectivityConstants.DEFAULT_CUSTOMER_ID);
newBookingEntry.putPropertyValue(ConnectivityConstants.AGENCY_ID,
ConnectivityConstants.DEFAUL_AGENCY_ID);

newBookingEntry.putPropertyValue(ConnectivityConstants.BOOKING_DATE,
Utils.formatDate(new Date(), mApplication.useJSONFormat()));

try
{
IRequest
request = RequestBuilderHelper.getInstance().buildPOSTRequest(this,
ConnectivityConstants.BOOKING_COLLECTION, newBookingEntry,
BOOKING_REQUEST_TAG);
mApplication.getRequestManager().makeRequest(request);

}
catch(Exception e)
{
e.printStackTrace();

}

}

一旦调用成功,会触发onSuccess方法:

@Override
public void onSuccess(IRequest aRequest,
IResponse aResponse) {
final IResponse response =
aResponse;
mMessages = new
ArrayList();
mCurrentRequestTag =
aRequest.getRequestTAG();
if
(aRequest.getRequestTAG().equalsIgnoreCase(BOOKING_REQUEST_TAG))
{
try
{

HttpEntity
responseEntity = response.getEntity();
String
responseString =
EntityUtils.toString(responseEntity);

Parser
parser = mApplication.getParser();
mBookingEntries
= parser.parseODataEntries(responseString,
ConnectivityConstants.FLIGHT_COLLECTION,
mApplication.getODataSchema());
showText();

} catch
(Exception e) {
e.printStackTrace();

}
}

}

onSuccess该方法的最后会给出会调用showText()方法,给用户提示预定机票成功,如下图所示:

<img src="/oldimg/50/https://www.ut163.com/wp-content/uploads/2019/08/20190827124503-60.jpg" alt="SMP3.0学习笔记之五使用ODataNativeSDK修改数据” />

showText()方法代码:
private void showText()
{
Message msg =
new
Message();

mHandler.sendMessage(msg);

}

private
Handler mHandler = new Handler()

{

public void handleMessage(Message msg)

{

if (mBookingEntries != null)

{

String bookingID =
mBookingEntries.get(0).getPropertyValu(ConnectivityConstants.BOOKING_ID);

Toast.makeText(getApplicationContext(), “Book Flight Successfully,
BookingID:” + bookingID, Toast.LENGTH_LONG).show();

}

};

};

最后编辑:
作者:yangsen
本站为个人博客网站,全由我个人维护,我从事SAP开发13年,其它ERP开发7年,基本都是零售行业。本站记录工作学习的过程, 有SAP相关询问专、兼职工作可随时联系我。 有网站相关的问题可直接在文章下方留言,或者联系我。 邮件:yan252@163.com给我。 QQ:415402519

留下一个回复

你的email不会被公开。

1 × 1 =