/// <summary> /// 更新一条数据 /// </summary> public bool Update(HTNResp.Model.SubMedicineProject model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update SubMedicineProject set "); strSql.Append("CommonName=@CommonName,"); strSql.Append("Dose=@Dose,"); strSql.Append("Usage=@Usage,"); strSql.Append("ProjectId=@ProjectId"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@CommonName", SqlDbType.NVarChar, 10), new SqlParameter("@Dose", SqlDbType.NVarChar, 20), new SqlParameter("@Usage", SqlDbType.NVarChar, 20), new SqlParameter("@ProjectId", SqlDbType.Int, 4), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.CommonName; parameters[1].Value = model.Dose; parameters[2].Value = model.Usage; parameters[3].Value = model.ProjectId; parameters[4].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public HTNResp.Model.SubMedicineProject DataRowToModel(DataRow row) { HTNResp.Model.SubMedicineProject model = new HTNResp.Model.SubMedicineProject(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["CommonName"] != null) { model.CommonName = row["CommonName"].ToString(); } if (row["Dose"] != null) { model.Dose = row["Dose"].ToString(); } if (row["Usage"] != null) { model.Usage = row["Usage"].ToString(); } if (row["ProjectId"] != null && row["ProjectId"].ToString() != "") { model.ProjectId = int.Parse(row["ProjectId"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(HTNResp.Model.SubMedicineProject model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into SubMedicineProject("); strSql.Append("CommonName,Dose,Usage,ProjectId)"); strSql.Append(" values ("); strSql.Append("@CommonName,@Dose,@Usage,@ProjectId)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CommonName", SqlDbType.NVarChar, 10), new SqlParameter("@Dose", SqlDbType.NVarChar, 20), new SqlParameter("@Usage", SqlDbType.NVarChar, 20), new SqlParameter("@ProjectId", SqlDbType.Int, 4) }; parameters[0].Value = model.CommonName; parameters[1].Value = model.Dose; parameters[2].Value = model.Usage; parameters[3].Value = model.ProjectId; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public HTNResp.Model.SubMedicineProject GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,CommonName,Dose,Usage,ProjectId from SubMedicineProject "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; HTNResp.Model.SubMedicineProject model = new HTNResp.Model.SubMedicineProject(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }