/// <summary> /// 更新一条数据 /// </summary> public bool Update(DTULogEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update DTU_log set "); strSql.Append("DTU_ID=@DTU_ID,"); strSql.Append("DTU_IP=@DTU_IP,"); strSql.Append("DTU_port=@DTU_port,"); strSql.Append("DTU_login_time=@DTU_login_time,"); strSql.Append("DTU_logout_time=@DTU_logout_time,"); strSql.Append("DTU_Logout_Value=@DTU_Logout_Value"); strSql.Append(" where Dl_ID=@Dl_ID"); SqlParameter[] parameters = { new SqlParameter("@DTU_ID", SqlDbType.NVarChar, 50), new SqlParameter("@DTU_IP", SqlDbType.NVarChar, 50), new SqlParameter("@DTU_port", SqlDbType.Int, 4), new SqlParameter("@DTU_login_time", SqlDbType.DateTime), new SqlParameter("@DTU_logout_time", SqlDbType.DateTime), new SqlParameter("@DTU_Logout_Value", SqlDbType.Float, 8), new SqlParameter("@Dl_ID", SqlDbType.Int, 4) }; parameters[0].Value = model.DTU_ID; parameters[1].Value = model.DTU_IP; parameters[2].Value = model.DTU_port; parameters[3].Value = model.DTU_login_time; parameters[4].Value = model.DTU_logout_time; parameters[5].Value = model.DTU_Logout_Value; parameters[6].Value = model.Dl_ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public DTULogEntity DataRowToModel(DataRow row) { DTULogEntity model = new DTULogEntity(); if (row != null) { if (row["Dl_ID"] != null && row["Dl_ID"].ToString() != "") { model.Dl_ID = int.Parse(row["Dl_ID"].ToString()); } if (row["DTU_ID"] != null) { model.DTU_ID = row["DTU_ID"].ToString(); } if (row["DTU_IP"] != null) { model.DTU_IP = row["DTU_IP"].ToString(); } if (row["DTU_port"] != null && row["DTU_port"].ToString() != "") { model.DTU_port = int.Parse(row["DTU_port"].ToString()); } if (row["DTU_login_time"] != null && row["DTU_login_time"].ToString() != "") { model.DTU_login_time = DateTime.Parse(row["DTU_login_time"].ToString()); } if (row["DTU_logout_time"] != null && row["DTU_logout_time"].ToString() != "") { model.DTU_logout_time = DateTime.Parse(row["DTU_logout_time"].ToString()); } if (row["DTU_Logout_Value"] != null && row["DTU_Logout_Value"].ToString() != "") { model.DTU_Logout_Value = decimal.Parse(row["DTU_Logout_Value"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(DTULogEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into DTU_log("); strSql.Append("DTU_ID,DTU_IP,DTU_port,DTU_login_time,DTU_logout_time,DTU_Logout_Value)"); strSql.Append(" values ("); strSql.Append("@DTU_ID,@DTU_IP,@DTU_port,@DTU_login_time,@DTU_logout_time,@DTU_Logout_Value)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@DTU_ID", SqlDbType.NVarChar, 50), new SqlParameter("@DTU_IP", SqlDbType.NVarChar, 50), new SqlParameter("@DTU_port", SqlDbType.Int, 4), new SqlParameter("@DTU_login_time", SqlDbType.DateTime), new SqlParameter("@DTU_logout_time", SqlDbType.DateTime), new SqlParameter("@DTU_Logout_Value", SqlDbType.Float, 8) }; parameters[0].Value = model.DTU_ID; parameters[1].Value = model.DTU_IP; parameters[2].Value = model.DTU_port; parameters[3].Value = model.DTU_login_time; parameters[4].Value = model.DTU_logout_time; parameters[5].Value = model.DTU_Logout_Value; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public DTULogEntity GetModel(int Dl_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Dl_ID,DTU_ID,DTU_IP,DTU_port,DTU_login_time,DTU_logout_time,DTU_Logout_Value from DTU_log "); strSql.Append(" where Dl_ID=@Dl_ID"); SqlParameter[] parameters = { new SqlParameter("@Dl_ID", SqlDbType.Int, 4) }; parameters[0].Value = Dl_ID; DTULogEntity model = new DTULogEntity(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DTULogEntity model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(DTULogEntity model) { return(dal.Add(model)); }