예제 #1
0
    public PrizeExercisePlan ChangeExercisePlanLocation(PrizeExercisePlan originalPlan, string sLocation)
    {
        try
        {
            db.Database.Connection.Open();
            PrizePlanLocation location = (from l in db.PrizePlanLocations
                                          where l.Name.Equals(sLocation)
                                          select l).FirstOrDefault();

            PrizeExercisePlan nextPlan = (from c in db.PrizeExercisePlans
                                          where c.LocationId == location.Id && c.ProgramId == originalPlan.ProgramId && c.ExperienceId == originalPlan.ExperienceId && c.LevelId == originalPlan.LevelId &&
                                          c.IsTrialPlan == 0
                                          select c).FirstOrDefault();

            return(nextPlan);
        }
        finally
        {
            db.Database.Connection.Close();
        }
    }
예제 #2
0
    public string GetPlanName(PrizeExercisePlan plan)
    {
        string           planName    = "";
        PrizePlanProgram planProgram = (from l in db.PrizePlanPrograms
                                        where l.Id == plan.ProgramId
                                        select l).FirstOrDefault();

        PrizePlanLocation planLocation = (from l in db.PrizePlanLocations
                                          where l.Id == plan.LocationId
                                          select l).FirstOrDefault();

        PrizePlanExperience planExp = (from l in db.PrizePlanExperiences
                                       where l.Id == plan.ExperienceId
                                       select l).FirstOrDefault();

        PrizePlanLevel planLevel = (from l in db.PrizePlanLevels
                                    where l.Id == plan.LevelId
                                    select l).FirstOrDefault();

        planName = planProgram.Name + "_" + planLocation.Name + "_" + planLevel.Name + "_" + planExp.Name;
        return(planName);
    }
예제 #3
0
    protected void Insert(object sender, EventArgs e)
    {
        using (DIYPTEntities db = new DIYPTEntities())
        {
            db.Database.Connection.Open();
            {
                string pname      = ddlProgram.SelectedItem.Text;
                string plevel     = ddlLevel.SelectedItem.Text;
                string plocation  = ddlLocation.SelectedItem.Text;
                string pexpericen = ddlExperience.SelectedItem.Text;

                PrizePlanProgram planprogram = (from c in db.PrizePlanPrograms
                                                where c.Name == pname
                                                select c).FirstOrDefault();

                int pid = planprogram.Id;


                PrizePlanLocation planlocation = (from d in db.PrizePlanLocations
                                                  where d.Name == plocation
                                                  select d).FirstOrDefault();

                int locationid = planlocation.Id;


                PrizePlanLevel planlevel = (from g in db.PrizePlanLevels
                                            where g.Name == plevel
                                            select g).FirstOrDefault();

                int levelid = planlevel.Id;

                PrizePlanExperience planexperience = (from f in db.PrizePlanExperiences
                                                      where f.Name == pexpericen
                                                      select f).FirstOrDefault();

                int expid = planexperience.Id;

                double dPrice;
                if (!double.TryParse(txtPrice.Text, out dPrice))
                {
                    dPrice = 0;
                }
                PrizeExercisePlan exerciseplan;
                int trialFlag = 0;

                if (cbTrialFlag.Checked)
                {
                    exerciseplan = (
                        from ExercisePlan in db.PrizeExercisePlans
                        join Program in db.PrizePlanPrograms on ExercisePlan.ProgramId equals Program.Id
                        join Location in db.PrizePlanLocations on ExercisePlan.LocationId equals Location.Id
                        join Experience in db.PrizePlanExperiences on ExercisePlan.ExperienceId equals Experience.Id
                        join Level in db.PrizePlanLevels on ExercisePlan.LevelId equals Level.Id
                        where Program.Name == pname &&
                        Level.Name == plevel && Location.Name == plocation && Experience.Name == pexpericen && ExercisePlan.IsTrialPlan == 1
                        select ExercisePlan).FirstOrDefault();
                    trialFlag = 1;
                }
                else
                {
                    exerciseplan = (
                        from ExercisePlan in db.PrizeExercisePlans
                        join Program in db.PrizePlanPrograms on ExercisePlan.ProgramId equals Program.Id
                        join Location in db.PrizePlanLocations on ExercisePlan.LocationId equals Location.Id
                        join Experience in db.PrizePlanExperiences on ExercisePlan.ExperienceId equals Experience.Id
                        join Level in db.PrizePlanLevels on ExercisePlan.LevelId equals Level.Id
                        where Program.Name == pname &&
                        Level.Name == plevel && Location.Name == plocation && Experience.Name == pexpericen && ExercisePlan.IsTrialPlan == 0
                        select ExercisePlan).FirstOrDefault();
                }



                if (exerciseplan != null)
                {
                    string errorText = "Exercise plan already exist!";
                    Response.Write(
                        @"<SCRIPT LANGUAGE=""JavaScript"">alert('" + errorText + "')</SCRIPT>");
                }
                else
                {
                    string planname = ddlProgram.SelectedItem.Text + "_" + ddlLocation.SelectedItem.Text
                                      + "_" + ddlExperience.SelectedItem.Text + "_" + ddlLevel.SelectedItem.Text;
                    PrizeExercisePlan addplan = new PrizeExercisePlan();
                    addplan.PlanName     = planname;
                    addplan.ProgramId    = pid;
                    addplan.LevelId      = levelid;
                    addplan.ExperienceId = expid;
                    addplan.LocationId   = locationid;
                    addplan.Price        = dPrice;
                    addplan.IsTrialPlan  = trialFlag;
                    addplan.Description  = "";
                    db.PrizeExercisePlans.Add(addplan);
                    db.SaveChanges();
                    this.BindGrid();
                    ddlProgram.SelectedIndex    = 0;
                    ddlLocation.SelectedIndex   = 0;
                    ddlLevel.SelectedIndex      = 0;
                    ddlExperience.SelectedIndex = 0;
                }
            }

            //   transaction.Complete();
            db.Database.Connection.Close();
        }
    }
