// Exceptions: // System.ArgumentException: // eventTimeInfo is null when saving EventTimeInfo public void Save(EventTimeInfo eventTimeInfo) { if (eventTimeInfo.IsNull) { throw new System.ArgumentException("eventTimeInfo is null when saving EventTimeInfo", "eventTimeInfo"); } if (EventTimeInfoExists(eventTimeInfo.UniqueID)) { EventTimeInfo upToDateItemBase = new EventTimeInfo(); try { Load(upToDateItemBase, eventTimeInfo.UniqueID); } catch { SaveInternal(eventTimeInfo); return; } if (eventTimeInfo.CompareTo(upToDateItemBase) != 0) { UpdateInternal(eventTimeInfo); } } else { SaveInternal(eventTimeInfo); } }
protected void SaveInternal(EventTimeInfo eventTimeInfo) { try { eventTimeInfo.LastDALChange = DateTime.Now.Ticks; SqlCommand sqlCommand = new SqlCommand("Insert Into EventTimeInfo" + " (EventUniqueID, LastDALChange, CreationTime, BecomeActive, BecomeInactive) values ('" + eventTimeInfo.EventUniqueID.ToString() + "', '" + eventTimeInfo.LastDALChange.ToString() + "', '" + eventTimeInfo.CreationTime.Value.Ticks.ToString() + "', '" + eventTimeInfo.BecomeActive.Value.Ticks.ToString() + "', '" + ((eventTimeInfo.BecomeInactive != null) ? eventTimeInfo.BecomeInactive.Value.Ticks.ToString() : "0") + "');"); sqlCommand.Connection = mSqlConnection; int lineInserted = sqlCommand.ExecuteNonQuery(); if (lineInserted != 1) { throw new System.ArgumentException("Insert Into EventTimeInfo UniqueID=" + eventTimeInfo.EventUniqueID + " failed", "eventTimeInfo"); } } catch (Exception exception) { throw exception; } finally { mSqlConnection.Close(); } }
protected void UpdateInternal(EventTimeInfo eventTimeInfo) { try { eventTimeInfo.LastDALChange = DateTime.Now.Ticks; SqlCommand sqlCommand = new SqlCommand("Update EventTimeInfo set " + "LastDALChange='" + eventTimeInfo.LastDALChange.ToString() + "'," + "CreationTime='" + eventTimeInfo.CreationTime.Value.Ticks.ToString() + "'," + "BecomeActive='" + eventTimeInfo.BecomeActive.Value.Ticks.ToString() + "'," + "BecomeInactive='" + eventTimeInfo.BecomeInactive.Value.Ticks.ToString() + "' " + "Where EventUniqueID='" + eventTimeInfo.EventUniqueID.ToString() + "'"); sqlCommand.Connection = mSqlConnection; int lineInserted = sqlCommand.ExecuteNonQuery(); if (lineInserted != 1) { throw new System.ArgumentException("Update Into EventTimeInfo Where EventUniqueID=" + eventTimeInfo.UniqueID.ToString() + " failed", "EventUniqueID"); } } catch (Exception exception) { throw exception; } finally { mSqlConnection.Close(); } }
protected void DeleteInternal(EventTimeInfo eventTimeInfo) { try { eventTimeInfo.LastDALChange = DateTime.Now.Ticks; SqlCommand sqlCommand = new SqlCommand("delete from EventTimeInfo where " + "EventUniqueID = '" + eventTimeInfo.EventUniqueID.ToString() + "';"); sqlCommand.Connection = mSqlConnection; int lineRemoved = sqlCommand.ExecuteNonQuery(); if (lineRemoved != 1) { throw new System.ArgumentException("Delete from EventTimeInfo Where EventUniqueID=" + eventTimeInfo.EventUniqueID.ToString() + " failed", "EventUniqueID"); } } catch (Exception exception) { throw exception; } finally { mSqlConnection.Close(); } }
public bool IsLatest(EventTimeInfo eventTimeInfo) { EventTimeInfo upToDateEventTimeInfo = new EventTimeInfo(); Load(upToDateEventTimeInfo, eventTimeInfo.UniqueID); return(upToDateEventTimeInfo.LastDALChange == eventTimeInfo.LastDALChange); }
public void Delete(EventTimeInfo eventTimeInfo) { if (!eventTimeInfo.IsLoaded()) { Load(eventTimeInfo); } mEventTimeInfoDAL.Delete(eventTimeInfo); }
public void ClearValues(EventTimeInfo eventTimeInfo) { eventTimeInfo.UniqueID = 0; eventTimeInfo.CreationTime = null; eventTimeInfo.BecomeActive = null; eventTimeInfo.BecomeInactive = null; }
// Exceptions: // System.ArgumentException: // Load Failed protected void LoadInternal(EventTimeInfo eventTimeInfo) { try { mEventTimeInfoDAL.Load(eventTimeInfo, eventTimeInfo.UniqueID); } catch { throw new System.ArgumentException("Load Failed", "eventTimeInfo"); } }
// Exceptions: // System.ArgumentException: // eventTimeInfo is null when loading EventTimeInfo // Load Failed public void Load(EventTimeInfo eventTimeInfo) { try { if (eventTimeInfo.IsNull) { throw new System.ArgumentException("eventTimeInfo is null when loading EventTimeInfo", "eventTimeInfo"); } LoadInternal(eventTimeInfo); } catch { throw new System.ArgumentException("Load Failed", "eventTimeInfo"); } }
public void Delete(EventTimeInfo eventTimeInfo) { if (eventTimeInfo.IsNull) { throw new System.ArgumentException("eventTimeInfo is null when removing EventTimeInfo", "eventTimeInfo"); } if (EventTimeInfoExists(eventTimeInfo.UniqueID)) { DeleteInternal(eventTimeInfo); } else { throw new System.ArgumentException("eventTimeInfo does not exists while removing EventTimeInfo", "eventTimeInfo"); } }
public void Load(EventTimeInfo eventTimeInfo, UInt64 eventUniqueID) { SqlDataReader sqlReader = null; SqlCommand sqlCommand = null; try { sqlCommand = new SqlCommand("select * from EventTimeInfo where EventUniqueID = @1", mSqlConnection); SqlParameter sqlParameter = new SqlParameter("@1", SqlDbType.BigInt); sqlParameter.Value = eventUniqueID; sqlCommand.Parameters.Add(sqlParameter); sqlReader = sqlCommand.ExecuteReader(); if (!sqlReader.Read()) { throw new System.ArgumentException("eventTimeInfo with EventUniqueID=" + eventUniqueID.ToString() + " was not found", "eventUniqueID"); } eventTimeInfo.EventUniqueID = eventUniqueID; eventTimeInfo.LastDALChange = Convert.ToInt64(sqlReader["LastDALChange"].ToString()); eventTimeInfo.CreationTime = new DateTime(Convert.ToInt64(sqlReader["CreationTime"].ToString())); eventTimeInfo.BecomeActive = new DateTime(Convert.ToInt64(sqlReader["BecomeActive"].ToString())); eventTimeInfo.BecomeInactive = new DateTime(Convert.ToInt64(sqlReader["BecomeInactive"].ToString())); if (sqlReader.Read()) { throw new ArgumentException("Multiple EventUniqueID=" + eventUniqueID.ToString() + " were found in EventTimeInfo", "eventUniqueID"); } } catch (Exception exception) { throw exception; } finally { sqlReader.Close(); mSqlConnection.Close(); } }
public void Save(EventTimeInfo eventTimeInfo) { mEventTimeInfoDAL.Save(eventTimeInfo); }