Beispiel #1
0
        /// <summary>
        /// Получить базу замеров.
        /// </summary>
        /// <returns></returns>
        public List <Froze> GetFrozeBase(string idGager, string date)
        {
            // Подключение к БД
            try
            {
                _connect.Connection.Open();
            }
            catch (MySqlException)
            {
                MessageBox.Show("Проблемы с подключениек к базе данных.", "Ошибка", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(null);
            }

            var query = "SELECT * FROM froze_base WHERE id_gager = '" + idGager + "' AND date = '" + date + "'";

            var command = new MySqlCommand(query, _connect.Connection);
            var reader  = command.ExecuteReader();

            var frozeBase = new List <Froze>();

            while (reader.Read())
            {
                var froze = new Froze {
                    IdFroze = (int)reader[0], Time = (int)reader[1]
                };

                DateTime.TryParseExact(reader[3].ToString(), "dd/MM/yyyy",
                                       CultureInfo.InvariantCulture, DateTimeStyles.None, out var newDate);
                froze.Date = newDate;

                froze.City          = reader[3].ToString();
                froze.Street        = reader[4].ToString();
                froze.HouseNumber   = (int)reader[5];
                froze.PhoneNumber   = reader[7].ToString();
                froze.Apartment     = (int)reader[6];
                froze.Comment       = reader[8].ToString();
                froze.CheckWasFroze = (bool)reader[12];
                froze.IdGager       = reader[14].ToString();
                froze.CreateFroze   = reader[16].ToString();

                frozeBase.Add(froze);
            }

            _connect.Connection.Close();
            return(frozeBase);
        }
Beispiel #2
0
        /// <summary>
        /// Добавить новый замер в БД.
        /// </summary>
        public bool AddFroze(Froze froze)
        {
            var time        = froze.Time;
            var date        = froze.Date.ToString("dd/MM/yyyy");
            var city        = froze.City;
            var street      = froze.Street;
            var houseNumber = froze.HouseNumber;
            var apartment   = froze.Apartment;
            var phoneNumber = froze.PhoneNumber;
            var comment     = froze.Comment;
            var idGager     = froze.IdGager;
            var create      = froze.CreateFroze;

            try
            {
                _connect.Connection.Open();
            }
            catch (MySqlException)
            {
                MessageBox.Show("Проблемы с подключениек к базе данных.", "Ошибка", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(false);
            }

            string query = "INSERT INTO `froze_base` ( " +
                           "`time` , `date` , `city` ,`street` , `house_number` ,`apartment` , `phone_number` , `coment` ,`id_gager`" +
                           ",`create`)" +
                           "VALUES(" + time + ", '" + date + "', '" + city + "', '" + street + "', " + houseNumber + ", " + apartment +
                           ", '" + phoneNumber + "', '" + comment + "', '" + idGager + "', '" + create + "');";

            var command = new MySqlCommand(query, _connect.Connection);

            command.ExecuteNonQuery();

            _connect.Connection.Close();
            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Просмотр замера по двойному клику мыши.
        /// </summary>
        private void ShowFrozeDataGridView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            DataGridView dataGrid = SelectedDataGridViewFroze(sender);

            if ((TestMagnatBL.Froze)dataGrid.SelectedCells[8].Value != null)
            {
                var showFrozeForm = new ShowFrozeForm();
                showFrozeForm.CurrentFroze = (TestMagnatBL.Froze)dataGrid.SelectedCells[8].Value;
                showFrozeForm.Show();
            }
            else
            {
                if (!UserProfile.Data.CurrentPosition.CheckAddFroze)
                {
                    MessageBox.Show("Вы не можете добавить новый замер.", "Ошибка", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);

                    return;
                }

                int index = _showGagerDataGridViewList.FindIndex(t => t == dataGrid);

                var newFroze = new TestMagnatBL.Froze();
                newFroze.Date    = _dateTimePickerList[index].Value;
                newFroze.IdGager = _gager[index].ToString();
                newFroze.Time    = int.Parse(dataGrid.SelectedCells[0].Value.ToString());

                var addFrozeForm = new AddFrozeForm();
                addFrozeForm.CurrentFroze = newFroze;

                if (addFrozeForm.ShowDialog() == DialogResult.OK)
                {
                    UpdateDataSelectTableFroze(dataGrid, _gager[index], _dateTimePickerList[index].Value);
                }
            }
        }