Esempio n. 1
0
        private void signUp_button(object sender, EventArgs e)
        {
            if (allFilled() == false)
            {
                MessageBox.Show("Fill All Details");
                return;
            }
            if (PASSWORD_BOX.Text != PASSWORDAGAIN_BOX.Text)
            {
                MessageBox.Show("Password Not Matching");
                return;
            }
            int flag = 0;

            for (int i = 0; i < 10; i++)
            {
                if (APPLICATION_BOX.Text.ToString()[0] > '9' || APPLICATION_BOX.Text.ToString()[0] < '0')
                {
                    flag = 1;
                    break;
                }
            }
            if (APPLICATION_BOX.Text.ToString().Length != 10 || flag == 1)
            {
                MessageBox.Show("Please enter 10 digit number without country-code or characters");
                return;
            }
            if (PASSWORD_BOX.Text.ToString().Length <= 8)
            {
                MessageBox.Show("Password should be minimum of  9 characters");
                return;
            }
            if (employeeValidation() == false)
            {
                MessageBox.Show("You are not matching employee");
                return;
            }
            SqlConnection  con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\suman\Documents\Login.mdf;Integrated Security=True;Connect Timeout=30");
            SqlDataAdapter sda = new SqlDataAdapter("Select EMAIL from [Table] where EMPCODE ='" + EMPCODE_BOX.Text + "'", con);
            DataTable      dt;

            dt = new DataTable();
            sda.Fill(dt);
            W_EMAIL = dt.Rows[0][0].ToString();

            /*SqlCommand cmd;
             * con.Open();
             * string s = "UPDATE [Table] SET ADDRESS =@p3 , GENDER = @p4,PASSWORD = @p8, BLOODGROUP = @p9, EMAIL = @p10,BIRTHDATE = @p11  WHERE EMPCODE = '"+EMPCODE_BOX.Text+"'";
             * cmd = new SqlCommand(s, con);
             * cmd.Parameters.AddWithValue("@p3", ADDRESS_BOX.Text);
             * cmd.Parameters.AddWithValue("@p4", GENDER_BOX.SelectedItem.ToString());
             * cmd.Parameters.AddWithValue("@p8", PASSWORD_BOX.Text);
             * cmd.Parameters.AddWithValue("@p9", BLOODGROUP_BOX.Text);
             * cmd.Parameters.AddWithValue("@p10", EMAIL_BOX.Text);
             * cmd.Parameters.AddWithValue("@p11", dateTimePicker1.Value.ToString("dd/MM/yyyy"));
             * cmd.CommandType = CommandType.Text;
             * int i = cmd.ExecuteNonQuery();
             * con.Close();*/
            W_ADDRESS = ADDRESS_BOX.Text;
            W_GENDER  = GENDER_BOX.SelectedItem.ToString();
            W_BG      = BLOODGROUP_BOX.Text;
            //W_EMAIL = EMAIL_BOX.Text;
            W_PASSWORD = PASSWORD_BOX.Text;
            W_DATE     = dateTimePicker1.Value.ToString("dd/MM/yyyy");
            W_EMP      = EMPCODE_BOX.Text;
            W_PHONE    = APPLICATION_BOX.Text;
            //MessageBox.Show("Account created Successfully ");
            dateTimePicker1.Value = DateTime.Now;
            Random rnd = new Random();

            randomNumber = (rnd.Next(100000, 999999)).ToString();
            MessageBox.Show("OTP is sent to your registered email");
            Form11 xq = new Form11();

            // Display form modelessly
            xq.Show();
            this.Hide();
            //  ALlow main UI thread to properly display please wait form.
            Application.DoEvents();
            try
            {
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add(new MailAddress(W_EMAIL));
                mail.Subject           = "OTP to setup new account";
                mail.Body              = "Your OTP is " + randomNumber + ". This OTP is valid for 5 minutes only.";
                SmtpServer.Port        = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "MuNnU@1999");
                SmtpServer.EnableSsl   = true;

                SmtpServer.Send(mail);
                //MessageBox.Show("mail Send");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            xq.Hide();
            //this.Hide();
            Form10 x = new Form10();

            x.Show();
        }