Пример #1
0
        /// <summary>
        /// Обработка события при желении сохранить файл путем изменения текущего файла
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FileSave_btn_Click(object sender, EventArgs e)
        {
            // Перевести в кодировку csv
            List <string> encoded = MyMethods.Serialization(atms).ToList();
            string        head    = "region,city,address,installplace,int_cards_support,sbercart," +
                                    "american_express,for_organizations,accepts_money,prints_onepass,access," +
                                    "comments,bank_code,bank_name,org_id,org_name,phone";

            encoded.Insert(0, head);
            File.WriteAllLines(path, encoded.ToArray(), Encoding.UTF8);
        }
Пример #2
0
 /// <summary>
 /// Обработка события клика мышкой на кнопку для сброса изменений после фильтрации.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button1_Click(object sender, EventArgs e)
 {
     atms.Clear();
     atms.AddRange(backupAtms);
     this.SuspendLayout();
     Cursor = Cursors.AppStarting;
     MyMethods.ShowTable(atms.Count, atms, ref dt);
     Cursor = Cursors.Default;
     this.ResumeLayout();
     button1.Enabled = false;
     button2.Enabled = true;
 }
Пример #3
0
        /// <summary>
        /// Событие возникающее, если пользователь выбрал удаление строки.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int firstindex = dataGridView1.FirstDisplayedScrollingRowIndex;

            atms.RemoveAt(currindex);
            Cursor = Cursors.AppStarting;
            MyMethods.ShowTable(atms.Count, atms, ref dt);
            if (dataGridView1.RowCount > 0)
            {
                dataGridView1.FirstDisplayedScrollingRowIndex = firstindex;
            }
            Cursor = Cursors.Default;
        }
Пример #4
0
        /// <summary>
        /// Событие, возникающее когда пользователь нажал на кнопку, осуществляющую добавление новой записи о Банкомате
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            AddChange Addnote = new AddChange(ref atms);

            Addnote.ShowDialog();
            if (Addnote.DialogResult == DialogResult.OK)
            {
                Cursor = Cursors.AppStarting;
                dataGridView1.SuspendLayout();
                MyMethods.ShowTable(atms.Count, atms, ref dt);
                dataGridView1.ResumeLayout();
                dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount - 1;
                Cursor = Cursors.Default;
            }
        }
Пример #5
0
        /// <summary>
        /// Обработка события при желении сохранить файл путем создания нового файла
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void сохранитькакToolStripButton_Click(object sender, EventArgs e)
        {
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // Перевести в кодировку csv
                List <string> encoded = MyMethods.Serialization(atms).ToList();
                string        head    = "region,city,address,installplace,int_cards_support,sbercart," +
                                        "american_express,for_organizations,accepts_money,prints_onepass,access," +
                                        "comments,bank_code,bank_name,org_id,org_name,phone";
                encoded.Insert(0, head);

                File.WriteAllLines(saveFileDialog1.FileName, encoded.ToArray(), Encoding.UTF8);

                path      = saveFileDialog1.FileName;
                this.Text = "BANKOMATES" + path;
                сохранитьToolStripButton.Enabled = true;
            }
        }
Пример #6
0
        /// <summary>
        /// Событие возникающее, если пользователь выбрал изменение строки.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void изменитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int       firstindex = dataGridView1.FirstDisplayedScrollingRowIndex;
            AddChange Change     = new AddChange(ref atms, currindex);

            Change.ShowDialog();

            Cursor = Cursors.AppStarting;
            if (Change.DialogResult == DialogResult.OK)
            {
                Cursor = Cursors.AppStarting;
                dataGridView1.SuspendLayout();
                MyMethods.ShowTable(atms.Count, atms, ref dt);
                dataGridView1.ResumeLayout();
                dataGridView1.FirstDisplayedScrollingRowIndex = firstindex;
                Cursor = Cursors.Default;
            }
            dataGridView1.FirstDisplayedScrollingRowIndex = firstindex;
        }
