private static CalendarsData GetDataObjectFromReader(SqlDataReader dataReader) { CalendarsData data = new CalendarsData(); if (dataReader.IsDBNull(dataReader.GetOrdinal("CalendarsID"))) { data.CalendarsID = IdType.UNSET; } else { data.CalendarsID = new IdType(dataReader.GetInt32(dataReader.GetOrdinal("CalendarsID"))); } if (dataReader.IsDBNull(dataReader.GetOrdinal("Description"))) { data.Description = StringType.UNSET; } else { data.Description = StringType.Parse(dataReader.GetString(dataReader.GetOrdinal("Description"))); } if (dataReader.IsDBNull(dataReader.GetOrdinal("OrgGroupsID"))) { data.OrgGroupsID = IntegerType.UNSET; } else { data.OrgGroupsID = new IntegerType(dataReader.GetInt32(dataReader.GetOrdinal("OrgGroupsID"))); } return(data); }
public static IdType Insert(CalendarsData data) { // Create and execute the command string sql = "Insert Into " + TABLE + "(" + "Description," + "OrgGroupsID," ; sql = sql.Substring(0, sql.Length - 1) + ") values(" + "@Description," + "@OrgGroupsID," ; sql = sql.Substring(0, sql.Length - 1) + ");select Scope_Identity() Id"; SqlCommand cmd = GetSqlCommand(DatabaseEnum.INTRANET, sql, CommandType.Text, COMMAND_TIMEOUT); //Create the parameters and append them to the command object cmd.Parameters.Add(new SqlParameter("@Description", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "Description", DataRowVersion.Proposed, data.Description.DBValue)); cmd.Parameters.Add(new SqlParameter("@OrgGroupsID", SqlDbType.Int, 0, ParameterDirection.Input, false, 10, 0, "OrgGroupsID", DataRowVersion.Proposed, data.OrgGroupsID.DBValue)); // Execute the query SqlDataReader returnValue = cmd.ExecuteReader(); returnValue.Read(); int returnId = (int)(returnValue.GetDecimal(0)); returnValue.Close(); // Set the output paramter value(s) return(new IdType(returnId)); }
public static CalendarsData Load(IdType calendarsID) { WhereClause w = new WhereClause(); w.And("CalendarsID", calendarsID.DBValue); SqlDataReader dataReader = GetListReader(DatabaseEnum.INTRANET, TABLE, w, null, true); if (!dataReader.Read()) { dataReader.Close(); throw new FinderException("Load found no rows for Calendars."); } CalendarsData data = GetDataObjectFromReader(dataReader); dataReader.Close(); return(data); }
public static void Update(CalendarsData data) { // Create and execute the command CalendarsData oldData = Load(data.CalendarsID); string sql = "Update " + TABLE + " set "; if (!oldData.Description.Equals(data.Description)) { sql = sql + "Description=@Description,"; } if (!oldData.OrgGroupsID.Equals(data.OrgGroupsID)) { sql = sql + "OrgGroupsID=@OrgGroupsID,"; } WhereClause w = new WhereClause(); w.And("CalendarsID", data.CalendarsID.DBValue); sql = sql.Substring(0, sql.Length - 1) + w.FormatSql(); SqlCommand cmd = GetSqlCommand(DatabaseEnum.INTRANET, sql, CommandType.Text, COMMAND_TIMEOUT); //Create the parameters and append them to the command object if (!oldData.CalendarsID.Equals(data.CalendarsID)) { cmd.Parameters.Add(new SqlParameter("@CalendarsID", SqlDbType.Int, 0, ParameterDirection.Input, false, 10, 0, "CalendarsID", DataRowVersion.Proposed, data.CalendarsID.DBValue)); } if (!oldData.Description.Equals(data.Description)) { cmd.Parameters.Add(new SqlParameter("@Description", SqlDbType.VarChar, 50, ParameterDirection.Input, false, 0, 0, "Description", DataRowVersion.Proposed, data.Description.DBValue)); } if (!oldData.OrgGroupsID.Equals(data.OrgGroupsID)) { cmd.Parameters.Add(new SqlParameter("@OrgGroupsID", SqlDbType.Int, 0, ParameterDirection.Input, false, 10, 0, "OrgGroupsID", DataRowVersion.Proposed, data.OrgGroupsID.DBValue)); } // Execute the query if (cmd.Parameters.Count > 0) { cmd.ExecuteNonQuery(); } }