Esempio n. 1
0
        /// <summary>
        /// Конструктор, що створює новий екземпляр класу, надаючи йому наступний порядковий номер і додає даний план в бд
        /// </summary>
        /// <param name="date"></param>
        /// <param name="text"></param>
        /// <param name="implementation"></param>
        public Plan(DateTime date, string text, bool implementation)
        {
            MySqlConnection connection = Plans.Connection();

            connection.Open();
            string          commandStr = "SELECT MAX(Id) FROM plans";
            MySqlCommand    command    = new MySqlCommand(commandStr, connection);
            MySqlDataReader reader     = command.ExecuteReader();
            int             Id         = 1;

            while (reader.Read())
            {
                try
                {
                    Id += Convert.ToInt32(reader[0]);
                }
                catch (Exception)
                {
                    Id = 1;
                }
            }

            connection.Close();
            this.id             = Id;
            this.date           = date;
            this.text           = text;
            this.implementation = implementation;
            this.AddToDB();
        }
Esempio n. 2
0
        public MainWindow()
        {
            InitializeComponent();
            Plans plansForDataGrid = new Plans();

            DataGridPlanYourLife.ItemsSource = plansForDataGrid.plans;
        }
Esempio n. 3
0
        public void DeleteFromDB()
        {
            string          commandStr = "DELETE FROM plans WHERE Id='" + this.id + "'";
            MySqlConnection connection = Plans.Connection();

            connection.Open();
            MySqlCommand command = new MySqlCommand(commandStr, connection);

            command.ExecuteNonQuery();
            connection.Close();
        }
Esempio n. 4
0
        public void UpdateText(string Text)
        {
            string          commandStr = "UPDATE plans SET Text='" + Text + "' WHERE Id='" + this.id + "'";
            MySqlConnection connection = Plans.Connection();

            connection.Open();
            MySqlCommand command = new MySqlCommand(commandStr, connection);

            command.ExecuteNonQuery();
            connection.Close();
        }
Esempio n. 5
0
        public void UpdateDate(DateTime newDate)
        {
            string DateStr    = newDate.ToString("yyyy-MM-dd hh:mm:ss");
            string commandStr = "UPDATE plans SET Date='" + DateStr + "'" +
                                " WHERE Id='" + this.id + "'";
            MySqlConnection connection = Plans.Connection();

            connection.Open();
            MySqlCommand command = new MySqlCommand(commandStr, connection);

            command.ExecuteNonQuery();
            connection.Close();
        }
Esempio n. 6
0
        public void AddToDB()
        {
            string DateStr    = this.date.ToString("yyyy-MM-dd hh:mm:ss");
            string commandStr = "INSERT INTO plans (Id, Date, Text, Implementation) VALUES " +
                                "('" + this.id + "', '" + DateStr + "', '" + this.text + "', '" + this.implementation + "')";
            MySqlConnection connection = Plans.Connection();

            connection.Open();
            MySqlCommand command = new MySqlCommand(commandStr, connection);

            command.ExecuteNonQuery();
            connection.Close();
        }
Esempio n. 7
0
        //public static void ChangePlan(int id, DateTime newDate, string newText, bool newImplementation)
        //{
        //    string DateStr = newDate.ToString("yyyy-MM-dd hh:mm:ss");
        //    string commandStr = "";

        //}

        public void ChangeImplamentation()
        {
            bool Implemetation = !this.implementation;
            int  newImplementation;

            if (Implemetation)
            {
                newImplementation = 1;
            }
            else
            {
                newImplementation = 0;
            }
            string          commandStr = "UPDATE plans SET Implementation='" + newImplementation + "' WHERE Id='" + this.id + "'";
            MySqlConnection connection = Plans.Connection();

            connection.Open();
            MySqlCommand command = new MySqlCommand(commandStr, connection);

            command.ExecuteNonQuery();
            connection.Close();
        }
Esempio n. 8
0
        private void MenuItemUpdata_Click(object sender, RoutedEventArgs e)
        {
            Plans updataPlans = new Plans();

            this.DataGridPlanYourLife.ItemsSource = updataPlans.plans;
        }