public boolean deleteAll() { boolean flag = false; String deleteHeadSql = "DELETE FROM ProductGroupHead"; String deleteDetailSql = "DELETE FROM ProductGroupDetail"; SQLiteDatabase db = AssetsDatabaseManager.getManager().getDatabase(); try { // 开启事务 db.beginTransaction(); SQLiteStatement detail_stat = db.compileStatement(deleteDetailSql); detail_stat.executeUpdateDelete(); SQLiteStatement head_stat = db.compileStatement(deleteHeadSql); head_stat.executeUpdateDelete(); // 数据插入成功,设置事物成功标志 db.setTransactionSuccessful(); // 保存数据 db.endTransaction(); flag = true; } catch (SQLException e) { // 结束事物,在这里没有设置成功标志,结束后不保存 ZillionLog.e(this.getClass().getName(), e.getMessage(), e); db.endTransaction(); e.printStackTrace(); } return flag; }
/** * 批量增加产品组合主表记录数据 * * @param list */ public boolean batchAddProductGroupHead(List<ProductGroupHeadData> list) { boolean flag = false; String headSql = "insert into ProductGroupHead(PG1_ID,PG1_M02_ID,PG1_CU1_ID,PG1_CODE,PG1_Name,PG1_CreateUser,PG1_CreateTime,PG1_ModifyUser,PG1_ModifyTime,PG1_RowVersion)" + "values(?,?,?,?,?,?,?,?,?,?)"; String detailSql = "insert into ProductGroupDetail(PG2_ID,PG2_M02_ID,PG2_PG1_ID,PG2_PD1_ID,PG2_GroupQty,PG2_CreateUser,PG2_CreateTime,PG2_ModifyUser,PG2_ModifyTime,PG2_RowVersion)" + "values(?,?,?,?,?,?,?,?,?,?)"; SQLiteDatabase db = AssetsDatabaseManager.getManager().getDatabase(); try { // 开启事务 db.beginTransaction(); for (ProductGroupHeadData productGroupHead : list) { SQLiteStatement stat = db.compileStatement(headSql); stat.bindString(1, productGroupHead.getPg1Id()); stat.bindString(2, productGroupHead.getPg1M02Id()); stat.bindString(3, productGroupHead.getPg1Cu1Id()); stat.bindString(4, productGroupHead.getPg1Code()); stat.bindString(5, productGroupHead.getPg1Name()); stat.bindString(6, productGroupHead.getPg1CreateUser()); stat.bindString(7, productGroupHead.getPg1CreateTime()); stat.bindString(8, productGroupHead.getPg1ModifyUser()); stat.bindString(9, productGroupHead.getPg1ModifyTime()); stat.bindString(10, productGroupHead.getPg1RowVersion()); stat.executeInsert(); List<ProductGroupDetailData> children = productGroupHead.getChildren(); if (children != null) { for (ProductGroupDetailData productGroupDetail : children) { SQLiteStatement detail_stat = db.compileStatement(detailSql); detail_stat.bindString(1, productGroupDetail.getPg2Id()); detail_stat.bindString(2, productGroupDetail.getPg2M02Id()); detail_stat.bindString(3, productGroupDetail.getPg2Pg1Id()); detail_stat.bindString(4, productGroupDetail.getPg2Pd1Id()); detail_stat.bindLong(5, productGroupDetail.getPg2GroupQty()); detail_stat.bindString(6, productGroupDetail.getPg2CreateUser()); detail_stat.bindString(7, productGroupDetail.getPg2CreateTime()); detail_stat.bindString(8, productGroupDetail.getPg2ModifyUser()); detail_stat.bindString(9, productGroupDetail.getPg2ModifyTime()); detail_stat.bindString(10, productGroupDetail.getPg2RowVersion()); detail_stat.executeInsert(); } } } // 数据插入成功,设置事物成功标志 db.setTransactionSuccessful(); // 保存数据 db.endTransaction(); flag = true; } catch (SQLException e) { // 结束事物,在这里没有设置成功标志,结束后不保存 ZillionLog.e(this.getClass().getName(), e.getMessage(), e); db.endTransaction(); e.printStackTrace(); } return flag; }
/** * 网络请求 * * @param json * @param requestURL */ public void requestInitData(String optType, String requestURL, String vendingCode) { JSONObject json = new JSONObject(); try { json.put("VD1_CODE", vendingCode); DataParseHelper helper = new DataParseHelper(this); helper.requestSubmitServer(optType, json, requestURL); } catch (Exception e) { e.printStackTrace(); ZillionLog.e(this.getClass().toString(), "======>>>>>初始化请求验证网络请求数据异常!"); } }