private void vendorDetailsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Vendor v = new Vendor();
     v.Show();
 }
 private void button1_Click(object sender, EventArgs e)
 {
     Vendor v = new Vendor();
     v.Show();
 }
Пример #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "" || txtAddress.Text == "" || txtCity.Text == "" || txtState.Text == "")
            {
                MessageBox.Show("Fill All the Required Fields", "", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            else
            {
                if (mtbMobile.Text != "" || mtbContact.Text != "")
                {
                    if (mtbMobile.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 Vendor(VendorName,Address,City,State,ContactNo,MobileNo,EmailID) values(@b,@c,@d,@e,@f,@g,@h)", con);
                            cmd.Parameters.AddWithValue("@b", txtName.Text);
                            cmd.Parameters.AddWithValue("@c", txtAddress.Text);
                            cmd.Parameters.AddWithValue("@d", txtCity.Text);
                            cmd.Parameters.AddWithValue("@e", txtState.Text);
                            cmd.Parameters.AddWithValue("@f", mtbContact.Text);
                            cmd.Parameters.AddWithValue("@g", mtbMobile.Text);
                            cmd.Parameters.AddWithValue("@h", txtEmail.Text);

                            try
                            {
                                r = cmd.ExecuteNonQuery();
                                cmd = new SqlCommand("Select VendorID from Vendor", con);
                                SqlDataReader dr = cmd.ExecuteReader();
                                if (dr.HasRows)
                                {
                                    while (dr.Read())
                                    {
                                        res = dr[0].ToString();
                                    }
                                }
                                MessageBox.Show("Vendor Unique Number"+":"+""+""+res, "Succesfully Added", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            }
                            catch (Exception exc)
                            {
                                MessageBox.Show(exc.ToString());
                            }
                            finally
                            {
                                txtAddress.Text = "";
                                txtCity.Text = "";
                                txtEmail.Text = "";
                                txtName.Text = "";
                                txtState.Text = "";
                                mtbMobile.Text = "";
                                mtbContact.Text = "";
                                con.Close();
                            }
                        }
                        else if (!strregex.IsMatch(valid))
                        {
                            MessageBox.Show("Incorrect Email", "", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        }
                    }
                    Vendor v = new Vendor();
                    v.Show();
                }
            }
        }