/// <summary> /// 更新一条数据 /// </summary> public bool Update(CdHotelManage.Model.cost_type model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update cost_type set "); strSql.Append("ct_number=@ct_number,"); strSql.Append("ct_name=@ct_name,"); strSql.Append("ct_iftype=@ct_iftype,"); strSql.Append("ct_remark=@ct_remark,"); strSql.Append("ct_money=@ct_money,"); strSql.Append("ct_categories=@ct_categories"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@ct_number", SqlDbType.NVarChar, 50), new SqlParameter("@ct_name", SqlDbType.NVarChar, 50), new SqlParameter("@ct_iftype", SqlDbType.Int, 4), new SqlParameter("@ct_remark", SqlDbType.NVarChar, -1), new SqlParameter("@ct_money", SqlDbType.Money, 8), new SqlParameter("@ct_categories", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.ct_number; parameters[1].Value = model.ct_name; parameters[2].Value = model.ct_iftype; parameters[3].Value = model.ct_remark; parameters[4].Value = model.ct_money; parameters[5].Value = model.ct_categories; parameters[6].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public CdHotelManage.Model.cost_type GetModels(string swhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,ct_number,ct_name,ct_iftype,ct_remark,ct_money,ct_categories from cost_type "); strSql.Append(" swhere"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; CdHotelManage.Model.cost_type model = new CdHotelManage.Model.cost_type(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(CdHotelManage.Model.cost_type model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into cost_type("); strSql.Append("ct_number,ct_name,ct_iftype,ct_remark,ct_money,ct_categories)"); strSql.Append(" values ("); strSql.Append("@ct_number,@ct_name,@ct_iftype,@ct_remark,@ct_money,@ct_categories)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ct_number", SqlDbType.NVarChar, 50), new SqlParameter("@ct_name", SqlDbType.NVarChar, 50), new SqlParameter("@ct_iftype", SqlDbType.Int, 4), new SqlParameter("@ct_remark", SqlDbType.NVarChar, -1), new SqlParameter("@ct_money", SqlDbType.Money, 8), new SqlParameter("@ct_categories", SqlDbType.Int, 4) }; parameters[0].Value = model.ct_number; parameters[1].Value = model.ct_name; parameters[2].Value = model.ct_iftype; parameters[3].Value = model.ct_remark; parameters[4].Value = model.ct_money; parameters[5].Value = model.ct_categories; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 获得数据列表 /// </summary> /// <summary> /// 得到一个对象实体 /// </summary> public CdHotelManage.Model.cost_type DataRowToModel(DataRow row) { CdHotelManage.Model.cost_type model = new CdHotelManage.Model.cost_type(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["ct_number"] != null) { model.ct_number = row["ct_number"].ToString(); } if (row["ct_name"] != null) { model.ct_name = row["ct_name"].ToString(); } if (row["ct_iftype"] != null && row["ct_iftype"].ToString() != "") { model.ct_iftype = int.Parse(row["ct_iftype"].ToString()); } if (row["ct_remark"] != null) { model.ct_remark = row["ct_remark"].ToString(); } if (row["ct_money"] != null && row["ct_money"].ToString() != "") { model.ct_money = decimal.Parse(row["ct_money"].ToString()); } if (row["ct_categories"] != null && row["ct_categories"].ToString() != "") { model.ct_categories = int.Parse(row["ct_categories"].ToString()); } } return(model); }