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

            db.AddInt("CompanyID", CompanyID);

            db.AddBoolean("IsAgent", AdgangsKontrol.IsAgent());
            db.AddGuid("AgentID", CurrentUserID);

            SqlDataReader dr = default(SqlDataReader);

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

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

            sb.Append(tekst);
            sb.Replace("[VARE.TYPE]", "Service");
            sb.Replace("[SERVICE.TYPE]", "[VARE.NAVN]");

            sb.Replace("[DUEDATE]", item.ServiceDueDate.ToString("MMMM yyyy"));
            sb.Replace("[SERVICE.DUEDATE]", item.ServiceDueDate.ToString("MMMM yyyy"));
            sb.Replace("[SERVICE.BESØGSDATO]", item.ServiceDueDate.ToString("MMMM yyyy"));

            sb.Replace("[SERVICE.VISITEDDATE]", item.ServiceVisitedDate.ToString("dd MMMM yyyy"));
            sb.Replace("[SERVICE.BESØGTDATO]", item.ServiceVisitedDate.ToString("dd MMMM yyyy"));

            //.Replace("[SERVICE.EMAILSENDT]", item.ServiceEmailSendt.ToString())
            sb.Replace("[SERVICE.GUID]", item.Guid.ToString());

            sb.Replace("[SERVICE.VARENR]", "[VARE.VARENR]");
            sb.Replace("[SERVICE.SALGSPRIS]", "[VARE.SALGSPRIS]");
            sb.Replace("[SERVICE.RABAT]", "[VARE.RABAT]");
            sb.Replace("[SERVICE.PRIS]", "[VARE.PRIS]");
            sb.Replace("[SERVICE.KUNDEPRIS]", "[VARE.KUNDEPRIS]");
            sb.Replace("[SERVICE.FRAGTGEBYR]", "[VARE.FRAGTGEBYR]");
            sb.Replace("[SERVICE.FRAGTPRIS]", "[VARE.FRAGTPRIS]");
            sb.Replace("[SERVICE.MOMS]", "[VARE.MOMS]");
            sb.Replace("[SERVICE.TOTAL]", "[VARE.TOTAL]");

            res = sb.ToString();
            res = item.KundeGrpPris.Tags(res);
            res = item.EYE.Tags(res);

            return(res);
        }
        public static int Insert(EyeWash_Service S)
        {
            DBAccess db = new DBAccess();

            AddParms(ref db, S);

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

            objParam.Direction = ParameterDirection.Output;
            db.Parameters.Add(objParam);

            int retval = db.ExecuteNonQuery(_SQLInsert);

            if (retval == 1)
            {
                S.ID = int.Parse(objParam.Value.ToString());
                AddLog(Status: "EyeWash_Service", Logtext: string.Format("Create EyeWash_Service: ID:{0}", S.ID), Metode: "Insert");
                return(S.ID);
            }
            else
            {
                AddLog(Status: "EyeWash_Service", Logtext: string.Format("Failure to Create EyeWash_Service:"), logtype: LogTypeEnum.Error, Metode: "Insert");
                return(-1);
            }
        }
        public static List <EyeWash_Service> GetServicesByEYE(int EYE_FK)
        {
            List <EyeWash_Service> result = new List <EyeWash_Service>();
            int      ID = -1;
            DBAccess db = new DBAccess();

            db.AddInt("EYE_FK", EYE_FK);

            db.AddBoolean("IsAgent", AdgangsKontrol.IsAgent());
            db.AddGuid("AgentID", CurrentUserID);

            SqlDataReader dr = default(SqlDataReader);

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

            return(result);
        }
        public static int Delete(int ID)
        {
            EyeWash_Service S = new EyeWash_Service();

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

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

            AddLog(Status: "EyeWash_Service", Logtext: string.Format("Delete EyeWash_Service: ID:{0}", S.ID), Metode: "Delete");
            return(retval);
        }
        public static int Save(EyeWash_Service c)
        {
            int retval = 0;

            if (c.ID > 0)
            {
                retval = c.Update();
            }
            else
            {
                retval = c.Insert();
            }
            return(retval);
        }
        protected static void Populate(SqlDataReader dr, EyeWash_Service rec)
        {
            PopulateStandard(dr, rec);
            var with_1 = rec;

            with_1.Status              = (RescueTekniq.BOL.EyeWash_ServiceStatusType)(dr.DBtoInt("Status"));
            with_1.EYE_FK              = System.Convert.ToInt32(dr.DBtoInt("EYE_FK"));
            with_1.ServiceType         = System.Convert.ToInt32(dr.DBtoInt("ServiceType"));
            with_1.ServiceActive       = System.Convert.ToBoolean(dr.DBtoBoolean("ServiceActive"));
            with_1.ServiceDueDate      = System.Convert.ToDateTime(dr.DBtoDate("ServiceDueDate"));
            with_1.ServiceVisitedDate  = System.Convert.ToDateTime(dr.DBtoDate("ServiceVisitedDate"));
            with_1.ServiceConsultantID = System.Convert.ToInt32(dr.DBtoInt("ServiceConsultantID"));
            with_1.ServiceConsultant   = dr.DBtoString("ServiceConsultant");
            with_1.ServicePrice        = System.Convert.ToDouble(dr.DBtoDouble("ServicePrice"));
        }
        private static void AddParms(ref DBAccess db, EyeWash_Service rec)
        {
            var with_1 = rec;

            db.AddInt("Status", (System.Int32)with_1.Status);
            db.AddInt("EYE_FK", with_1.EYE_FK);

            db.AddInt("ServiceType", with_1.ServiceType);
            db.AddBoolean("ServiceActive", with_1.ServiceActive);
            db.AddDateTime("ServiceDueDate", with_1.ServiceDueDate);
            db.AddDateTime("ServiceVisitedDate", with_1.ServiceVisitedDate);
            db.AddInt("ServiceConsultantID", with_1.ServiceConsultantID);
            db.AddNVarChar("ServiceConsultant", with_1.ServiceConsultant, 50);
            db.AddMoney("ServicePrice", with_1.ServicePrice);
            //
            AddParmsStandard(db, rec);
        }
        public static List <EyeWash_Service> GetServicesByCriteria(string OrderBY, string criteria, params SqlParameter[] @params)
        {
            DBAccess db = new DBAccess();
            //Dim conn As SqlConnection = DataFunctions.GetConnection()
            string query = "";

            query += "SELECT ";
            if (OrderBY != "")
            {
                query += " TOP (100) PERCENT ";
            }
            query += " * FROM vw_Co2Db_EyeWash_Service ";
            query += " WHERE ( @IsAgent = 0 OR ( @IsAgent = 1 AND [AgentID] = @AgentID ) )";
            if (criteria != "")
            {
                query += " AND (" + criteria + ")";
            }
            if (OrderBY != "")
            {
                query += " ORDER BY " + OrderBY;
            }

            //Dim cmd As New SqlCommand(query, conn)
            db.CommandType = CommandType.Text;
            db.CommandText = query;
            db.AddRange(@params);
            db.AddBoolean("IsAgent", AdgangsKontrol.IsAgent());
            db.AddGuid("AgentID", CurrentUserID);

            db.Open();
            SqlDataReader dr = (SqlDataReader)(db.ExecuteReader());  //cmd.ExecuteReader()

            List <EyeWash_Service> list = new List <EyeWash_Service>();

            while (dr.Read())
            {
                EyeWash_Service service = new EyeWash_Service();
                EyeWash_Service.Populate(dr, service);
                list.Add(service);
            }

            db.Dispose();

            return(list);
        }
        public static EyeWash_Service GetService(System.Guid Guid)
        {
            EyeWash_Service c  = new EyeWash_Service();
            DBAccess        db = new DBAccess();

            db.AddGuid("Guid", Guid);

            db.AddBoolean("IsAgent", AdgangsKontrol.IsAgent());
            db.AddGuid("AgentID", CurrentUserID);

            SqlDataReader dr = (SqlDataReader)(db.ExecuteReader(_SQLSelectByGuid));

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