/// <summary> /// 更新一条数据 /// </summary> public bool Update(WeiXinPF.Model.wx_zh_gz model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wx_zh_gz set "); strSql.Append("linkman=@linkman,"); strSql.Append("tel=@tel,"); strSql.Append("company_name=@company_name,"); strSql.Append("qq=@qq,"); strSql.Append("fax=@fax,"); strSql.Append("mobile=@mobile,"); strSql.Append("createdate=@createdate,"); strSql.Append("sort_id=@sort_id"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@linkman", SqlDbType.NVarChar, 200), new SqlParameter("@tel", SqlDbType.NVarChar, 400), new SqlParameter("@company_name", SqlDbType.NVarChar, 200), new SqlParameter("@qq", SqlDbType.NVarChar, 200), new SqlParameter("@fax", SqlDbType.NVarChar, 200), new SqlParameter("@mobile", SqlDbType.NVarChar, 400), new SqlParameter("@createdate", SqlDbType.DateTime), new SqlParameter("@sort_id", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.linkman; parameters[1].Value = model.tel; parameters[2].Value = model.company_name; parameters[3].Value = model.qq; parameters[4].Value = model.fax; parameters[5].Value = model.mobile; parameters[6].Value = model.createdate; parameters[7].Value = model.sort_id; parameters[8].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WeiXinPF.Model.wx_zh_gz DataRowToModel(DataRow row) { WeiXinPF.Model.wx_zh_gz model = new WeiXinPF.Model.wx_zh_gz(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["linkman"] != null) { model.linkman = row["linkman"].ToString(); } if (row["tel"] != null) { model.tel = row["tel"].ToString(); } if (row["company_name"] != null) { model.company_name = row["company_name"].ToString(); } if (row["qq"] != null) { model.qq = row["qq"].ToString(); } if (row["fax"] != null) { model.fax = row["fax"].ToString(); } if (row["mobile"] != null) { model.mobile = row["mobile"].ToString(); } if (row["createdate"] != null && row["createdate"].ToString() != "") { model.createdate = DateTime.Parse(row["createdate"].ToString()); } if (row["sort_id"] != null && row["sort_id"].ToString() != "") { model.sort_id = int.Parse(row["sort_id"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WeiXinPF.Model.wx_zh_gz model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into wx_zh_gz("); strSql.Append("linkman,tel,company_name,qq,fax,mobile,createdate,sort_id)"); strSql.Append(" values ("); strSql.Append("@linkman,@tel,@company_name,@qq,@fax,@mobile,@createdate,@sort_id)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@linkman", SqlDbType.NVarChar, 200), new SqlParameter("@tel", SqlDbType.NVarChar, 400), new SqlParameter("@company_name", SqlDbType.NVarChar, 200), new SqlParameter("@qq", SqlDbType.NVarChar, 200), new SqlParameter("@fax", SqlDbType.NVarChar, 200), new SqlParameter("@mobile", SqlDbType.NVarChar, 400), new SqlParameter("@createdate", SqlDbType.DateTime), new SqlParameter("@sort_id", SqlDbType.Int, 4) }; parameters[0].Value = model.linkman; parameters[1].Value = model.tel; parameters[2].Value = model.company_name; parameters[3].Value = model.qq; parameters[4].Value = model.fax; parameters[5].Value = model.mobile; parameters[6].Value = model.createdate; parameters[7].Value = model.sort_id; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WeiXinPF.Model.wx_zh_gz GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,linkman,tel,company_name,qq,fax,mobile,createdate,sort_id from wx_zh_gz "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; WeiXinPF.Model.wx_zh_gz model = new WeiXinPF.Model.wx_zh_gz(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }