public bool update(Department dept, DbTransaction transaction) { IFPObjectDAO fpObjectDAO = DAOFactory.getInstance().createFPObjectDAO(); fpObjectDAO.add(dept, transaction); SqlTransaction trans = (SqlTransaction)transaction; String sql = "update Department set name=@name, other=@other where ObjectId = @ObjectId"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Transaction = trans; cmd.Connection = trans.Connection; cmd.Parameters.Add(genSqlParameter("ObjectId", SqlDbType.Int, 10, dept.objectId)); cmd.Parameters.Add(genSqlParameter("name", SqlDbType.NVarChar, 255, dept.name)); cmd.Parameters.Add(genSqlParameter("other", SqlDbType.NVarChar, 255, dept.other)); cmd.ExecuteNonQuery(); cmd.Dispose(); return true; }
private List<Department> getQueryResult(SqlCommand cmd) { DbDataReader reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); List<Department> departments = new List<Department>(); Department department = null; dt.Load(reader); reader.Close(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { department = new Department(); department.objectId = getInt(dt.Rows[i]["ObjectId"]); department.createDate = getDateTime(dt.Rows[i]["CreateDate"]); department.updateDate = getDateTime(dt.Rows[i]["UpdateDate"]); department.updateBy = getString(dt.Rows[i]["UpdateBy"]); department.isDeleted = (getInt(dt.Rows[i]["IsDeleted"]) == 1); department.name = getString(dt.Rows[i]["name"]); department.other = getString(dt.Rows[i]["other"]); departments.Add(department); } } return departments; }
public bool delete(Department dept, DbTransaction transaction) { IFPObjectDAO fpObjectDAO = DAOFactory.getInstance().createFPObjectDAO(); return fpObjectDAO.delete(dept, transaction); }