Exemplo n.º 1
0
        private void sendBtn_Click(object sender, EventArgs e)
        {
            string name = nameInput.Text.Trim();
            string tel  = telInput.Text.Trim();
            string dataInput;

            if (name.Length == 0 && tel.Length == 0)
            {
                MessageBox.Show("Введите корректные значения");
            }
            else
            {
                if (man.Checked)
                {
                    var man = new Men(name, tel);
                    list.Add(man);
                    dataInput = man.name + "|" + man.tel + "|" + man.dateTime + "|man";
                }
                else if (woman.Checked)
                {
                    var woman = new Women(name, tel);
                    list.Add(woman);
                    dataInput = woman.name + "|" + woman.tel + "|" + woman.dateTime + "|woman";
                }
                else
                {
                    MessageBox.Show("Выберите пол");
                    return;
                }

                // Обычный массив-----------------------------
                //var people = new People(name, tel);
                //list[people.getCount()] = people;
                //Array.Resize<object>(ref list, list.Length+1);
                //--------------------------------------------

                file.Write(dataInput);


                nameInput.Text = "";
                telInput.Text  = "";
            }
        }
Exemplo n.º 2
0
        private void uploadBtn_Click(object sender, EventArgs e)
        {
            ArrayList dataOutput;
            string    pathTextFile = "";

            try
            {
                uploadFileDialog.ShowDialog();
                pathTextFile = uploadFileDialog.FileName;
                dataOutput   = file.ReadFilePath(pathTextFile);
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
                throw;
            }

            foreach (string item in dataOutput)
            {
                var str = item.Split('|');

                string name   = str[0].Trim();
                string tel    = str[1].Trim();
                string gender = str[str.Length - 1].Trim();
                if (gender.ToLower() == "man")
                {
                    var man = new Men(name, tel);
                    list.Add(man);
                }
                else
                {
                    var woman = new Women(name, tel);
                    list.Add(woman);
                }
                // Обычный массив-----------------------------
                //var people = newPpeople(name, tel);
                //list[people.getcount()] = people;
                //array.resize<object>(ref list, list.length + 1);
                //--------------------------------------------
            }
        }