public FormHorseViewEdit(FormGrangerMain mainForm, Horse horse, GrangerContext context, HorseViewEditOpType optype, string herdID)
        {
            this.MainForm = mainForm;
            this.horse = horse;
            this.Context = context;
            this.HerdID = herdID;
            InitializeComponent();

            disableAllFields();

            List<string> list = new List<string>();
            list.AddRange(Context.Horses.Select(x => x.Name));
            list.AddRange(Context.Horses.Select(x => x.MotherName));
            list.AddRange(Context.Horses.Select(x => x.FatherName));
            string[] allHorseNamesInDatabase = list.Distinct().Where(x => x != null).ToArray();

            comboBoxFather.Items.AddRange(allHorseNamesInDatabase);
            comboBoxMother.Items.AddRange(allHorseNamesInDatabase);

            comboBoxColor.Items.AddRange(HorseColor.GetColorsEnumStrArray());
            comboBoxColor.Text = HorseColor.GetDefaultColorStr();
            comboBoxAge.Items.AddRange(HorseAge.GetColorsEnumStrArray());
            comboBoxAge.Text = HorseAge.GetDefaultAgeStr();

            this.OpMode = optype;
        }
Beispiel #2
0
        public override void Initialize()
        {
            base.Initialize();
            Settings = new PersistentObject<GrangerSettings>(new GrangerSettings());
            Settings.SetFilePathAndLoad(Path.Combine(base.ModuleDataDir, "settings.xml"));

            //init database
            DBSchema.SetConnectionString(Path.Combine(this.ModuleDataDir, "grangerDB.s3db"));

            SQLiteHelper.CreateTableIfNotExists(DBSchema.HorsesSchema, DBSchema.HorsesTableName, DBSchema.ConnectionString);
            SQLiteHelper.ValidateTable(DBSchema.HorsesSchema, DBSchema.HorsesTableName, DBSchema.ConnectionString);

            SQLiteHelper.CreateTableIfNotExists(DBSchema.TraitValuesSchema, DBSchema.TraitValuesTableName, DBSchema.ConnectionString);
            SQLiteHelper.ValidateTable(DBSchema.TraitValuesSchema, DBSchema.TraitValuesTableName, DBSchema.ConnectionString);

            SQLiteHelper.CreateTableIfNotExists(DBSchema.HerdsSchema, DBSchema.HerdsTableName, DBSchema.ConnectionString);
            SQLiteHelper.ValidateTable(DBSchema.HerdsSchema, DBSchema.HerdsTableName, DBSchema.ConnectionString);

            Context = new GrangerContext(new SQLiteConnection(DBSchema.ConnectionString));

            GrangerUI = new FormGrangerMain(this, Settings, Context);

            LogFeedMan = new LogFeedManager(this, Context);
            LogFeedMan.UpdatePlayers(Settings.Value.CaptureForPlayers);
            GrangerUI.Granger_PlayerListChanged += GrangerUI_Granger_PlayerListChanged;
        }
        public BreedingAdvisor(FormGrangerMain mainForm, string advisorID, GrangerContext Context)
        {
            this.MainForm = mainForm;
            this.AdvisorID = advisorID;
            this.Context = Context;

            IsDisabled = false;
            if (advisorID == DISABLED_id)
            {
                BreedEvalutator = new DisabledBreedingEvaluator();
                IsDisabled = true;
            }

            if (advisorID == DEFAULT_id)
            {
                BreedEvalutator = new DefaultBreedingEvaluator();
            }

            if (BreedEvalutator != null)
            {
                object options = mainForm.Settings.Value.GetBreedingEvalOptions(BreedEvalutator.GetType());
                if (options != null)
                    BreedEvalutator.SetOptions(options);
            }
        }
 internal void Init(FormGrangerMain formGrangerMain, GrangerContext context)
 {
     MainForm = formGrangerMain;
     _debug_MainFormAssigned = true;
     Context = context;
     if (MainForm.Settings.Value.TraitViewState != null) objectListView1.RestoreState(MainForm.Settings.Value.TraitViewState);
     Manager = new TraitViewManager(MainForm, Context, objectListView1);
 }
 public FormEditComments(FormGrangerMain formGrangerMain, string horseComments, string horseName)
 {
     this.formGrangerMain = formGrangerMain;
     this.HorseComments = horseComments;
     InitializeComponent();
     this.Text = "Edit comments for: " + horseName;
     this.textBox1.Text = HorseComments;
     textBox1.Select();
 }
