Java Code Examples for org.litepal.crud.DataSupport#find()

The following examples show how to use org.litepal.crud.DataSupport#find() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddItemActivity.java    From Ucount with GNU General Public License v3.0 5 votes vote down vote up
public void putItemInData(double money) {
    IOItem ioItem = new IOItem();
    BookItem bookItem = DataSupport.find(BookItem.class, GlobalVariables.getmBookId());
    String tagName = (String) bannerText.getTag();
    int tagType = (int) bannerImage.getTag();

    if (tagType < 0) {
        ioItem.setType(ioItem.TYPE_COST);
    } else ioItem.setType(ioItem.TYPE_EARN);

    ioItem.setName(bannerText.getText().toString());
    ioItem.setSrcName(tagName);
    ioItem.setMoney(money);
    ioItem.setTimeStamp(formatItem.format(new Date()));         // 存储记账时间
    ioItem.setDescription(GlobalVariables.getmDescription());
    ioItem.setBookId(GlobalVariables.getmBookId());
    ioItem.save();

    // 将收支存储在对应账本下
    bookItem.getIoItemList().add(ioItem);
    bookItem.setSumAll(bookItem.getSumAll() + money*ioItem.getType());
    bookItem.save();

    calculateMonthlyMoney(bookItem, ioItem.getType(), ioItem);

    // 存储完之后及时清空备注
    GlobalVariables.setmDescription("");
}
 
Example 2
Source File: IOItemAdapter.java    From Ucount with GNU General Public License v3.0 5 votes vote down vote up
public void removeItem(int position) {
    IOItem ioItem = mIOItemList.get(position);
    BookItem bookItem = DataSupport.find(BookItem.class, GlobalVariables.getmBookId());
    int type = ioItem.getType();
    bookItem.setSumAll(bookItem.getSumAll() - ioItem.getMoney()*type);
    // 判断收支类型
    if (type < 0) bookItem.setSumMonthlyCost(bookItem.getSumMonthlyCost() - ioItem.getMoney());
    else bookItem.setSumMonthlyEarn(bookItem.getSumMonthlyEarn() - ioItem.getMoney());
    bookItem.save();
    DataSupport.delete(IOItem.class, mIOItemList.get(position).getId());

    mIOItemList.remove(position);
    notifyItemRemoved(position);
}
 
Example 3
Source File: MainActivity.java    From Ucount with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume() {
    super.onResume();

    initBookItemList(this);
    initIoItemList(this);

    showBtn.setText("显示余额");

    BookItem tmp = DataSupport.find(BookItem.class, bookItemList.get(GlobalVariables.getmBookPos()).getId());
    monthlyCost.setText(decimalFormat.format(tmp.getSumMonthlyCost()));
    monthlyEarn.setText(decimalFormat.format(tmp.getSumMonthlyEarn()));
}
 
Example 4
Source File: BookItem.java    From Ucount with GNU General Public License v3.0 4 votes vote down vote up
public boolean isThereABook(int id) {
    if (DataSupport.find(BookItem.class, id) == null)
        return false;
    return true;
}