示例#1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // name, price and duration cannot be empty
            if (txtName.Text.Trim() != "" && txtPrice.Text.Trim() != "" && txtDuration.Text.Trim() != "")
            {
                if (edit_mode)
                {
                    // update plan
                    plan.Name     = txtName.Text;
                    plan.Duration = Int32.Parse(txtDuration.Text);
                    plan.Price    = Decimal.Parse(txtPrice.Text);
                    plan.Notes    = txtNotes.Text;

                    if (DataLayer.Plan.UpdatePlan(plan) > 0)
                    {
                        MessageBox.Show("Plan updated!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        // refresh the listbox
                        this.mylistbox.DataSource    = DataLayer.Plan.GetAllPlans().ToList();
                        this.mylistbox.ValueMember   = "Key";
                        this.mylistbox.DisplayMember = "Value";
                    }
                    else
                    {
                        MessageBox.Show("Failed to update. Please try again", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else if (!edit_mode)
                {
                    // create a new plan
                    plan          = new DataLayer.Plan();
                    plan.Name     = txtName.Text;
                    plan.Duration = Int32.Parse(txtDuration.Text);
                    plan.Price    = Decimal.Parse(txtPrice.Text);
                    plan.Notes    = txtNotes.Text;

                    // insert new plan into database
                    if (DataLayer.Plan.CreateNewPlan(plan) > 0)
                    {
                        MessageBox.Show("Plan created!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        // refresh the listbox
                        this.mylistbox.DataSource    = DataLayer.Plan.GetAllPlans().ToList();
                        this.mylistbox.ValueMember   = "Key";
                        this.mylistbox.DisplayMember = "Value";
                    }
                    else
                    {
                        MessageBox.Show("Failed create a new plan. Please try again", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Name, price and duration cannot be empty!", "Gym Manager Pro", MessageBoxButtons.OK);
            }
        }
示例#2
0
        //constructor for editing an existing plan
        public EditPlan(DataLayer.Plan myplan, ListBox lb)
        {
            InitializeComponent();

            plan = new DataLayer.Plan();
            this.plan = myplan;

            txtName.Text = plan.Name;
            txtDuration.Text = plan.Duration.ToString();
            txtPrice.Text = plan.Price.ToString();
            if (plan.Notes != null)
                txtNotes.Text = plan.Notes.ToString();
            this.Text = "Edit Plan '" + plan.Name + "'";

            mylistbox = lb as ListBox;
        }
示例#3
0
        //constructor for editing an existing plan
        public EditPlan(DataLayer.Plan myplan, ListBox lb)
        {
            InitializeComponent();

            plan      = new DataLayer.Plan();
            this.plan = myplan;

            txtName.Text     = plan.Name;
            txtDuration.Text = plan.Duration.ToString();
            txtPrice.Text    = plan.Price.ToString();
            if (plan.Notes != null)
            {
                txtNotes.Text = plan.Notes.ToString();
            }
            this.Text = "Edit Plan '" + plan.Name + "'";

            mylistbox = lb as ListBox;
        }
示例#4
0
        private void listBoxPlans_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (form_loaded)
            {
                if (listBoxPlans.SelectedIndex != -1)
                {
                    // get selected plan
                    int planId = Convert.ToInt32(listBoxPlans.SelectedValue.ToString());
                    plan = DataLayer.Plan.GetPlan(planId);

                    //populate textboxes with plan's data
                    txtPlanName.Text = plan.Name;
                    txtPlanDuration.Text = plan.Duration.ToString();
                    txtPlanPrice.Text = plan.Price.ToString();
                    if (plan.Notes != null)
                        txtPlanNotes.Text = plan.Notes.ToString();
                    else
                        txtPlanNotes.Text = null;
                }
            }
        }
示例#5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // name, price and duration cannot be empty
            if (txtName.Text.Trim() != "" && txtPrice.Text.Trim() != "" && txtDuration.Text.Trim() != "")
            {
                if (edit_mode)
                {
                    // update plan
                    plan.Name = txtName.Text;
                    plan.Duration = Int32.Parse(txtDuration.Text);
                    plan.Price = Decimal.Parse(txtPrice.Text);
                    plan.Notes = txtNotes.Text;

                    if (DataLayer.Plan.UpdatePlan(plan) > 0)
                    {
                        MessageBox.Show("Plan updated!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        // refresh the listbox
                        this.mylistbox.DataSource = DataLayer.Plan.GetAllPlans().ToList();
                        this.mylistbox.ValueMember = "Key";
                        this.mylistbox.DisplayMember = "Value";
                    }
                    else
                    {
                        MessageBox.Show("Failed to update. Please try again", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else if (!edit_mode)
                {
                    // create a new plan
                    plan = new DataLayer.Plan();
                    plan.Name = txtName.Text;
                    plan.Duration = Int32.Parse(txtDuration.Text);
                    plan.Price = Decimal.Parse(txtPrice.Text);
                    plan.Notes = txtNotes.Text;

                    // insert new plan into database
                    if (DataLayer.Plan.CreateNewPlan(plan) > 0)
                    {
                        MessageBox.Show("Plan created!", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        // refresh the listbox
                        this.mylistbox.DataSource = DataLayer.Plan.GetAllPlans().ToList();
                        this.mylistbox.ValueMember = "Key";
                        this.mylistbox.DisplayMember = "Value";
                    }
                    else
                    {
                        MessageBox.Show("Failed create a new plan. Please try again", "Gym Manager Pro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Name, price and duration cannot be empty!", "Gym Manager Pro", MessageBoxButtons.OK);
            }
        }