public int Update() { if (this.id < 1) { return(-1); } if (this.device_id < 1) { return(-1); } DBConn dBConn = null; DbCommand dbCommand = null; try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; string commandText = "update line_info set max_voltage=?,min_voltage=?,max_power=?,min_power=?,max_current=?,min_current=? where id=" + this.id; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("@max_voltage", this.max_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_voltage", this.min_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_power", this.max_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_power", this.min_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_current", this.max_current, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_current", this.min_current, dbCommand)); int result = dbCommand.ExecuteNonQuery(); dbCommand.Parameters.Clear(); DBCacheStatus.Device = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_Device" }); return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(-1); }
public static long DeleteLogByRecords(int records) { long result = 0L; string commandText = "select min(log.id) from (select top " + records + " id from logrecords order by id desc ) as log"; string arg = "delete from logrecords where id < "; DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getLogConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; if (DBUrl.SERVERMODE) { commandText = "select min(logg.id) from (select id from logrecords order by id desc LIMIT " + records + " OFFSET 0 ) as logg"; } dbCommand.CommandText = commandText; object obj = dbCommand.ExecuteScalar(); if (obj != null && obj != DBNull.Value) { int num = 0; try { num = Convert.ToInt32(obj); } catch { } dbCommand.CommandText = arg + num; result = (long)dbCommand.ExecuteNonQuery(); } dbCommand.Dispose(); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(result); }
public static bool SetEventInfo(DataTable eventlist) { bool result = false; DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); foreach (DataRow dataRow in eventlist.Rows) { dbCommand.CommandType = CommandType.Text; dbCommand.CommandText = string.Concat(new object[] { "update event_info set logflag = ", Convert.ToInt16(dataRow["logflag"]), ", mailflag = ", Convert.ToInt16(dataRow["mailflag"]), " where eventid = '", Convert.ToString(dataRow["eventid"]), "' " }); dbCommand.ExecuteNonQuery(); } dbCommand.Dispose(); DBCacheStatus.Event = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_Event" }); return(true); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(result); }
public static int InsertRackEffect(string str_sql, DateTime dt_inserttime) { if (DBUrl.SERVERMODE) { WorkQueue <string> .getInstance_rackeffect().WorkSequential = true; WorkQueue <string> .getInstance_rackeffect().EnqueueItem(str_sql); return(1); } if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL")) { WorkQueue <string> .getInstance_rackeffect().WorkSequential = true; WorkQueue <string> .getInstance_rackeffect().EnqueueItem(str_sql); return(1); } DBConn dBConn = null; DbCommand dbCommand = null; try { dBConn = DBConnPool.getThermalConnection(); if (dBConn != null && dBConn.con != null) { dbCommand = dBConn.con.CreateCommand(); } dbCommand.CommandText = str_sql.Replace("'", "#"); dbCommand.ExecuteNonQuery(); dbCommand.Dispose(); dBConn.Close(); return(1); } catch (Exception ex) { try { dbCommand.Dispose(); } catch { } try { dBConn.Close(); } catch { } DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Generate RackEffect Error : " + ex.Message + "\n" + ex.StackTrace); } return(-1); }
public static int InsertBillReport(string str_title, string str_writer, DateTime dt_time, string str_path) { int result = -1; DBConn dBConn = null; DbCommand dbCommand = null; try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); if (DBUrl.SERVERMODE) { string commandText = "insert into reportbill(Title,Writer,ReportTime,ReportPath) values(?Title,?Writer,?ReportTime,?ReportPath)"; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("?Title", str_title, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?Writer", str_writer, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?ReportTime", dt_time.ToString("yyyy-MM-dd HH:mm:ss"), dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?ReportPath", str_path, dbCommand)); } else { string commandText = "insert into reportbill(Title,Writer,ReportTime,ReportPath) values(?,?,?,?)"; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("@Title", str_title, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@Writer", str_writer, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@ReportTime", dt_time.ToString("yyyy-MM-dd HH:mm:ss"), dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@ReportPath", str_path, dbCommand)); } result = dbCommand.ExecuteNonQuery(); return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { if (dbCommand != null) { dbCommand.Dispose(); } if (dBConn.con != null) { dBConn.Close(); } } return(result); }
public static int UpdateGroupStatus(int i_selectflag, string str_groups) { int result = -1; DBConn dBConn = null; DbCommand dbCommand = null; try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; string commandText = string.Concat(new object[] { "update data_group set isselect = ", i_selectflag, " where id in (", str_groups, " )" }); dbCommand.CommandText = commandText; result = dbCommand.ExecuteNonQuery(); DBCacheStatus.Group = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_Group" }); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(result); }
public static void DeleteOverallRemainLastSomeHours(int hours, DateTime currentTime) { DateTime dateTime = currentTime.AddHours((double)(-(double)hours)); Convert.ToDateTime(dateTime.ToString("yyyy-MM-dd HH:mm:ss")); string text = "delete from rack_effect where insert_time < #" + dateTime.ToString("yyyy-MM-dd HH:mm:ss") + "#"; if (DBUrl.SERVERMODE || DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL")) { WorkQueue <string> .getInstance_rackeffect().WorkSequential = true; WorkQueue <string> .getInstance_rackeffect().EnqueueItem(text); return; } DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getThermalConnection(); if (dBConn != null && dBConn.con != null) { dbCommand = dBConn.con.CreateCommand(); dbCommand.CommandType = CommandType.Text; dbCommand.CommandText = text; dbCommand.ExecuteNonQuery(); } dbCommand.Dispose(); dBConn.Close(); } catch (Exception ex) { try { dbCommand.Dispose(); } catch { } try { dBConn.Close(); } catch { } DebugCenter.GetInstance().appendToFile("Delete Rack effect: " + ex.Message + "\n" + ex.StackTrace); } }
public static long DeleteLogByDay(int iDays) { long result = 0L; DateTime dateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")).AddDays((double)(-(double)(iDays - 1))); new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0); string commandText = "delete from logrecords where ticks < #" + DateTime.Now.AddHours((double)(-24 * iDays)).ToString("yyyy-MM-dd HH:mm:ss") + "#"; DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getLogConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; dbCommand.CommandText = commandText; if (DBUrl.SERVERMODE) { dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'"); } result = (long)dbCommand.ExecuteNonQuery(); } dbCommand.Dispose(); } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(result); }
public int update() { int num = -1; DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getConnection(); string commandText = "update sys_para set para_value = '" + this.maintenance + "' where para_name = 'LIMITTYPE' and para_type = 'int' "; string commandText2 = "update sys_para set para_value = '" + this.days + "' where para_name = 'DAYLIMIT' and para_type = 'int' "; string commandText3 = "update sys_para set para_value = '" + this.recordNum + "' where para_name = 'RECORDSLIMIT' and para_type = 'int' "; string commandText4 = "update sys_para set para_value = '" + this.pageSize + "' where para_name = 'PAGESIZE' and para_type = 'int' "; string commandText5 = "update sys_para set para_value = '" + this.saveRange + "' where para_name = 'SAVERANGE' and para_type = 'int' "; dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; dbCommand.CommandText = commandText; num = dbCommand.ExecuteNonQuery(); if (num < 1) { int result = num; return(result); } dbCommand.CommandText = commandText2; num = dbCommand.ExecuteNonQuery(); if (num < 1) { int result = num; return(result); } dbCommand.CommandText = commandText3; num = dbCommand.ExecuteNonQuery(); if (num < 1) { int result = num; return(result); } dbCommand.CommandText = commandText4; num = dbCommand.ExecuteNonQuery(); if (num < 1) { int result = num; return(result); } dbCommand.CommandText = commandText5; num = dbCommand.ExecuteNonQuery(); dbCommand.Dispose(); DBCacheStatus.SystemParameter = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_SystemParameter" }); } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(num); }
public void workQueue_DBWork(object sender, WorkQueue <string> .EnqueueEventArgs e) { try { if (!DBWorkThread.STOP_THREAD) { string text = ""; if (TaskStatus.GetDBStatus() == -1) { try { this.con.Close(); this.con.Dispose(); this.con = null; } catch { } } if (this.con == null) { if (DBUrl.SERVERMODE) { string cONNECT_STRING = DBUrl.CONNECT_STRING; string[] array = cONNECT_STRING.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); this.con = new MySqlConnection(string.Concat(new string[] { "Database=eco", DBUrl.SERVERID, ";Data Source=", array[0], ";Port=", array[1], ";User Id=", array[2], ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=50;Default Command Timeout=0;charset=utf8;" })); this.con.Open(); } else { if (DBWorkThread.STOP_THREAD) { return; } switch (this.DBTYPE) { case 0: break; case 1: try { this.con = new MySqlConnection(string.Concat(new object[] { "Database=", DBUrl.DB_CURRENT_NAME, ";Data Source=", DBUrl.CURRENT_HOST_PATH, ";Port=", DBUrl.CURRENT_PORT, ";User Id=", DBUrl.CURRENT_USER_NAME, ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=150;Default Command Timeout=0;charset=utf8;" })); this.con.Open(); DebugCenter.GetInstance().clearStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true); goto IL_2A6; } catch (Exception e2) { DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true); DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e2, false, " ")); goto IL_2A6; } break; default: goto IL_2A6; } try { "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBUrl.CURRENT_HOST_PATH + ";Jet OLEDB:Database Password="******"Waiting DBConnection : " + num); num++; } DBConn dynaConnection = DBConnPool.getDynaConnection(); if (dynaConnection != null) { this.con = dynaConnection.con; } else { this.con = null; } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } } } try { IL_2A6: if (this.con.State != ConnectionState.Open) { try { this.con.Close(); this.con.Open(); } catch (Exception e3) { this.con = null; DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true); DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e3, false, " ")); } } } catch { } try { if (this.cmd != null) { this.cmd.Dispose(); } } catch (Exception ex2) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex2.Message + "\n" + ex2.StackTrace); } try { string item = e.Item; if (item.StartsWith("PDEND")) { InSnergyGateway.Need_Calculate_PUE = true; DBWorkThread.NEEDLOG = true; } else { if (item.IndexOf("END") > -1) { DBCacheStatus.LastInsertTime = DateTime.Now; DBWorkThread.NEEDLOG = true; } else { this.cmd = this.con.CreateCommand(); int num2 = this.NeedU2I(item); if (this.DBTYPE == 1 || DBUrl.SERVERMODE) { string commandText = item.Replace("#", "'"); this.cmd.CommandText = commandText; } else { this.cmd.CommandText = item; } text = this.cmd.CommandText; if (!DBWorkThread.STOP_THREAD) { int num3 = this.cmd.ExecuteNonQuery(); if (num3 < 1 && num2 > 0) { if (this.DBTYPE == 1 || DBUrl.SERVERMODE) { string text2 = this.ChgU2I(item, num2); text2 = text2.Replace("#", "'"); this.cmd.CommandText = text2; } else { this.cmd.CommandText = this.ChgU2I(item, num2); } text = this.cmd.CommandText; if (DBWorkThread.STOP_THREAD) { return; } this.cmd.ExecuteNonQuery(); } this.cmd.Dispose(); if (TaskStatus.GetDBStatus() == -1) { try { this.con.Close(); } catch { } try { this.con.Dispose(); } catch { } this.con = null; } } } } } catch (Exception ex3) { if (ex3.GetType().FullName.Equals("MySql.Data.MySqlClient.MySqlException")) { string tableName = DBUtil.GetTableName(text); if (tableName != null && tableName.Length > 0) { DBUtil.SetMySQLInfo(tableName); DebugCenter.GetInstance().appendToFile("MySQL database is marked as crashed, EcoSensor Monitor Service will be shutdown "); DBUtil.StopService(); } } if (ex3.Message.ToLower().IndexOf("fatal error encountered during command execution") < 0) { if (text.IndexOf("rack_effect") > 0) { try { DBTools.Write_DBERROR_Log(); goto IL_56F; } catch { goto IL_56F; } } if (DBWorkThread.NEEDLOG) { try { DBTools.Write_DBERROR_Log(); } catch { } DBWorkThread.NEEDLOG = false; } IL_56F: DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex3.Message + "\n" + ex3.StackTrace); } try { this.cmd.Dispose(); this.con.Close(); } catch (Exception) { } this.con = null; } } } finally { try { if (this.con != null) { this.con.Close(); } this.con = null; } catch { } } }
public DBWorkThread(int i_type) { if (DBUrl.SERVERMODE) { string cONNECT_STRING = DBUrl.CONNECT_STRING; string[] array = cONNECT_STRING.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); this.con = new MySqlConnection(string.Concat(new string[] { "Database=eco", DBUrl.SERVERID, ";Data Source=", array[0], ";Port=", array[1], ";User Id=", array[2], ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=50;Default Command Timeout=0;charset=utf8;" })); this.con.Open(); } else { this.DBTYPE = i_type; switch (this.DBTYPE) { case 0: break; case 1: try { this.con = new MySqlConnection(string.Concat(new object[] { "Database=", DBUrl.DB_CURRENT_NAME, ";Data Source=", DBUrl.CURRENT_HOST_PATH, ";Port=", DBUrl.CURRENT_PORT, ";User Id=", DBUrl.CURRENT_USER_NAME, ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=150;Default Command Timeout=0;charset=utf8;" })); this.con.Open(); DebugCenter.GetInstance().clearStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true); goto IL_25B; } catch (Exception e) { DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true); DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e, false, " ")); goto IL_25B; } break; default: goto IL_25B; } try { int num = 0; while (TaskStatus.GetDBStatus() == -1 && num < 600) { Thread.Sleep(50); DebugCenter.GetInstance().appendToFile(this.ToString() + "Waiting DBConnection : " + num); num++; } DBConn dynaConnection = DBConnPool.getDynaConnection(); if (dynaConnection != null) { this.con = dynaConnection.con; } else { this.con = null; } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } } IL_25B: this.debug = DebugCenter.GetInstance(); }
public static int DeleteByName(string str_zonename) { DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { string commandText = "select * from zone_info z inner join group_detail g on z.id = g.dest_id where z.zone_nm = '" + str_zonename + "' and g.grouptype = 'zone'"; dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; dbCommand.CommandText = commandText; DbDataAdapter dataAdapter = DBConn.GetDataAdapter(dBConn.con); dataAdapter.SelectCommand = dbCommand; DataTable dataTable = new DataTable(); dataAdapter.Fill(dataTable); if (dataTable.Rows.Count > 0) { string commandText2 = string.Concat(new object[] { "delete from group_detail where grouptype = 'zone' and group_id = ", dataTable.Rows[0]["group_id"], " and dest_id =", dataTable.Rows[0]["dest_id"] }); dbCommand.CommandText = commandText2; dbCommand.ExecuteNonQuery(); } string commandText3 = "delete from zone_info where zone_nm = '" + str_zonename + "'"; dbCommand.CommandText = commandText3; int result = dbCommand.ExecuteNonQuery(); dbCommand.Parameters.Clear(); DBCacheStatus.ZONE = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_ZONE" }); return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(-1); }
public static int CreateZoneInfo(string str_name, string str_racklist, int i_sx, int i_sy, int i_ex, int i_ey, string str_color) { DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; if (DBUrl.SERVERMODE) { string commandText = "insert into zone_info ( zone_nm,racks,sx,sy,ex,ey,color,reserve ) values(?zone_nm,?racks,?sx,?sy,?ex,?ey,?color,?reserve)"; dbCommand.CommandText = commandText; dbCommand.Parameters.Clear(); dbCommand.Parameters.Add(DBTools.GetParameter("?zone_nm", str_name, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?racks", str_racklist, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?sx", i_sx, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?sy", i_sy, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?ex", i_ex, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?ey", i_ey, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?color", str_color, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?reserve", Convert.ToInt32("0"), dbCommand)); } else { string commandText = "insert into zone_info ( zone_nm,racks,sx,sy,ex,ey,color,reserve ) values(?,?,?,?,?,?,?,?)"; dbCommand.CommandText = commandText; dbCommand.Parameters.Clear(); dbCommand.Parameters.Add(DBTools.GetParameter("@zone_nm", str_name, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@racks", str_racklist, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@sx", i_sx, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@sy", i_sy, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@ex", i_ex, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@ey", i_ey, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@color", str_color, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@reserve", Convert.ToInt32("0"), dbCommand)); } int num = dbCommand.ExecuteNonQuery(); dbCommand.Parameters.Clear(); DBCacheStatus.ZONE = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_ZONE" }); int result = num; return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); if (ex.Message.IndexOf(" duplicate values ") > 0) { int result = -2; return(result); } } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(-1); }
public static int GetRowCount(int i_range_type, DateTime dt_start, DateTime dt_end) { DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); long arg_0F_0 = dt_start.Ticks; long arg_17_0 = dt_end.Ticks; try { dBConn = DBConnPool.getLogConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; switch (i_range_type) { case 0: dbCommand.CommandText = "select count(id) from logrecords"; break; case 1: dbCommand.CommandText = string.Concat(new string[] { "select count(id) from logrecords where ticks >= #", dt_start.ToString("yyyy-MM-dd HH:mm:ss"), "# and ticks <= #", dt_end.ToString("yyyy-MM-dd HH:mm:ss"), "# " }); break; case 2: dbCommand.CommandText = string.Concat(new string[] { "select count(id) from logrecords where ticks <= #", dt_start.ToString("yyyy-MM-dd HH:mm:ss"), "# or ticks >= #", dt_end.ToString("yyyy-MM-dd HH:mm:ss"), "# " }); break; } if (DBUrl.SERVERMODE) { dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'"); } object obj = dbCommand.ExecuteScalar(); dbCommand.Dispose(); int result; if (obj == null || obj is DBNull || Convert.ToInt32(obj) < 1) { result = -1; return(result); } result = Convert.ToInt32(obj); return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(-1); }
public static DataTable GetPrePage(int i_key, int i_range_type, DateTime dt_start, DateTime dt_end, int i_pagenum, int i_pagesize, int i_total) { DateTime now = DateTime.Now; DataTable dataTable = new DataTable(); DataColumn dataColumn = new DataColumn("insert_time"); dataColumn.DataType = Type.GetType("System.String"); dataTable.Columns.Add(dataColumn); DataColumn dataColumn2 = new DataColumn("eventid"); dataColumn2.DataType = Type.GetType("System.String"); dataTable.Columns.Add(dataColumn2); DataColumn dataColumn3 = new DataColumn("parametervalue"); dataColumn3.DataType = Type.GetType("System.String"); dataTable.Columns.Add(dataColumn3); DataColumn dataColumn4 = new DataColumn("id"); dataColumn4.DataType = Type.GetType("System.Int32"); dataTable.Columns.Add(dataColumn4); DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); long arg_BF_0 = dt_start.Ticks; long arg_C7_0 = dt_end.Ticks; string text = ""; switch (i_range_type) { case 0: text = string.Concat(new object[] { " 2=2 id > ", i_key, " and ticks <= #", dt_end.ToString("yyyy-MM-dd HH:mm:ss"), "# " }); break; case 1: text = string.Concat(new object[] { " 2=2 id > ", i_key, " and ticks >= #", dt_start.ToString("yyyy-MM-dd HH:mm:ss"), "# and ticks <= #", dt_end.ToString("yyyy-MM-dd HH:mm:ss"), "# " }); break; case 2: text = string.Concat(new object[] { " 2=2 id > ", i_key, " and (ticks <= #", dt_start.ToString("yyyy-MM-dd HH:mm:ss"), "# or ticks >= #", dt_end.ToString("yyyy-MM-dd HH:mm:ss"), "# )" }); break; } try { dBConn = DBConnPool.getLogConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; long num = 0L; long num2 = 0L; DataTable dataTable2 = new DataTable(); string commandText; if (i_pagenum * i_pagesize > i_total) { int num3 = i_pagenum * i_pagesize - i_total; commandText = string.Concat(new object[] { "select top ", i_pagesize - num3, " id from (select top ", i_pagesize - num3, " id from logrecords where ", text, " order by id asc) order by id desc" }); } else { commandText = string.Concat(new object[] { "select id from ( select top ", i_pagesize, " id from logrecords where ", text, " order by id asc ) order by id desc" }); } dbCommand.CommandText = commandText; if (DBUrl.SERVERMODE) { dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'"); } DbDataReader dbDataReader = dbCommand.ExecuteReader(); if (dbDataReader.HasRows) { dataTable2 = DBConn.ConvertOleDbReaderToDataTable(dbDataReader); } dbDataReader.Close(); DataRow[] array = dataTable2.Select("", "id DESC"); if (array.Length > 0) { num2 = Convert.ToInt64(array[0]["id"]); num = Convert.ToInt64(array[array.Length - 1]["id"]); } dbCommand.CommandText = string.Concat(new object[] { "select * from logrecords where id >= ", num, " and id <= ", num2, " order by id desc" }); if (DBUrl.SERVERMODE) { dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'"); } DbDataReader dbDataReader2 = dbCommand.ExecuteReader(); while (dbDataReader2.Read()) { string value = Convert.ToDateTime(dbDataReader2.GetValue(1)).ToString("yyyy-MM-dd HH:mm:ss"); string @string = dbDataReader2.GetString(2); string string2 = dbDataReader2.GetString(3); int num4 = Convert.ToInt32(dbDataReader2.GetValue(0)); DataRow dataRow = dataTable.NewRow(); dataRow["insert_time"] = value; dataRow["eventid"] = @string; dataRow["parametervalue"] = string2; dataRow["id"] = num4; dataTable.Rows.Add(dataRow); } dbDataReader2.Close(); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } Console.WriteLine("million sencods is : " + (DateTime.Now - now).TotalMilliseconds.ToString()); return(dataTable); }
public static DataTable GetSearchResult(int i_range_type, DateTime dt_start, DateTime dt_end, int i_pagenum, int i_pagesize, int i_total) { DateTime now = DateTime.Now; DataTable dataTable = new DataTable(); DataColumn dataColumn = new DataColumn("insert_time"); dataColumn.DataType = Type.GetType("System.String"); dataTable.Columns.Add(dataColumn); DataColumn dataColumn2 = new DataColumn("eventid"); dataColumn2.DataType = Type.GetType("System.String"); dataTable.Columns.Add(dataColumn2); DataColumn dataColumn3 = new DataColumn("parametervalue"); dataColumn3.DataType = Type.GetType("System.String"); dataTable.Columns.Add(dataColumn3); DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); long arg_95_0 = dt_start.Ticks; long arg_9D_0 = dt_end.Ticks; string text = ""; switch (i_range_type) { case 0: text = " 2=2 "; break; case 1: text = string.Concat(new string[] { " 2=2 and ticks >= #", dt_start.ToString("yyyy-MM-dd HH:mm:ss"), "# and ticks <= #", dt_end.ToString("yyyy-MM-dd HH:mm:ss"), "# " }); break; case 2: text = string.Concat(new string[] { " 2=2 and (ticks <= #", dt_start.ToString("yyyy-MM-dd HH:mm:ss"), "# or ticks >= #", dt_end.ToString("yyyy-MM-dd HH:mm:ss"), "# )" }); break; } try { dBConn = DBConnPool.getLogConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; if (i_pagenum == 0 && i_pagesize == 0) { dbCommand.CommandText = "select ticks,eventid,logpara from logrecords where " + text + " order by id desc"; if (DBUrl.SERVERMODE) { dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'"); } DbDataReader dbDataReader = dbCommand.ExecuteReader(); while (dbDataReader.Read()) { string value = Convert.ToDateTime(dbDataReader.GetValue(0)).ToString("yyyy-MM-dd HH:mm:ss"); string @string = dbDataReader.GetString(1); string string2 = dbDataReader.GetString(2); DataRow dataRow = dataTable.NewRow(); dataRow["insert_time"] = value; dataRow["eventid"] = @string; dataRow["parametervalue"] = string2; dataTable.Rows.Add(dataRow); } dbDataReader.Close(); } else { if (LogInfo.m_type == i_range_type && DateTime.Compare(LogInfo.mdt_start, dt_start) == 0 && DateTime.Compare(LogInfo.mdt_end, dt_end) == 0) { long num; long num2; if (i_pagenum * i_pagesize > i_total) { num = Convert.ToInt64(LogInfo.ht_cache[(i_pagenum - 1) * i_pagesize + 1]); num2 = Convert.ToInt64(LogInfo.ht_cache[i_total]); } else { num = Convert.ToInt64(LogInfo.ht_cache[(i_pagenum - 1) * i_pagesize + 1]); num2 = Convert.ToInt64(LogInfo.ht_cache[i_pagenum * i_pagesize]); } dbCommand.CommandText = string.Concat(new object[] { "select * from logrecords where id >= ", num2, " and id <= ", num, " order by id desc" }); if (DBUrl.SERVERMODE) { dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'"); } DbDataReader dbDataReader2 = dbCommand.ExecuteReader(); while (dbDataReader2.Read()) { string value2 = Convert.ToDateTime(dbDataReader2.GetValue(1)).ToString("yyyy-MM-dd HH:mm:ss"); string string3 = dbDataReader2.GetString(2); string string4 = dbDataReader2.GetString(3); DataRow dataRow2 = dataTable.NewRow(); dataRow2["insert_time"] = value2; dataRow2["eventid"] = string3; dataRow2["parametervalue"] = string4; dataTable.Rows.Add(dataRow2); } dbDataReader2.Close(); } else { LogInfo.m_type = i_range_type; LogInfo.mdt_start = dt_start; LogInfo.mdt_end = dt_end; LogInfo.ht_cache = new Hashtable(); dbCommand.CommandText = "select id from logrecords where " + text + " order by id desc"; if (DBUrl.SERVERMODE) { dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'"); } DbDataReader dbDataReader3 = dbCommand.ExecuteReader(); int num3 = 1; while (dbDataReader3.Read()) { LogInfo.ht_cache.Add(num3, dbDataReader3.GetValue(0)); num3++; } dbDataReader3.Close(); new DataTable(); long num5; long num6; if (i_pagenum * i_pagesize > i_total) { int num4 = i_pagenum * i_pagesize - i_total; string.Concat(new object[] { "select top ", i_pagesize - num4, " id from (select top ", i_pagesize - num4, " id from logrecords where ", text, " order by id asc) order by id desc" }); num5 = Convert.ToInt64(LogInfo.ht_cache[(i_pagenum - 1) * i_pagesize + 1]); num6 = Convert.ToInt64(LogInfo.ht_cache[i_total]); } else { num5 = Convert.ToInt64(LogInfo.ht_cache[(i_pagenum - 1) * i_pagesize + 1]); num6 = Convert.ToInt64(LogInfo.ht_cache[i_pagenum * i_pagesize]); if (i_pagenum * i_pagesize > i_total / 2) { string.Concat(new object[] { "select top ", i_pagesize, " id from (select top ", i_total - i_pagenum * i_pagesize + i_pagesize, " id from logrecords where ", text, " order by id asc) order by id desc" }); } else { string.Concat(new object[] { "select id from (select top ", i_pagesize, " id from (select top ", i_pagenum * i_pagesize, " id from logrecords where ", text, " order by id desc) order by id asc) order by id desc" }); } } dbCommand.CommandText = string.Concat(new object[] { "select * from logrecords where id >= ", num6, " and id <= ", num5, " order by id desc" }); if (DBUrl.SERVERMODE) { dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'"); } DbDataReader dbDataReader4 = dbCommand.ExecuteReader(); while (dbDataReader4.Read()) { string value3 = Convert.ToDateTime(dbDataReader4.GetValue(1)).ToString("yyyy-MM-dd HH:mm:ss"); string string5 = dbDataReader4.GetString(2); string string6 = dbDataReader4.GetString(3); DataRow dataRow3 = dataTable.NewRow(); dataRow3["insert_time"] = value3; dataRow3["eventid"] = string5; dataRow3["parametervalue"] = string6; dataTable.Rows.Add(dataRow3); } dbDataReader4.Close(); } } dbCommand.Dispose(); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } Console.WriteLine("million sencods is : " + (DateTime.Now - now).TotalMilliseconds.ToString()); return(dataTable); }
public static int updatesetting4newdb(int i_port, string str_usr, string str_pwd) { DbConnection dbConnection = null; DbCommand dbCommand = new OleDbCommand(); int result; try { dbConnection = new MySqlConnection(string.Concat(new object[] { "Database=", DBUrl.DB_CURRENT_NAME, ";Data Source=127.0.0.1;Port=", i_port, ";User Id=", str_usr, ";Password="******";Default Command Timeout=0;charset=utf8;" })); dbConnection.Open(); dbCommand = new MySqlCommand(); dbCommand.Connection = dbConnection; string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "sysdb.mdb;Jet OLEDB:Database Password=^tenec0Sensor"; OleDbCommand oleDbCommand = new OleDbCommand(); using (OleDbConnection oleDbConnection = new OleDbConnection(connectionString)) { try { oleDbConnection.Open(); oleDbCommand.Connection = oleDbConnection; oleDbCommand.CommandType = CommandType.Text; oleDbCommand.CommandText = string.Concat(new object[] { "update dbsource set db_type='MYSQL',db_name='eco',host_path='127.0.0.1',port= ", i_port, ",user_name = '", str_usr, "',pwd='", str_pwd, "' where active_flag = 2 " }); int num = oleDbCommand.ExecuteNonQuery(); if (num < 0) { result = -5; return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); result = -5; return(result); } finally { oleDbCommand.Dispose(); } } DBConnPool.DisconnectDatabase(); DBUrl.initconfig(); result = 100; } catch (Exception ex2) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex2.Message + "\n" + ex2.StackTrace); result = -5; } finally { dbCommand.Dispose(); if (dbConnection != null) { dbConnection.Close(); } } return(result); }
public int UpdateSetting() { DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; if (DBUrl.SERVERMODE) { string commandText = "update smtpsetting set EnableSMTP=?EnableSMTP , ServerAddress=?ServerAddress , PortId=?PortId , EmailFrom=?EmailFrom , EmailTo=?EmailTo , SendEvent=?SendEvent , EnableAuth=?EnableAuth, Account=?Account, UserPwd=?UserPwd "; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("?EnableSMTP", this.smtp_enable, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?ServerAddress", this.smtp_server, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?PortId", this.smtp_port, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?EmailFrom", this.smtp_from, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?EmailTo", this.smtp_to, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?SendEvent", this.smtp_event, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?EnableAuth", this.smtp_auth, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?Account", this.smtp_account, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?UserPwd", this.smtp_pwd, dbCommand)); } else { string commandText = "update smtpsetting set EnableSMTP=? , ServerAddress=? , PortId=? , EmailFrom=? , EmailTo=? , SendEvent=? , EnableAuth=?, Account=?, UserPwd=? "; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("@EnableSMTP", this.smtp_enable, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@ServerAddress", this.smtp_server, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@PortId", this.smtp_port, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@EmailFrom", this.smtp_from, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@EmailTo", this.smtp_to, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@SendEvent", this.smtp_event, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@EnableAuth", this.smtp_auth, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@Account", this.smtp_account, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@UserPwd", this.smtp_pwd, dbCommand)); } int num = dbCommand.ExecuteNonQuery(); dbCommand.Parameters.Clear(); DBCacheStatus.Smtp = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_Smtp" }); int result = num; return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); if (ex.Message.IndexOf(" duplicate values ") > 0) { int result = -2; return(result); } } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(-1); }
public int Save() { DbCommand dbCommand = null; DBConn dBConn = null; try { int result; if (this.gid == null || this.gid.Length < 1 || this.gid.Equals("0")) { result = -1; return(result); } if (this.bid == null || this.bid.Length < 1 || this.bid.Equals("0")) { result = -1; return(result); } "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBUrl.DEFAULT_HOST_PATH + ";Jet OLEDB:Database Password="******"update gatewaytable set eleflag=", current.ElectricityUsage, ",capacity=", current.Capacity, " where slevel=2 and gid='", this.gid, "' and bid='", this.bid, "' and sid='", current.SubmeterID, "' " }); dbCommand.ExecuteNonQuery(); } dbCommand.CommandText = string.Concat(new string[] { "update gatewaytable set disname = '", this.bname, "',location='", this.location, "' where slevel = 1 and gid = '", this.gid, "' and bid='", this.bid, "' " }); int num = dbCommand.ExecuteNonQuery(); dbCommand.Transaction.Commit(); dbCommand.Dispose(); dBConn.Close(); result = num; return(result); } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); if (dbCommand != null) { try { dbCommand.Transaction.Rollback(); dbCommand.Dispose(); } catch (Exception) { } } if (dBConn.con != null) { try { dBConn.Close(); } catch (Exception) { } } } return(-1); }
public int Update() { if (this.id < 1) { return(-1); } if (this.device_id < 1) { return(-1); } DBConn dBConn = null; DbCommand dbCommand = null; try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; if (DBUrl.SERVERMODE) { string commandText = "update bank_info set port_nums=?port_nums,bank_nm=?bank_nm,voltage=?voltage,max_voltage=?max_voltage,min_voltage=?min_voltage,max_power_diss=?max_power_diss,min_power_diss=?min_power_diss,max_power=?max_power,min_power=?min_power,max_current=?max_current,min_current=?min_current where id=" + this.id; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("?port_nums", this.portlists, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?bank_nm", this.bank_nm, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?voltage", this.voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?max_voltage", this.max_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?min_voltage", this.min_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?max_power_diss", this.max_power_diss, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?min_power_diss", this.min_power_diss, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?max_power", this.max_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?min_power", this.min_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?max_current", this.max_current, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?min_current", this.min_current, dbCommand)); } else { if (this.bank_nm != null && this.bank_nm.Equals("\r\n")) { string commandText = "update bank_info set port_nums=?,voltage=?,max_voltage=?,min_voltage=?,max_power_diss=?,min_power_diss=?,max_power=?,min_power=?,max_current=?,min_current=? where id=" + this.id; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("@port_nums", this.portlists, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@voltage", this.voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_voltage", this.max_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_voltage", this.min_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_power_diss", this.max_power_diss, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_power_diss", this.min_power_diss, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_power", this.max_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_power", this.min_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_current", this.max_current, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_current", this.min_current, dbCommand)); } else { string commandText = "update bank_info set port_nums=?,bank_nm=?,voltage=?,max_voltage=?,min_voltage=?,max_power_diss=?,min_power_diss=?,max_power=?,min_power=?,max_current=?,min_current=? where id=" + this.id; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("@port_nums", this.portlists, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@bank_nm", this.bank_nm, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@voltage", this.voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_voltage", this.max_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_voltage", this.min_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_power_diss", this.max_power_diss, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_power_diss", this.min_power_diss, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_power", this.max_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_power", this.min_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_current", this.max_current, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_current", this.min_current, dbCommand)); } } int result = dbCommand.ExecuteNonQuery(); dbCommand.Parameters.Clear(); DBCacheStatus.Device = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_Device" }); return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(-1); }
public int Update() { if (this.id < 1) { return(-1); } if (this.device_id < 1) { return(-1); } DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; if (DBUrl.SERVERMODE) { string commandText = "update device_sensor_info set sensor_nm=?sensor_nm,max_humidity=?max_humidity,min_humidity=?min_humidity,max_temperature=?max_temperature,min_temperature=?min_temperature,max_press=?max_press,min_press=?min_press,sensor_type=?sensor_type,location_type=?location_type where id=" + this.id; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("?sensor_nm", this.sensor_nm, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?max_humidity", this.max_humidity, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?min_humidity", this.min_humidity, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?max_temperature", this.max_temperature, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?min_temperature", this.min_temperature, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?max_press", this.max_press, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?min_press", this.min_press, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?sensor_type", this.sensor_type, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?location_type", this.sensor_locationtype, dbCommand)); } else { string commandText = "update device_sensor_info set sensor_nm=?,max_humidity=?,min_humidity=?,max_temperature=?,min_temperature=?,max_press=?,min_press=?,sensor_type=?,location_type=? where id=" + this.id; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("@sensor_nm", this.sensor_nm, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_humidity", this.max_humidity, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_humidity", this.min_humidity, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_temperature", this.max_temperature, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_temperature", this.min_temperature, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_press", this.max_press, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_press", this.min_press, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@sensor_type", this.sensor_type, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@location_type", this.sensor_locationtype, dbCommand)); } int result = dbCommand.ExecuteNonQuery(); dbCommand.Parameters.Clear(); DBCacheStatus.Device = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_Device" }); return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(-1); }
private static string getExpiryfromlog() { DBConn dBConn = null; DbCommand dbCommand = null; try { dBConn = DBConnPool.getLogConnection(); if (dBConn != null && dBConn.con != null) { string result; if (DBUtil.DetermineTableExist(dBConn.con, "sys_info")) { dbCommand = dBConn.con.CreateCommand(); dbCommand.CommandText = "select * from sys_info "; object obj = dbCommand.ExecuteScalar(); if (obj != null && obj != DBNull.Value) { string text = Convert.ToString(obj); if (text.Length == 0) { result = "VALUENULL"; return(result); } try { text = AESEncryptionUtility.Decrypt(text, "evaluate_date-time"); result = text; return(result); } catch { result = "FATAL"; return(result); } } result = "NOVALUE"; return(result); } result = "NOTABLE"; return(result); } } catch (Exception) { string result = ""; return(result); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { try { dBConn.close(); } catch { } } } return(""); }
public int UpdateZone() { DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; if (DBUrl.SERVERMODE) { string commandText = "update zone_info set zone_nm=?zone_nm , racks=?racks , sx=?sx ,sy=?sy, ex=?ex ,ey=?ey, color=?color , reserve=?reserve where id= " + this.z_id; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("?zone_nm", this.z_name, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?racks", this.z_racklist, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?sx", this.z_s_x, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?sy", this.z_s_y, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?ex", this.z_e_x, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?ey", this.z_e_y, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?color", this.z_color, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?reserve", this.z_reserve, dbCommand)); } else { string commandText = "update zone_info set zone_nm=? , racks=? , sx=? ,sy=?, ex=? ,ey=?, color=? , reserve=? where id= " + this.z_id; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("@zone_nm", this.z_name, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@racks", this.z_racklist, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@sx", this.z_s_x, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@sy", this.z_s_y, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@ex", this.z_e_x, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@ey", this.z_e_y, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@color", this.z_color, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@reserve", this.z_reserve, dbCommand)); } int num = dbCommand.ExecuteNonQuery(); dbCommand.Parameters.Clear(); DBCacheStatus.ZONE = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_ZONE" }); int result = num; return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); if (ex.Message.IndexOf(" duplicate values ") > 0) { int result = -2; return(result); } } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(-1); }
public static int DeleteGroupByID(long l_id) { DBConn dBConn = null; DbCommand dbCommand = null; try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; string commandText = "delete from group_detail where group_id = " + l_id; dbCommand.CommandText = commandText; int result = dbCommand.ExecuteNonQuery(); dbCommand.Parameters.Clear(); dbCommand.CommandText = "delete from groupcontroltask where groupid = " + l_id; result = dbCommand.ExecuteNonQuery(); dbCommand.CommandText = "delete from taskschedule where groupid = " + l_id; result = dbCommand.ExecuteNonQuery(); dbCommand.CommandText = "delete from data_group where id = " + l_id; result = dbCommand.ExecuteNonQuery(); dbCommand.CommandText = "delete from ugp where gid =" + l_id; dbCommand.ExecuteNonQuery(); DBCacheStatus.Group = true; DBCacheStatus.GroupTask = true; DBCacheStatus.User = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_Group" }); DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_GroupTask" }); DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_User" }); return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { dBConn.close(); } } return(-1); }
public static DataTable GetAllPortPD() { DataTable dataTable = new DataTable(); DBConn dBConn = null; DbCommand dbCommand = null; DbDataAdapter dbDataAdapter = null; string commandText; if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL") || DBUrl.SERVERMODE) { commandText = "select * from port_data_daily" + DateTime.Now.ToString("yyyyMMdd"); try { dBConn = DBConnPool.getDynaConnection(); if (dBConn != null && dBConn.con != null) { dbDataAdapter = DBConn.GetDataAdapter(dBConn.con); dbCommand = dBConn.con.CreateCommand(); dbCommand.CommandText = commandText; dbDataAdapter.SelectCommand = dbCommand; dbDataAdapter.Fill(dataTable); dbDataAdapter.Dispose(); dbCommand.Dispose(); dBConn.Close(); } return(dataTable); } catch (Exception) { try { dbDataAdapter.Dispose(); } catch { } try { dbCommand.Dispose(); } catch { } try { dBConn.Close(); } catch { } return(dataTable); } } commandText = "select * from port_data_daily "; try { dBConn = DBConnPool.getDynaConnection(DateTime.Now); if (dBConn != null && dBConn.con != null) { dbDataAdapter = new OleDbDataAdapter(); dbCommand = dBConn.con.CreateCommand(); dbCommand.CommandText = commandText; dbDataAdapter.SelectCommand = dbCommand; dbDataAdapter.Fill(dataTable); dbDataAdapter.Dispose(); dbCommand.Dispose(); dBConn.Close(); } } catch (Exception) { try { dbDataAdapter.Dispose(); } catch { } try { dbCommand.Dispose(); } catch { } try { dBConn.Close(); } catch { } } return(dataTable); }
public int Update() { if (this.id < 1) { return(-1); } if (this.device_id < 1) { return(-1); } DBConn dBConn = null; DbCommand dbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { dbCommand = DBConn.GetCommandObject(dBConn.con); dbCommand.CommandType = CommandType.Text; if (DBUrl.SERVERMODE) { string commandText = "update port_info set port_nm=?port_nm,port_confirmation=?port_confirmation,port_ondelay_time=?port_ondelay_time,port_offdelay_time=?port_offdelay_time,max_voltage=?max_voltage,min_voltage=?min_voltage,max_power_diss=?max_power_diss,min_power_diss=?min_power_diss,max_power=?max_power,min_power=?min_power,max_current=?max_current,min_current=?min_current,shutdown_method=?shutdown_method ,mac=?mac where id=" + this.id; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("?port_nm", this.port_nm, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?port_confirmation", this.port_confirmation, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?port_ondelay_time", this.port_ondelay_time, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?port_offdelay_time", this.port_offdelay_time, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?max_voltage", this.max_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?min_voltage", this.min_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?max_power_diss", this.max_power_diss, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?min_power_diss", this.min_power_diss, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?max_power", this.max_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?min_power", this.min_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?max_current", this.max_current, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?min_current", this.min_current, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?shutdown_method", this.shutdown_method, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("?mac", this.port_mac, dbCommand)); } else { string commandText = "update port_info set port_nm=?,port_confirmation=?,port_ondelay_time=?,port_offdelay_time=?,max_voltage=?,min_voltage=?,max_power_diss=?,min_power_diss=?,max_power=?,min_power=?,max_current=?,min_current=?,shutdown_method=? ,mac=? where id=" + this.id; dbCommand.CommandText = commandText; dbCommand.Parameters.Add(DBTools.GetParameter("@port_nm", this.port_nm, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@port_confirmation", this.port_confirmation, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@port_ondelay_time", this.port_ondelay_time, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@port_offdelay_time", this.port_offdelay_time, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_voltage", this.max_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_voltage", this.min_voltage, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_power_diss", this.max_power_diss, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_power_diss", this.min_power_diss, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_power", this.max_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_power", this.min_power, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@max_current", this.max_current, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@min_current", this.min_current, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@shutdown_method", this.shutdown_method, dbCommand)); dbCommand.Parameters.Add(DBTools.GetParameter("@mac", this.port_mac, dbCommand)); } int result = dbCommand.ExecuteNonQuery(); dbCommand.Parameters.Clear(); DBCacheStatus.Device = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_Device" }); return(result); } } catch (Exception ex) { DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); } finally { dbCommand.Dispose(); if (dBConn != null) { dBConn.close(); } } return(-1); }
private static int setExpiry4log(string strV, int iType) { DBConn dBConn = null; DbCommand dbCommand = null; try { dBConn = DBConnPool.getLogConnection(); if (dBConn != null && dBConn.con != null) { dbCommand = dBConn.con.CreateCommand(); switch (iType) { case 0: try { dbCommand.CommandText = "create table sys_info (sysid varchar(255) )"; dbCommand.ExecuteNonQuery(); dbCommand.CommandText = "insert into sys_info (sysid ) values ('" + strV + "' )"; dbCommand.ExecuteNonQuery(); int result = 1; return(result); } catch { int result = -1; return(result); } break; case 1: break; case 2: goto IL_A8; case 3: goto IL_CE; default: goto IL_F4; } try { dbCommand.CommandText = "insert into sys_info (sysid ) values ('" + strV + "' )"; dbCommand.ExecuteNonQuery(); int result = 1; return(result); } catch { int result = -1; return(result); } try { IL_A8: dbCommand.CommandText = "update sys_info set sysid = '" + strV + "'"; dbCommand.ExecuteNonQuery(); int result = 1; return(result); } catch { int result = -1; return(result); } try { IL_CE: dbCommand.CommandText = "update sys_info set sysid = '" + strV + "'"; dbCommand.ExecuteNonQuery(); int result = 1; return(result); } catch { int result = -1; return(result); } } IL_F4 :; } catch { int result = -1; return(result); } finally { try { dbCommand.Dispose(); } catch { } if (dBConn != null) { try { dBConn.close(); } catch { } } } return(-1); }
public int Update() { DBConn dBConn = null; OleDbCommand oleDbCommand = new OleDbCommand(); try { dBConn = DBConnPool.getConnection(); if (dBConn.con != null) { OleDbTransaction transaction = (OleDbTransaction)dBConn.con.BeginTransaction(); oleDbCommand = (OleDbCommand)dBConn.con.CreateCommand(); oleDbCommand.CommandType = CommandType.Text; oleDbCommand.Transaction = transaction; oleDbCommand.Parameters.Clear(); oleDbCommand.CommandText = "delete from group_detail where group_id = ? "; oleDbCommand.Parameters.Add("?", OleDbType.Integer); oleDbCommand.Prepare(); oleDbCommand.Parameters[0].Value = this.id; int result; try { oleDbCommand.ExecuteNonQuery(); } catch { oleDbCommand.Transaction.Rollback(); result = -1; return(result); } oleDbCommand.Parameters.Clear(); oleDbCommand.CommandText = string.Concat(new object[] { "insert into group_detail (group_id,grouptype,dest_id) values (", this.id, ",'", this.group_type, "',?)" }); oleDbCommand.Parameters.Add("?", OleDbType.Integer); oleDbCommand.Prepare(); string[] array = this.members.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string value = array2[i]; oleDbCommand.Parameters[0].Value = Convert.ToInt64(value); int num = oleDbCommand.ExecuteNonQuery(); if (num < 0) { oleDbCommand.Transaction.Rollback(); result = num; return(result); } } oleDbCommand.Parameters.Clear(); oleDbCommand.CommandText = "update data_group set groupname= ?, grouptype = ?, linecolor = ?, isselect = ?, thermalflag = ?, billflag = ? where id = " + this.id; oleDbCommand.Parameters.Add("?", OleDbType.VarChar); oleDbCommand.Parameters.Add("?", OleDbType.VarChar); oleDbCommand.Parameters.Add("?", OleDbType.VarChar); oleDbCommand.Parameters.Add("?", OleDbType.Integer); oleDbCommand.Parameters.Add("?", OleDbType.Integer); oleDbCommand.Parameters.Add("?", OleDbType.Integer); oleDbCommand.Parameters[0].Value = this.group_name; oleDbCommand.Parameters[1].Value = this.group_type; oleDbCommand.Parameters[2].Value = this.color; oleDbCommand.Parameters[3].Value = Convert.ToInt32(this.isselected); oleDbCommand.Parameters[4].Value = Convert.ToInt64(this.thermalflag); oleDbCommand.Parameters[5].Value = Convert.ToInt64(this.billflag); try { oleDbCommand.ExecuteNonQuery(); } catch { oleDbCommand.Transaction.Rollback(); result = -1; return(result); } oleDbCommand.Parameters.Clear(); oleDbCommand.Transaction.Commit(); DBCacheStatus.Group = true; DBCacheStatus.DBSyncEventSet(true, new string[] { "DBSyncEventName_Service_Group" }); result = 1; return(result); } } catch (Exception ex) { oleDbCommand.Transaction.Rollback(); DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace); if (ex.Message.IndexOf(" duplicate values ") > 0) { int result = -2; return(result); } } finally { oleDbCommand.Dispose(); if (dBConn != null) { dBConn.close(); } } return(-1); }