/// <summary> /// 得到一个对象实体 /// </summary> public DHMSClass.Model.DHMS_Purchase DataRowToModel(DataRow row) { DHMSClass.Model.DHMS_Purchase model = new DHMSClass.Model.DHMS_Purchase(); if (row != null) { if (row["Purchase_ID"] != null) { model.Purchase_ID = row["Purchase_ID"].ToString(); } if (row["Material_ID"] != null) { model.Material_ID = row["Material_ID"].ToString(); } if (row["Purchase_Number"] != null && row["Purchase_Number"].ToString() != "") { model.Purchase_Number = int.Parse(row["Purchase_Number"].ToString()); } if (row["Purchase_DateTime"] != null && row["Purchase_DateTime"].ToString() != "") { model.Purchase_DateTime = DateTime.Parse(row["Purchase_DateTime"].ToString()); } if (row["Teacher_Tno"] != null) { model.Teacher_Tno = row["Teacher_Tno"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(DHMSClass.Model.DHMS_Purchase model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.Purchase_ID != null) { strSql1.Append("Purchase_ID,"); strSql2.Append("'" + model.Purchase_ID + "',"); } if (model.Material_ID != null) { strSql1.Append("Material_ID,"); strSql2.Append("'" + model.Material_ID + "',"); } if (model.Purchase_Number != null) { strSql1.Append("Purchase_Number,"); strSql2.Append("" + model.Purchase_Number + ","); } if (model.Purchase_DateTime != null) { strSql1.Append("Purchase_DateTime,"); strSql2.Append("'" + model.Purchase_DateTime + "',"); } if (model.Teacher_Tno != null) { strSql1.Append("Teacher_Tno,"); strSql2.Append("'" + model.Teacher_Tno + "',"); } strSql.Append("insert into DHMS_Purchase("); 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); } }
/// <summary> /// 得到一个对象实体 /// </summary> public DHMSClass.Model.DHMS_Purchase GetModel(string Purchase_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" Purchase_ID,Material_ID,Purchase_Number,Purchase_DateTime,Teacher_Tno "); strSql.Append(" from DHMS_Purchase "); strSql.Append(" where Purchase_ID='" + Purchase_ID + "' "); DHMSClass.Model.DHMS_Purchase model = new DHMSClass.Model.DHMS_Purchase(); 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(DHMSClass.Model.DHMS_Purchase model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update DHMS_Purchase set "); if (model.Material_ID != null) { strSql.Append("Material_ID='" + model.Material_ID + "',"); } if (model.Purchase_Number != null) { strSql.Append("Purchase_Number=" + model.Purchase_Number + ","); } if (model.Purchase_DateTime != null) { strSql.Append("Purchase_DateTime='" + model.Purchase_DateTime + "',"); } if (model.Teacher_Tno != null) { strSql.Append("Teacher_Tno='" + model.Teacher_Tno + "',"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where Purchase_ID='" + model.Purchase_ID + "' "); int rowsAffected = DbHelperSQL.ExecuteSql(strSql.ToString()); if (rowsAffected > 0) { return(true); } else { return(false); } }