private void btnSave_Click(object sender, EventArgs e) { if (txtCntctPerson.Text == "" || txtAddress.Text == "" || txtCity.Text == "" || txtState.Text == "") { MessageBox.Show("Fill the data correctly", "Wrong Input", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { if (mtbOffice.Text != "" || mtbContact.Text != "") { if (mtbOffice.Text.Length < 10 && mtbContact.Text.Length < 10) { MessageBox.Show("Incorrect No.", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { string valid; Regex strregex = new Regex("([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})"); valid = txtEmail.Text; if (strregex.IsMatch(valid)) { con.Open(); cmd = new SqlCommand("Insert into CustomerInfo(CompanyName,ContactPerson,Address,City,State,ContactNo,OfficeNo,EmailID) values(@b,@c,@d,@e,@f,@g,@h,@i)", con); cmd.Parameters.AddWithValue("@b", txtCmpnyName.Text); cmd.Parameters.AddWithValue("@c", txtCntctPerson.Text); cmd.Parameters.AddWithValue("@d", txtAddress.Text); cmd.Parameters.AddWithValue("@e", txtCity.Text); cmd.Parameters.AddWithValue("@f", txtState.Text); cmd.Parameters.AddWithValue("@g", mtbContact.Text); cmd.Parameters.AddWithValue("@h", mtbOffice.Text); cmd.Parameters.AddWithValue("@i", txtEmail.Text); try { int r = cmd.ExecuteNonQuery(); cmd = new SqlCommand("Select CustomerID from CustomerInfo", con); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { res = dr[0].ToString(); } } dr.Close(); MessageBox.Show("Customer Unique Number" + ":" + "" + "" + res, "Contact Added Succesfully", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception exc) { MessageBox.Show(exc.ToString()); } finally { txtCmpnyName.Text = ""; txtCntctPerson.Text = ""; txtAddress.Text = ""; txtCity.Text = ""; txtState.Text = ""; txtEmail.Text = ""; mtbContact.Text = ""; mtbOffice.Text = ""; con.Close(); } } else if (!strregex.IsMatch(valid)) { MessageBox.Show("Incorrect Email", "", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } Customer c = new Customer(); c.Show(); } } }
private void button1_Click(object sender, EventArgs e) { Customer c = new Customer(); c.Show(); }
private void newEntryToolStripMenuItem3_Click(object sender, EventArgs e) { Customer c = new Customer(); c.Show(); }