/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Staff DataRowToModel(DataRow row) { Maticsoft.Model.Staff model = new Maticsoft.Model.Staff(); if (row != null) { if (row["staID"] != null) { model.staID = row["staID"].ToString(); } if (row["staName"] != null) { model.staName = row["staName"].ToString(); } if (row["staSex"] != null) { model.staSex = row["staSex"].ToString(); } if (row["staAge"] != null && row["staAge"].ToString() != "") { model.staAge = int.Parse(row["staAge"].ToString()); } if (row["staPhoto"] != null && row["staPhoto"].ToString() != "") { model.staPhoto = (byte[])row["staPhoto"]; } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Maticsoft.Model.Staff model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.staID != null) { strSql1.Append("staID,"); strSql2.Append("'" + model.staID + "',"); } if (model.staName != null) { strSql1.Append("staName,"); strSql2.Append("'" + model.staName + "',"); } if (model.staSex != null) { strSql1.Append("staSex,"); strSql2.Append("'" + model.staSex + "',"); } if (model.staAge >= 18 && model.staAge <= 60) { strSql1.Append("staAge,"); strSql2.Append("" + model.staAge + ","); } if (model.staPhoto != null) { strSql1.Append("staPhoto,"); strSql2.Append("" + model.staPhoto + ","); } strSql.Append("insert into Staff("); 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); } }
public Maticsoft.Model.Staff GetModel1(string str1) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" staID,staName,staSex,staAge,staPhoto "); strSql.Append(" from Staff "); strSql.Append(" where " + str1 + " "); Maticsoft.Model.Staff model = new Maticsoft.Model.Staff(); 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 Update(Maticsoft.Model.Staff model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Staff set "); if (model.staName != "") { strSql.Append("staName='" + model.staName + "',"); } if (model.staSex != "") { strSql.Append("staSex='" + model.staSex + "',"); } if (model.staAge >= 18 && model.staAge <= 60) { strSql.Append("staAge=" + model.staAge + ","); } if (model.staPhoto != null && model.staPhoto.Length > 0) { strSql.Append("staPhoto='" + model.staPhoto + "',"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where staID='" + model.staID + "' "); int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rowsAffected > 0) { return(true); } else { return(false); } }