private static void ModificaPreferenzeClickHandler(object sender, EventArgs e)
        {
            PropertyInfo       pi          = ((PropertyAndObject)((Control)sender).Tag).PropertyInfo;
            object             obj         = ((PropertyAndObject)((Control)sender).Tag).Object;
            IList <Ingredient> preferences = (IList <Ingredient>)pi.GetValue(obj);
            PreferencesDialog  dialog      = new PreferencesDialog();

            dialog.PreferencesList.DataSource         = ManagerProvider.getManager <KitchenManager>().Ingredients;
            dialog.PreferencesList.AllowColumnReorder = false;
            dialog.PreferencesList.FullRowSelect      = false;

            foreach (Ingredient i in preferences)
            {
                dialog.PreferencesList.Items.Where(el => el.DataBoundItem == i).Single().CheckState = Telerik.WinControls.Enumerations.ToggleState.On;
            }
            dialog.PreferencesList.SelectedItem = null;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                List <Ingredient> newPrefs = new List <Ingredient>();
                foreach (ListViewDataItem element in dialog.PreferencesList.CheckedItems)
                {
                    Ingredient i = (Ingredient)element.DataBoundItem;
                    newPrefs.Add(i);
                }
                pi.SetValue(obj, newPrefs);
            }
        }
        private void ModificaPreferenzeClickHandler(object sender, EventArgs e)
        {
            PreferencesDialog dialog = new PreferencesDialog();

            dialog.PreferencesList.DataSource         = ManagerProvider.getManager <KitchenManager>().Ingredients;
            dialog.PreferencesList.AllowColumnReorder = true;
            dialog.PreferencesList.FullRowSelect      = false;

            foreach (Ingredient i in Model.CurrentUser.Preferences)
            {
                dialog.PreferencesList.Items.Where(el => el.DataBoundItem == i).Single().CheckState = Telerik.WinControls.Enumerations.ToggleState.On;
            }
            dialog.PreferencesList.SelectedItem = null;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                List <Ingredient> newPrefs = new List <Ingredient>();
                foreach (ListViewDataItem element in dialog.PreferencesList.CheckedItems)
                {
                    Ingredient i = (Ingredient)element.DataBoundItem;
                    newPrefs.Add(i);
                }
                Model.CurrentUser.Preferences = newPrefs;
            }
        }
Ejemplo n.º 3
0
 public SingleProfileModel()
 {
     _userProfileManager              = ManagerProvider.getManager <UserProfileManager>();
     _userProfileManager.UserAdded   += _userProfileManager_UserAdded;
     _userProfileManager.UserRemoved += _userProfileManager_UserRemoved;
     _userProfileManager.UserUpdated += _userProfileManager_UserUpdated;
 }
 private void RecalculateTargetWeight()
 {
     try {
         TargetWeightLabel.Text = "Il tuo peso forma è: " + ManagerProvider.getManager <TargetWeightFormulaManager>().Formula.Calculate(Model.CurrentUser.Details);
     } catch (Exception)
     {
         //ignore
     }
 }
 public VersionDialog()
 {
     InitializeComponent();
     _versionsListView.VisualItemCreating += _preferencesList_VisualItemCreating;
     _versionsListView.CurrentItemChanged += _versionsListView_CurrentItemChanged;
     _versionsListView.DataSource          = ManagerProvider.getManager <VersionManager>().AllVersions.Where(v => v.CompareTo(ManagerProvider.getManager <VersionManager>().CurrentVersion) > 0);
     _versionsListView.CurrentItem         = null;
     _okButton.Click += _okButton_Click;
     foreach (RichTextBox codeBox in _buttonPanel.Controls.OfType <RichTextBox>())
     {
         codeBox.KeyUp += CodeBox_KeyUp;
     }
 }
        internal static void SetEnabledStatus(Control control, bool enabled)
        {
            if (control.Tag == null || !(control.Tag is PropertyAndObject))
            {
                return;
            }

            PropertyInfo pi  = ((PropertyAndObject)control.Tag).PropertyInfo;
            object       obj = ((PropertyAndObject)control.Tag).Object;

            if (pi.PropertyType == typeof(Load))
            {
                ((RadRating)control).ReadOnly = !enabled;
            }
            else if (new Type[] { typeof(DateTime), typeof(string), typeof(int) }.Contains(pi.PropertyType))
            {
                control.Enabled = enabled;
            }
            else if (pi.PropertyType.IsEnum)
            {
                foreach (RadioButton r in ((GroupBox)control).Controls)
                {
                    r.Enabled = enabled;
                }
            }
            else if (pi.PropertyType.GetInterfaces().Contains(typeof(IList)) && pi.PropertyType.IsGenericType)
            {
                if (ManagerProvider.getManager <VersionManager>().Allows(Feature.CHANGE_PREFERENCES))
                {
                    control.Click    += ModificaPreferenzeClickHandler;
                    control.BackColor = Color.White;
                }
                string pref = "";
                if (((IList <Ingredient>)pi.GetValue(obj)).Any())
                {
                    pref = (from p in ((IList <Ingredient>)pi.GetValue(obj)) select p.Name).Aggregate((x, y) => x + ", " + y);
                }
                ((TextBox)control).Text = pref;
            }
        }
        private void _okButton_Click(object sender, EventArgs e)
        {
            Code code = new Code(_codeBox1.Text, _codeBox2.Text, _codeBox3.Text, _codeBox4.Text);

            Versions.Version attempt = (Versions.Version)_versionsListView.CurrentItem.DataBoundItem;
            if (ManagerProvider.getManager <VersionManager>().ChangeVersion(attempt, code))
            {
                MessageBox.Show("Upgrade riuscito, ora puoi provare le nuove features", "AGGIORNAMENTO RIUSCITO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                if (MessageBox.Show("Il codice inserito non è valido per la versione selezionata", "CODICE NON VALIDO", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
                {
                    this.DialogResult = DialogResult.None;
                }
                else
                {
                    this.DialogResult = DialogResult.Cancel;
                }
            }
        }
        private void ModificaPreferenzeClickHandler(object sender, EventArgs e)
        {
            PreferencesDialog dialog = new PreferencesDialog();

            dialog.PreferencesList.DataSource         = ManagerProvider.getManager <KitchenManager>().Ingredients;
            dialog.PreferencesList.AllowColumnReorder = false;
            dialog.PreferencesList.AllowDragDrop      = false;
            dialog.PreferencesList.AllowDrop          = false;
            dialog.PreferencesList.FullRowSelect      = false;
            dialog.PreferencesList.AllowEdit          = false;
            dialog.PreferencesList.AllowRemove        = false;
            dialog.PreferencesList.CheckOnClickMode   = CheckOnClickMode.FirstClick;
            dialog.PreferencesList.HotTracking        = true;


            foreach (Ingredient i in Model.CurrentUser.Preferences)
            {
                dialog.PreferencesList.Items.Where(el => el.DataBoundItem == i).Single().CheckState = Telerik.WinControls.Enumerations.ToggleState.On;
            }
            dialog.PreferencesList.SelectedItem = null;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                List <Ingredient> newPrefs = new List <Ingredient>();
                foreach (ListViewDataItem element in dialog.PreferencesList.CheckedItems)
                {
                    Ingredient i = (Ingredient)element.DataBoundItem;
                    newPrefs.Add(i);
                }
                Model.CurrentUser.Preferences = newPrefs;
                string pref = "";
                if (newPrefs.Any())
                {
                    pref = (from p in newPrefs select p.Name).Aggregate((x, y) => x + ", " + y);
                }
                ProfilePanel.Controls.OfType <Label>().First(c => c.Name == "Preferences").Text = pref;
            }
        }
