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.IO;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
namespace FecilitiesMgt
{
public partial class AddNewUser : Form
{
public AddNewUser()
{
InitializeComponent();
}
SqlConnection con = new SqlConnection("uid=sa;password=123;database=FacilityMgt");
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Form f = new AdminMenu();
f.Show();
this.Hide();
}
private void btnsubmit_Click(object sender, EventArgs e)
{
if (txtname.Text == "" || txtprsno.Text == "" || txtrank.Text == "" || txtcont.Text == "" || txtmail.Text == "" || txtuser.Text == "" || txtpwd.Text == "")
{
MessageBox.Show(this, "Enter all fields", "Facility", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
string s = "insert into adduser values('" + txtname.Text + "','" + txtprsno.Text + "','" + txtrank.Text + "','" + txtcont.Text + "','" + txtmail.Text + "','" + txtuser.Text + "','" + txtpwd.Text + "')";
SqlCommand cmd = new SqlCommand(s, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("User added");
txtname.Text = txtprsno.Text = txtrank.Text = txtcont.Text = txtmail.Text = txtuser.Text = txtpwd.Text = "";
}
}
private void txtcont_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == false)
{
MessageBox.Show("Enter digit Only");
e.Handled = true;
}
}
private void txtname_Leave(object sender, EventArgs e)
{
if (txtname.Text == "")
{
MessageBox.Show("Enter name");
txtname.Focus();
}
}
private void txtprsno_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == false)
{
MessageBox.Show("Enter digit Only");
e.Handled = true;
}
}
private void txtuser_Leave(object sender, EventArgs e)
{
if (txtuser.Text.Length < 6)
{
MessageBox.Show(this, "username should not be less than 6 characters", "username", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtuser.Focus();
}
}
private void txtpwd_Leave(object sender, EventArgs e)
{
if (txtpwd.Text.Length < 6)
{
MessageBox.Show(this, "password: min 6 characters ", "password", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtpwd.Focus();
}
}
private void txtcont_Leave(object sender, EventArgs e)
{
if (txtcont.Text == "")
{
MessageBox.Show("Enter Mobile number");
txtcont.Focus();
}
}
//private void AddNewUser_Load(object sender, EventArgs e)
//{
//}
private void txtname_TextChanged(object sender, EventArgs e)
{
}
private void txtprsno_Leave(object sender, EventArgs e)
{
if (txtprsno.Text == "")
{
MessageBox.Show("Enter personal no");
txtprsno.Focus();
}
}
private void txtrank_Leave(object sender, EventArgs e)
{
if (txtrank.Text == "")
{
MessageBox.Show("Enter Rank");
txtrank.Focus();
}
}
private void txtmail_Leave(object sender, EventArgs e)
{
//if (txtmail.Text == "")
//{
// MessageBox.Show("enter Email-ID");
// txtmail.Focus();
//}
if (!Regex.Match(txtmail.Text, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*").Success)
{
MessageBox.Show(txtmail.Text+ " is Invalid Email");
txtmail.Focus();
}
}
private void txtcont_Validating(object sender, CancelEventArgs e)
{
if (txtcont.Text.Length != 10)
{
MessageBox.Show(this, "contact number must 10 numbers", "Contact", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtcont.Focus();
}
}
private void lblname_Click(object sender, EventArgs e)
{
}
private void txtname_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsLetter(e.KeyChar) == false)
{
MessageBox.Show("Enter text only");
txtname.Focus();
}
}}