Пример #1
0
        private void ModifyPlayer_Load(object sender, EventArgs e)
        {
            verifyFile.fileExist();



            try
            {
                //load player name in cmbName
                foreach (ListViewItem itm in myFrm.listView1.Items)
                {
                    cmbName.Items.Add(itm.SubItems[0].Text);
                }
            }
            catch (Exception ex)
            {
                err = ex.ToString();
            }
        }
Пример #2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            //checking file exist or not
            //if not then it will create it
            cTextFile verifyTxtFile = new cTextFile();

            verifyTxtFile.fileExist();


            validation();


            try
            {
                //logics of validation

                if (val == true)
                {
                    if (MessageBox.Show("Do you Want to Add this Player", "Add Profile", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        //obj reference of cPlayer
                        cPlayers player = new cPlayers();


                        //reading text and cmbbox value
                        player.name       = txtName.Text;
                        player.age        = txtAge.Text;
                        player.number     = txtNumber.Text;
                        player.role       = cmbRole.SelectedItem.ToString();
                        player.battiing   = cmbBatting.SelectedItem.ToString();
                        player.bowling    = cmbBowling.SelectedItem.ToString();
                        player.signedYear = cmbSignedYear.SelectedItem.ToString();
                        player.salary     = txtSalary.Text;
                        player.country    = cmbCountry.SelectedItem.ToString();


                        //STORING INDEX NUMBER INTO ARRAY FOR TEXTFILE.
                        string[] entries = new string[9];

                        entries[0] = player.name;
                        entries[1] = player.age;
                        entries[2] = player.number;
                        entries[3] = cmbRole.SelectedIndex.ToString();       //selecting index of combo box to add in text file.
                        entries[4] = cmbBatting.SelectedIndex.ToString();    //selecting index of combo box to add in text file.
                        entries[5] = cmbBowling.SelectedIndex.ToString();    //selecting index of combo box to add in text file.
                        entries[6] = cmbSignedYear.SelectedIndex.ToString(); //selecting index of combo box to add in text file.
                        entries[7] = player.salary;
                        entries[8] = cmbCountry.SelectedIndex.ToString();    //selecting index of combo box to add in text file.

                        //Write into Text file
                        StreamWriter sw = new StreamWriter(cPath.pathPlayers, true);
                        sw.WriteLine(entries[0] + ";" + entries[1] + ";" + entries[2] + ";" + entries[3] + ";" + entries[4] + ";" + entries[5] + ";" + entries[6] + ";" + entries[7] + ";" + entries[8]);
                        sw.Close();
                        MessageBox.Show("New Player has been Added Successfully!!!.", "Player Added", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

                        //Write into list view
                        myFrm.listView1.Items.Add(new ListViewItem(new string[] { player.name, player.age, player.number, player.role, player.battiing, player.bowling, player.signedYear, player.salary, player.country }));

                        txtAge.Clear();
                        txtName.Clear();
                        txtNumber.Clear();
                        txtSalary.Clear();
                        cmbBatting.Items.Clear();
                        cmbBowling.Items.Clear();
                        cmbCountry.Items.Clear();
                        cmbRole.Items.Clear();
                        cmbSignedYear.Items.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                err = ex.ToString();
            }
        }