﻿/*
 * @kdgilangputra <gilangputra@icloud.com>
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form3 : Form
    {
        helper h = new helper();
        public Form3()
        {
            InitializeComponent();
            this.FormClosing += Form3_FormClosing;
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = bindingSource1;
            dataGridView2.DataSource = bindingSource2;
            h.getDataDB("SELECT email, name FROM [user]", dataGridView1, bindingSource1);
            h.getDataDB("SELECT Id, Name, Address, Price FROM [hotel]", dataGridView2, bindingSource2);
        }
        private void Form3_FormClosing(object sender, FormClosingEventArgs e) {
            h.forceClose(sender, e);
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            h.delDataDB(dataGridView1, sender, e, "user", "email");
        }
        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            h.delDataDB(dataGridView2, sender, e, "hotel", "Id"); 
        }
        private void register_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Form1 form = new Form1();
            this.Visible = false;
            form.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            Form4 form = new Form4();
            form.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("are you sure to delete all data hotel ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (result == DialogResult.Yes)
            {
                for (int i = 0; i < dataGridView2.RowCount; i++)
                    dataGridView2.Rows.RemoveAt(i);

                h.connectDB("DELETE FROM [hotel]");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form7 form = new Form7();
            form.Show();
            this.Visible = false;
        }
    }
}
