Exemplo n.º 1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (cmbGroup.SelectedItem != null)
            {
                string selectedGroup = (string)cmbGroup.SelectedItem;
                string message       = String.Format("Are you sure you want to delete this {0} ? All shops assigned to this {0} is not shown in the shop listing.", groupType);
                if (MessageBox.Show(message, String.Format("Delete {0}", groupType), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (group.Items.Contains(selectedGroup))
                    {
                        group.Items.Remove(selectedGroup);
                        group.Save();

                        foreach (Shop shop in ShopManager.Shops)
                        {
                            if (shop.Category == selectedGroup)
                            {
                                shop.Category = "";
                            }
                        }

                        ShopManager.Save();
                    }

                    this.DialogResult = DialogResult.OK;
                }
            }
        }
Exemplo n.º 2
0
        private void btnCreateGroup_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtNewGroup.Text))
            {
                string message = String.Format("{0} name cannot be empty. Please enter the new {0} name", groupType);
                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (group.Items.Contains(txtNewGroup.Text))
            {
                MessageBox.Show(String.Format("{0} with the name {1} already exists. Please enter a new {0} name", groupType, txtNewGroup.Text), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            group.Items.Add(txtNewGroup.Text);
            group.Save();

            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 3
0
        private void btnRename_Click(object sender, EventArgs e)
        {
            // check whether value is given
            if (cmbCurrentGroup.SelectedItem == null)
            {
                MessageBox.Show("Current category name is not selected.", "Rename", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            if (String.IsNullOrEmpty(txtNewGroup.Text))
            {
                MessageBox.Show("New category name is not provided.", "Rename", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            // check whether it already exists
            if (group.Items.Contains(txtNewGroup.Text))
            {
                MessageBox.Show("New category name " + txtNewGroup.Text + " is already defined.", "Rename", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            // rename all shops assigned to this category
            string selectedCurrentCategory = (string)cmbCurrentGroup.SelectedItem;

            foreach (Shop shop in ShopManager.Shops)
            {
                if (shop.Category == selectedCurrentCategory)
                {
                    shop.Category = txtNewGroup.Text;
                }
            }

            ShopManager.Save();

            group.Items.Remove(selectedCurrentCategory);
            group.Items.Add(txtNewGroup.Text);
            group.Save();

            this.DialogResult = DialogResult.OK;
        }