81041
2019-11-18 86397b404b0f18da000b2eb9ad64a5cbedb4cc93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.fgkj.impl;
 
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
 
import com.fgkj.dao.ActionUtil;
import com.fgkj.dao.BaseDAO;
import com.fgkj.dto.Battinf;
import com.sqlite_DaoHelper.CallBack;
import com.sqlite_DaoHelper.DAOHelper;
import com.sqlite_DaoHelper.DBUtil;
 
import java.io.File;
import java.sql.ResultSet;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
 
public class BattinfImpl implements BaseDAO, CallBack {
    //插入电池组信息
    @Override
    public boolean add(SQLiteDatabase db,Object obj) {
        Battinf binf=(Battinf) obj;
        boolean bl=true;
        String sql=" insert into tb_battinf(BattGroupId,BattGroupName,BattGroupName1,BattFloatCurrent,MonCount,MonCapStd,MonVolStd,MonResStd,MonSerStd,MonTmpStd,BattProducer,BattInUseDate,station_install) " +
                "   values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
        db.execSQL(sql,new  Object[]{binf.getBattGroupId(),binf.getBattGroupName(),binf.getBattGroupName1(),binf.getBattFloatCurrent(),binf.getMonCount(),binf.getMonCapStd(),binf.getMonVolStd()
                ,binf.getMonResStd(),binf.getMonSerStd(),binf.getMonTmpStd(),binf.getBattProducer(),ActionUtil.getSimpDate(binf.getBattInUseDate()),binf.getStation_install()});
        try {
            return bl;
        } catch (Exception e) {
            bl=false;
            e.printStackTrace();
        }
        return  bl;
    }
    //根据battgroupid修改表的数据
    @Override
    public boolean update(SQLiteDatabase db,Object obj) {
        Battinf binf=(Battinf) obj;
        boolean bl=true;
        String sql=" update tb_battinf set BattGroupName=?,BattGroupName1=?,BattFloatCurrent=?,MonCount=?,MonCapStd=?,MonVolStd=?,MonResStd=?,MonSerStd=?,MonTmpStd=?,BattProducer=?,BattInUseDate=?,station_install=? where BattGroupId=? ";
        try {
            db.execSQL(sql,new  Object[]{binf.getBattGroupName(),binf.getBattGroupName1(),binf.getBattFloatCurrent(),binf.getMonCount(),binf.getMonCapStd(),binf.getMonVolStd()
                    ,binf.getMonResStd(),binf.getMonSerStd(),binf.getMonTmpStd(),binf.getBattProducer(),ActionUtil.getSimpDate(binf.getBattInUseDate()),binf.getStation_install(),binf.getBattGroupId()});
        } catch (SQLException e) {
            bl=false;
            e.printStackTrace();
        }
        return bl;
    }
    //根据id删除
    @Override
    public boolean del(SQLiteDatabase db,Object obj) {
        Battinf binf=(Battinf)obj;
        boolean bl=true;
        String sql=" delete from tb_battinf where BattGroupId=? ";
        try {
            db.execSQL(sql,new Object[]{binf.getBattGroupId()});
        } catch (SQLException e) {
            bl=false;
            e.printStackTrace();
        }
 
        return bl;
    }
    //查询库中存在的所有电池组信息
    @Override
    public List searchAll(SQLiteDatabase db) {
        String sql=" select * from tb_battinf where station_install=1 order by battgroupid asc ";
         List list=new ArrayList();
         Cursor rs = db.rawQuery(sql,new String[]{});
         while(rs.moveToNext()){
             Battinf binf=new Battinf();
             binf.setNum(rs.getInt(rs.getColumnIndex("num")));
             binf.setBattGroupId(rs.getInt(rs.getColumnIndex("BattGroupId")));
             binf.setBattGroupName(rs.getString(rs.getColumnIndex("BattGroupName")));
             binf.setBattGroupName1(rs.getString(rs.getColumnIndex("BattGroupName1")));
             binf.setBattFloatCurrent(rs.getDouble(rs.getColumnIndex("BattFloatCurrent")));
             binf.setMonCapStd(rs.getDouble(rs.getColumnIndex("MonCapStd")));
             binf.setMonVolStd(rs.getDouble(rs.getColumnIndex("MonVolStd")));
             binf.setMonCount(rs.getInt(rs.getColumnIndex("MonCount")));
             binf.setMonResStd(rs.getDouble(rs.getColumnIndex("MonResStd")));
             binf.setMonSerStd(rs.getDouble(rs.getColumnIndex("MonSerStd")));
             binf.setMonTmpStd(rs.getDouble(rs.getColumnIndex("MonTmpStd")));
             binf.setBattProducer(rs.getString(rs.getColumnIndex("BattProducer")));
             try {
                 Date date= ActionUtil.sdfwithOut.parse( rs.getString(rs.getColumnIndex("BattInUseDate")));
                 binf.setBattInUseDate(date);
             } catch (ParseException e) {
                 e.printStackTrace();
             } 
             binf.setStation_install(rs.getInt(rs.getColumnIndex("station_install")));
             list.add(binf);
         }
        rs.close();
        return list;
    }
    //根据电池组id查询电池组信息
    @Override
    public List serchByCondition(SQLiteDatabase db,Object obj) {
        Battinf b=(Battinf)obj;
        String sql=" select * from tb_battinf where BattGroupId=? order by battgroupid asc ";
        List list=new ArrayList();
        Cursor rs = db.rawQuery(sql,new String[]{String.valueOf(b.getBattGroupId())});
        while(rs.moveToNext()){
            Battinf binf=new Battinf();
            binf.setNum(rs.getInt(rs.getColumnIndex("num")));
            binf.setBattGroupId(rs.getInt(rs.getColumnIndex("BattGroupId")));
            binf.setBattGroupName(rs.getString(rs.getColumnIndex("BattGroupName")));
            binf.setBattGroupName1(rs.getString(rs.getColumnIndex("BattGroupName1")));
            binf.setBattFloatCurrent(rs.getDouble(rs.getColumnIndex("BattFloatCurrent")));
            binf.setMonCapStd(rs.getDouble(rs.getColumnIndex("MonCapStd")));
            binf.setMonVolStd(rs.getDouble(rs.getColumnIndex("MonVolStd")));
            binf.setMonCount(rs.getInt(rs.getColumnIndex("MonCount")));
            binf.setMonResStd(rs.getDouble(rs.getColumnIndex("MonResStd")));
            binf.setMonSerStd(rs.getDouble(rs.getColumnIndex("MonSerStd")));
            binf.setMonTmpStd(rs.getDouble(rs.getColumnIndex("MonTmpStd")));
            binf.setBattProducer(rs.getString(rs.getColumnIndex("BattProducer")));
            try {
                Date date= ActionUtil.sdfwithOut.parse( rs.getString(rs.getColumnIndex("BattInUseDate")));
                binf.setBattInUseDate(date);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            binf.setStation_install(rs.getInt(rs.getColumnIndex("station_install")));
            list.add(binf);
        }
        rs.close();
        return list;
    }
 
    @Override
    public List serchByInfo(SQLiteDatabase db,Object obj) {
        return null;
    }
 
    @Override
    public List getResults(ResultSet rs) {
        return null;
    }
 
    public static void main (String[] args) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = sdf.parse("2000-01-01");
   
        Battinf binf=new Battinf();
        binf.setBattGroupId(1000002);
        binf.setBattGroupName("电池组2");
        binf.setBattGroupName1("电池组");
        binf.setBattFloatCurrent(51.5);
        binf.setMonCapStd(150);
        binf.setMonVolStd(12);
        binf.setMonCount(4);
        binf.setMonResStd(5000);
        binf.setMonSerStd(0.002);
        binf.setMonTmpStd(50.2);
        binf.setBattProducer("理士");
        binf.setBattInUseDate(ActionUtil.getSimpDate(date1));
        //System.out.println(DAOHelper.getSimpDate(date1));
       // System.out.println(binf.getBattInUseDate());
        binf.setStation_install(1);
        BattinfImpl bimpl=new BattinfImpl();
        /*boolean bl=bimpl.add(binf);
        System.out.println(bl);*/
        String path=System.getProperty("user.dir");
        String db_path= "/app/assets/sqlites/fbs9600.db";
        String filePath = path+db_path;
        System.out.println(filePath);
        File jhPath=new File(filePath);
        SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(jhPath, null);
        List<Battinf> list=bimpl.searchAll(db);
        for (Battinf b:list
             ) {
            System.out.println(b);
        }
    }
}