rendered paste body public int SaveBaitStation (CommonClasses.TBaitStation vBaitStation)
{
int returnVar;
StringBuilder sql = new StringBuilder ();
try
{
sql.Append (CommonConsts.SQL_GET_ALL_BAIT_STATIONS);
bool update = !vBaitStation.NewItem;
if (update)
{
sql.Append (" Where BaitStationID = :j1 ");
}
string tableName = "BaitStation";
DataRow row;
OleDbDataAdapter adapter = new OleDbDataAdapter (sql.ToString (), adoConGrainPlan);
if (update)
{
adapter.UpdateCommand.Parameters.AddWithValue (":j1", vBaitStation.ID);
}
OleDbCommandBuilder cmdBldr = new OleDbCommandBuilder (adapter);
DataSet ds = new DataSet ();
adapter.Fill (ds, tableName);
if (update)
{
row = ds.Tables[tableName].Rows[0];
row.BeginEdit ();
}
else
{ // new row
row = ds.Tables[tableName].NewRow ();
}
row["ParentStorageSiteID"] = vBaitStation.ParentID;
row["BaitStationName"] = vBaitStation.Name;
row["DateBaitStationPlaced"] = vBaitStation.Date;
if (vBaitStation.DateRemoved != "")
{
row["DateBaitStationRemoved"] = Convert.ToDateTime (vBaitStation.DateRemoved);
}
row["BaitStationLocation"] = vBaitStation.Location;
row["Notes"] = vBaitStation.Observations;
if (update)
{
row.EndEdit ();
}
else
{
ds.Tables[tableName].Rows.Add (row);
}
adapter.Update (ds, tableName);
returnVar = WriteData ("BaitStationID", tableName);
}
catch (Exception E)
{
gpLog.MessageBox (string.Format ("Error saving BaitStation record.\n%s.", E.Message));
returnVar = CommonConsts.DATABASE_ERROR_CODE;
}
return returnVar;
}