Exemple #1
0
    private void CheckIfExist()
    {
        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["HPSCDBNEW"].ConnectionString);

        cn.Open();
        String     sql = "select count(*) as Record from  ApplicantDetails where CandidateName = @Name and FatherHusbandName=@FName and MotherName = @MName and DOB = @DOB AND PostCode = @PostCode";
        SqlCommand cmd = new SqlCommand(sql, cn);

        cmd.Parameters.AddWithValue("@Name", lblname.Text.Trim());
        cmd.Parameters.AddWithValue("@FName", lblfname.Text.Trim());
        cmd.Parameters.AddWithValue("@MName", lblmname.Text.Trim());
        cmd.Parameters.AddWithValue("@POSTCODE", lblpostcode.Text);
        IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true);
        String          datetime = lbldob.Text.Trim();
        DateTime        dt       = DateTime.Parse(datetime, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);

        cmd.Parameters.AddWithValue("@DOB", dt);
        //SqlCommand cmd = new SqlCommand(query, cn);
        string iemail = cmd.ExecuteScalar().ToString();

        //cn.Close();
        if (iemail == "0")
        {
            DataSet R = new DataSet();

            if (Convert.ToInt16(Session["addedit"].ToString()) == 1)
            {
                R = entryobj.CreateRecord();
                Session["data"] = R;
                Response.Redirect("Regprintset.aspx");
            }
            else
            {
                //entryobj.Postcode = Convert.ToInt32(ds.Tables[0].Rows[0]["PAddress"].ToString());
                R = entryobj.UpdateRecord(Session["RegestrationNumber"].ToString());
                Session["data"] = R;
                Response.Redirect("Regprintset.aspx");
            }
        }
        else
        {
            String     sql1 = "select Regno from  SSB2010Entrydetail where Name = @Name and Fname=@FName and mname = @MName and DOb = @DOB and postcode = @postcode";
            SqlCommand cmd1 = new SqlCommand(sql1, cn);
            cmd1.Parameters.AddWithValue("@Name", lblname.Text.Trim());
            cmd1.Parameters.AddWithValue("@FName", lblfname.Text.Trim());
            cmd1.Parameters.AddWithValue("@MName", lblmname.Text.Trim());
            cmd1.Parameters.AddWithValue("@POSTCODE", Convert.ToInt32(lblpostcode.Text));


            String   datetime1 = lbldob.Text.Trim();
            DateTime dt1       = DateTime.Parse(datetime, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
            cmd1.Parameters.AddWithValue("@DOB", dt1);
            SqlDataReader dr;
            dr = cmd1.ExecuteReader();
            if (dr.HasRows)
            {
                dr.Read();
                Session["regno"] = dr["Regno"].ToString();
                Session["edit"]  = 1;
                Response.Redirect("Regedit.aspx");
            }
        }
    }
    private void CheckIfExist()
    {
        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["HPSCDBNEW"].ConnectionString);

        cn.Open();
        String     sqlaadhar = "select * from  ApplicantDetails where  Aadharnumber=@Aadharnumber and PostCode=@PostCode";
        SqlCommand cmdaadhar = new SqlCommand(sqlaadhar, cn);

        cmdaadhar.Parameters.AddWithValue("@POSTCODE", Convert.ToInt32(ddlpost.SelectedValue));
        cmdaadhar.Parameters.AddWithValue("@Aadharnumber", TxtAdhaarNo.Text.Trim());
        SqlDataAdapter daaadhar = new SqlDataAdapter(cmdaadhar);
        DataSet        dsaadhar = new DataSet();

        daaadhar.Fill(dsaadhar);
        if (dsaadhar.Tables[0].Rows.Count > 0 && dsaadhar.Tables[0].Rows[0]["PostCode"].ToString() == ddlpost.SelectedValue)
        {
            lblErrMsg.Text = "You have alredy applied for this Post. Please login with User Name and Password send on your registered Email.  <a href = 'HomePage.aspx'  target=_blank>Click Here</a> ";
        }
        else
        {
            String     sql = "select * from  ApplicantDetails where (CandidateName = @Name and FatherHusbandName=@FName and MotherName = @MName AND PostCode = @PostCode) and Aadharnumber=@Aadharnumber";
            SqlCommand cmd = new SqlCommand(sql, cn);
            cmd.Parameters.AddWithValue("@Name", txtName.Text.Trim());
            cmd.Parameters.AddWithValue("@FName", txtFname.Text.Trim());
            cmd.Parameters.AddWithValue("@MName", txtMname.Text.Trim());
            cmd.Parameters.AddWithValue("@POSTCODE", Convert.ToInt32(ddlpost.SelectedValue));
            cmd.Parameters.AddWithValue("@Aadharnumber", TxtAdhaarNo.Text);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet        ds = new DataSet();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataSet R = new DataSet();
                Session["RegestrationNumber"] = ds.Tables[0].Rows[0]["RegestrationNumber"].ToString();
                Session["PostCode"]           = ds.Tables[0].Rows[0]["PostCode"].ToString();
                Session["PostName"]           = ddlpost.SelectedItem.Text;
                Session["Aadharnumber"]       = ds.Tables[0].Rows[0]["Aadharnumber"].ToString();
                Session["Password"]           = ds.Tables[0].Rows[0]["Password"].ToString();
                Session["data"]    = ds;
                Session["addedit"] = 1;
                Response.Redirect("Register2.aspx");
            }
            else
            {
                DataSet R = new DataSet();
                entryobj.PostCode           = ddlpost.SelectedValue;
                entryobj.Aadharnumber       = TxtAdhaarNo.Text.Trim();
                entryobj.Retiredemployee    = rbtnGover.SelectedItem.Text;
                entryobj.RegestrationNumber = "";
                entryobj.CandidateName      = txtName.Text.Trim();
                entryobj.FatherHusbandName  = txtFname.Text.Trim();
                entryobj.MotherName         = txtMname.Text.Trim();
                entryobj.DOB = Convert.ToDateTime(txtDOb.Text);
                string Password = CreateRandomPassword(8);
                entryobj.Password      = Password;
                entryobj.Mobile_Number = txtmobilenumber.Text.Trim();
                entryobj.Email_field   = txtemail.Text.Trim();
                R = entryobj.CreateRecord();
                SqlDataAdapter aaa = new SqlDataAdapter(cmdaadhar);

                String     sqlaa = "select * from  ApplicantDetails where PostCode = @PostCode and Aadharnumber=@Aadharnumber";
                SqlCommand cmdaa = new SqlCommand(sqlaa, cn);
                cmdaa.Parameters.AddWithValue("@POSTCODE", Convert.ToInt32(ddlpost.SelectedValue));
                cmdaa.Parameters.AddWithValue("@Aadharnumber", TxtAdhaarNo.Text);
                SqlDataAdapter daaa = new SqlDataAdapter(cmd);
                DataSet        aa   = new DataSet();
                daaa.Fill(aa);
                if (aa.Tables[0].Rows.Count > 0)
                {
                    Session["RegestrationNumber"] = aa.Tables[0].Rows[0]["RegestrationNumber"].ToString();
                    Session["data"]    = R;
                    Session["addedit"] = 0;
                    // Session["RegestrationNumber"] = builder.ToString();
                    Session["Aadharnumber"] = TxtAdhaarNo.Text.Trim();
                    Session["Password"]     = Password;
                    try
                    {
                        MailMessage Msg = new MailMessage();
                        // Sender e-mail address.
                        Msg.From = new MailAddress("*****@*****.**");
                        // Recipient e-mail address.
                        Msg.To.Add(txtemail.Text.Trim());
                        Msg.Subject = "You have been registered for the online application";
                        Msg.Body    = "You have applied for the post" + ddlpost.SelectedItem.Text + "in HSRLM,Panchkula . Your Registration number is " + Session["RegestrationNumber"] + " and Password is " + Session["Password"];

                        SmtpClient smtp = new SmtpClient();
                        smtp.Host        = "smtp.gmail.com";
                        smtp.Port        = 587;
                        smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "hsrlm@123");
                        smtp.EnableSsl   = true;
                        smtp.Send(Msg);
                        Msg = null;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("{0} Exception caught.", ex);
                    }



                    Response.Redirect("Register2.aspx");
                }
                lblErrMsg.Text = "Yor are over Age";
            }
        }
    }