protected void btnSave_Click(object sender, EventArgs e) { if (RouteData.Values.ContainsKey("sid")) { Wgw_slideEntity se = bllslide.GetModel(int.Parse(RouteData.Values["sid"].ToString())); se.name = txtname.Value.Trim(); se.imgdesc = txtdescription.Value.Trim(); se.imgorder = int.Parse(txtsort.Value.Trim()); //se.isshow = ckisshow.Checked; se.typeone = bscontrol1.type1value; se.typetwo = ""; se.source = hdpicurl.Value.Trim(); se.clientid = 1; bllslide.Add(se); } else { Wgw_slideEntity se = new Wgw_slideEntity() { name = txtname.Value.Trim(), imgdesc = txtdescription.Value.Trim(), imgorder = int.Parse(txtsort.Value.Trim()), //isshow = ckisshow.Checked, typeone = bscontrol1.type1value, typetwo = bscontrol1.type2value, source = hdpicurl.Value.Trim(), clientid = 1 }; bllslide.Add(se); } Response.Redirect("/microsite/slide"); }
/// <summary> /// 获得数据列表 /// </summary> public List<Wgw_slideEntity> DataTableToList(DataTable dt) { List<Wgw_slideEntity> modelList = new List<Wgw_slideEntity>(); int rowsCount = dt.Rows.Count; int result; if (rowsCount > 0) { Wgw_slideEntity model; for (int n = 0; n < rowsCount; n++) { model = new Wgw_slideEntity(); if (dt.Rows[n]["id"].ToString() != "") { model.id = int.Parse(dt.Rows[n]["id"].ToString()); } model.id = int.TryParse(dt.Rows[n]["id"].ToString(), out result) ? result : 0; if (dt.Rows[n]["clientid"].ToString() != "") { model.clientid = int.Parse(dt.Rows[n]["clientid"].ToString()); } model.clientid = int.TryParse(dt.Rows[n]["clientid"].ToString(), out result) ? result : 0; model.name = dt.Rows[n]["name"].ToString(); model.imgdesc = dt.Rows[n]["imgdesc"].ToString(); if (dt.Rows[n]["imgorder"].ToString() != "") { model.imgorder = int.Parse(dt.Rows[n]["imgorder"].ToString()); } model.imgorder = int.TryParse(dt.Rows[n]["imgorder"].ToString(), out result) ? result : 0; model.source = dt.Rows[n]["source"].ToString(); if (dt.Rows[n]["isshow"].ToString() != "") { if ((dt.Rows[n]["isshow"].ToString() == "1") || (dt.Rows[n]["isshow"].ToString().ToLower() == "true")) { model.isshow = true; } else { model.isshow = false; } } model.typeone = dt.Rows[n]["typeone"].ToString(); model.typetwo = dt.Rows[n]["typetwo"].ToString(); modelList.Add(model); } } return modelList; }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Wgw_slideEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Wgw_slide("); strSql.Append("clientid,name,imgdesc,imgorder,source,isshow,typeone,typetwo"); strSql.Append(") values ("); strSql.Append("@clientid,@name,@imgdesc,@imgorder,@source,@isshow,@typeone,@typetwo"); strSql.Append(") "); strSql.Append(";select SCOPE_IDENTITY()"); SqlParameter[] parameters = { new SqlParameter("@clientid", SqlDbType.Int,4) , new SqlParameter("@name", SqlDbType.NVarChar,50) , new SqlParameter("@imgdesc", SqlDbType.NVarChar,300) , new SqlParameter("@imgorder", SqlDbType.Int,4) , new SqlParameter("@source", SqlDbType.VarChar,300) , new SqlParameter("@isshow", SqlDbType.Bit,1) , new SqlParameter("@typeone", SqlDbType.NVarChar,150) , new SqlParameter("@typetwo", SqlDbType.NVarChar,150) }; parameters[0].Value = model.clientid; parameters[1].Value = model.name; parameters[2].Value = model.imgdesc; parameters[3].Value = model.imgorder; parameters[4].Value = model.source; parameters[5].Value = model.isshow; parameters[6].Value = model.typeone; parameters[7].Value = model.typetwo; DataTable dt = DBExecuteUtil.querySqlTable(strSql.ToString(), parameters); if (dt.Rows.Count == 0) { return 0; } else { return Convert.ToInt32(dt.Rows[0][0].ToString()); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Wgw_slideEntity model) { return dal.Add(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Wgw_slideEntity model) { return dal.Update(model); }
/// <summary> /// 获得分页数据 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="model"></param> /// <returns></returns> public DataTable GetPage(int pageIndex, int pageSize, Wgw_slideEntity model, out int count) { return dal.GetPage(pageIndex, pageSize, model, out count); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Wgw_slideEntity model) { StringBuilder strSql = new StringBuilder(); List<SqlParameter> parameters = new List<SqlParameter>(); strSql.Append("update Wgw_slide set "); if (true) { strSql.Append(" clientid = @clientid , "); parameters.Add(new SqlParameter("@clientid", model.clientid)); } if (!string.IsNullOrEmpty(model.name)) { strSql.Append(" name = @name , "); parameters.Add(new SqlParameter("@name", model.name)); } if (!string.IsNullOrEmpty(model.imgdesc)) { strSql.Append(" imgdesc = @imgdesc , "); parameters.Add(new SqlParameter("@imgdesc", model.imgdesc)); } if (true) { strSql.Append(" imgorder = @imgorder , "); parameters.Add(new SqlParameter("@imgorder", model.imgorder)); } if (!string.IsNullOrEmpty(model.source)) { strSql.Append(" source = @source , "); parameters.Add(new SqlParameter("@source", model.source)); } strSql.Append(" isshow = @isshow , "); parameters.Add(new SqlParameter("@isshow", model.isshow)); if (!string.IsNullOrEmpty(model.typeone)) { strSql.Append(" typeone = @typeone , "); parameters.Add(new SqlParameter("@typeone", model.typeone)); } if (!string.IsNullOrEmpty(model.typetwo)) { strSql.Append(" typetwo = @typetwo , "); parameters.Add(new SqlParameter("@typetwo", model.typetwo)); } strSql = strSql.Remove(strSql.Length - 2, 2); strSql.Append(" where id=@id "); parameters.Add(new SqlParameter("@id", model.id)); int rows = DBExecuteUtil.ExecuteSqlWithParams(strSql.ToString(), parameters.ToArray()); if (rows > 0) { return true; } else { return false; } }
/// <summary> /// 获取分页数据 /// </summary> /// <returns></returns> public DataTable GetPage(int pageIndex, int pageSize, Wgw_slideEntity model, out int count) { count = 0; SqlParameter[] items = new SqlParameter[]{ new SqlParameter("pageIndex",pageIndex), new SqlParameter("pageSize",pageSize), new SqlParameter("count",count) }; items[2].Direction = ParameterDirection.Output; var dt = DBStoreProUtil.queryProTable4Params("proc_Wgw_slide_Pagedata", items); count = int.Parse(items[2].Value.ToString()); return dt; }
/// <summary> /// 得到一个对象实体 /// </summary> public Wgw_slideEntity GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, clientid, name, imgdesc, imgorder, source, isshow, typeone, typetwo "); strSql.Append(" from Wgw_slide "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Wgw_slideEntity model = new Wgw_slideEntity(); DataTable dt = DBExecuteUtil.querySqlTable(strSql.ToString(), parameters); if (dt.Rows.Count > 0) { if (dt.Rows[0]["id"].ToString() != "") { model.id = int.Parse(dt.Rows[0]["id"].ToString()); } if (dt.Rows[0]["clientid"].ToString() != "") { model.clientid = int.Parse(dt.Rows[0]["clientid"].ToString()); } model.name = dt.Rows[0]["name"].ToString(); model.imgdesc = dt.Rows[0]["imgdesc"].ToString(); if (dt.Rows[0]["imgorder"].ToString() != "") { model.imgorder = int.Parse(dt.Rows[0]["imgorder"].ToString()); } model.source = dt.Rows[0]["source"].ToString(); if (dt.Rows[0]["isshow"].ToString() != "") { if ((dt.Rows[0]["isshow"].ToString() == "1") || (dt.Rows[0]["isshow"].ToString().ToLower() == "true")) { model.isshow = true; } else { model.isshow = false; } } model.typeone = dt.Rows[0]["typeone"].ToString(); model.typetwo = dt.Rows[0]["typetwo"].ToString(); return model; } else { return null; } }