/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public int AddRecord(SDutyData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into SDuty("); strSql.Append("id,dutyNm,mark)"); strSql.Append(" values ("); strSql.Append("@id,@dutyNm,@mark)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@dutyNm", SqlDbType.NVarChar,50), new SqlParameter("@mark", SqlDbType.NVarChar,500) }; parameters[0].Value = model.id; parameters[1].Value = model.dutyNm; parameters[2].Value = model.mark; int id = 0; try { object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ret != null && ret != DBNull.Value) { id = Convert.ToInt32(ret); } } catch (Exception ex) { throw ex; } return id; }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public bool ModifyRecord(SDutyData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update SDuty set "); strSql.Append("dutyNm=@dutyNm,"); strSql.Append("mark=@mark"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@dutyNm", SqlDbType.NVarChar,50), new SqlParameter("@mark", SqlDbType.NVarChar,500) }; parameters[0].Value = model.id; parameters[1].Value = model.dutyNm; parameters[2].Value = model.mark; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public bool ModifyRecord(SDutyData model) { return this.dutyDB.ModifyRecord(model); }
/// <summary> /// �õ�һ��model /// </summary> /// <param name="id">����ֵ</param> /// <returns>model</returns> public SDutyData GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from SDuty"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int) }; parameters[0].Value = id; SDutyData model = new SDutyData(); DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (row["id"] != DBNull.Value) { model.id = Convert.ToInt32(row["id"]); } if (row["dutyNm"] != DBNull.Value) { model.dutyNm = Convert.ToString(row["dutyNm"]); } if (row["mark"] != DBNull.Value) { model.mark = Convert.ToString(row["mark"]); } return model; } else { return null; } }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public int AddRecord(SDutyData model) { return this.dutyDB.AddRecord(model); }