/// <summary> /// 更新一条数据 /// </summary> public bool Update(Maticsoft.Model.CustomerHistoryRecord model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CustomerHistoryRecord set "); if (model.historyTimes > 0) { strSql.Append("historyTimes=" + model.historyTimes + ","); } if (model.discountRate >= 0 && model.discountRate < 1) { strSql.Append("discountRate=" + model.discountRate + ","); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where cusID='" + model.cusID + "' "); int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rowsAffected > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.CustomerHistoryRecord DataRowToModel(DataRow row) { Maticsoft.Model.CustomerHistoryRecord model = new Maticsoft.Model.CustomerHistoryRecord(); if (row != null) { if (row["cusID"] != null) { model.cusID = row["cusID"].ToString(); } if (row["historyTimes"] != null && row["historyTimes"].ToString() != "") { model.historyTimes = int.Parse(row["historyTimes"].ToString()); } if (row["discountRate"] != null && row["discountRate"].ToString() != "") { model.discountRate = decimal.Parse(row["discountRate"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.CustomerHistoryRecord GetModel(string cusID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" cusID,historyTimes,discountRate "); strSql.Append(" from CustomerHistoryRecord "); strSql.Append(" where cusID='" + cusID + "' "); Maticsoft.Model.CustomerHistoryRecord model = new Maticsoft.Model.CustomerHistoryRecord(); DataSet ds = DbHelperSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.CustomerHistoryRecord model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.cusID != null) { strSql1.Append("cusID,"); strSql2.Append("'" + model.cusID + "',"); } if (model.historyTimes > 0) { strSql1.Append("historyTimes,"); strSql2.Append("" + model.historyTimes + ","); } if (model.discountRate >= 0 && model.discountRate < 1) { strSql1.Append("discountRate,"); strSql2.Append("" + model.discountRate + ","); } strSql.Append("insert into CustomerHistoryRecord("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); int rows = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rows > 0) { return(true); } else { return(false); } }