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

            c.Dato = DateTime.Now;

            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)
            {
                c.ID = Funktioner.ToInt(objParam.Value, -1); //Integer.Parse(objParam.Value.ToString)
                return(c.ID);                                //Integer.Parse(objParam.Value.ToString)
            }
            else
            {
                return(-1);
            }
        }
        //SELECT ID, status, KundeGrpID, KundeGrpNavn, VareID, SalgsPris, Rabat, KundePris, FragtGebyr, Dato, VareNr, Navn, VareGrpID, VareGrpNr FROM vw_Co2Db_KundeGrp_Pris
        private static void Populate(SqlDataReader dr, KundeGrp_Pris c)
        {
            var with_1 = c;

            with_1.Status        = (RescueTekniq.BOL.KundeGrpStatusEnum)(dr.DBtoInt("Status"));
            with_1.KundeGrpID    = System.Convert.ToInt32(dr.DBtoInt("KundeGrpID"));
            with_1._KundeGrpNavn = dr.DBtoString("KundeGrpNavn");

            with_1._SalgsPris = System.Convert.ToDecimal(dr.DBtoDecimal("SalgsPris"));
            with_1.Rabat      = System.Convert.ToDecimal(dr.DBtoDecimal("Rabat"));
            with_1._KundePris = System.Convert.ToDecimal(dr.DBtoDecimal("KundePris"));
            with_1.FragtGebyr = System.Convert.ToDecimal(dr.DBtoDecimal("FragtGebyr"));
            with_1.Dato       = System.Convert.ToDateTime(dr.DBtoDate("Dato"));

            with_1.VareID    = System.Convert.ToInt32(dr.DBtoInt("VareID"));
            with_1._VareNr   = dr.DBtoString("VareNr");
            with_1._VareNavn = dr.DBtoString("Navn");

            with_1._VareGrpID   = System.Convert.ToInt32(dr.DBtoInt("VareGrpID"));
            with_1._VareGrpNavn = dr.DBtoString("VareGrpNr");

            with_1._ProvisionRate = System.Convert.ToDecimal(dr.DBtoDecimal("ProvisionRate"));

            PopulateStandard(dr, c);
        }
        public static int Update(KundeGrp_Pris c)
        {
            DBAccess db = new DBAccess();

            c.Dato = DateTime.Now;
            db.AddInt("ID", c.ID);
            AddParms(ref db, c);

            int retval = db.ExecuteNonQuery(_SQLUpdate);

            return(retval);
        }
        //  SET [KundeGrpID] = <KundeGrpID, int,>
        //     ,[VareID] = <VareID, int,>
        //     ,[status] = <status, int,>
        //     ,[Rabat] = <Rabat, float,>
        //     ,[FragtGebyr] = <FragtGebyr, float,>
        //     ,[Dato] = <Dato, datetime,>

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

            db.AddInt("KundeGrpID", with_1.KundeGrpID);
            db.AddInt("VareID", with_1.VareID);
            db.AddInt("Status", (System.Int32)with_1.Status);
            db.AddDecimal("Rabat", with_1.Rabat);
            db.AddDecimal("FragtGebyr", with_1.FragtGebyr);
            db.AddDateTime("Dato", with_1.Dato);
            db.AddDecimal("ProvisionRate", with_1.ProvisionRate);
            AddParmsStandard(db, c);
        }
        //  SET [KundeGrpID] = <KundeGrpID, int,>
        //     ,[VareID] = <VareID, int,>
        //     ,[status] = <status, int,>
        //     ,[Rabat] = <Rabat, float,>
        //     ,[FragtGebyr] = <FragtGebyr, float,>
        //     ,[Dato] = <Dato, datetime,>
        public static int Insert(KundeGrpStatusEnum Status, int KundeGrpID, int VareID, decimal Rabat, decimal FragtGebyr, DateTime Dato)
        {
            KundeGrp_Pris c = new KundeGrp_Pris();

            c.Status     = Status;
            c.KundeGrpID = KundeGrpID;
            c.VareID     = VareID;

            c.Rabat      = Rabat;
            c.FragtGebyr = FragtGebyr;
            c.Dato       = Dato;

            return(Insert(c));
        }
        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 int Update(int ID, KundeGrpStatusEnum Status, int KundeGrpID, int VareID, decimal Rabat, decimal FragtGebyr, DateTime Dato)
        {
            KundeGrp_Pris c = new KundeGrp_Pris(ID);

            if (c.Status <= (int)KundeGrpStatusEnum.Opret)
            {
                c.Status = KundeGrpStatusEnum.Aktiv;
            }
            c.Status     = Status;
            c.KundeGrpID = KundeGrpID;
            c.VareID     = VareID;

            c.Rabat      = Rabat;
            c.FragtGebyr = FragtGebyr;
            c.Dato       = Dato;

            return(Update(c));
        }
        public static System.Collections.Generic.List <KundeGrp_Pris> GetKundeGrp_PrisList(int KundeGrpID, string Sort, int SortDir)
        {
            System.Collections.Generic.List <KundeGrp_Pris> result = new System.Collections.Generic.List <KundeGrp_Pris>();
            int ID = -1;

            // @Sort='VareNr'
            // @Sort='VareNavn'
            // @Sort='ID'
            // @Sort='Dato'
            if (Sort == "")
            {
                Sort = "VareNr";
            }

            DBAccess db = new DBAccess();

            db.AddInt("KundeGrpID", KundeGrpID);
            db.AddNVarChar("Sort", Sort, 50);
            db.AddInt("SortDir", SortDir);

            SqlDataReader dr = default(SqlDataReader);

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

            return(result);
        }
        public static KundeGrp_Pris GetKundeGrp_Pris(int ID)
        {
            KundeGrp_Pris c = new KundeGrp_Pris();

            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);
        }
        public static string Tags(string tekst, RescueTekniq.BOL.KundeGrp_Pris item)
        {
            string  InvoceVat = ConfigurationManager.AppSettings["invoice.vat"];
            decimal vat       = 25;

            try
            {
                vat = decimal.Parse(InvoceVat);
            }
            catch
            {
            }

            string        res = "";
            StringBuilder sb  = new StringBuilder(); // = New StringBuilder

            sb.Append(tekst);

            sb.Replace("[VARE.SALGSPRIS]", item.SalgsPris.ToString("C"));
            sb.Replace("[VARE.RABAT]", item.Rabat.ToString("0.0000 %"));

            sb.Replace("[VARE.PRIS]", item.KundePris.ToString("C"));
            sb.Replace("[VARE.KUNDEPRIS]", item.KundePris.ToString("C"));

            sb.Replace("[VARE.FRAGTPRIS]", item.FragtGebyr.ToString("C"));
            sb.Replace("[VARE.FRAGTGEBYR]", item.FragtGebyr.ToString("C"));

            decimal moms  = 0;
            decimal total = 0;

            moms  = (item.KundePris + item.FragtGebyr) * (vat / 100); //0.25
            total = item.KundePris + item.FragtGebyr + moms;

            sb.Replace("[VARE.MOMS]", moms.ToString("C"));
            sb.Replace("[VARE.TOTAL]", total.ToString("C"));

            res = sb.ToString();
            res = item.Vare.Tags(res);
            res = item.KundeGrp.Tags(res);
            return(res);
        }
        public static KundeGrp_Pris GetKundeGrp_VarePris(int KundeGrpID, string VareNr)
        {
            KundeGrp_Pris c = new KundeGrp_Pris();

            DBAccess db = new DBAccess();

            db.AddInt("KundeGrpID", KundeGrpID);
            db.AddNVarChar("VareNr", VareNr, 50);
            SqlDataReader dr = (SqlDataReader)(db.ExecuteReader(_SQLSelectByKundeGrpVareNr));

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

            return(c);
        }
 public static int Delete(KundeGrp_Pris c)
 {
     return(Delete(c.ID));
 }