예제 #4
0
    public int FindNewPlan(string sProgram, string sLocation, string sLevel, string sExp, bool bIsTrial = false)
    {
        int           newPlanId = -1;
        DIYPTEntities db        = new DIYPTEntities();

        try
        {
            db.Database.Connection.Open();
            PrizePlanProgram program = (from c in db.PrizePlanPrograms
                                        where c.Name == sProgram
                                        select c).FirstOrDefault();
            if (program == null)
            {
                return(PrizeErrorCode.ERROR_WRONG_PROGRAM);
            }


            PrizePlanLocation location = (from c in db.PrizePlanLocations
                                          where c.Name == sLocation
                                          select c).FirstOrDefault();
            if (location == null)
            {
                return(PrizeErrorCode.ERROR_WRONG_LOCATION);
            }

            PrizePlanLevel level = (from c in db.PrizePlanLevels
                                    where c.Name == sLevel
                                    select c).FirstOrDefault();
            if (level == null)
            {
                return(PrizeErrorCode.ERROR_WRONG_LEVEL);
            }

            PrizePlanExperience exp = (from c in db.PrizePlanExperiences
                                       where c.Name == sExp
                                       select c).FirstOrDefault();
            if (exp == null)
            {
                return(PrizeErrorCode.ERROR_WRONG_LEVEL);
            }

            PrizeExercisePlan plan;

            if (bIsTrial == false)
            {
                plan = (from c in db.PrizeExercisePlans
                        where c.ProgramId == program.Id && c.LocationId == location.Id &&
                        c.LevelId == level.Id && c.ExperienceId == exp.Id && c.IsTrialPlan == 0
                        select c).FirstOrDefault();
            }
            else
            {
                plan = (from c in db.PrizeExercisePlans
                        where c.ProgramId == program.Id && c.LocationId == location.Id &&
                        c.LevelId == level.Id && c.ExperienceId == exp.Id && c.IsTrialPlan == 1
                        select c).FirstOrDefault();
            }

            if (plan != null)
            {
                newPlanId = plan.Id;
            }

            return(newPlanId);
        }
        finally
        {
            db.Dispose();
        }
    }