You are on page 1of 4

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Repeat
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void memberBindingNavigatorSaveItem_Click(object sender, EventArgs e)


{
this.Validate();
this.memberBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.memberDataSet);

private void Form1_Load(object sender, EventArgs e)


{
// TODO: This line of code loads data into the 'memberDataSet.Member' table.
You can move, or remove it, as needed.
this.memberTableAdapter.Fill(this.memberDataSet.Member);

private void name_Leave(object sender, EventArgs e)


{
if (!Regex.Match(name.Text, "^[A-Z]'?[- a-zA-Z]*$").Success)
{
MessageBox.Show("User Name Must Additional Name", "Warning",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
name.Text = "";
name.Focus();
}
}

private void salary_Leave(object sender, EventArgs e)


{
if (!Regex.Match(salary.Text, "^[0-9]{3,6}").Success)
{
MessageBox.Show("6 Digit Must", "Warning", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
salary.Text = "";
salary.Focus();
}
}
private void occupation_Leave(object sender, EventArgs e)
{
if (!Regex.Match(occupation.Text, "^[A-z]{1,10}$").Success)
{
MessageBox.Show("Occupation Not Empty", "Warning", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
occupation.Text = "";
occupation.Focus();

}
}

private void martial_Leave(object sender, EventArgs e)


{
if (!Regex.Match(martial.Text, "^[A-z]{1,10}$").Success)
{
MessageBox.Show("Martial Not Empty", "Warning", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
martial.Text = "";
martial.Focus();

}
}

private void health_Leave(object sender, EventArgs e)


{
if (!Regex.Match(health.Text, "^[A-z]{1,10}$").Success)
{
MessageBox.Show("Health Not Empty", "Warning", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
health.Text = "";
health.Focus();

}
}

private void children_Leave(object sender, EventArgs e)


{
if (!Regex.Match(children.Text, "^[0-9]{1,2}").Success)
{
MessageBox.Show("Not Null", "Warning", MessageBoxButtons.OK,
MessageBoxIcon.Warning);
children.Text = "";
children.Focus();
}
}

private void register_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection("Data Source=DESKTOP-KRENN7E;Initial
Catalog=Member;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "insert into Member.dbo.Member(Name, DOB, Occupation,
Salary, Marital,Health,Children)Values(@Name, @DOB, @Occupation, @Salary,
@Marital,@Health,@Children)";
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Name",name.Text);
cmd.Parameters.AddWithValue("@DOB", dob.Value.Date);
cmd.Parameters.AddWithValue("@Occupation", occupation.Text);
cmd.Parameters.AddWithValue("@Salary", Convert.ToInt32(salary.Text));
cmd.Parameters.AddWithValue("@Marital", martial.Text);
cmd.Parameters.AddWithValue("@Health", health.Text);
cmd.Parameters.AddWithValue("@Children",Convert.ToInt32(children.Text));
try
{
int n; n = cmd.ExecuteNonQuery();
if (n > 0)
{
MessageBox.Show("Member Data Inserted", "Member",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else MessageBox.Show("Error");
}
catch (SqlException ex)
{ MessageBox.Show(ex.Message); }
con.Close();
}

}
}

You might also like