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

namespace Nano_System
{
    public partial class frmRegister : Form
    {

        public void dbConnection()
        {
            clsGrideview dbCon1 = new clsGrideview();
            dataGridView1.DataSource = dbCon1.dbConnection(@"SELECT dbo.MemberList1.* FROM dbo.MemberList1");
        }

        public void dbConnection2()
        {
            clsForCombo cmbP2 = new clsForCombo();
            comboBox1.DataSource =  cmbP2.dbConnection2(@"SELECT StateID, MemberState FROM MemberState");
            comboBox1.ValueMember = "StateID";
            comboBox1.DisplayMember = "MemberState";
        }
        public void insSql()
        {
            clsAdding insTodb = new clsAdding();
            insTodb.insSql("insert into Members (MemBerID, Name, Sname, RegDate, ExprDate, melliCode, memberState, Notes)values('" + textBox1.Text + "' , '" + textBox2.Text + "' , '" + textBox3.Text + "' , '" + textBox4.Text + "' , '" + textBox5.Text + "' , '" + textBox6.Text + "' , '" + comboBox1.SelectedValue + "' , '" + textBox7.Text + "')");
            dbConnection();
        }
        
        public frmRegister()
        {
            InitializeComponent();
        }

        private void btnReg_Click(object sender, EventArgs e)
        {
                    if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "" || comboBox1.Text == "")
                    {
                        MessageBox.Show("تمامی فیلدها بایستی دارای مقدار باشند");
                    }
                    else
                    {
                        insSql();
                    }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dbConnection();
            dbConnection2();
            
        }
    }
}