예제 #1
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            GraphDataModel testData = new GraphDataModel("Ethnic Groups in Nepal", "Percentage", "Ethnic Group");

            testData.AddItem("Chhetteri", 16.6);
            testData.AddItem("Brahman - Hill", 16.6);
            testData.AddItem("Magar", 7.1);
            testData.AddItem("Tharu", 6.6);
            testData.AddItem("Tamang", 5.8);
            testData.AddItem("Newar", 5);
            testData.AddItem("Kami", 4.8);
            testData.AddItem("Muslim", 4.4);
            testData.AddItem("Yadav", 4);
            testData.AddItem("Rai", 2.3);
            testData.AddItem("Gurung", 2);
            testData.AddItem("Damai / Dholii", 1.8);
            testData.AddItem("Thakuri", 1.6);
            testData.AddItem("Limbu", 1.5);
            testData.AddItem("Sarki", 1.4);
            testData.AddItem("Teli", 1.4);
            testData.AddItem("Chamar / Harijan / Ram", 1.3);
            testData.AddItem("Kooiri / Kushwaha", 1.2);
            testData.AddItem("Other", 19);

            Random           rnd   = new Random();
            List <ItemModel> items = testData.GetItemList();

            foreach (ItemModel item in items)
            {
                testData.ChangeItemAt(items.IndexOf(item), item.Name, item.Data, Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)));
            }
            testData.gType = 0;
            graphData      = testData;
            UpdateForm(1);
        }
예제 #2
0
        private void btnAddItem_Click(object sender, EventArgs e)
        {
            string name = txtItemName.Text;

            if (!name.Equals("") && int.TryParse(txtItemData.Text, out int data))
            {
                if (btnAddItem.Text == "Add")
                {
                    graphData.AddItem(name, data, lblColorBox.BackColor);
                }
                else if (btnAddItem.Text == "Change")
                {
                    graphData.ChangeItemAt(lstData.SelectedIndex, name, data, lblColorBox.BackColor);
                }
                ResetItemFields();
            }
            else
            {
                //TODO: Customize error message based on what is missing
                MessageBox.Show("Neither 'Name' nor 'Data' can be empty.", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            RefreshListBox();
        }