//根据id查询实体 public DemoEntity GetInfoBySystemID(int systemId) { string sql = "select * from tbl_demo where SystemID='"+systemId+"'"; DemoEntity info = new DemoEntity(); using (SqlDataReader reader = DBHelper.GetReader(sql)) { info = GetEntityById(reader); } return info; }
/// <summary> /// if获取读取器数据 /// </summary> /// <param name="reader">读取器</param> /// <returns>数据实体</returns> private DemoEntity GetEntityById(SqlDataReader reader) { DemoEntity demo = null; if (reader.Read()) { demo = new DemoEntity(); if (reader["SystemID"] != DBNull.Value) { demo.SystemID = Convert.ToInt32(reader["SystemID"]); } if (reader["CompanyName"] != DBNull.Value) { demo.CompanyName = Convert.ToString(reader["CompanyName"]); } if (reader["Referees"] != DBNull.Value) { demo.Referees = Convert.ToString(reader["Referees"]); } if (reader["NetState"] != DBNull.Value) { demo.NetState = Convert.ToString(reader["NetState"]); } if (reader["OrderTime"] != DBNull.Value && reader["OrderTime"] != "") { demo.OrderTime = Convert.ToString(reader["OrderTime"]); } else { demo.OrderTime = "-"; } if (reader["NetSourse"] != DBNull.Value) { demo.NetSourse = Convert.ToString(reader["NetSourse"]); } if (reader["DeGiftBag"] != DBNull.Value && reader["DeGiftBag"] != "") { demo.DeGiftBag = Convert.ToString(reader["DeGiftBag"]); } else { demo.DeGiftBag = "-"; } if (reader["GiftBag"] != DBNull.Value && reader["GiftBag"] != "") { demo.GiftBag = Convert.ToString(reader["GiftBag"]); } else { demo.GiftBag = "-"; } } return demo; }
/// <summary> /// 循环获取读取器数据 /// </summary> /// <param name="reader">读取器</param> /// <returns>数据集合</returns> private List<DemoEntity> GetEntity(SqlDataReader reader) { List<DemoEntity> list = new List<DemoEntity>(); DemoEntity demo = null; while (reader.Read()) { demo = new DemoEntity(); if (reader["SystemID"] != DBNull.Value) { demo.SystemID = Convert.ToInt32(reader["SystemID"]); } if (reader["CompanyName"] != DBNull.Value) { demo.CompanyName = Convert.ToString(reader["CompanyName"]); } if (reader["Referees"] != DBNull.Value) { demo.Referees = Convert.ToString(reader["Referees"]); } if (reader["NetState"] != DBNull.Value) { demo.NetState = Convert.ToString(reader["NetState"]); } if (reader["OrderTime"] != DBNull.Value && reader["OrderTime"]!="") { demo.OrderTime = Convert.ToString(reader["OrderTime"]); } else { demo.OrderTime = "-"; } if (reader["NetSourse"] != DBNull.Value) { demo.NetSourse = Convert.ToString(reader["NetSourse"]); } if (reader["DeGiftBag"] != DBNull.Value && reader["DeGiftBag"] != "") { demo.DeGiftBag = Convert.ToString(reader["DeGiftBag"]); } else { demo.DeGiftBag = "-"; } if (reader["GiftBag"] != DBNull.Value && reader["GiftBag"] != "") { demo.GiftBag = Convert.ToString(reader["GiftBag"]); } else { demo.GiftBag = "-"; } list.Add(demo); } return list; }
//更新 public int UpdateInfoBySystemId(DemoEntity info) { string sql = "update tbl_demo set CompanyName='"+info.CompanyName+"',Referees='"+info.Referees+"',NetState='"+info.NetState+"',OrderTime='"+info.OrderTime+"',NetSourse='"+info.NetSourse+"',DeGiftBag='"+info.DeGiftBag+"',GiftBag='"+info.GiftBag+"' where SystemID='"+info.SystemID+"'"; int count = DBHelper.ExecSql(sql); return count; }
//添加 public int InsertInfo(DemoEntity info) { string sql = "insert into tbl_demo(CompanyName, Referees, NetState, OrderTime, NetSourse, DeGiftBag, GiftBag) values('"+info.CompanyName+"','"+info.Referees+"','"+info.NetState+"','"+info.OrderTime+"','"+info.NetSourse+"','"+info.DeGiftBag+"','"+info.GiftBag+"')"; int count = DBHelper.ExecSql(sql); return count; }
/// <summary> /// 添加实体 /// </summary> /// <param name="info"></param> /// <returns></returns> public static int InsertInfo(DemoEntity info) { return service.InsertInfo(info); }
/// <summary> /// 更新实体 /// </summary> /// <param name="info"></param> /// <returns></returns> public static int UpdateInfoBySystemId(DemoEntity info) { return service.UpdateInfoBySystemId(info); }