标签:
近几天公司交给我一个任务,就是讲公司一个app中的某个功能模块的数据存储方式由sharePreference转为sqlite存储。我已开始就是通过最基础的方式来做的,即这样:
package com.mesada.financing.dbutils; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; public class FinancingDbHelper extends SQLiteOpenHelper { // 表名 public static final String TABLE_NAME = "financing"; // 用于标识是哪个申请的融资信息的字段 public static final String CLIENTID = "clientId"; // 方案类型 public static final String PRE_TYPE_ID = "type_id"; public static final String PRE_TYPE = "type_name"; // 方案名称 public static final String PRE_PLAN_ID = "plan_id"; public static final String PRE_PLAN = "plan_name"; // 指导价 public static final String PRE_GUIDE_PRICE = "guideprice"; // GPS硬件 public static final String PRE_GPS = "GPS"; // 制造商 public static final String PRE_MAN_ID = "man_id"; public static final String PRE_MAN = "man_name"; // 品牌 public static final String PRE_BRAND_ID = "brand_id"; public static final String PRE_BRAND = "brand_name"; // 车型 public static final String PRE_CAR_ID = "car_id"; public static final String PRE_CAR = "car_name"; // 车辆售价 public static final String PRE_PRICE = "price"; public final String PRE_SEAT = "seat"; public final String PRE_TONNAGE = "tonnage"; public final String PRE_DISPLACEMENT = "Displacement"; // 融资期限 public static final String PRE_FINANCING_LIMIT = "financing_limit"; // 抵押城市 public final String PRE_CITY = "city"; // 营运 public final String PRE_OPERATE = "operate"; // 融延保 public final String PRE_RONG_YAN_BAO = "rong_yan_bao"; // 融保险 public final String PRE_RONG_BAO_XIAN = "rong_bao_xian"; // 融安心宝 public final String PRE_RONG_ANXIN_BAO = "rong_anxin_bao"; // 安心宝 public static final String PRE_ANXIN_BAO = "anxin_bao"; // 三方责任限额 public final String PRE_RESPONSE_LIMIT = "responsibility_limit"; // 车上人员责任险(司机) public final String PRE_ZEREN_DRIVER = "zeren_insurance_driver"; // 车上人员责任险 (乘客) public final String PRE_ZEREN_PASSENGER = "zeren_insurance_passenger"; // 车上人员责任险不计免赔 public final String PRE_ZEREN_DEDUCTIBLE = "zeren_insurance_deductible"; // 车辆划伤险 public final String PRE_SCRATCH_INSURANCE = "scratch_insurance"; // 车辆划伤不计赔 public final String PRE_SCRATCH_DEDUCTIBLE = "scratch_insurance_deductible"; // 玻璃险 public final String PRE_GLASS_INSURANCE = "glass_insurance"; // 专修险 public final String PRE_REPAIR_INSURANCE = "repair_insurance"; // 购置税 public final String PRE_PURCHASE_TAX = "purchase_tax"; // 延保 public static final String PRE_EX_INSURANCE = "ex_insurance"; // 车船税 public final String PRE_TRAVEL_TAX = "travel_tax"; // 商业保险 public final String PRE_BUS_INSURANCE = "bus_insurance"; // 交强险 public final String PRE_COST_INSURANCE = "insurance_cost"; // 首付比例 public final String PRE_SHOUFU = "shoufu"; // 首付金额 public final String PRE_SHOWFU_MONEY = "shoufu_money"; // 首付比例逻辑 public final String PRE_SHOWFU_LOGIC = "shoufu_logic"; // 尾付比例 public final String PRE_WEIFU = "weifu"; // 尾付金额 public final String PRE_WEIFU_MONEY = "weifu_money"; // 尾付比例逻辑 public final String PRE_WEIFU_LOGIC = "weifu_logic"; // 融资金额 public final String PRE_FINANCING_MONEY = "financing_money"; // 手续是否分期 public final String PRE_STAGING = "staging"; // 手续费率 public final String PRE_RATE = "rate"; // 手续费 public final String PRE_PROCEDURE = "procedure_money"; // 保证金率 public final String PRE_MARGIN = "margin"; // 保证金 public final String PRE_MARGIN_MONEY = "margin_money"; // 保证金比例逻辑 public final String PRE_MARGIN_LOGIC = "margin_logic"; // 投资总额 public final String PRE_TOTAL = "total"; // 销售经理 public final String PRE_SALES_MANAGER_ID = "sales_manager_id"; public static final String PRE_SALES_MANAGER = "sales_manager"; // 销售助理 public final String PRE_SALES_ASSISTANT_ID = "sales_assistant_id"; public static final String PRE_SALES_ASSISTANT = "sales_assistant"; // 开户银行 public static final String PRE_BANK = "bank"; // 开户姓名 public static final String PRE_NAME = "name"; // 银行账号 public static final String PRE_BANK_NUMBER = "bank_number"; // 征信是否后置 public static final String PRE_CREDIT = "credit"; // 备注 public static final String PRE_REMARKS = "remarks"; public static final String PRE_INSURANCE = "insurance"; public static final String PRE_LOADPLAN = "loadplan"; // 页标识 public static final String PRE_FRIST = "frist"; public static final String PRE_SECOND = "second"; public static final String PRE_THIRD = "third"; public static final String PRE_FOUTH = "fouth"; public static final String PRE_FIFTH = "fifth"; private static FinancingDbHelper financingDbHelper = null; private FinancingDbHelper(Context context) { super(context, "FinancingDb.db", null, 1); } public static FinancingDbHelper getIns(Context context) { if (financingDbHelper == null) { synchronized (FinancingDbHelper.class) { if (financingDbHelper == null) { financingDbHelper = new FinancingDbHelper(context); } } } return financingDbHelper; } @Override public void onCreate(SQLiteDatabase db) { // 建表 String sql_CreateTable = " create table if not exists " + TABLE_NAME + "(_id integer primary key autoincrement," + CLIENTID + " text," // 用于标识是哪个申请的融资信息的字段 // 方案类型 + PRE_TYPE_ID + " text," + PRE_TYPE + " text," // 方案名称 + PRE_PLAN_ID + " text," + PRE_PLAN + " text," + PRE_GUIDE_PRICE + " text,"// 指导价 + PRE_GPS + " text," // GPS硬件 // 制造商 + PRE_MAN_ID + " text," + PRE_MAN + " text," // 品牌 + PRE_BRAND_ID + " text," + PRE_BRAND + " text," // 车型 + PRE_CAR_ID + " text," + PRE_CAR + " text," // 车辆售价 + PRE_PRICE + " text," + PRE_SEAT + " text," + PRE_TONNAGE + " text," + PRE_DISPLACEMENT + " text," + PRE_FINANCING_LIMIT + " text," // 融资期限 + PRE_CITY + " text," // 抵押城市 + PRE_OPERATE + " text,"//只能写true或false 营运 + PRE_RONG_YAN_BAO + " text,"//只能写true或false 融延保 + PRE_RONG_BAO_XIAN + " text,"//只能写true或false 融保险 + PRE_RONG_ANXIN_BAO + " text,"//只能写true或false 融安心宝 + PRE_ANXIN_BAO + " text," // 安心宝 + PRE_RESPONSE_LIMIT + " text," // 三方责任限额 + PRE_ZEREN_DRIVER + " text," // 车上人员责任险(司机) + PRE_ZEREN_PASSENGER + " text," // 车上人员责任险 (乘客) + PRE_ZEREN_DEDUCTIBLE + " text," // 车上人员责任险不计免赔 + PRE_SCRATCH_INSURANCE + " text," // 车辆划伤险 + PRE_SCRATCH_DEDUCTIBLE + " text," // 车辆划伤不计赔 + PRE_GLASS_INSURANCE + " text," // 玻璃险 + PRE_REPAIR_INSURANCE + " text," // 专修险 + PRE_PURCHASE_TAX + " text," // 购置税 + PRE_EX_INSURANCE + " text," // 延保 + PRE_TRAVEL_TAX + " text," // 车船税 + PRE_BUS_INSURANCE + " text," // 商业保险 + PRE_COST_INSURANCE + " text," // 交强险 + PRE_SHOUFU + " text," // 首付比例 + PRE_SHOWFU_MONEY + " text," // 首付金额 + PRE_SHOWFU_LOGIC + " text," // 首付比例逻辑 + PRE_WEIFU + " text," // 尾付比例 + PRE_WEIFU_MONEY + " text," // 尾付金额 + PRE_WEIFU_LOGIC + " text," // 尾付比例逻辑 + PRE_FINANCING_MONEY + " text," // 融资金额 + PRE_STAGING + " text,"//只能写true或false 手续是否分期 + PRE_RATE + " text," // 手续费率 + PRE_PROCEDURE + " text," // 手续费 + PRE_MARGIN + " text," // 保证金率 + PRE_MARGIN_MONEY + " text," // 保证金 + PRE_MARGIN_LOGIC + " text," // 保证金比例逻辑 + PRE_TOTAL + " text," // 投资总额 // 销售经理 + PRE_SALES_MANAGER_ID + " text," + PRE_SALES_MANAGER + " text," // 销售助理 + PRE_SALES_ASSISTANT_ID + " text," + PRE_SALES_ASSISTANT + " text," + PRE_BANK + " text," // 开户银行 + PRE_NAME + " text," // 开户姓名 + PRE_BANK_NUMBER + " text," // 银行账号 + PRE_CREDIT + " text,"//只能写true或false 征信是否后置 + PRE_REMARKS + " text," // 备注 + PRE_INSURANCE + " text," + PRE_LOADPLAN + " text," // 页标识 + PRE_FRIST + " text,"//只能写true或false + PRE_SECOND + " text,"//只能写true或false + PRE_THIRD + " text,"//只能写true或false + PRE_FOUTH + " text,"//只能写true或false + PRE_FIFTH + " text"//只能写true或false + ")"; //执行sql语句,创建数据库表 db.execSQL(sql_CreateTable); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // 版本发生变化时更新数据库 db.delete(TABLE_NAME, null, null); onCreate(db); } }
然后在定义一个文件对表进行操作:
package com.mesada.financing.dbutils; import com.baidu.a.a.a.c; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; public class FinancingDbDao { FinancingDbHelper financingDbHelper; public FinancingDbDao(Context context) { // 生成FinancingDbHelper对象 this.financingDbHelper = FinancingDbHelper.getIns(context); } /** * 打开融资信息模块时首先向表中插入一条数据 * * @param clientId * 用于标识是哪个申请的融资信息的字段 */ public void insert(String clientId) { SQLiteDatabase db = financingDbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(FinancingDbHelper.CLIENTID, clientId); values.put(FinancingDbHelper.PRE_FRIST, "false"); values.put(FinancingDbHelper.PRE_SECOND, "false"); values.put(FinancingDbHelper.PRE_THIRD, "false"); values.put(FinancingDbHelper.PRE_FOUTH, "false"); values.put(FinancingDbHelper.PRE_FIFTH, "false"); values.put(FinancingDbHelper.PRE_TYPE_ID, "0"); values.put(FinancingDbHelper.PRE_TYPE, ""); values.put(FinancingDbHelper.PRE_PLAN_ID, "0"); values.put(FinancingDbHelper.PRE_PLAN, ""); values.put(FinancingDbHelper.PRE_MAN_ID, "0"); values.put(FinancingDbHelper.PRE_MAN, ""); values.put(FinancingDbHelper.PRE_BRAND_ID, "0"); values.put(FinancingDbHelper.PRE_BRAND, ""); values.put(FinancingDbHelper.PRE_CAR_ID, "0"); values.put(FinancingDbHelper.PRE_CAR, ""); values.put(FinancingDbHelper.PRE_GUIDE_PRICE, "0"); values.put(financingDbHelper.PRE_SEAT, "0"); values.put(financingDbHelper.PRE_TONNAGE, "0"); values.put(financingDbHelper.PRE_DISPLACEMENT, "0"); values.put(FinancingDbHelper.PRE_PRICE, "0"); values.put(FinancingDbHelper.PRE_GPS, "0"); values.put(FinancingDbHelper.PRE_FINANCING_LIMIT, ""); values.put(financingDbHelper.PRE_CITY, ""); values.put(financingDbHelper.PRE_OPERATE, "false"); values.put(financingDbHelper.PRE_RONG_YAN_BAO, "false"); values.put(financingDbHelper.PRE_RONG_BAO_XIAN, "true"); values.put(financingDbHelper.PRE_RONG_ANXIN_BAO, "true"); values.put(FinancingDbHelper.PRE_ANXIN_BAO, "0"); values.put(financingDbHelper.PRE_RESPONSE_LIMIT, "20"); values.put(financingDbHelper.PRE_ZEREN_DRIVER, "0"); values.put(financingDbHelper.PRE_ZEREN_PASSENGER, "0"); values.put(financingDbHelper.PRE_ZEREN_DEDUCTIBLE, "false"); values.put(financingDbHelper.PRE_SCRATCH_INSURANCE, "0"); values.put(financingDbHelper.PRE_SCRATCH_DEDUCTIBLE, "false"); values.put(financingDbHelper.PRE_GLASS_INSURANCE, "无"); values.put(financingDbHelper.PRE_REPAIR_INSURANCE, "false"); values.put(financingDbHelper.PRE_PURCHASE_TAX, "0"); values.put(FinancingDbHelper.PRE_EX_INSURANCE, "0"); values.put(financingDbHelper.PRE_TRAVEL_TAX, ""); values.put(financingDbHelper.PRE_BUS_INSURANCE, ""); values.put(financingDbHelper.PRE_COST_INSURANCE, ""); values.put(financingDbHelper.PRE_SHOUFU, "0"); values.put(financingDbHelper.PRE_SHOWFU_MONEY, "0"); values.put(financingDbHelper.PRE_SHOWFU_LOGIC, "0"); values.put(financingDbHelper.PRE_WEIFU, "0"); values.put(financingDbHelper.PRE_WEIFU_MONEY, "0"); values.put(financingDbHelper.PRE_WEIFU_LOGIC, "0"); values.put(financingDbHelper.PRE_FINANCING_MONEY, "0"); values.put(financingDbHelper.PRE_STAGING, "false"); values.put(financingDbHelper.PRE_RATE, "0"); values.put(financingDbHelper.PRE_PROCEDURE, "0"); values.put(financingDbHelper.PRE_MARGIN, ""); values.put(financingDbHelper.PRE_MARGIN_MONEY, "0"); values.put(financingDbHelper.PRE_MARGIN_LOGIC, "0"); values.put(financingDbHelper.PRE_SALES_MANAGER_ID, "0"); values.put(FinancingDbHelper.PRE_SALES_MANAGER, ""); values.put(financingDbHelper.PRE_SALES_ASSISTANT_ID, "0"); values.put(FinancingDbHelper.PRE_SALES_ASSISTANT, ""); values.put(FinancingDbHelper.PRE_BANK, ""); values.put(FinancingDbHelper.PRE_BANK_NUMBER, ""); values.put(FinancingDbHelper.PRE_CREDIT, "否"); values.put(FinancingDbHelper.PRE_REMARKS, ""); db.insert(FinancingDbHelper.TABLE_NAME, null, values); db.close(); } /** * @param clientId 用于标识是哪个申请的融资信息的字段 * @param column 要查询的字段 * @return 返回要查询的字段的值 */ public String query(String clientId, String column) { SQLiteDatabase db = financingDbHelper.getReadableDatabase(); Cursor cursor = db.query(FinancingDbHelper.TABLE_NAME, new String[] { column }, FinancingDbHelper.CLIENTID + "=?", new String[] { clientId }, null, null, null); String info=null; while (cursor.moveToNext()) { info=cursor.getString(0); } cursor.close(); db.close(); return info; } /** * 该方法用于更新数据库表中指定字段的值 * @param clientId 用于标识是哪个申请的融资信息的字段 * @param column 要保存的字段 * @param info 要保存的字段的值 */ public void update(String clientId, String column,String info){ SQLiteDatabase db=financingDbHelper.getWritableDatabase(); ContentValues values=new ContentValues(); values.put(column, info); db.update(FinancingDbHelper.TABLE_NAME, values, FinancingDbHelper.CLIENTID+"=?", new String[]{clientId}); db.close(); } /** * @param clientId 要重置的数据的标识 */ public void delete(String clientId) { SQLiteDatabase db=financingDbHelper.getWritableDatabase(); db.delete(FinancingDbHelper.TABLE_NAME, FinancingDbHelper.CLIENTID+"=?", new String[]{clientId}); db.close(); } }
但是后来完成后发现由于此功能对数据库表的操作比较频繁,这样的结果就是较耗时,不符合要求。
经过研究与查资料,发现xutils中的dbutils可以使序列化后的对象变成数据库表,取出来时也是对象,大家都知道对象的好处,因此我就决定使用dbutils。
首先,创建一个基础类,此类实现了serializable借口,如下:
package com.mesada.data.model; import java.io.Serializable; import com.lidroid.xutils.db.annotation.Column; import com.lidroid.xutils.db.annotation.Id; public class FinancingMsgModel implements Serializable { /** * */ private static final long serialVersionUID = -3866706611954627888L; @Id public int id; // 用于标识是哪个申请的融资信息的字段 @Column public String clientId; // 方案类型 @Column public String type_id; @Column public String type; // 方案名称 @Column public String plan_id; @Column public String plan; // 指导价 @Column public String guideprice; // GPS硬件 @Column public String GPS; // 制造商 @Column public String man_id; @Column public String man; // 品牌 @Column public String brand_id; @Column public String brand; // 车型 @Column public String car_id; @Column public String car; // 车辆售价 @Column public String price; @Column public String seat; @Column public String tonnage; @Column public String displacement; // 融资期限 @Column public String financing_limit; // 抵押城市 @Column public String city; // 营运 @Column public String operate; // 融延保 @Column public String rong_yan_bao; // 融保险 @Column public String rong_bao_xian; // 融安心宝 @Column public String rong_anxin_bao; // 安心宝 @Column public String anxin_bao; // 三方责任限额 @Column public String responsibility_limit; // 车上人员责任险(司机) @Column public String zeren_insurance_driver; // 车上人员责任险 (乘客) @Column public String zeren_insurance_passenger; // 车上人员责任险不计免赔 @Column public String zeren_insurance_deductible; // 车辆划伤险 @Column public String scratch_insurance; // 车辆划伤不计赔 @Column public String scratch_insurance_deductible; // 玻璃险 @Column public String glass_insurance; // 专修险 @Column public String repair_insurance; // 购置税 @Column public String purchase_tax; // 延保 @Column public String ex_insurance; // 车船税 @Column public String travel_tax; // 商业保险 @Column public String bus_insurance; // 交强险 @Column public String cost_insurance; // 首付比例 @Column public String shoufu; // 首付金额 @Column public String shoufu_money; // 首付比例逻辑 @Column public String shoufu_logic; // 尾付比例 @Column public String weifu; // 尾付金额 @Column public String weifu_money; // 尾付比例逻辑 @Column public String weifu_logic; // 融资金额 @Column public String financing_money; // 手续是否分期 @Column public String staging; // 手续费率 @Column public String rate; // 手续费 @Column public String procedure_money; // 保证金率 @Column public String margin; // 保证金 @Column public String margin_money; // 保证金比例逻辑 @Column public String margin_logic; // 投资总额 @Column public String total; // 销售经理 @Column public String sales_manager_id; public String sales_manager; // 销售助理 @Column public String sales_assistant_id; public String sales_assistant; // 开户银行 @Column public String bank; // 开户姓名 @Column public String bank_card_name; // 银行账号 @Column public String bank_number; // 征信是否后置 @Column public String credit; // 备注 @Column public String remarks; @Column public String insurance; @Column public String loadplan; // 页标识 @Column public String first; @Column public String second; @Column public String third; @Column public String fourth; @Column public String fifth; }
然后生成表,并对表做一些基本操作:
package com.mesada.newclient; import java.util.List; import android.content.Context; import android.util.Log; import com.lidroid.xutils.DbUtils; import com.lidroid.xutils.DbUtils.DaoConfig; import com.lidroid.xutils.db.sqlite.Selector; import com.lidroid.xutils.db.sqlite.WhereBuilder; import com.lidroid.xutils.exception.DbException; import com.mesada.data.model.FinancingMsgModel; public class NewClientDbUtils { public static NewClientDbUtils instance; private DbUtils db; private NewClientDbUtils() { }; private String TAG = getClass().getSimpleName(); public static NewClientDbUtils getInstance() { if (instance == null) { synchronized (NewClientDbUtils.class) { if (instance == null) { instance = new NewClientDbUtils(); } } } return instance; } public void init(Context context) { DaoConfig config = new DaoConfig(context); config.setDbVersion(1); db = DbUtils.create(config); db.configAllowTransaction(true); try { db.createTableIfNotExist(FinancingMsgModel.class); } catch (DbException e) { e.printStackTrace(); } } /** * @param clientId * @return 获取融资信息的基本信息 */ public FinancingMsgModel getFinancingMsg(String clientId) { FinancingMsgModel model = null; try { model = db.findFirst(Selector.from(FinancingMsgModel.class) .where(WhereBuilder.b("clientId", "=", clientId))); } catch (DbException e) { e.printStackTrace(); } return model; } /** * 删除融资信息 * * @return */ public void deleteFinancingMsg(String clientId) { try { db.delete(FinancingMsgModel.class, WhereBuilder.b("clientId", "=", clientId)); } catch (DbException e) { Log.d(TAG, "删除客户地址信息异常:" + e.getMessage()); e.printStackTrace(); } } /** * 修改或保存融资信息 * * @return */ public void updateOrSaveFinancingMsg(FinancingMsgModel model) { try { db.saveOrUpdate(model); } catch (DbException e) { Log.d(TAG, "修改或保存融资信息异常:" + e.getMessage()); e.printStackTrace(); } } }
最后就可以在自己需要的地方做处理了:
package com.mesada.financing; import java.util.ArrayList; import android.content.Context; import android.text.TextUtils; import android.util.Log; import com.mesada.data.model.FinancingMsgModel; import com.mesada.financing.Protocol.Data; import com.mesada.financing.Protocol.GuidePrice; import com.mesada.heraldleasingworkassistant.context.User; import com.mesada.heraldleasingworkassistant.context.UserContext; import com.mesada.newclient.NewClientDbUtils; public class DataMgr { private int mComplated = 0; private ArrayList<Protocol.Data> mManList = null; private ArrayList<Protocol.Data> mBrandList = null; private ArrayList<Protocol.Data> mCarList = null; private String clientId = null; public NewClientDbUtils dbUtils = NewClientDbUtils.getInstance(); public FinancingMsgModel financingMsg = null; private static class DataMgrHolder { private static DataMgr sDataMgr = new DataMgr(); } public static DataMgr getIns() { return DataMgrHolder.sDataMgr; } public void init(Context context, String clientId) { User user = UserContext.get().getCurrentUser(); this.clientId = clientId; financingMsg = dbUtils.getFinancingMsg(clientId); Log.i("123456financingMsg", String.valueOf(financingMsg==null)); if (financingMsg == null) { financingMsg = new FinancingMsgModel(); financingMsg.clientId = clientId; financingMsg.first = "false"; financingMsg.second = "false"; financingMsg.third = "false"; financingMsg.fourth = "false"; financingMsg.fifth = "false"; financingMsg.type_id = "0"; financingMsg.type = ""; financingMsg.plan_id = "0"; financingMsg.plan = ""; financingMsg.man_id = "0"; financingMsg.man = ""; financingMsg.brand_id = "0"; financingMsg.brand = ""; financingMsg.car_id = "0"; financingMsg.car = ""; financingMsg.guideprice = "0"; financingMsg.seat = "0"; financingMsg.tonnage = "0"; financingMsg.displacement = "0"; financingMsg.price = "0"; financingMsg.GPS = "0"; financingMsg.financing_limit = ""; financingMsg.city = ""; financingMsg.operate = "false"; financingMsg.rong_yan_bao = "false"; financingMsg.rong_bao_xian = "true"; financingMsg.rong_anxin_bao = "true"; financingMsg.anxin_bao = "0"; financingMsg.responsibility_limit = "20"; financingMsg.zeren_insurance_driver = "0"; financingMsg.zeren_insurance_passenger = "0"; financingMsg.zeren_insurance_deductible = "false"; financingMsg.scratch_insurance = "0"; financingMsg.scratch_insurance_deductible = "false"; financingMsg.glass_insurance = "无"; financingMsg.repair_insurance = "false"; financingMsg.purchase_tax = "0"; financingMsg.ex_insurance = "0"; financingMsg.travel_tax = ""; financingMsg.bus_insurance = ""; financingMsg.cost_insurance = ""; financingMsg.shoufu = "0"; financingMsg.shoufu_money = "0"; financingMsg.shoufu_logic = "0"; financingMsg.weifu = "0"; financingMsg.weifu_money = "0"; financingMsg.weifu_logic = "0"; financingMsg.financing_money = "0"; financingMsg.staging = "false"; financingMsg.rate = "0"; financingMsg.procedure_money = "0"; financingMsg.margin = ""; financingMsg.margin_money = "0"; financingMsg.margin_logic = "0"; financingMsg.sales_assistant_id = "0"; financingMsg.sales_assistant = ""; financingMsg.sales_manager_id = "0"; financingMsg.sales_manager = ""; financingMsg.bank = ""; financingMsg.bank_card_name=""; financingMsg.bank_number = ""; financingMsg.credit = "否"; financingMsg.remarks = ""; dbUtils.updateOrSaveFinancingMsg(financingMsg); } Protocol.getIns().Init(context, user.userId); } /* * 删除数据 */ public void clear() { dbUtils.deleteFinancingMsg(clientId); } /* * 获取项目总数 */ public int GetCount() { // 先默认5页 int i = 5; return i;// data.length; } /* * 返回已完成项目数 */ public int getCompleted() { mComplated = 0; if ("true".equals(financingMsg.first)) { mComplated++; } if ("true".equals(financingMsg.second)) { mComplated++; } if ("true".equals(financingMsg.third)) { mComplated++; } if ("true".equals(financingMsg.fourth)) { mComplated++; } if ("true".equals(financingMsg.fifth)) { mComplated++; } return mComplated; } public void setType(Protocol.Data data) { financingMsg.type_id=data.getBalbid(); financingMsg.type=data.getBalbmc(); } public Protocol.Data getType() { Data d = new Protocol().new Data(); d.setBalbid(financingMsg.type_id); d.setBalbmc(financingMsg.type); return d; } public void setPlan(Protocol.Data data) { financingMsg.plan_id=data.getBalbid(); financingMsg.plan=data.getBalbmc(); } public Protocol.Data getPlan() { Protocol.Data data = new Protocol().new Data(); data.setBalbid(financingMsg.plan_id); data.setBalbmc(financingMsg.plan); return data; } public void setCarInfo(CarInfo info) { if (info.getManufacturer() != null) { financingMsg.man_id=info.getManufacturer().getBalbid(); financingMsg.man=info.getManufacturer().getBalbmc(); } if (info.getBrand() != null) { financingMsg.brand_id=info.getBrand().getBalbid(); financingMsg.brand=info.getBrand().getBalbmc(); } if (info.getCar() != null) { financingMsg.car_id=info.getCar().getBalbid(); financingMsg.car=info.getCar().getBalbmc(); } } public CarInfo getCarInfo() { CarInfo info = new CarInfo(); info.setManufacturer(saveMan()); info.setBrand(saveBrand()); info.setCar(saveModels()); return info; } public Protocol.Data saveMan() { Data d = new Protocol().new Data(); d.setBalbid(financingMsg.man_id); d.setBalbmc(financingMsg.man); return d; } public Protocol.Data saveBrand() { Data d = new Protocol().new Data(); d.setBalbid(financingMsg.brand_id); d.setBalbmc(financingMsg.brand); return d; } public Protocol.Data saveModels() { Data d = new Protocol().new Data(); d.setBalbid(financingMsg.car_id); d.setBalbmc(financingMsg.car); return d; } public void setGuidePrice(Protocol.GuidePrice data) { financingMsg.guideprice=data.getBazdjg(); financingMsg.seat=data.getBazwsl(); financingMsg.tonnage=data.getBacldw(); financingMsg.displacement=data.getBaclpl(); } public Protocol.GuidePrice getGuidePrice() { GuidePrice data = new Protocol().new GuidePrice(); data.setBazdjg(financingMsg.guideprice); data.setBazwsl(financingMsg.seat); data.setBacldw(financingMsg.tonnage); data.setBaclpl(financingMsg.displacement); return data; } public void setPrice(String strValue) { financingMsg.price=strValue; } public String getPrice() { return financingMsg.price; } public void setGPS(String strValue) { financingMsg.GPS=strValue; } public String getGPS() { return financingMsg.GPS; } public void setFinancingLimit(String strValue) { financingMsg.financing_limit=strValue; } public String getFinancingLimit() { return financingMsg.financing_limit; } public void setCity(String strValue) { financingMsg.city=strValue; } public String getCity() { return financingMsg.city; } public void setOperate(boolean b) { financingMsg.operate=String.valueOf(b); } public boolean getOperate() { return Boolean.parseBoolean(financingMsg.operate); } public void setRongYanBao(boolean bool) { financingMsg.rong_yan_bao=String.valueOf(bool); } public boolean getRongYanBao() { return Boolean.parseBoolean(financingMsg.rong_yan_bao); } public void setRongBaoXian(boolean bool) { financingMsg.rong_bao_xian=String.valueOf(bool); } public boolean getRongBaoXian() { return Boolean.parseBoolean(financingMsg.rong_bao_xian); } public void setRongAnxinBao(boolean bool) { financingMsg.rong_anxin_bao=String.valueOf(bool); } public boolean getRongAnxinBao() { return Boolean.parseBoolean(financingMsg.rong_anxin_bao); } public void setAnxinBao(String strValue) { financingMsg.anxin_bao=strValue; } public String getAnxinBao() { return financingMsg.anxin_bao; } public void setResponsibilityLimit(String strValue) { financingMsg.responsibility_limit=strValue; } public String getResponsibilityLimit() { return financingMsg.responsibility_limit; } public void setZerenDriver(String strValue) { financingMsg.zeren_insurance_driver=strValue; } public String getZerenDriver() { return financingMsg.zeren_insurance_driver; } public void setZerenPassenger(String strValue) { financingMsg.zeren_insurance_passenger=strValue; } public String getZerenPassenger() { return financingMsg.zeren_insurance_passenger; } public void setZeren_deductible(boolean intValue) { financingMsg.zeren_insurance_deductible=String.valueOf(intValue); } public boolean getZeren_deductible() { return Boolean.parseBoolean(financingMsg.zeren_insurance_deductible); } public void setScratchInsurance(String strValue) { financingMsg.scratch_insurance=strValue; } public String getScratchInsurance() { return financingMsg.scratch_insurance; } public void setScratchDeductible(boolean intValue) { financingMsg.scratch_insurance_deductible=String.valueOf(intValue); } public boolean getScratchDeductible() { return Boolean.parseBoolean(financingMsg.scratch_insurance_deductible); } public void setGlassInsurance(String strValue) { financingMsg.glass_insurance=strValue; } public String getGlassInsurance() { return financingMsg.glass_insurance; } public void setRepairInsurance(boolean intValue) { financingMsg.repair_insurance=String.valueOf(intValue); } public boolean getRepairInsurance() { return Boolean.parseBoolean(financingMsg.repair_insurance); } public void setManList(ArrayList<Protocol.Data> l) { mManList = l; } public ArrayList<Protocol.Data> getManList() { return mManList; } public void setBrandList(ArrayList<Protocol.Data> l) { mBrandList = l; } public ArrayList<Protocol.Data> getBrandList() { return mBrandList; } public ArrayList<Protocol.Data> getCarList() { return mCarList; } public void setCarList(ArrayList<Protocol.Data> mCarList) { this.mCarList = mCarList; } public void setPurchaseTax(String strValue) { financingMsg.purchase_tax=strValue; } public String getPurchaseTax() { return financingMsg.purchase_tax; } public void setExInsurance(String strValue) { financingMsg.ex_insurance=strValue; } public String getExInsurance() { return financingMsg.ex_insurance; } public void setTravelTax(String strValue) { financingMsg.travel_tax=strValue; } /** * @return 车船税 */ public String getTravelTax() { return financingMsg.travel_tax; } public void setBusInsurance(String strValue) { financingMsg.bus_insurance=strValue; } /** * @return 商业保险 */ public String getBusInsurance() { return financingMsg.bus_insurance; } public void setCostInsurance(String strValue) { financingMsg.cost_insurance=strValue; } /** * @return 交强险 */ public String getCostInsurance() { return financingMsg.cost_insurance; } public String cost2String() { return financingMsg.cost_insurance; } public String bus2String() { return financingMsg.bus_insurance; } public String travel2String() { return financingMsg.travel_tax; } public void setShouFu(String strValue) { financingMsg.shoufu=strValue; } public String getShowFu() { return financingMsg.shoufu; } public void setShowFuMoney(String strValue) { financingMsg.shoufu_money=strValue; } public String getShowFuMoney() { return financingMsg.shoufu_money; } public void setShowFuLogic(String strValue) { financingMsg.shoufu_logic=strValue; } public String getShowFuLogic() { return financingMsg.shoufu_logic; } public void setWeiFu(String strValue) { financingMsg.weifu=strValue; } public String getWeiFu() { return financingMsg.weifu; } public void setWeiFuLogic(String strValue) { financingMsg.weifu_logic=strValue; } public String getWeiFuLogic() { return financingMsg.weifu_logic; } public void setWeiFuMoney(String strValue) { financingMsg.weifu_money=strValue; } public String getWeiFuMoney() { return financingMsg.weifu_money; } public void setFinancingMoney(String strValue) { financingMsg.financing_money=strValue; } public String getFinancingMoney() { return financingMsg.financing_money; } public void setStaging(boolean boolValue) { financingMsg.staging=String.valueOf(boolValue); } public boolean getStaging() { return Boolean.parseBoolean(financingMsg.staging); } public void setRate(String strValue) { financingMsg.rate=strValue; } public String getRate() { return financingMsg.rate; } public void setProcedure(String strValue) { financingMsg.procedure_money=strValue; } public String getProcedure() { return financingMsg.procedure_money; } public void setMargin(String strValue) { financingMsg.margin=strValue; } public String getMargin() { return financingMsg.margin; } public void setMarginMoney(String strValue) { financingMsg.margin_money=strValue; } public String getMarginMoney() { return financingMsg.margin_money; } public void setMarginLogic(String strValue) { financingMsg.margin_logic=strValue; } public String getMarginLogic() { return financingMsg.margin_logic; } public void setSalesManager(Protocol.Data mgr) { financingMsg.sales_manager_id=mgr.getBalbid(); financingMsg.sales_manager=mgr.getBalbmc(); } public Protocol.Data getSalesManager() { Protocol.Data d = new Protocol().new Data(); d.setBalbid(financingMsg.sales_manager_id); d.setBalbmc(financingMsg.sales_manager); return d; } public void setSalesAssistant(Protocol.Data data) { financingMsg.sales_assistant_id=data.getBalbid(); financingMsg.sales_assistant=data.getBalbmc(); } public Protocol.Data getSalesAssistant() { Protocol.Data d = new Protocol().new Data(); d.setBalbid(financingMsg.sales_assistant_id); d.setBalbmc(financingMsg.sales_assistant); return d; } public void setBrank(String brank) { financingMsg.bank=brank; } public String getBrank() { return financingMsg.bank; } public void setBankNumber(String number) { financingMsg.bank_number=number; } public String getBankNumber() { return financingMsg.bank_number; } // 初始化后调用该接口 public void setBankCardName(String name) { financingMsg.bank_card_name=name; } public String getBankCardName() { return financingMsg.bank_card_name; } public void setCredit(String strValue) { financingMsg.credit=strValue; } public String getCredit() { return financingMsg.credit; } public void setRemarks(String strValue) { financingMsg.remarks=strValue; } public String getRemarks() { return financingMsg.remarks; } public Float getTotal() { float f = MyUtil.SafeValue(DataMgr.getIns().getPrice()) + MyUtil.SafeValue(DataMgr.getIns().getPurchaseTax()) + MyUtil.SafeValue(DataMgr.getIns().getExInsurance()) + MyUtil.SafeValue(DataMgr.getIns().getGPS()) + MyUtil.SafeValue(DataMgr.getIns().getAnxinBao()); if (getRongBaoXian()) { if (!TextUtils.isEmpty(getCostInsurance())) { f += Float.valueOf(getCostInsurance()); } if (!TextUtils.isEmpty(getBusInsurance())) { f += Float.valueOf(getBusInsurance()); } if (!TextUtils.isEmpty(getTravelTax())) { f += Float.valueOf(getTravelTax()); } } Log.i(getClass().getName(), "GetTotalCost:" + getCostInsurance()); Log.i(getClass().getName(), "GetTotalBus:" + getBusInsurance()); Log.i(getClass().getName(), "GetTotalTravel:" + getTravelTax()); return f; } public float getMoney() { float m = MyUtil.SafeValue(DataMgr.getIns().getPrice()) + MyUtil.SafeValue(DataMgr.getIns().getAnxinBao()) + MyUtil.SafeValue(DataMgr.getIns().getExInsurance()) - MyUtil.SafeValue(DataMgr.getIns().getShowFuMoney()); if (getRongBaoXian()) { if (!TextUtils.isEmpty(getCostInsurance())) { m += Float.valueOf(getCostInsurance()); } if (!TextUtils.isEmpty(getBusInsurance())) { m += Float.valueOf(getBusInsurance()); } if (!TextUtils.isEmpty(getTravelTax())) { m += Float.valueOf(getTravelTax()); } } ; Log.i(getClass().getName(), "GetPrice:" + MyUtil.SafeValue(DataMgr.getIns().getPrice())); Log.i(getClass().getName(), "GetAnxinBao:" + MyUtil.SafeValue(DataMgr.getIns().getAnxinBao())); Log.i(getClass().getName(), "GetExInsurance:" + MyUtil.SafeValue(DataMgr.getIns().getExInsurance()));// 延保 Log.i(getClass().getName(), "GetTotalCost:" + getCostInsurance());// 交强险 Log.i(getClass().getName(), "GetTotalBus:" + DataMgr.getIns().getBusInsurance());// 商业保险 Log.i(getClass().getName(), "GetTotalTravel:" + DataMgr.getIns().getTravelTax());// 车船税 Log.i(getClass().getName(), "GetShowFuMoney:" + MyUtil.SafeValue(DataMgr.getIns().getShowFuMoney()));// 首付金额 return m; } public class CarInfo { /** * 制造商 */ private Protocol.Data manufacturer; /** * 品牌 */ private Protocol.Data brand; /** * 车型 */ private Protocol.Data car; public CarInfo() { } public Protocol.Data getManufacturer() { return manufacturer; } public void setManufacturer(Protocol.Data manufacturer) { this.manufacturer = manufacturer; } public Protocol.Data getBrand() { return brand; } public void setBrand(Protocol.Data brand) { this.brand = brand; } public Protocol.Data getCar() { return car; } public void setCar(Protocol.Data car) { this.car = car; } } }
标签:
原文地址:http://www.cnblogs.com/aihaozhe/p/5090817.html