public boolean isThereABook(int id) { if (DataSupport.find(BookItem.class, id) == null) return false; return true; }
private boolean isSavePage(int pageNo) { return DataSupport.find(MyPage.class, pageNo) != null; }
/** * Finds the record by a specific id. * * <pre> * Person p = DataSupport.find(Person.class, 1); * </pre> * * The modelClass determines which table to query and the object type to * return. If no record can be found, then return null. <br> * * Note that the associated models won't be loaded by default considering * the efficiency, but you can do that by using * {@link org.litepal.crud.DataSupport#find(Class, long, boolean)}. * * @param modelClass * Which table to query and the object type to return. * @param id * Which record to query. * @return An object with found data from database, or null. */ public static synchronized <T> T find(Class<T> modelClass, long id) { return find(modelClass, id, false); }
public static List<TimetableModel> getAllWithScheduleId(int id) { Log.d(TAG, "getAllWithScheduleId: "+id); ScheduleName scheduleName = DataSupport.find(ScheduleName.class, id); if(scheduleName==null) return null; return scheduleName.getModels(); }
private int getStartPosition(int pageNo) { if (pageNo < 1) { return 0; } if (isSavePage(pageNo)) { return DataSupport.find(MyPage.class, pageNo).getStartPosition(); } return 0; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { if (getArguments().containsKey(ARG_BOOK_ID)) { book = DataSupport.find(Book.class, getArguments().getInt(ARG_BOOK_ID)); } else if (getArguments().containsKey(ARG_BOOK)) { book = (Book) getArguments().getSerializable(ARG_BOOK); } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { if (getArguments().containsKey(ARG_BOOK_ID)) { book = DataSupport.find(Book.class, getArguments().getInt(ARG_BOOK_ID)); } else if (getArguments().containsKey(ARG_BOOK)) { book = (Book) getArguments().getSerializable(ARG_BOOK); } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { if (getArguments().containsKey(ARG_BOOK_ID)) { book = DataSupport.find(Book.class, getArguments().getInt(ARG_BOOK_ID)); } else if (getArguments().containsKey(ARG_BOOK)) { book = (Book) getArguments().getSerializable(ARG_BOOK); } } }
@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())); }
public void loadData() { // 图书数据 Book book = DataSupport.find(Book.class, booId); String note = book.getNote(); String note_date = book.getNote_date(); if (note.isEmpty()) { note = "\n暂无笔记,点击右上角的按钮开始写笔记吧!\n"; } tvContent.setText(note); if (note_date.isEmpty()) { ivIconDate.setAlpha(0f); tvContent.setGravity(Gravity.CENTER); } else { ivIconDate.setAlpha(1f); tvContent.setGravity(Gravity.NO_GRAVITY); } tvDate.setText(note_date); }
@OnClick(R.id.cv_save) public void save() { String name = nameEdit.getText().toString(); if (TextUtils.isEmpty(name)) { Toasty.warning(this, "课表名称不可为空", Toast.LENGTH_SHORT).show(); } else if (name.equals("默认课表")) { Toasty.error(this, "名称不合法").show(); } else { ScheduleName scheduleName = DataSupport.find(ScheduleName.class, id); if (scheduleName != null) { scheduleName.setName(name); scheduleName.update(scheduleName.getId()); Toasty.success(this, "修课表成功", Toast.LENGTH_SHORT).show(); goBack(); } else { Toasty.error(this, "修改课表失败", Toast.LENGTH_SHORT).show(); } } }
case R.id.show_money_button: if (showBtn.getText() == "显示余额") { BookItem tmp = DataSupport.find(BookItem.class, GlobalVariables.getmBookId());
TimetableModel thisModel=DataSupport.find(TimetableModel.class,id); thisModel.setName(name); thisModel.setTeacher(teacher);
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_book_note_edit); // Context context = this; // 返回按钮 ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } // 图书ID int itemId = getIntent().getIntExtra("id", -1); // 图书Obj book = DataSupport.find(Book.class, itemId); // Activity标题 setTitle("编辑笔记"); // 笔记输入框 etNote = (EditText) findViewById(R.id.et_note); // 显示笔记内容 etNote.setText(book.getNote()); }
public void delete(Schedule schedule) { if (schedule != null) { int id = (int) schedule.getExtras().get(TimetableModel.EXTRA_ID); TimetableModel model = DataSupport.find(TimetableModel.class, id); if (model != null) { model.delete(); ScheduleDao.changeFuncStatus(this,true); ShareTools.put(this, "course_update", 1); Toasty.success(this, "删除成功!").show(); ScheduleDao.changeStatus(this,true); BroadcastUtils.refreshAppWidget(this); goBack(); } } }
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); }
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(""); }
private void adjustAndGetData() { int id = ScheduleDao.getApplyScheduleId(context); ScheduleName scheduleName = DataSupport.where("name=?", "默认课表").findFirst(ScheduleName.class); if (scheduleName == null) { scheduleName = new ScheduleName(); scheduleName.setName("默认课表"); scheduleName.setTime(System.currentTimeMillis()); scheduleName.save(); id = scheduleName.getId(); ShareTools.put(context, ShareConstants.INT_SCHEDULE_NAME_ID, id); } if(scheduleName==null) return; ScheduleName newName = DataSupport.find(ScheduleName.class, id); if(newName==null) return; FindMultiExecutor executor=newName.getModelsAsync(); executor.listen(new FindMultiCallback() { @Override public <T> void onFinish(List<T> t) { List<TimetableModel> dataModels = (List<TimetableModel>) t; if (dataModels != null) { mTimetableView.data(ScheduleSupport.transform(dataModels)).updateView(); mWeekView.data(ScheduleSupport.transform(dataModels)).showView(); } } }); }
ScheduleName newName = DataSupport.find(ScheduleName.class, ScheduleDao.getApplyScheduleId(getActivity())); if(newName==null) return; mCurScheduleTextView.setText(newName.getName());
ActivityTools.toBackActivityAnim(this,MultiScheduleActivity.class); }else{ ScheduleName newName=DataSupport.find(ScheduleName.class,scheduleNameId); FindMultiExecutor executor=newName.getModelsAsync(); executor.listen(new FindMultiCallback() {