public static System.Collections.Generic.List <AED_Redning> GetRedningListCompany(int CompanyID)
        {
            System.Collections.Generic.List <AED_Redning> result = new System.Collections.Generic.List <AED_Redning>();
            int      ID = -1;
            DBAccess db = new DBAccess();

            db.AddInt("CompanyID", CompanyID);

            SqlDataReader dr = default(SqlDataReader);

            try
            {
                dr = (System.Data.SqlClient.SqlDataReader)(db.ExecuteReader(_SQLSelectByCompany));
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        ID = System.Convert.ToInt32(dr.DBtoInt("ID"));
                        result.Add(AED_Redning.GetRedning(ID));
                    }
                }
                dr.Close();
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            return(result);
        }
        public static int Insert(AED_Redning R)
        {
            DBAccess db = new DBAccess();

            AddParms(ref db, R);

            SqlParameter objParam = new SqlParameter("@ID", 0);

            objParam.Direction = ParameterDirection.Output;
            db.Parameters.Add(objParam);
            int retval = db.ExecuteNonQuery(_SQLInsert);

            if (retval == 1)
            {
                int res = Funktioner.ToInt(objParam.Value.ToString());
                R.ID = res;
                AddLog(Status: "AED_Redning", Logtext: string.Format("Create AED_Redning: ID:{0}", R.ID), Metode: "Insert");
                return(res);
            }
            else
            {
                AddLog(Status: "AED_Redning", Logtext: string.Format("Failure to Create AED_Redning:"), logtype: LogTypeEnum.Error, Metode: "Insert");
                return(-1);
            }
        }
        public static System.Collections.Generic.List <AED_Redning> GetRedningList(int AED_FK)
        {
            System.Collections.Generic.List <AED_Redning> result = new System.Collections.Generic.List <AED_Redning>();
            int      ID = -1;
            DBAccess db = new DBAccess();

            db.AddInt("AED_FK", AED_FK);

            SqlDataReader dr = default(SqlDataReader);

            //Try
            dr = (System.Data.SqlClient.SqlDataReader)(db.ExecuteReader(_SQLSelectByAED));
            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    ID = System.Convert.ToInt32(dr.DBtoInt("ID"));
                    result.Add(AED_Redning.GetRedning(ID));
                }
            }
            dr.Close();
            //Catch ex As Exception
            //Throw ex
            //End Try

            return(result);
        }
        public static int Delete(int ID)
        {
            AED_Redning R = new AED_Redning();

            R.ID = ID;
            return(Delete(R));
        }
        public static int Delete(AED_Redning R)
        {
            DBAccess db = new DBAccess();

            db.AddInt("ID", R.ID);
            int retval = db.ExecuteNonQuery(_SQLDelete);

            AddLog(Status: "AED_Redning", Logtext: string.Format("Delete AED_Redning: ID:{0}", R.ID), Metode: "Delete");
            return(retval);
        }
        private static void AddParms(ref DBAccess db, AED_Redning c)
        {
            var with_1 = c;

            db.AddInt("Status", (System.Int32)with_1.Status);
            db.AddInt("AED_FK", with_1.AED_FK);
            db.AddInt("CompanyID", with_1.CompanyID);
            db.AddInt("RedningType", with_1.RedningType);
            db.AddDateTime("RedningDate", with_1.RedningDate);
            db.AddNVarChar("RedningNote", with_1.RedningNote, -1);
            AddParmsStandard(db, c);
        }
        private static void Populate(System.Data.SqlClient.SqlDataReader dr, AED_Redning c)
        {
            var with_1 = c;

            with_1.Status    = (RescueTekniq.BOL.AEDStatusEnum)(dr.DBtoInt("Status"));
            with_1.AED_FK    = System.Convert.ToInt32(dr.DBtoInt("AED_FK"));
            with_1.CompanyID = System.Convert.ToInt32(dr.DBtoInt("CompanyID"));

            with_1.RedningType = System.Convert.ToInt32(dr.DBtoInt("RedningType"));
            with_1.RedningDate = System.Convert.ToDateTime(dr.DBtoDate("RedningDate"));
            with_1.RedningNote = dr.DBtoString("RedningNote");
            PopulateStandard(dr, c);
        }
        public static int Save(AED_Redning R)
        {
            int retval = 0;

            if (R.ID > 0)
            {
                retval = Update(R);
            }
            else
            {
                retval = Insert(R);
            }
            return(retval);
        }
        public static int Update(int ID, AEDStatusEnum Status, int AED_FK, int CompanyID, int RedningType, DateTime RedningDate, string RedningNote)
        {
            AED_Redning c = new AED_Redning(ID);

            c.Status    = Status;
            c.AED_FK    = AED_FK;
            c.CompanyID = CompanyID;

            c.RedningType = RedningType;
            c.RedningDate = RedningDate;
            c.RedningNote = RedningNote;

            return(Update(c));
        }
        public static AED_Redning GetRedning(int ID)
        {
            AED_Redning c  = new AED_Redning();
            DBAccess    db = new DBAccess();

            db.AddInt("ID", ID);
            SqlDataReader dr = (SqlDataReader)(db.ExecuteReader(_SQLSelectOne));

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Populate(dr, c);
                }
            }
            dr.Close();
            return(c);
        }