寂寞笑我太堕落吧 关注:4贴子:443
  • 0回复贴,共1
public void checkEmptyMaintenaceEquipmentInfo() {
String sql = "SELECT * FROM "
+ DBHelper.Maintenace_Equipment_Table_Name
+ " WHERE equipmentName=''";
Cursor cs = null;
String args[] = null;
try {
cs = db.rawQuery(sql, args);
if (cs.getCount() > 0) {
while (cs.moveToNext()) {
args = null;
long id = Long.parseLong(cs.getString(cs
.getColumnIndex("equipmentId")));
String equipmentName = queryEquipmentName(id);
String args1[] = { id + "" };
sql = "update " + DBHelper.Maintenace_Equipment_Table_Name
+ " set equipmentName='" + equipmentName
+ "' WHERE equipmentId=?";
db.execSQL(sql, args1);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cs != null && !cs.isClosed()) {
cs.close();
}
}
}
private String queryEquipmentName(long id) {
String args[] = { id + "" };
String sql = "SELECT * FROM " + DBHelper.Base_Equipment_Table_Name
+ " Where id=?";
Cursor cs = null;
String name = "";
try {
cs = db.rawQuery(sql, args);
if (cs.getCount() > 0) {
while (cs.moveToNext()) {
name = cs.getString(cs.getColumnIndex("equipmentName"));
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cs != null && !cs.isClosed()) {
cs.close();
}
}
return name;
}
public void checkEmptyInspectionEquipmenInfo() {
String sql = "SELECT * FROM "
+ DBHelper.Inspection_Equipment_Table_Name
+ " WHERE equipmentName=''";
Cursor cs = null;
String args[] = null;
try {
cs = db.rawQuery(sql, args);
if (cs.getCount() > 0) {
while (cs.moveToNext()) {
args = null;
long id = Long.parseLong(cs.getString(cs
.getColumnIndex("equipmentId")));
String equipmentName = queryEquipmentName(id);
sql = "update " + DBHelper.Inspection_Equipment_Table_Name
+ " set equipmentName='" + equipmentName
+ "' WHERE equipmentId=?";
String args1[] = { id + "" };
db.execSQL(sql, args1);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cs != null && !cs.isClosed()) {
cs.close();
}
}
}
public String queryEquipmentItemName(long id) {
String itemName = "";
Cursor cs = null;
try {
String args[] = { id + "" };
cs = db.rawQuery("SELECT * FROM "
+ DBHelper.Base_Equipment_Spotcheck_Table_Name
+ " WHERE id = ? ", args);
if (cs.getCount() > 0) {
cs.moveToFirst();
itemName = cs.getString(cs.getColumnIndex("name"));
Log.d(TAG, "queryEquipmentItem > itemName : " + itemName);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cs != null && !cs.isClosed()) {
cs.close();
}
}
return itemName;
}
public void checkEmptyInspectionProjectInfo() {
String sql = "SELECT * FROM " + DBHelper.Inspection_Item_Table_Name
+ " WHERE equipmentSpotcheckName=''";
Cursor cs = null;
String args[] = null;
try {
cs = db.rawQuery(sql, args);
if (cs.getCount() > 0) {
while (cs.moveToNext()) {
args = null;
long id = Long.parseLong(cs.getString(cs
.getColumnIndex("equipmentSpotcheckId")));
String equipmentSpotcheckName = queryEquipmentItemName(id);
sql = "update " + DBHelper.Inspection_Item_Table_Name
+ " set equipmentSpotcheckName='" + equipmentSpotcheckName + "'"
+ " WHERE equipmentSpotcheckId=?";
String args1[] = { id + "" };
db.execSQL(sql, args1);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (cs != null && !cs.isClosed()) {
cs.close();
}
}
}
public boolean deleteEquipmentSparePartRelation() {
try {
String deleteInfoSqlString = "DELETE FROM "
+ DBHelper.Base_Equipment_SparePart_Table_Name;
db.execSQL(deleteInfoSqlString);
} catch (Exception e) {
return false;
}
return true;
}
public boolean deleteBaseCategory() {
try {
String deleteInfoSqlString = "DELETE FROM "
+ DBHelper.Base_Category_Table_Name;
db.execSQL(deleteInfoSqlString);
} catch (Exception e) {
return false;
}
return true;
}
public long insertEquipmentSparePartRelation(EquipmentSparePart entity) {
long result = 0;
try {
ContentValues cv = new ContentValues();
cv.put("id", entity.id + "");
cv.put("equid", entity.equid + "");
cv.put("spapartid", entity.spapartid + "");
result = db.insert(DBHelper.Base_Equipment_SparePart_Table_Name, null,
cv);
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}
public long insertBaseCategory(BaseCategory entity){
long result = 0;
try{
ContentValues cv=new ContentValues();
cv.put("id", entity.id);
cv.put("name", entity.name);
cv.put("parentid", entity.parentid);
result=db.insert(DBHelper.Base_Category_Table_Name, null, cv);
}catch(SQLException e){
e.printStackTrace();
}
return result;
}
public boolean deleteBaseImage() {
try{
String sql="DELETE FROM "
+DBHelper.Base_Image_Table_Name;
db.execSQL(sql);
}catch(Exception e){
return false;
}
return true;
}
public long insertBaseImage(BaseImage image) {
long result = 0;
try{
String [] args=image.id.split(",");
for(int i =0;i<args.length;i++){
ContentValues cv=new ContentValues();
cv.put("id", args[i].toString());
//cv.put("url", args[i].toString());
result=db.insert(DBHelper.Base_Image_Table_Name, null, cv);
}
}catch(SQLException e){
e.printStackTrace();
}
return result;
}
public boolean deleteBaseOperationNotice() {
try{
String sql = "DELETE FROM "
+DBHelper.Base_Operation_Notice;
db.execSQL(sql);
}catch(Exception e){
return false;
}
return true;
}
public long insertBaseOperationNotice(BaseOperationNotice notice) {
long result = 0;
try{
ContentValues cv=new ContentValues();
cv.put("id", notice.id);
cv.put("equipmentId", notice.equipmentId);
cv.put("type", notice.type);
cv.put("notice", notice.notice);
result=db.insert(DBHelper.Base_Operation_Notice, null,cv);
}catch(Exception e){
e.printStackTrace();
}
return result;
}
public boolean deleteEquipCheckPicture() {
try{
String sql="DELETE FROM "
+DBHelper.Base_Equip_Check_Picture;
db.execSQL(sql);
}catch(Exception e){
return false;
}
return true;
}
public long insertBaseEquipCheckPicture(EquipCheckPicture entity) {
long result = 0;
try{
ContentValues cv=new ContentValues();
cv.put("id", entity.id);
cv.put("pictureId", entity.pictureId);
cv.put("checksubjectId", entity.checksubjectId);
result=db.insert(DBHelper.Base_Equip_Check_Picture, null,cv);
}catch(Exception e){
e.printStackTrace();
}
return result;
}
public List<BaseImage> queryBaseImage() {
List<BaseImage> list=new ArrayList<BaseImage>();
Cursor cs=null;
try{
String sql="SELECT * FROM "+DBHelper.Base_Image_Table_Name;
cs=db.rawQuery(sql, null);
if(cs.getCount() > 0){
while(cs.moveToNext()){
BaseImage base=new BaseImage();
base.id=cs.getString(cs.getColumnIndex("id"));
//base.url=cs.getString(cs.getColumnIndex("url"));
list.add(base);
}
}
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
if(cs !=null && !cs.isClosed()){
cs.close();
}
}
return list;
}
public void insertBaseImageId(EquipCheckPicture entity) {
try{
ContentValues cv=new ContentValues();
cv.put("id", entity.pictureId);
db.insert(DBHelper.Base_Image_Table_Name, null, cv);
}catch(Exception e){
e.printStackTrace();
}
}
public void deleteBaseEquipmentAttachment() {
try{
db.execSQL("DELETE FROM "
+ DBHelper.Base_Equip_Attachment);
}catch(Exception e){
e.printStackTrace();
}
}
public void insertBaseEquipmentAttachment(BaseEquipmentAttachment attachment) {
try{
ContentValues cv=new ContentValues();
cv.put("id",attachment.id);
cv.put("equipId", attachment.equipId);
cv.put("fileId", attachment.fileId);
cv.put("fileName",attachment.fileName);
db.insert(DBHelper.Base_Equip_Attachment, null, cv);
}catch(Exception e){
e.printStackTrace();
}
}
public List<BaseEquipmentAttachment> queryBaseEquipmentAttachment() {
List <BaseEquipmentAttachment> list = new ArrayList<BaseEquipmentAttachment>();
Cursor cr=null;
try{
String sql="SELECT * FROM " + DBHelper.Base_Equip_Attachment;
cr=db.rawQuery(sql, null);
while(cr.moveToNext()){
BaseEquipmentAttachment atth = new BaseEquipmentAttachment();
atth.fileId = cr.getString(cr.getColumnIndex("fileId"));
atth.fileName = cr.getString(cr.getColumnIndex("fileName"));
list.add(atth);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(cr !=null && !cr.isClosed()){
cr.close();
}
}
return list;
}
public List<ResEquipmentSparePart1> queryBaseEquipmentSparPart(long equId){
List<ResEquipmentSparePart1> list = new ArrayList<ResEquipmentSparePart1>();
Cursor cs=null;
try{
String sql="SELECT * FROM "+ DBHelper.Base_Equipment_SparePart_Table_Name
+" a join "+DBHelper.Base_SparePart_Table_Name + " b on a.spapartid = b.id WHERE equid=?";
cs=db.rawQuery(sql, new String[]{equId+""});
while(cs.moveToNext()){
ResEquipmentSparePart1 entity = new ResEquipmentSparePart1();
entity.spapartid = Long.parseLong(cs.getString(cs.getColumnIndex("spapartid")));
entity.name = cs.getString(cs.getColumnIndex("name"));
list.add(entity);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(cs!=null && !cs.isClosed()){
cs.close();
}
}
return list;
}
public String querySparePartName(long id) {
String name="";
String sql = "SELECT * FROM " + DBHelper.Base_SparePart_Table_Name
+" WHERE id=?";
Cursor cs=null;
try{
cs=db.rawQuery(sql,new String[]{id +""});
while(cs.moveToNext()){
name=cs.getString(cs.getColumnIndex("name"));
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(cs !=null && !cs.isClosed()){
cs.close();
}
}
return name;
}
public String updateSparepartcontent(long equipmentId,
String sparepartContent) {
String sql="SELECT * FROM "+ DBHelper.Base_Equipment_SparePart_Table_Name
+" a join "+DBHelper.Base_SparePart_Table_Name + " b on a.spapartid = b.id WHERE equid=?";
Cursor cs=null;
try{
cs=db.rawQuery(sql, new String[]{equipmentId+""});
while(cs.moveToNext()){
sparepartContent=sparepartContent.replace(cs.getString(cs.getColumnIndex("spapartid")), cs.getString(cs.getColumnIndex("name")));
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(cs!=null && cs.isClosed()){
cs.close();
}
}
return sparepartContent;
}
}


1楼2015-09-01 17:18回复