Ejemplo n.º 9
0
 private void UpdateAddUserButtonState()
 {
     AddUserButton.Enabled = Model.AllUsers.Count() == 0 || ManagerProvider.getManager <VersionManager>().Allows(Feature.ADD_USER);
 }
 public KcalDietCalculator()
 {
     _kitchenManager = ManagerProvider.getManager <KitchenManager>();
 }
        private void ModifyClickHandler(Object sender, EventArgs e)
        {
            for (int i = 0; i < ProfilePanel.RowCount; i++)
            {
                Control control = ProfilePanel.GetControlFromPosition(1, i);
                if (control.GetType() == typeof(RadRating))
                {
                    ((RadRating)control).ReadOnly = false;
                }
                else if (control.GetType() == typeof(GroupBox))
                {
                    if (((PropertyInfo)control.Tag).PropertyType == typeof(Goal))
                    {
                        if (ManagerProvider.getManager <VersionManager>().Allows(Feature.CHANGE_GOAL))
                        {
                            (control.Controls.OfType <RadioButton>()).ToList <RadioButton>().ForEach(o => o.Enabled = true);
                        }
                    }
                    else
                    {
                        (control.Controls.OfType <RadioButton>()).ToList <RadioButton>().ForEach(o => o.Enabled = true);
                    }
                }
                else if (control.Tag is PropertyInfo && ((PropertyInfo)control.Tag).PropertyType.GetInterfaces().Contains(typeof(IList)) && ((PropertyInfo)control.Tag).PropertyType.IsGenericType)
                {
                    if (ManagerProvider.getManager <VersionManager>().Allows(Feature.CHANGE_PREFERENCES))
                    {
                        control.Click    += ModificaPreferenzeClickHandler;
                        control.BackColor = Color.White;
                    }
                }
                else
                {
                    control.Enabled = true;
                }
            }


            TableLayoutPanel buttonPanel = new TableLayoutPanel();

            buttonPanel.RowCount    = 1;
            buttonPanel.ColumnCount = 2;
            RadButton salva = new RadButton();

            salva.Text    = "Salva";
            salva.Click  += SaveClickHandler;
            salva.Enabled = false;
            RadButton annulla = new RadButton();

            annulla.Text   = "Annulla";
            annulla.Click += CancelClickHandler;

            salva.Dock   = DockStyle.Fill;
            annulla.Dock = DockStyle.Fill;
            buttonPanel.Controls.Add(salva, 0, 0);
            buttonPanel.Controls.Add(annulla, 1, 0);
            buttonPanel.Dock = DockStyle.Fill;

            for (int j = 0; j < buttonPanel.ColumnCount; j++)
            {
                buttonPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50));
            }
            MenuPanel.Controls.Clear();
            MenuPanel.Controls.Add(buttonPanel);

            FormChangedHandler(null, null);
            Model.StartModify();
        }
Ejemplo n.º 12
0
 public Presenter(SingleProfileModel model)
 {
     this._model = model;
     ManagerProvider.getManager <VersionManager>().VersionChanged += Presenter_VersionChanged;
 }