Пример #7
0
        static void Main(string[] args)
        {
            // Delegates
            MyDelegate.Run();

            // Events
            MyEvents.Run();


            // LINQ
            MyLINQ.Run();


            // Methods
            MyMethods.Run();


            Console.WriteLine("Press Enter to end the program.");
            Console.ReadLine();
        }
Пример #8
0
        /// <summary>
        /// Событие в котром обрабатывается открытие файла
        /// </summary>
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                numericTextBox1.Enabled = false;
            }
            else
            {
                numericTextBox1.Enabled = true;
            }
            button1.Enabled = false;
            viewToolStripMenuItem.Enabled = false;
            button2.Enabled = false;
            сохранитьToolStripButton.Enabled    = false;
            saveAsToolStripMenuItem.Enabled     = false;
            SaveMenuToolStripItem.Enabled       = false;
            сохранитькакToolStripButton.Enabled = false;
            создатьToolStripButton.Enabled      = false;

            try
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    isFiltered = false;
                    atms       = new List <Банкомат>();
                    dt.Rows.Clear();
                    dt.Columns.Clear();
                    dataGridView1.DataSource = dt;
                    path = openFileDialog1.FileName;
                    viewToolStripMenuItem.Enabled = true;
                    List <string> rows = File.ReadAllLines(path, Encoding.UTF8).ToList();

                    if (rows[0].Split(',').Length != 17)
                    {
                        throw new Exception();
                    }
                    // Заполнение заголовков колонок значениями.
                    foreach (var item in rows[0].Split(','))
                    {
                        dt.Columns.Add(item);
                    }

                    // Отрисовка таблицы в случае, если пользователь решил вывести все элементы.
                    if (checkBox1.Checked)
                    {
                        for (int i = 1; i <= rows.Count - 1; i++)
                        {
                            atms.Add(new Банкомат(rows[i]));
                        }


                        dataGridView1.SuspendLayout();
                        Cursor = Cursors.AppStarting;
                        MyMethods.ShowTable(atms.Count, atms, ref dt);
                        Cursor = Cursors.Default;
                        //dataGridView1.DataSource = dt;
                        dataGridView1.ResumeLayout();
                    }
                    // В случе если пользовтель сам выбрал число в выводимых строк, осуществляется проверка введенных значений.
                    else if (numericTextBox1.IntValue > 0 && !string.IsNullOrWhiteSpace(numericTextBox1.Text))
                    {
                        if (numericTextBox1.IntValue > rows.Count - 1)// Если пользователь ввел значение превышающее допустимое.
                        {
                            if (MessageBox.Show("Запрашивоемое число строк превышает кол-во существующих." +
                                                string.Format("\nМаксимальное число для вывода:{0}", rows.Count - 1) +
                                                "\nБудут выведены все строки файла.",
                                                "Ошибка ввода.", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                            {
                                for (int i = 1; i <= rows.Count - 1; i++)
                                {
                                    atms.Add(new Банкомат(rows[i]));
                                }
                                numericTextBox1.Text = (atms.Count).ToString();
                                dataGridView1.SuspendLayout();
                                Cursor = Cursors.AppStarting;
                                MyMethods.ShowTable(numericTextBox1.IntValue, atms, ref dt);
                                Cursor = Cursors.Default;

                                dataGridView1.ResumeLayout();
                            }
                            else
                            {
                                return;
                            }
                        }
                        else // Если пользователь ввел все верно.
                        {
                            for (int i = 1; i <= numericTextBox1.IntValue; i++)
                            {
                                atms.Add(new Банкомат(rows[i]));
                            }
                            dataGridView1.SuspendLayout();
                            Cursor = Cursors.AppStarting;
                            MyMethods.ShowTable(numericTextBox1.IntValue, atms, ref dt);
                            Cursor = Cursors.Default;
                            dataGridView1.ResumeLayout();
                            dataGridView1.ClearSelection();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Введено некорректное кол-во строк для вывода", "Ошибка ввода.",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    button2.Enabled = true;
                    сохранитьToolStripButton.Enabled    = true;
                    saveAsToolStripMenuItem.Enabled     = true;
                    SaveMenuToolStripItem.Enabled       = true;
                    сохранитькакToolStripButton.Enabled = true;
                    создатьToolStripButton.Enabled      = true;
                    this.Text = "BANKOMATES -" + path;
                }
            }
            catch (ArgumentNullException ex)
            {
                numericTextBox1.Focus();
                System.Media.SystemSounds.Beep.Play();
                MessageBox.Show(ex.Message);
            }
            catch (Exception)
            {
                MessageBox.Show("Веротяно, выбран недопустимый файл.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #9
0
        /// <summary>
        /// По клику на заголовок столбца выполняется сортировка.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_ColumnHeaderMouseClick(
            object sender, DataGridViewCellMouseEventArgs e)
        {
            DataGridViewColumn newColumn = dataGridView1.Columns[e.ColumnIndex];


            if (newColumn.Name == "bank_code")
            {
                dataGridView1.Columns["accepts_money"].HeaderCell.SortGlyphDirection = SortOrder.None;

                if (direction == ListSortDirection.Ascending)
                {
                    dataGridView1.SuspendLayout();
                    try {
                        atms.Sort((x, y) => int.Parse(x.bank_code).CompareTo(int.Parse(y.bank_code)));
                        Cursor = Cursors.AppStarting;
                        MyMethods.ShowTable(atms.Count, atms, ref dt);
                    }
                    catch (Exception) { MessageBox.Show("Файл содержит недопустимые для сортировки значения в поле \"bank_code\"", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }
                    Cursor = Cursors.Default;
                    // dataGridView1.DataSource = dt;
                    dataGridView1.ResumeLayout();
                    direction = ListSortDirection.Descending;

                    newColumn.HeaderCell.SortGlyphDirection =
                        direction == ListSortDirection.Ascending ?
                        SortOrder.Descending : SortOrder.Ascending;
                }
                else
                {
                    dataGridView1.SuspendLayout();
                    atms.Reverse();
                    Cursor = Cursors.AppStarting;
                    MyMethods.ShowTable(atms.Count, atms, ref dt);
                    Cursor = Cursors.Default;

                    dataGridView1.ResumeLayout();
                    direction = ListSortDirection.Ascending;

                    newColumn.HeaderCell.SortGlyphDirection =
                        direction == ListSortDirection.Ascending ?
                        SortOrder.Descending : SortOrder.Ascending;
                }
            }
            else if (newColumn.Name == "accepts_money")
            {
                dataGridView1.Columns["bank_code"].HeaderCell.SortGlyphDirection = SortOrder.None;

                if (direction == ListSortDirection.Ascending)
                {
                    dataGridView1.SuspendLayout();
                    atms.Sort((x, y) => x.accepts_money.CompareTo(y.accepts_money));
                    Cursor = Cursors.AppStarting;
                    MyMethods.ShowTable(atms.Count, atms, ref dt);
                    Cursor = Cursors.Default;
                    //  dataGridView1.DataSource = dt;
                    dataGridView1.ResumeLayout();
                    direction = ListSortDirection.Descending;


                    newColumn.HeaderCell.SortGlyphDirection =
                        direction == ListSortDirection.Ascending ?
                        SortOrder.Descending : SortOrder.Ascending;
                }
                else
                {
                    dataGridView1.SuspendLayout();
                    atms.Reverse();
                    Cursor = Cursors.AppStarting;
                    MyMethods.ShowTable(atms.Count, atms, ref dt);
                    Cursor = Cursors.Default;
                    //   dataGridView1.DataSource = dt;
                    dataGridView1.ResumeLayout();
                    direction = ListSortDirection.Ascending;

                    newColumn.HeaderCell.SortGlyphDirection =
                        direction == ListSortDirection.Ascending ?
                        SortOrder.Descending : SortOrder.Ascending;
                }
            }
        }