public static int Insert(KundeGrp c)
        {
            DBAccess db = new DBAccess();

            if (c.Status <= (int)KundeGrpStatusEnum.Opret)
            {
                c.Status = KundeGrpStatusEnum.Aktiv;
            }
            AddParms(ref db, c);

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

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

            if (retval == 1)
            {
                return(int.Parse(objParam.Value.ToString()));
            }
            else
            {
                return(-1);
            }
        }
        public static System.Collections.Generic.List <KundeGrp> GetKundeGrpList()
        {
            System.Collections.Generic.List <KundeGrp> result = new System.Collections.Generic.List <KundeGrp>();
            int      ID = -1;
            DBAccess db = new DBAccess();


            SqlDataReader dr = default(SqlDataReader);

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

            return(result);
        }
        private static void Populate(SqlDataReader dr, KundeGrp c)
        {
            var with_1 = c;

            with_1.Status       = (RescueTekniq.BOL.KundeGrpStatusEnum)(dr.DBtoInt("Status"));
            with_1.KundeGrpNavn = dr.DBtoString("KundeGrpNavn");
            with_1.Sort         = System.Convert.ToInt32(dr.DBtoInt("Sort"));
            PopulateStandard(dr, c);
        }
        //SELECT ID, KundeGrpNavn, status, sort, OprettetAf, OprettetDen, OprettetIP, RettetAf, RettetDen, RettetIP
        //FROM Co2Db_KundeGrp

        private static void AddParms(ref DBAccess db, KundeGrp c)
        {
            var with_1 = c;

            db.AddInt("Status", (System.Int32)with_1.Status);
            db.AddNVarChar("KundeGrpNavn", with_1.KundeGrpNavn, 50);
            db.AddInt("Sort", with_1.Sort);
            AddParmsStandard(db, c);
        }
        public static int Update(int ID, string KundeGrpNavn, int Status, int Sort)
        {
            KundeGrp c = new KundeGrp(ID);

            c.KundeGrpNavn = KundeGrpNavn;
            c.Status       = (KundeGrpStatusEnum)Status;
            c.Sort         = Sort;

            return(Update(c));
        }
        public static int Insert(string KundeGrpNavn, int Status, int Sort)
        {
            KundeGrp c = new KundeGrp();

            c.KundeGrpNavn = KundeGrpNavn;
            c.Status       = (KundeGrpStatusEnum)Status;
            c.Sort         = Sort;

            return(Insert(c));
        }
        public static string Tags(string tekst, RescueTekniq.BOL.KundeGrp item)
        {
            string        res = "";
            StringBuilder sb  = new StringBuilder();

            sb.Append(tekst);

            sb.Replace("[VARE.KUNDEGRP]", item.KundeGrpNavn);

            res = sb.ToString();
            return(res);
        }
        public static int Update(KundeGrp c)
        {
            DBAccess db = new DBAccess();

            if (c.Status == KundeGrpStatusEnum.Opret)
            {
                c.Status = KundeGrpStatusEnum.Aktiv;
            }
            db.AddInt("ID", c.ID);
            AddParms(ref db, c);

            int retval = db.ExecuteNonQuery(_SQLUpdate);

            return(retval);
        }
        public static KundeGrp_Pris GetCompany_VarePris(int CompanyID, int VareID)
        {
            KundeGrp      kg  = KundeGrp.GetKundeGrp_Company(CompanyID);
            KundeGrp_Pris kgp = KundeGrp_Pris.GetKundeGrp_VarePris(kg.ID, VareID);

            if (!kgp.loaded)
            {
                kgp            = new KundeGrp_Pris();
                kgp.KundeGrpID = kg.ID;
                kgp.VareID     = VareID;
                kgp.Rabat      = 0;
                kgp.FragtGebyr = 99.989999999999995M;
                kgp.Insert();
            }
            return(kgp);
        }
        public static KundeGrp GetKundeGrp_Company(int CompanyID)
        {
            KundeGrp c  = new KundeGrp();
            DBAccess db = new DBAccess();

            db.AddInt("CompanyID", CompanyID);
            SqlDataReader dr = (SqlDataReader)(db.ExecuteReader(_SQLSelectByCompany));

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Populate(dr, c);
                }
            }
            dr.Close();
            return(c);
        }
        public static KundeGrp GetKundeGrp(int ID)
        {
            DBAccess db = new DBAccess();

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

            if (dr.HasRows)
            {
                KundeGrp c = new KundeGrp();
                while (dr.Read())
                {
                    Populate(dr, c);
                }
                dr.Close();
                return(c);
            }
            else
            {
                dr.Close();
                return(null);
            }
        }
 public static int Delete(KundeGrp c)
 {
     return(Delete(c.ID));
 }