/// <summary> /// 增加一条数据 /// </summary> public int Add(FavoriateModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tbl_Favoriate("); strSql.Append("Symbol,Type,AddTime,Reserve)"); strSql.Append(" values ("); strSql.Append("@Symbol,@Type,@AddTime,@Reserve)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Symbol", SqlDbType.NVarChar, 10), new SqlParameter("@Type", SqlDbType.Int, 50), new SqlParameter("@AddTime", SqlDbType.Date, 20), new SqlParameter("@Reserve", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.Symbol; parameters[1].Value = model.Type; parameters[2].Value = model.AddTime; parameters[3].Value = model.Reserve; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public FavoriateModel DataRowToModel(DataRow row) { FavoriateModel model = new FavoriateModel(); if (row != null) { if (row["Symbol"] != null && row["Symbol"].ToString() != "") { model.Symbol = row["Symbol"].ToString(); } if (row["Type"] != null) { model.Type = (TradeType)Enum.ToObject(typeof(TradeType), int.Parse(row["Type"].ToString())); } if (row["AddTime"] != null) { model.AddTime = Convert.ToDateTime(row["AddTime"].ToString()); } if (row["Reserve"] != null) { model.Reserve = row["Reserve"].ToString(); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(FavoriateModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tbl_Favoriate set "); strSql.Append("Type=@Type,"); strSql.Append("AddTime=@AddTime,"); strSql.Append("Reserve=@Reserve,"); strSql.Append(" where Symbol=@Symbol"); SqlParameter[] parameters = { new SqlParameter("@Symbol", SqlDbType.NVarChar, 10), new SqlParameter("@Type", SqlDbType.Int, 50), new SqlParameter("@AddTime", SqlDbType.Date, 20), new SqlParameter("@Reserve", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.Symbol; parameters[1].Value = model.Type; parameters[2].Value = model.AddTime; parameters[3].Value = model.Reserve; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public FavoriateModel GetModel(string strSymbol) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Symbol,Type,AddTime,Reserve from tbl_Favoriate "); strSql.Append(" where Symbol=@Symbol"); SqlParameter[] parameters = { new SqlParameter("@Symbol", SqlDbType.NVarChar, 10) }; parameters[0].Value = strSymbol; FavoriateModel model = new FavoriateModel(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }