using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using Models; namespace DAL { public class ScenicSpotInfoServcies { List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new ScenicSpotInfo(), "ScenicSpotInfo", sql, CommandType.Text, param); } ScenicSpotInfo excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List hdList = excuteSql(sql, param); //判断集合是否为空 if (hdList == null || hdList.Count == 0) //返回null return null; //返回单个对象 return hdList[0]; } /// /// 增Add /// /// /// public bool Add(ScenicSpotInfo cg) { string sql = "insert into ScenicSpotInfo values(@Country,@City,@ScenicSpot,@ScenicSpotDetail,@Price,@Currency,@Rate,@Address,@Oper,@OpDate,@Isdel);SELECT @@IDENTITY"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Country",cg.Country), new SqlParameter("@City",cg.City), new SqlParameter("@ScenicSpot",cg.ScenicSpot), new SqlParameter("@ScenicSpotDetail",cg.ScenicSpotDetail), new SqlParameter("@Price",cg.Price), new SqlParameter("@Currency",cg.Currency), new SqlParameter("@Rate",cg.Rate), new SqlParameter("@Address",cg.Address), new SqlParameter("@Oper",cg.Oper), new SqlParameter("@OpDate",cg.OpDate), new SqlParameter("@Isdel",cg.Isdel) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 修改 /// /// /// public bool Edit(ScenicSpotInfo cg) { string sql = "update ScenicSpotInfo set Country=@Country,City=@City,ScenicSpot=@ScenicSpot ,ScenicSpotDetail=@ScenicSpotDetail,Price =@Price," + "Currency=@Currency,Rate=@Rate,Address=@Address,Oper=@Oper,OpDate=@OpDate,Isdel=@Isdel where Id = @Id"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@Country",cg.Country), new SqlParameter("@City",cg.City), new SqlParameter("@ScenicSpot",cg.ScenicSpot), new SqlParameter("@ScenicSpotDetail",cg.ScenicSpotDetail), new SqlParameter("@Price",cg.Price), new SqlParameter("@Currency",cg.Currency), new SqlParameter("@Rate",cg.Rate), new SqlParameter("@Address",cg.Address), new SqlParameter("@Oper",cg.Oper), new SqlParameter("@OpDate",cg.OpDate), new SqlParameter("@Isdel",cg.Isdel), new SqlParameter("@Id",cg.Id), }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 删 /// /// /// public bool delOA(int id) { if (SqlHelper.ExecuteNonQuery("update ScenicSpotInfo set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0) return true; return false; } /// /// 获取全部 - 分页 /// /// public List GetALL(int pageIndex, out int sumPage, out int totalRecord, string City) { string sqlwhere = "IsDel = 0"; if (!string.IsNullOrEmpty(City)) sqlwhere += " and City like '%" + City + "%'"; return PageBase.excutePageSql(new ScenicSpotInfo(), "ScenicSpotInfo", "ScenicSpotInfo", "*", "id asc", sqlwhere, 20, pageIndex, out sumPage, out totalRecord); } /// /// 获取全部 - 分页 /// /// public List GetALL(int pageIndex, out int sumPage, out int totalRecord, string City,string Countrys) { string sqlwhere = "IsDel = 0"; if (!string.IsNullOrEmpty(Countrys)) { if (Countrys.Contains("中国")) { if (Countrys == "中国") { sqlwhere += " and Country like '%" + City + "%'"; } else { sqlwhere += " and City like '%" + City + "%'"; } } else { string country1 = ""; string[] country = new string[] { }; if (Countrys.Contains(",")) country = Countrys.Split(','); else if (Countrys.Contains("、")) country = Countrys.Split('、'); else if (Countrys.Contains(",")) country = Countrys.Split(','); else if (Countrys.Contains(" ")) country = Countrys.Split(' '); if (country.Length >= 1) { for (int i = 0; i < country.Length; i++) { if (i == country.Length - 1) country1 += " '" + country[i] + "'"; else country1 += " '" + country[i] + "',"; } sqlwhere += " and Country in (" + country1 + ")"; } else sqlwhere += " and Country like '%" + Countrys + "%'"; } } else { sqlwhere += " and City like '%" + City + "%'"; } return PageBase.excutePageSql(new ScenicSpotInfo(), "ScenicSpotInfo", "ScenicSpotInfo", "*", "id asc", sqlwhere, 7, pageIndex, out sumPage, out totalRecord); } } }