public static List <ChildWeight> GetChildWeightAsList(DataTable dt) { List <ChildWeight> oList = new List <ChildWeight>(); foreach (DataRow row in dt.Rows) { try { ChildWeight o = new ChildWeight(); o.Id = Helper.ConvertToInt(row["ID"]); o.ChildId = Helper.ConvertToInt(row["CHILD_ID"]); o.Weight = Helper.ConvertToDecimal(row["WEIGHT"]); o.Date = Helper.ConvertToDate(row["DATE"]); o.Notes = row["NOTES"].ToString(); o.ModifiedOn = Helper.ConvertToDate(row["MODIFIED_ON"]); o.ModifiedBy = Helper.ConvertToInt(row["MODIFIED_BY"]); oList.Add(o); } catch (Exception ex) { Log.InsertEntity("ChildWeight", "GetChildWeightAsList", 1, ex.StackTrace.Replace("'", ""), ex.Message.Replace("'", "")); throw ex; } } return(oList); }
public static int Update(ChildWeight o) { try { string query = @"UPDATE ""CHILD_WEIGHT"" SET ""ID"" = @Id, ""CHILD_ID"" = @ChildId, ""WEIGHT"" = @Weight, ""DATE"" = @Date, ""NOTES"" = @Notes, ""MODIFIED_ON"" = @ModifiedOn, ""MODIFIED_BY"" = @ModifiedBy WHERE ""ID"" = @Id "; List <Npgsql.NpgsqlParameter> parameters = new List <NpgsqlParameter>() { new NpgsqlParameter("@ChildId", DbType.Int32) { Value = o.ChildId }, new NpgsqlParameter("@Weight", DbType.Double) { Value = o.Weight }, new NpgsqlParameter("@Date", DbType.Date) { Value = o.Date }, new NpgsqlParameter("@Notes", DbType.String) { Value = (object)o.Notes ?? DBNull.Value }, new NpgsqlParameter("@ModifiedOn", DbType.DateTime) { Value = o.ModifiedOn }, new NpgsqlParameter("@ModifiedBy", DbType.Int32) { Value = o.ModifiedBy }, new NpgsqlParameter("@Id", DbType.Int32) { Value = o.Id } }; int rowAffected = DBManager.ExecuteNonQueryCommand(query, CommandType.Text, parameters); AuditTable.InsertEntity("ChildWeight", o.Id.ToString(), 2, DateTime.Now, o.ModifiedBy); return(rowAffected); } catch (Exception ex) { Log.InsertEntity("ChildWeight", "Update", 2, ex.StackTrace.Replace("'", ""), ex.Message.Replace("'", "")); } return(-1); }
public static int Insert(ChildWeight o) { try { string query = @"INSERT INTO ""CHILD_WEIGHT"" (""CHILD_ID"", ""WEIGHT"", ""DATE"", ""NOTES"", ""MODIFIED_ON"", ""MODIFIED_BY"") VALUES (@ChildId, @Weight, @Date, @Notes, @ModifiedOn, @ModifiedBy) returning ""ID"" "; List <Npgsql.NpgsqlParameter> parameters = new List <NpgsqlParameter>() { new NpgsqlParameter("@ChildId", DbType.Int32) { Value = o.ChildId }, new NpgsqlParameter("@Weight", DbType.Double) { Value = o.Weight }, new NpgsqlParameter("@Date", DbType.Date) { Value = o.Date }, new NpgsqlParameter("@Notes", DbType.String) { Value = (object)o.Notes ?? DBNull.Value }, new NpgsqlParameter("@ModifiedOn", DbType.DateTime) { Value = o.ModifiedOn }, new NpgsqlParameter("@ModifiedBy", DbType.Int32) { Value = o.ModifiedBy } }; object id = DBManager.ExecuteScalarCommand(query, CommandType.Text, parameters); AuditTable.InsertEntity("ChildWeight", id.ToString(), 1, DateTime.Now, o.ModifiedBy); return(int.Parse(id.ToString())); } catch (Exception ex) { Log.InsertEntity("ChildWeight", "Insert", 1, ex.StackTrace.Replace("'", ""), ex.Message.Replace("'", "")); } return(-1); }