using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace WindowsApplication2
{
    public partial class Jarime : Form
    {
        public Jarime()
        {
            InitializeComponent();
        }

        private void Form18_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet21.penalty' table. You can move, or remove it, as needed.
            this.penaltyTableAdapter.Fill(this.dataSet21.penalty);
            label4.Text = ReturnCD.dateII;
            MMDClassLibrary.MDate mmm = new MMDClassLibrary.MDate();
            label5.Text = mmm.Today();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            sqlDataAdapter1.SelectCommand.Parameters.Clear();
            int maxRank;
            sqlDataAdapter1.SelectCommand.CommandText = "SELECT MAX(rank) AS rank FROM penalty";
            try
            {
                sqlConnection1.Open();
                maxRank = Convert.ToInt32(sqlDataAdapter1.SelectCommand.ExecuteScalar()) + 1;
                
            }
            catch
            {
                maxRank = 1;
            }
            sqlConnection1.Close();
            MMDClassLibrary.MDate myDate1 = new MMDClassLibrary.MDate();
            sqlDataAdapter1.InsertCommand.Parameters.Clear();
            sqlDataAdapter1.InsertCommand.CommandText = "INSERT INTO [penalty] ([rank], [idRemember], [datePenalty], [ratePenelty]) VALUES (@rank, @idRemember,@datePenalty, @ratePenelty)";
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@rank", maxRank);
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@idRemember",ReturnCD.IDR);
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@datePenalty",myDate1.Today());
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@ratePenelty", Convert.ToInt32(textBox1.Text));
            sqlConnection1.Open();
            sqlDataAdapter1.InsertCommand.ExecuteNonQuery();
            sqlConnection1.Close();
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}