示例#1
0
 /// <summary>
 /// Инициализирует новый экземпляр класса Charge, получая в качесте аргументов следущие параметры:
 /// </summary>
 /// <param name="phone">Телефонный номер</param>
 /// <param name="service">Услуга</param>
 /// <param name="sum">Сумма</param>
 /// <param name="date">Дата</param>
 public Charge(PhoneNumber phone, Service service, double sum, DateTime date)
 {
     _date = date;
     _phoneID = phone.ID;
     _serviceID = service.ID;
     _sum = sum + service.Cost;
     _phoneNumber = phone;
 }
        /// <summary>
        /// Возвращает новый не занятый номер телефона.
        /// </summary>
        /// <returns>Телефон</returns>
        public static PhoneNumber GetNewNumber()
        {
            PhoneNumber result = null;
            long number;
            try
            {
                connection.Open();

                MySqlCommand cmd = new MySqlCommand("SELECT MAX(number) FROM free_phone_number", connection);
                MySqlDataReader r = cmd.ExecuteReader();
                if (r.Read())
                {
                    number = r.GetInt64("MAX(number)");
                    r.Close();
                    MySqlCommand cmd2 = new MySqlCommand("UPDATE free_phone_number SET number = @number", connection);
                    cmd2.Parameters.AddWithValue("@number", number + 1);
                    cmd2.ExecuteNonQuery();
                    result = new PhoneNumber(-1, -1, "+" + number.ToString(), -1);
                }
                r.Close();
            }
            catch (MySqlException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
            finally
            {
                connection.Close();
            }
            return result;
        }
        /// <summary>
        /// Получает телефонный номер из БД по значению номера.
        /// </summary>
        /// <param name="phoneNumber">Значение номера</param>
        /// <returns>Телефонный номер</returns>
        public static PhoneNumber SelectPhoneNumberByNumber(string phoneNumber)
        {
            PhoneNumber result = null;
            try
            {
                connection.Open();

                MySqlCommand cmd = new MySqlCommand("SELECT * FROM phone_number WHERE number = @number", connection);
                cmd.Parameters.AddWithValue("@number", phoneNumber);
                MySqlDataReader r = cmd.ExecuteReader();
                if (r.Read())
                {
                    result = new PhoneNumber(r.GetInt64("id"), r.GetInt64("subscriber_id"), r.GetString("number"), r.GetInt64("tariff_id"));
                }
                r.Close();
            }
            catch (MySqlException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
            finally
            {
                connection.Close();
            }

            return result;
        }
 /// <summary>
 /// Создает экземпляр класса ChangeTariffController.
 /// </summary>
 /// <param name="number">Номер телефона</param>
 public ChangeTariffController(PhoneNumber number)
 {
     _number = number;
     _tariff = _number.GetTariff();
 }