public static int Insert(PractiMan rec)
        {
            DBAccess db = new DBAccess();

            AddParms(ref db, rec);

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

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

            int retval = db.ExecuteNonQuery(_SQLInsert);

            if (retval == 1)
            {
                rec.ID = Convert.ToInt32(objParam.Value);
                AddLog(Status: "PractiMan", Logtext: string.Format("Create PractiMan: ID:{0}", rec.ID), Metode: "Insert");
                return(rec.ID);
            }
            else
            {
                AddLog(Status: "PractiMan", Logtext: string.Format("Failure to Create PractiMan:"), logtype: LogTypeEnum.Error, Metode: "Insert");
                return(-1);
            }
        }
        public static string Tags(string tekst, RescueTekniq.BOL.PractiMan item)
        {
            string        res = "";
            StringBuilder sb  = new StringBuilder();

            //UPDATE [vicjos1_RescueTekniq].[vicjos1_sysadm].[Co2Db_PractiMan]
            //   SET [CompanyID] = <CompanyID, int,>
            //      ,[Status] = <Status, int,>
            //      ,[ModelID] = <ModelID, int,>
            //      ,[SerialNo] = <SerialNo, nvarchar(50),>
            //      ,[InvoiceID] = <InvoiceID, int,>
            //      ,[SalesDate] = <SalesDate, datetime,>

            // WHERE <Search Conditions,,>
            //GO

            sb.Append(tekst);
            //.Replace("[VARE.TYPE]", "PractiMan")
            //.Replace("[PractiMan.TYPE]", "[VARE.NAVN]")

            sb.Replace("[PractiMan.SalesDate]", item.SalesDate.ToString("dd. MMM yyyy"));
            sb.Replace("[PractiMan.Sales.DATE]", item.SalesDate.ToString("dd. MMM yyyy"));

            sb.Replace("[PractiMan.InvoiceID]", System.Convert.ToString(item.InvoiceID));
            sb.Replace("[PractiMan.ModelID]", System.Convert.ToString(item.ModelID));
            sb.Replace("[PractiMan.SerialNo]", item.SerialNo);

            sb.Replace("[PractiMan.GUID]", item.Guid.ToString());

            res = sb.ToString();

            return(res);
        }
        public static System.Collections.Generic.List <PractiMan> GetPractiManList()
        {
            System.Collections.Generic.List <PractiMan> result = new System.Collections.Generic.List <PractiMan>();
            int      ID = -1;
            DBAccess db = new DBAccess();

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

            SqlDataReader dr = default(SqlDataReader);

            try
            {
                dr = (System.Data.SqlClient.SqlDataReader)(db.ExecuteReader(_SQLSelectAll));
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        PractiMan pc = new PractiMan();
                        Populate(dr, pc);
                        result.Add(pc);
                    }
                }
                dr.Close();
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            return(result);
        }
        public static int Update(PractiMan rec)
        {
            DBAccess db = new DBAccess();

            db.AddInt("ID", rec.ID);
            AddParms(ref db, rec);

            int retval = db.ExecuteNonQuery(_SQLUpdate);

            AddLog(Status: "PractiMan", Logtext: string.Format("Update PractiMan: ID:{0}", rec.ID), Metode: "Update");
            return(retval);
        }
        //UPDATE [vicjos1_RescueTekniq].[vicjos1_sysadm].[Co2Db_PractiMan]
        //   SET [CompanyID] = <CompanyID, int,>
        //      ,[Status] = <Status, int,>
        //      ,[ModelID] = <ModelID, int,>
        //      ,[SerialNo] = <SerialNo, nvarchar(50),>
        //      ,[InvoiceID] = <InvoiceID, int,>
        //      ,[SalesDate] = <SalesDate, datetime,>

        //      ,[OprettetAf] = <OprettetAf, nvarchar(50),>
        //      ,[OprettetDen] = <OprettetDen, datetime,>
        //      ,[OprettetIP] = <OprettetIP, nvarchar(15),>
        //      ,[RettetAf] = <RettetAf, nvarchar(50),>
        //      ,[RettetDen] = <RettetDen, datetime,>
        //      ,[RettetIP] = <RettetIP, nvarchar(50),>
        // WHERE <Search Conditions,,>
        //GO

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

            db.AddInt("Status", (System.Int32)with_1.Status);
            db.AddInt("CompanyID", with_1.CompanyID);
            db.AddInt("ModelID", with_1.ModelID);
            db.AddInt("InvoiceID", with_1.InvoiceID);
            db.AddNVarChar("SerialNo", with_1.SerialNo, 50);
            db.AddDateTime("SalesDate", with_1.SalesDate);
            AddParmsStandard(db, c);
        }
        public static int Save(PractiMan rec)
        {
            int retval = 0;

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

            with_1.Status = (RescueTekniq.BOL.PractiManStatusType)(dr.DBtoInt("Status"));

            with_1.Status    = (RescueTekniq.BOL.PractiManStatusType)(dr.DBtoInt("Status"));
            with_1.CompanyID = System.Convert.ToInt32(dr.DBtoInt("CompanyID"));
            with_1.ModelID   = System.Convert.ToInt32(dr.DBtoInt("ModelID"));
            with_1.InvoiceID = System.Convert.ToInt32(dr.DBtoInt("InvoiceID"));
            with_1.SerialNo  = dr.DBtoString("SerialNo");
            with_1.SalesDate = System.Convert.ToDateTime(dr.DBtoDate("SalesDate"));
        }
        public static List <PractiMan> GetPractiMansByCriteria(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_PractiMan ";
            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());

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

            while (dr.Read())
            {
                PractiMan pc = new PractiMan();
                PractiMan.Populate(dr, pc);
                list.Add(pc);
            }

            db.Dispose();

            return(list);
        }
        public static PractiMan GetPractiMan(int ID)
        {
            PractiMan c  = new PractiMan();
            DBAccess  db = new DBAccess();

            db.AddInt("ID", ID);

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

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Populate(dr, c);
                }
            }
            dr.Close();
            return(c);
        }
        public static PractiMan GetPractiManByCompanyID(int CompanyID)
        {
            DBAccess  db = new DBAccess();
            PractiMan pc = new PractiMan();

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

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

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Populate(dr, pc);
                }
            }
            if (!dr.IsClosed)
            {
                dr.Close();
            }
            return(pc);
        }
 public static int Delete(PractiMan rec)
 {
     return(Delete(rec.ID));
 }