Beispiel #6
0
        public FormChooseHerd(FormGrangerMain mainForm, GrangerContext Context)
        {
            this.MainForm = mainForm;
            this.Context = Context;
            InitializeComponent();

            var herds = Context.Herds.ToArray();

            listBox1.Items.AddRange(herds);
        }
Beispiel #7
0
 public FormHerdMerge(GrangerContext context, FormGrangerMain mainForm, string sourceHerdName)
 {
     this.Context = context;
     this.MainForm = mainForm;
     this.SourceHerdName = sourceHerdName;
     InitializeComponent();
     textBoxFromHerd.Text = SourceHerdName;
     comboBoxToHerd.Items.AddRange(Context.Herds.Where(x => x.HerdID != sourceHerdName).ToArray());
     listBoxFromHerd.Items.AddRange(Context.Horses.Where(x => x.Herd == SourceHerdName).ToArray());
 }
Beispiel #8
0
 /// <summary>
 /// generates new valuator attempting to use custom values from database,
 /// exception when no values found
 /// </summary>
 /// <param name="valueMapID"></param>
 public TraitValuator(FormGrangerMain mainForm, string valueMapID, GrangerContext context)
 {
     MainForm = mainForm;
     Context = context;
     ValueMapID = valueMapID;
     if (valueMapID == DEFAULT_id) _usingDefault = true;
     else
     {
         RebuildValues();
         context.OnTraitValuesModified += new EventHandler<EventArgs>(context_OnTraitValuesModified)
             .MakeWeak(x => context.OnTraitValuesModified -= x);
     }
 }
        public void Init(FormGrangerMain mainForm, GrangerContext context)
        {
            MainForm = mainForm;
            Context = context;

            objectListView1.BooleanCheckStateGetter = new BrightIdeasSoftware.BooleanCheckStateGetterDelegate(x =>
                {
                    HerdEntity entity = (HerdEntity)x;
                    return entity.Selected;
                });
            objectListView1.BooleanCheckStatePutter = new BrightIdeasSoftware.BooleanCheckStatePutterDelegate((x, y) =>
                {
                    HerdEntity entity = (HerdEntity)x;
                    Context.UpdateHerdSelectedState(entity.HerdID, y);
                    return entity.Selected;
                });

            Context.OnHerdsModified += RefreshHerdList;
            RefreshHerdList(this, new EventArgs());
        }
        public TraitViewManager(FormGrangerMain mainForm, GrangerContext context, ObjectListView listview)
        {
            MainForm = mainForm;
            Context = context;
            OLV = listview;

            OLV.FormatRow += OLV_FormatRow;

            AllTraits = HorseTrait.GetAllTraitEnums().Select(x => new HorseTrait(x)).ToArray();
            BuildClearTraitView();

            listview.SetObjects(Items);
            Decide();

            MainForm.Granger_SelectedSingleHorseChanged += MainForm_Granger_SelectedHorsesChanged;
            MainForm.Granger_ValuatorChanged += MainForm_Granger_ValuatorChanged;
            MainForm.Granger_TraitViewDisplayModeChanged += MainForm_Granger_TraitViewDisplayModeChanged;
            Context.OnHerdsModified += Context_OnHerdsModified;
            Context.OnHorsesModified += Context_OnHorsesModified;
            Context.OnTraitValuesModified += Context_OnTraitValuesModified;
        }
Beispiel #11
0
 /// <summary>
 /// generates new valuator with default hardcoded trait values
 /// </summary>
 public TraitValuator(FormGrangerMain mainForm)
 {
     _usingDefault = true;
 }
