// ------------------------- AcVisitorMaster.Chain ---------------------------- // chain to row by OnlineId key public virtual AcVisitorMasterRow Chain(Web.AcPage InPage, string InVisitorId) { AcVisitorMasterRow row = null; SqlConnection conn = null; SqlCommand cmd; SqlDataReader reader = null; bool rc; try { conn = InPage.GetDatabaseConnection( ); cmd = new SqlCommand( ); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@VisitorId", InVisitorId)); cmd.CommandText = "SELECT *" + " FROM " + TableName + " WHERE VisitorId = @VisitorId"; reader = cmd.ExecuteReader(); rc = reader.Read(); // no rows if (rc == false) { throw (new VisitorMasterException("VisitorId " + InVisitorId + " is not found in AcVisitorMaster table")); } // got a row. extract each column from the reader. row = NewVisitorMasterRow( ); row.VisitorId = reader.GetString(0); row.UserId = reader.GetString(1); } finally { if (conn != null) { conn.Close( ); } if (reader != null) { reader.Close( ); } } return(row); }
// ----------------------- AcVisitorMaster.AddNewVisitor --------------------------- // create a new AcVisitorMaster row. public virtual AcVisitorMasterRow AddNewVisitor(Web.AcPage InPage, string InUserId) { SqlConnection conn = null; SqlCommand cmd; // build the row. AcVisitorMasterRow row = NewVisitorMasterRow( ); row.VisitorId = System.Guid.NewGuid( ).ToString( ); row.UserId = InUserId; try { conn = InPage.GetDatabaseConnection(); cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@VisitorId", row.VisitorId)); cmd.Parameters.Add(new SqlParameter("@UserId", row.UserId)); cmd.CommandText = "INSERT " + TableName + " ( VisitorId, UserId ) " + "VALUES( @VisitorId, @UserId )"; cmd.ExecuteNonQuery(); } catch (SqlException excp) { if (SqlCore.TableExists(conn, TableName) == false) { throw new AutoCoder.Sql.TableNotFound(TableName); } else { throw excp; } } finally { if (conn != null) { conn.Close(); } } return(row); }
// -------------------------- Add -------------------------------- public virtual AcVisitorMasterRow Add( AcPage InPage, AcVisitorMasterRow InRow) { SqlConnection conn = null; try { conn = InPage.GetDatabaseConnection( ); SqlCommand cmd = new SqlCommand(); // assign the VisitorId if (InRow.VisitorId == null) { InRow.VisitorId = System.Guid.NewGuid( ).ToString( ); } if (InRow.UserId == null) { InRow.UserId = ""; } cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@VisitorId", InRow.VisitorId)); cmd.Parameters.Add(new SqlParameter("@UserId", InRow.UserId)); cmd.CommandText = "INSERT " + TableName + " ( " + "VisitorId, UserId ) " + "Values( @VisitorId, @UserId )"; cmd.ExecuteNonQuery(); } finally { if (conn != null) { conn.Close( ); } } return(InRow); }
// ----------------------- AcVisitorMaster.AddNewVisitor --------------------------- // create a new AcVisitorMaster row. public virtual AcVisitorMasterRow AddNewVisitor(Web.AcPage InPage, string InUserId) { SqlConnection conn = null; SqlCommand cmd; // build the row. AcVisitorMasterRow row = NewVisitorMasterRow( ); row.VisitorId = System.Guid.NewGuid( ).ToString( ); row.UserId = InUserId; try { conn = InPage.GetDatabaseConnection( ); cmd = new SqlCommand( ); cmd.Connection = conn; cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqlParameter("@VisitorId", row.VisitorId)); cmd.Parameters.Add(new SqlParameter("@UserId", row.UserId)); cmd.CommandText = "INSERT " + TableName + " ( VisitorId, UserId ) " + "VALUES( @VisitorId, @UserId )"; cmd.ExecuteNonQuery(); } finally { if (conn != null) { conn.Close(); } } return(row); }