Blame view

src/com/ectrip/cyt/db/DbManager.java 5.12 KB
3c2353cd   杜方   1、畅游通核销app源码提交;
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
  package com.ectrip.cyt.db;
  
  import java.util.ArrayList;
  
  import android.database.Cursor;
  import android.database.SQLException;
  import android.database.sqlite.SQLiteDatabase;
  
  import com.ectrip.cyt.bean.ConfigBean;
  import com.ectrip.cyt.config.MyApp;
  
  public class DbManager {
  	/**
  	 * 获取配置文件
  	 */
  	public  static ArrayList<ConfigBean> GetConfigs() {
  		ArrayList<ConfigBean> products = new ArrayList<ConfigBean>();
  		synchronized (MyApp.getInstance().getDb()) {
  			try {
  				Cursor c = MyApp.getInstance().getDb()
  						.rawQuery("SELECT * FROM ec_configs", null);
  				for (int i = 0; i < c.getCount(); i++) {
  					c.moveToPosition(i);
  					products.add(new ConfigBean(c.getString(0), c.getString(1),
  							c.getString(2), c.getString(3), c.getString(4), c
  							.getString(5), c.getInt(6)));
  				}
  				c.close();
  			} catch (Exception e) {
  				e.printStackTrace();
  			}
  			return products;
  		}
  	}
  
  	public static void InsertConfig(String ec_id, String ec_ip,
  									String ec_passwd, String ec_mac, String ec_key, String ec_name,
  									int ec_isPrint) {
  		synchronized (MyApp.getInstance().getDb()) {
  			try {
  				MyApp.getInstance()
  						.getDb()
  						.execSQL(
  								"INSERT OR REPLACE INTO ec_configs (ec_cid,ec_ip, ec_passwd, ec_mac,ec_key,ec_name,ec_isPrint) VALUES(?,?,?,?,?,?,?)",
  								new Object[] { ec_id, ec_ip, ec_passwd, ec_mac,
  										ec_key, ec_name, ec_isPrint });
  			} catch (SQLException e) {
  				e.printStackTrace();
  			}
  		}
  	}
  
  	// update ec_contacts set ec_name=?,ec_tel=? where ec_id=?
  
  	/**
  	 * 修改配置文件
  	 */
  	public static void ModifyConfig(ConfigBean bean) {
  		synchronized (MyApp.getInstance().getDb()) {
  			try {
  				MyApp.getInstance()
  						.getDb()
  						.execSQL(
  								"update ec_configs set ec_ip=?, ec_passwd=?, ec_mac=?, ec_key=? ,ec_name=?,ec_isPrint=? where ec_cid=?",
  								new Object[] { bean.getEc_ip(),
  										bean.getEc_passwd(), bean.getEc_mac(),
  										bean.getEc_identity(), bean.getEc_signkey(),
  										bean.getEc_isPrint(), bean.getEc_id() });
  			} catch (SQLException e) {
  				e.printStackTrace();
  			}
  		}
  	}
  
  	/**
  	 * 插入配置文件
  	 */
  	public static void InsertConfig(ConfigBean bean) {
  		InsertConfig(bean.getEc_id(), bean.getEc_ip(), bean.getEc_passwd(),
  				bean.getEc_mac(), bean.getEc_identity(), bean.getEc_signkey(),
  				bean.getEc_isPrint());
  	}
  
  	/**
  	 */
  	public static void ClearConfig() {
  		synchronized (MyApp.getInstance().getDb()) {
  			try {
  				MyApp.getInstance().getDb().execSQL("DELETE FROM ec_configs");
  			} catch (SQLException e) {
  				e.printStackTrace();
  			}
  		}
  	}
  
  	/**
  	 * 插入打印过的票
  	 */
  	public static void insertPrint(String time, String content,
  								   String ec_order_number) {
  		synchronized (MyApp.getInstance().getDb()) {
  			SQLiteDatabase db = MyApp.getInstance().getDb();
  			// 开启事务
  			db.beginTransaction();
  			try {
  				MyApp.getInstance()
  						.getDb()
  						.execSQL(
  								"INSERT OR REPLACE INTO ec_save_print (ec_time, ec_content,ec_order_id) "
  										+ "VALUES(?,?,?)",
  								new Object[] { time, content, ec_order_number });
  				// 设置事务标志为成功,当结束事务时就会提交事务
  				db.setTransactionSuccessful();
  			} finally {
  				// 结束事务
  				db.endTransaction();
  			}
  		}
  	}
  
  	/**
  	 * 修改打印的票
  	 */
  	public static void ModifyPrint(String time, String content,
  								   String ec_order_number) {
  		synchronized (MyApp.getInstance().getDb()) {
  			SQLiteDatabase db = MyApp.getInstance().getDb();
  			// 开启事务
  			db.beginTransaction();
  			try {
  				MyApp.getInstance()
  						.getDb()
  						.execSQL(
  								"update ec_save_print set ec_time=?, ec_content=? where ec_order_id=?",
  								new Object[] { time, content, ec_order_number });
  				// 设置事务标志为成功,当结束事务时就会提交事务
  				db.setTransactionSuccessful();
  			} finally {
  				// 结束事务
  				db.endTransaction();
  			}
  		}
  	}
  
  	/**
  	 * 删除某一时间段内的数据
  	 */
  	public static void deletePrint(String time) {
  		synchronized (MyApp.getInstance().getDb()) {
  			try {
  				String strsql = "delete from ec_save_print where ec_time like '"
  						+ time + "%'";
  				MyApp.getInstance().getDb().execSQL(strsql);
  			} catch (SQLException e) {
  				e.printStackTrace();
  			}
  		}
  	}
  
  	/**
  	 * 根据订单号查询数据
  	 */
  	public static String queryOrderNumber(String orderId) {
  		String content = null;
  		synchronized (MyApp.getInstance().getDb()) {
  			try {
  				Cursor cursor = MyApp
  						.getInstance()
  						.getDb()
  						.rawQuery(
  								"select * from ec_save_print where ec_order_id like ?",
  								new String[] { "%" + orderId + "%" });
  
  				if (cursor.moveToFirst()) {
  					content = cursor.getString(cursor
  							.getColumnIndex("ec_content"));
  				}
  				cursor.close();
  			} catch (Exception e) {
  				e.printStackTrace();
  			}
  		}
  		return content;
  	}
  
  	/**
  	 * 删除指定时间以内的数据
  	 */
  	public static void regularDelect(String date) {
  		String sql = "delete FROM ec_save_print WHERE ec_time<'" + date + "'";
  		synchronized (MyApp.getInstance().getDb()) {
  			try {
  				MyApp.getInstance().getDb().execSQL(sql);
  			} catch (SQLException e) {
  				e.printStackTrace();
  			}
  		}
  	}
  }