private DataBaseAgent.DBOperator GetDBOperator() { DataBaseAgent.DBOperator myDB = null; if (_DataBaseName != "") { if (_DataBaseTypeID == 1 || _DataBaseTypeID == 2 || _DataBaseTypeID == 3 || _DataBaseTypeID == 4) { myDB = DataBaseAgent.DBFactory.GetDBOperator(_DataBaseTypeID, _DataBaseName); } else { myDB = DataBaseAgent.DBFactory.GetDBOperator(_DataBaseName); } } else { if (_DataBaseID != 1) { myDB = DataBaseAgent.DBFactory.GetDBOperator(_DataBaseTypeID, _DataBaseID); } else { myDB = DataBaseAgent.DBFactory.GetDBOperator(_DataBaseTypeID); } } return(myDB); }
private bool IsConnect() { DataBaseAgent.DBOperator myDB = GetDBOperator(); try { myDB.Open(); myDB.Close(); return(true); } catch (Exception exp) { myDB.RollbackTrans(); myDB.Close(); return(false); } }
private DataSet Read() { DataBaseAgent.DBOperator myDB = GetDBOperator(); try { myDB.Open(); myDB.BeginTrans(); DataSet ds = myDB.ReadData(_SqlString, _SqlCommandType, _SqlStringParams, _SqlStringParamsValues); myDB.Close(); return(ds); } catch (Exception exp) { //myDB.RollbackTrans(); myDB.Close(); WriteLog(exp.ToString(), "Read", 1, 5); //throw new Exception(exp.Message); //new Logs.LogManage().WriteLogs(exp.Message);//日志模块还没有完成 return(new DataSet()); } }
private int Write() { DataBaseAgent.DBOperator myDB = GetDBOperator(); try { myDB.Open(); myDB.BeginTrans(); int count = myDB.WriteData(_SqlString, _SqlCommandType, _SqlStringParams, _SqlStringParamsValues); myDB.CommitTrans(); myDB.Close(); return(count); } catch (Exception exp) { //myDB.RollbackTrans(); myDB.Close(); WriteLog(exp.ToString(), "Write", 1, 5); //throw new Exception(exp.Message); //new Logs.LogManage().WriteLogs(exp.Message);//日志模块还没有完成 return(0); } }