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;
using System.Data.SqlClient;

namespace Amlak_Management
{
    public partial class Form_Register : Form
    {
        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\amlak.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
        SqlCommand cmd = new SqlCommand();
        public Form_Register()
        {
            InitializeComponent();
        }

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

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtadres.Text == "" || txtcode.Text == "" | txtonvan.Text == "" || txttel.Text == "" || txttype.Text == "")
                MessageBox.Show("لطفا فیلدهای خالی را پر کنید");
            else
            {
                cmd.Connection = con;
                cmd.CommandText = "Insert Into [melk] (Name,Code,Type,Tel,Adres) Values (@p1,@p2,@p3,@p4,@p5)";
                cmd.Parameters.AddWithValue("@p1", txtonvan.Text);
                cmd.Parameters.AddWithValue("@p2", txtcode.Text);
                cmd.Parameters.AddWithValue("@p3", txttype.Text);
                cmd.Parameters.AddWithValue("@p4", txttel.Text);
                cmd.Parameters.AddWithValue("@p5", txtadres.Text);
                con.Open();
                cmd.ExecuteNonQuery();
                MessageBox.Show("ثبت گردید");
                txtadres.Text = txtcode.Text = txtonvan.Text = txttel.Text = txttype.Text = "";
                txtonvan.Focus();
                con.Close();
            }
        }
    }
}
