Пример #1
0
        private void UpdateClassBtn1(object sender, EventArgs e)
        {
            DBConnection.Instance().OpenConnection(); // Xác Định kết nối đến DB

            string   name        = classUpdateName.Text;
            int      floor       = Int32.Parse(classUpdateFloor.Text);
            int      capicity    = Int32.Parse(classUpdateCapitity.Text);
            string   description = classUpdateDescription.Text;
            StdClass class1      = new StdClass(name, floor, capicity, description);
            var      sqlQuery    = "UPDATE `stdclass` " +
                                   "SET `name`=@name,`floor`=@floor,`MaxCapicity`=@capicity,`Ddescription`=@description" +
                                   " WHERE `name`=@location";
            var cmd = new MySqlCommand(sqlQuery, DBConnection.Instance().Connection);

            cmd.Parameters.AddWithValue("@name", class1.Name);
            cmd.Parameters.AddWithValue("@floor", class1.Floor);
            cmd.Parameters.AddWithValue("@capicity", class1.MaxCapicity);
            cmd.Parameters.AddWithValue("@description", class1.Description);
            cmd.Parameters.AddWithValue("@location", originClassName.Text);
            cmd.ExecuteNonQuery();
            DBConnection.Instance().CloseConnection();
            MessageBox.Show("Updated");

            updateForm.onUpdate();

            Close();
        }
Пример #2
0
        private void button_add(object sender, EventArgs e)
        {
            DBConnection.Instance().OpenConnection(); // Xác Định kết nối đến DB

            string   name        = className.Text;
            int      floor       = Int32.Parse(classFloor.Text);
            int      capicity    = Int32.Parse(classCapitity.Text);
            string   description = classDescription.Text;
            StdClass class1      = new StdClass(name, floor, capicity, description);
            var      sqlQuery    = "INSERT INTO `stdclass`(`name`, `floor`, `MaxCapicity`, `Ddescription`) " +
                                   "VALUES " +
                                   "(@name,@floor,@capicity,@description)";
            var cmd = new MySqlCommand(sqlQuery, DBConnection.Instance().Connection);

            cmd.Parameters.AddWithValue("@name", class1.Name);
            cmd.Parameters.AddWithValue("@floor", class1.Floor);
            cmd.Parameters.AddWithValue("@capicity", class1.MaxCapicity);
            cmd.Parameters.AddWithValue("@description", class1.Description);
            cmd.ExecuteNonQuery();
            DBConnection.Instance().CloseConnection();
            showStdClass();
            MessageBox.Show("Add!!!");
        }