Ejemplo n.º 1
0
 public void OpenFile(string filename)
 {
     if (!System.IO.File.Exists(filename))
     {
         throw new Exception("Файл не существует");
     }
     if (spFiles.Count != 0)
     {
         DeletePeople();
     }
     using (StreamReader sw = new StreamReader(filename))
     {
         while (!sw.EndOfStream)
         {
             string   str          = sw.ReadLine();
             String[] dataFromFile = str.Split(new String[] { "|" },
                                               StringSplitOptions.RemoveEmptyEntries);
             ushort    id     = (ushort)Convert.ToInt32(dataFromFile[0]);
             string    nameC  = dataFromFile[1];
             string    emailC = dataFromFile[2];
             ushort    phoneC = (ushort)Convert.ToInt32(dataFromFile[3]);
             string    cityC  = dataFromFile[4];
             SpravFile spFile = new SpravFile(id, nameC, emailC, phoneC, cityC);
             AddPeopleFile(spFile);
         }
     }
 }
Ejemplo n.º 2
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            try
            {
                string nameC  = textBox1.Text;
                string emailC = textBox2.Text;
                ulong  phoneC = (ulong)Convert.ToInt32(textBox3.Text);
                string cityC  = textBox4.Text;
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";
                SpravFile spFile = new SpravFile(generateID(), nameC, emailC, phoneC, cityC);
                data.AddPeopleFile(spFile);
                int       n     = data.SpFiles.Count;
                SpravFile sprav = (SpravFile)data.SpFiles[n - 1];

                dataGridView1.Rows.Add(sprav.Id, nameC, emailC, phoneC, cityC);
                BanChangeColumn(n - 1);
            }
            catch (Exception exception)
            {
                MessageBox.Show($"Ошибка: {exception.Message}");
            }
        }
Ejemplo n.º 3
0
        int IComparer.Compare(object x, object y)
        {
            SpravFile sprav1 = (SpravFile)x;
            SpravFile sprav2 = (SpravFile)y;

            return((this.m_direction == SortDirection.Ascending) ?
                   sprav1.Id.CompareTo(sprav2.Id) :
                   sprav2.Id.CompareTo(sprav1.Id));
        }
Ejemplo n.º 4
0
        public void ChangePhone(ulong phoneC, int index)
        {
            SpravFile sprav = (SpravFile)SpFiles[index];

            if (phoneC > 99999999999)
            {
                throw new Exception("Неверно указан номер телефона!");
            }
            sprav.Phone = phoneC;
        }
Ejemplo n.º 5
0
        public List <int> SearchSpravFile(string query)
        {
            List <int> count = new List <int>();
            ushort     num_query;

            if (ushort.TryParse(query, out num_query))
            {
                for (int i = 0; i < spFiles.Count; i++)
                {
                    SpravFile sprav = (SpravFile)spFiles[i];
                    if (sprav.Id == num_query)
                    {
                        count.Add(i);
                        break;
                    }
                    else
                    {
                        if (sprav.Phone == num_query)
                        {
                            count.Add(i);
                        }
                    }
                }
                if (count.Count == 0)
                {
                    count.Add(-1);
                }
                return(count);
            }
            query = query.ToLower();
            query = query.Replace(" ", "");
            for (int i = 0; i < spFiles.Count; i++)
            {
                SpravFile sprav = (SpravFile)spFiles[i];
                if (sprav.Name.ToLower().Replace(" ", "").Contains(query))
                {
                    count.Add(i);
                }
                else
                if (sprav.Email.ToLower().Replace(" ", "").Contains(query))
                {
                    count.Add(i);
                }
                else
                if (sprav.City.ToLower().Replace(" ", "").Contains(query))
                {
                    count.Add(i);
                }
            }
            if (count.Count == 0)
            {
                count.Add(-1);
            }
            return(count);
        }
Ejemplo n.º 6
0
 public void WriteToDataGrid()
 {
     for (int i = 0; i < data.SpFiles.Count; i++)
     {
         SpravFile sprav = (SpravFile)data.SpFiles[i];
         dataGridView1.Rows.Add(sprav.Id, sprav.Name,
                                sprav.Email, sprav.Phone, sprav.City);
         BanChangeColumn(i);
     }
     dataGridView1.Rows[data.SpFiles.Count].ReadOnly = true;
 }
Ejemplo n.º 7
0
        public ushort generateID()
        {
            Random r  = new Random();
            int    id = r.Next(0, 1000);

            for (int i = 0; i < data.SpFiles.Count; i++)
            {
                SpravFile sprav = (SpravFile)data.SpFiles[i];
                if (sprav.Id == id)
                {
                    i  = 0;
                    id = r.Next(0, 1000);
                }
            }
            return((ushort)id);
        }
Ejemplo n.º 8
0
        public void ChangeCity(string cityC, int index)
        {
            SpravFile sprav = (SpravFile)SpFiles[index];

            sprav.City = cityC;
        }
Ejemplo n.º 9
0
        public void ChangeEmail(string emailC, int index)
        {
            SpravFile sprav = (SpravFile)SpFiles[index];

            sprav.Email = emailC;
        }
Ejemplo n.º 10
0
        public void ChangePeopleName(string nameC, int index)
        {
            SpravFile sprav = (SpravFile)SpFiles[index];

            sprav.Name = nameC;
        }
Ejemplo n.º 11
0
 public void AddPeopleFile(SpravFile spFile)
 {
     spFiles.Add(spFile);
 }