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

            if (rec.Status <= (int)CampaignCompany_StatusEnum.Create)
            {
                rec.Status = CampaignCompany_StatusEnum.Active;
            }
            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)
            {
                int res = -1;
                res = Funktioner.ToInteger(objParam.Value);
                AddLog(Status: "CampaignCompany", Logtext: string.Format("Create CampaignCompany: ID:{0}", rec.ID), Metode: "Insert");
                return(res);
            }
            else
            {
                AddLog(Status: "CampaignCompany", Logtext: string.Format("Failure to create CampaignCompany:"), logtype: LogTypeEnum.Error, Metode: "Insert");
                return(-1);
            }
        }
        public static System.Collections.Generic.List <CampaignCompany> GetCampaignCompanyList(int CampaignID)
        {
            System.Collections.Generic.List <CampaignCompany> result = new System.Collections.Generic.List <CampaignCompany>();
            CampaignCompany rec = default(CampaignCompany);

            DBAccess db = new DBAccess();

            db.AddInt("CampaignID", CampaignID);

            SqlDataReader dr = default(SqlDataReader);

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

            return(result);
        }
        private static void AddParms(ref DBAccess db, CampaignCompany rec)
        {
            var with_1 = rec;

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

            db.AddGuid("ResponsibleID", with_1.ResponsibleID);
            db.AddNVarChar("ResponsibleName", with_1.ResponsibleName, 50);
            db.AddNVarChar("ResponsibleEmail", with_1.ResponsibleEmail, 255);

            db.AddNVarChar("ContactPerson", with_1.ContactPerson, 50);
            db.AddBoolean("ContactedByPhone", with_1.ContactedByPhone);

            db.AddBoolean("MeetingHeld", with_1.MeetingHeld);
            db.AddBoolean("CampaignSale", with_1.CampaignSale);
            db.AddMoney("CampaignSaleAmount", (double)with_1.CampaignSaleAmount);
            db.AddBoolean("ExpectedSale", with_1.ExpectedSale);
            db.AddMoney("ExpectedSaleAmount", (double)with_1.ExpectedSaleAmount);

            db.AddNVarChar("Notes", with_1.Notes, -1);

            AddParmsStandard(db, rec);
        }
        public static int Save(CampaignCompany rec)
        {
            int retval = 0;

            if (rec.ID > 0)
            {
                retval = Update(rec);
            }
            else
            {
                retval = Insert(rec);
            }
            return(retval);
        }
        public static int Update(CampaignCompany rec)
        {
            DBAccess db = new DBAccess();

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

            int retval = 0;

            //Try
            retval = db.ExecuteNonQuery(_SQLUpdate);
            //Catch
            //End Try
            AddLog(Status: "CampaignCompany", Logtext: string.Format("Update CampaignCompany: ID:{0}", rec.ID), Metode: "Update");
            return(retval);
        }
        public static CampaignCompany GetCampaignCompany(int ID)
        {
            DBAccess        db  = new DBAccess();
            CampaignCompany rec = new CampaignCompany();

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

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Populate(dr, rec);
                }
            }
            if (!dr.IsClosed)
            {
                dr.Close();
            }
            return(rec);
        }
        public static string Tags(string tekst, RescueTekniq.BOL.CampaignCompany item)
        {
            string        res = "";
            StringBuilder sb  = new StringBuilder();

            sb.Append(tekst);
            sb.Replace("[CAMPAIGNCOMPANY.STATUS]", item.StatusText);

            sb.Replace("[CAMPAIGNCOMPANY.CAMPAIGNNO]", "[CAMPAIGN.CAMPAIGNNO]");
            sb.Replace("[CAMPAIGNCOMPANY.CAMPAIGNNAME]", "[CAMPAIGN.NAME]");
            sb.Replace("[CAMPAIGNCOMPANY.CAMPAIGNDESCRIPTION]", "[CAMPAIGN.DESCRIPTION]");
            sb.Replace("[CAMPAIGNCOMPANY.STARTDATE]", "[CAMPAIGN.STARTDATE]");
            sb.Replace("[CAMPAIGNCOMPANY.ENDDATE]", "[CAMPAIGN.ENDDATE]");
            sb.Replace("[CAMPAIGNCOMPANY.EXPECTEDIMEDIATESALE]", "[CAMPAIGN.EXPECTEDIMEDIATESALE]");
            sb.Replace("[CAMPAIGNCOMPANY.EXPECTEDFOLLOWUPSALE]", "[CAMPAIGN.EXPECTEDFOLLOWUPSALE]");

            sb.Replace("[CAMPAIGNCOMPANY.RESPONSIBLENAME]", item.ResponsibleName);
            sb.Replace("[CAMPAIGNCOMPANY.RESPONSIBLEEMAIL]", item.ResponsibleEmail);
            sb.Replace("[CAMPAIGNCOMPANY.CONTACTPERSON]", item.ContactPerson);
            sb.Replace("[CAMPAIGNCOMPANY.CONTACTEDBYPHONE]", System.Convert.ToString(item.ContactedByPhone ? "Ja" : "Nej"));
            sb.Replace("[CAMPAIGNCOMPANY.ITEMNMEETINGHELDO]", System.Convert.ToString(item.MeetingHeld ? "Ja" : "Nej"));

            sb.Replace("[CAMPAIGNCOMPANY.CAMPAIGNSALE]", System.Convert.ToString(item.CampaignSale ? "Ja" : "Nej"));
            sb.Replace("[CAMPAIGNCOMPANY.CAMPAIGNSALEAMOUNT]", item.CampaignSaleAmount.ToString("C"));

            sb.Replace("[CAMPAIGNCOMPANY.CAMPAIGNSALE]", System.Convert.ToString(item.ExpectedSale ? "JA" : "Nej"));
            sb.Replace("[CAMPAIGNCOMPANY.EXPECTEDSALEAMOUNT]", item.ExpectedSaleAmount.ToString("C"));

            sb.Replace("[CAMPAIGN.NOTES]", item.Notes);

            res = sb.ToString();
            res = item.Campaign.Tags(res);
            res = item.Company.Tags(res);

            return(res);
        }
        private static void Populate(SqlDataReader dr, CampaignCompany rec)
        {
            PopulateStandard(dr, rec);
            var with_1 = rec;

            with_1.CampaignID = System.Convert.ToInt32(dr.DBtoInt("CampaignID"));
            with_1.CampaignID = System.Convert.ToInt32(dr.DBtoInt("CampaignID"));
            with_1.Status     = (RescueTekniq.BOL.CampaignCompany_StatusEnum)(dr.DBtoInt("Status"));

            with_1.ResponsibleID    = dr.DBtoGuid("ResponsibleID");
            with_1.ResponsibleName  = dr.DBtoString("ResponsibleName");
            with_1.ResponsibleEmail = dr.DBtoString("ResponsibleEmail");

            with_1.ContactPerson    = dr.DBtoString("ContactPerson");
            with_1.ContactedByPhone = System.Convert.ToBoolean(dr.DBtoBoolean("ContactedByPhone"));

            with_1.MeetingHeld        = System.Convert.ToBoolean(dr.DBtoBoolean("MeetingHeld"));
            with_1.CampaignSale       = System.Convert.ToBoolean(dr.DBtoBoolean("CampaignSale"));
            with_1.CampaignSaleAmount = System.Convert.ToDecimal(dr.DBtoDecimal("CampaignSaleAmount"));
            with_1.ExpectedSale       = System.Convert.ToBoolean(dr.DBtoBoolean("ExpectedSale"));
            with_1.ExpectedSaleAmount = decimal.Parse(dr.DBtoString("ExpectedSaleAmount"));

            with_1.Notes = dr.DBtoString("Notes");
        }
 public static int Delete(CampaignCompany rec)
 {
     return(Delete(rec.ID));
 }