Beispiel #12
0
        //other data?

        public Horse(FormGrangerMain mainForm, HorseEntity entity, GrangerContext context)
        {
            MainForm = mainForm;
            Entity = entity;
            Context = context;
        }
        public void Init(FormGrangerMain mainForm, GrangerContext context)
        {
            MainForm = mainForm;
            _debug_MainFormAssigned = true;
            if (mainForm.Settings.Value.HorseListState != null)
            {
                this.objectListView1.RestoreState(mainForm.Settings.Value.HorseListState);
            }
            Context = context;

            olvColumnPairedWith.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
                {
                    Horse horse = (Horse)x;
                    Horse mate = horse.GetMate();
                    if (mate != null)
                    {
                        string[] output = new string[2] { horse.ToString(), mate.ToString() };
                        return string.Join(" + ", output.OrderBy(y => y));
                    }
                    else return "Free";
                });

            //olvColumnValue.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            //    {
            //        Horse horse = (Horse)x;
            //        return horse.ValueAspect;
            //    });
            olvColumnValue.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Horse horse = (Horse)x;
                if (horse.Value >= 0) return "Positive";
                else return "Negative";
            });
            olvColumnValue.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
            {
                return x.ToString();
            });

            //olvColumnBreedValue.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            //    {
            //        Horse horse = (Horse)x;
            //        var result = horse.BreedValueAspect;
            //        return result != null ? result.ToString() : "Not comparing";
            //    });
            olvColumnBreedValue.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
                {
                    Horse horse = (Horse)x;
                    double? val = horse.BreedValueAspect;
                    if (val == null) return "Being Compared / Not comparing";
                    else return "Candidates";
                });
            olvColumnBreedValue.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
                {
                    if (x is double)
                    {
                        double val = (double)x;
                        if (val == double.NegativeInfinity) return "-inf";
                        else return val.ToString("F0");
                    }
                    else if (x == null) return string.Empty;
                    else return x.ToString();
                });

            olvColumnTraits.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
                {
                    Horse horse = (Horse)x;
                    var traits = horse.Traits;
                    HorseTrait[] positives = HorseTrait.GetGoodTraits(traits, MainForm.CurrentValuator);
                    HorseTrait[] negatives = HorseTrait.GetBadTraits(traits, MainForm.CurrentValuator);
                    return string.Format("Good: {0}, Neutral: {1}, Bad: {2}",
                        positives.Length,
                        traits.Length - positives.Length - negatives.Length,
                        negatives.Length);
                });

            olvColumnTraitsInspectedAt.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
                {
                    Horse horse = (Horse)x;
                    var traitinfo = horse.TraitsInspectedAtSkillAspect;
                    if (traitinfo.Skill > HorseTrait.GetFullTraitVisibilityCap(traitinfo.EpicCurve))
                        return "Fully known";
                    else return "Known partially";
                });

            olvColumnAge.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
                {
                    HorseAge age = ((Horse)x).Age;
                    return (int)age.EnumVal;
                });
            olvColumnAge.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
                {
                    int result = (int)x;
                    return (new HorseAge(result.ToString()).ToString());
                });

            //////////////
            // GroupKeyGetter needs to be sortable to position them correctly,
            // GroupKeyToTitleConverter converts that key into something more meaningful to display
            // AspectToStringConverter converts aspect into display string in special way

            olvColumnNotInMoodFor.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
                {
                    Horse horse = (Horse)x;
                    //DateTime notInMoodUntil = horse.NotInMoodUntil;
                    TimeSpan tms = horse.NotInMoodForAspect;// notInMoodUntil - DateTime.Now;
                    if (tms.TotalDays >= 0)
                    {
                        return 0; // "Not in mood";
                    }
                    else
                    {
                        return 1; // "In mood";
                    }
                });
            olvColumnNotInMoodFor.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
                {
                    if (x is TimeSpan)
                    {
                        TimeSpan ts = (TimeSpan)x;
                        if (ts.TotalDays >= 0)
                            return TimeHelper.FormatTimeSpanForDisplay(ts);
                        else return string.Empty;
                    }
                    else return string.Empty;
                });
            olvColumnNotInMoodFor.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
                {
                    int result = (int)x;
                    switch (result)
                    {
                        case 0:
                            return "Not in mood";
                        case 1:
                            return "In mood";
                        default:
                            return "";
                    }
                });


            olvColumnGroomedAgo.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
                {
                    Horse horse = (Horse)x;
                    //DateTime groomedon = horse.GroomedOn;
                    TimeSpan tms = horse.GroomedAgoAspect; // DateTime.Now - groomedon;
                    if (tms.TotalHours <= 1)
                    {
                        return "Less than 1 hour ago";
                    }
                    else
                    {
                        return "More than 1 hour ago";
                    }
                });
            olvColumnGroomedAgo.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
                {
                    if (x is TimeSpan)
                    {
                        TimeSpan ts = (TimeSpan)x;
                        if (ts < MainForm.Settings.Value.ShowGroomingTime)
                            return TimeHelper.FormatTimeSpanForDisplay(ts);
                        else return string.Empty;
                    }
                    else return string.Empty;
                });
            olvColumnGroomedAgo.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
                {
                    return x.ToString();
                });


            olvColumnPregnantFor.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Horse horse = (Horse)x;
                DateTime pregnantUntil = horse.PregnantUntil;
                TimeSpan tms = pregnantUntil - DateTime.Now;

                if (tms.Ticks <= 0)
                {
                    if (tms.TotalDays >= -1) return 2; // "Gave birth within last 24h";
                    else if (tms.TotalDays >= -7) return 3; // "Gave birth in last 7 days";
                    else return 4; // "Not pregnant";   
                }
                else if (tms.TotalDays <= 1)
                {
                    return 0; // "Will give birth within 24h";
                }
                else
                {
                    return 1; // "Will give birth in more than 24h";
                }
            });
            olvColumnPregnantFor.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
            {
                if (x is TimeSpan)
                {
                    TimeSpan ts = (TimeSpan)x;
                    if (ts.Ticks >= 0)
                        return TimeHelper.FormatTimeSpanForDisplay(ts);
                    else return string.Empty;
                }
                else return string.Empty;
            });
            olvColumnPregnantFor.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
            {
                int group = (int)x;
                switch (group)
                {
                    case 0:
                        return "Will give birth within 24h";
                    case 1:
                        return "Will give birth in more than 24h";
                    case 2:
                        return "Gave birth within last 24h";
                    case 3:
                        return "Gave birth within last 7 days";
                    case 4:
                        return "Not pregnant";
                    default:
                        return "";
                }
            });


            olvColumnBirthDate.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Horse horse = (Horse)x;
                return horse.BirthDate.Date;
            });
            olvColumnBirthDate.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
            {
                if (x is DateTime)
                {
                    DateTime dt = (DateTime)x;
                    if (dt < _treshholdDtValueForBirthDate)
                    {
                        return string.Empty;
                    }
                    else
                    {
                        return dt.ToString(CultureInfo.CurrentCulture);
                    }
                }
                else return string.Empty;
            });
            olvColumnBirthDate.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
            {
                DateTime dt = (DateTime) x;
                if (dt < _treshholdDtValueForBirthDate)
                {
                    return "No birth date available";
                }
                else
                {
                    return dt.ToShortDateString();
                }
            });


            olvColumnExactAge.GroupKeyGetter = new BrightIdeasSoftware.GroupKeyGetterDelegate(x =>
            {
                Horse horse = (Horse)x;
                var val = (int)horse.ExactAgeAspect.TotalDays;
                if (val > _treshholdDaysValueForExactAge) return int.MaxValue;
                else return val;
            });
            olvColumnExactAge.AspectToStringConverter = new BrightIdeasSoftware.AspectToStringConverterDelegate(x =>
            {
                if (x is TimeSpan)
                {
                    TimeSpan ts = (TimeSpan)x;
                    if (ts > _treshholdTsValueForExactAge)
                    {
                        return string.Empty;
                    }
                    else
                    {
                        return TimeHelper.FormatTimeSpanForDisplay(ts);
                    }
                }
                else return string.Empty;
            });
            olvColumnExactAge.GroupKeyToTitleConverter = new BrightIdeasSoftware.GroupKeyToTitleConverterDelegate(x =>
            {
                int gkey = (int)x;
                if (gkey > _treshholdDaysValueForExactAge)
                {
                    return "No birth date available";
                }
                else
                {
                    return string.Format("{0} real days", gkey);
                }
            });


            Context.OnHerdsModified += Context_OnHerdsModified;
            Context.OnHorsesModified += Context_OnHorsesModified;
            MainForm.Granger_UserViewChanged += MainForm_UserViewChanged;
            MainForm.Granger_AdvisorChanged += MainForm_Granger_AdvisorChanged;
            MainForm.Granger_ValuatorChanged += MainForm_Granger_ValuatorChanged;

            UpdateCurrentHorsesData();
            UpdateDataForView();
            timer1.Enabled = true;
        }
 void MainForm_UserViewChanged(object sender, FormGrangerMain.UserViewChangedEventArgs e)
 {
     if (e.HerdViewVisible) tableLayoutPanel1.RowStyles[0].Height = 0;
     else tableLayoutPanel1.RowStyles[0].Height = 30;
 }