/// <summary> /// returns an array of the immutable USSPolicy objects that correspond to the supplied ussPolicyIds /// </summary> /// <param name="ussPolicyIds"></param> /// <returns></returns> public static USSPolicy[] GetUSSPolicies(int[] ussPolicyIds) { USSPolicy[] ussPolicies = new USSPolicy[ussPolicyIds.Length]; for (int i = 0; i < ussPolicyIds.Length; i++) { ussPolicies[i] = new USSPolicy(); } // create sql connection DbConnection connection = FactoryDB.GetConnection(); // create sql command // command executes the "RetrieveUSSPolicyByID" stored procedure DbCommand cmd = FactoryDB.CreateCommand("RetrieveUSSPolicyByID", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(FactoryDB.CreateParameter(cmd,"@ussPolicyId", null, DbType.Int32)); //execute the command try { connection.Open(); for (int i = 0; i < ussPolicyIds.Length; i++) { // populate the parameters cmd.Parameters["@ussPolicyId"].Value = ussPolicyIds[i]; DbDataReader dataReader = null; dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { ussPolicies[i].ussPolicyId = ussPolicyIds[i]; if (dataReader[0] != System.DBNull.Value) ussPolicies[i].experimentInfoId = (int)dataReader.GetInt32(0); if (dataReader[1] != System.DBNull.Value) ussPolicies[i].rule = dataReader.GetString(1); if (dataReader[2] != System.DBNull.Value) ussPolicies[i].credentialSetId = (int)dataReader.GetInt32(2); } dataReader.Close(); } } catch (Exception ex) { throw new Exception("Exception thrown in get usspolicies", ex); } finally { connection.Close(); } return ussPolicies; }
/// <summary> /// This method fires when the Policy dropdown changes. /// If the index is greater than zero, the specified Policy will be looked up /// and its values will be used to populate the text fields on the form. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ddlPolicy_SelectedIndexChanged(object sender, System.EventArgs e) { if (ddlPolicy.SelectedIndex == 0) // prepare for a new record { ClearFormFields(); SetReadOnly(false); } else //retrieve an existing record { USSPolicy policy = new USSPolicy(); policy = policies[ddlPolicy.SelectedIndex - 1]; txtMaxReservableTimeSlots.Text = PolicyParser.getProperty(policy.rule, lblfield2.Text); txtMinReservableTimeSlots.Text = PolicyParser.getProperty(policy.rule, lblfield3.Text); ddlGroup.ClearSelection(); ddlGroup.Items.FindByValue(policy.credentialSetId.ToString()).Selected = true; ddlExperiment.ClearSelection(); ddlExperiment.Items.FindByValue(policy.experimentInfoId.ToString()).Selected = true; SetReadOnly(true); } }