using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; using System.Data; using System.Net; using System.IO; public partial class Customer_RegisterCustomer : System.Web.UI.Page { string connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString(); SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString); SqlCommand cmd; SqlDataReader dr; string strqry; string message; public static string PackageID, EmpID, RandomPass; List allnodes = new List(); List allnodesstatus = new List(); string lnode; int alllnode = 0; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { } } protected void txtName_TextChanged(object sender, EventArgs e) { if (txtName.Text == "") { message = "javascript: alert('Please Enter Name.')"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", message, true); txtName.Focus(); } else if (txtName.Text.Length < 3) { message = "javascript: alert('Please Enter valid Name.')"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", message, true); txtName.Focus(); } } int a = 0; public string GenRegNo(string name) { string nam = name.Substring(0, 3).ToUpper(); string sno = "0"; if (con.State == ConnectionState.Closed) { con.Open(); } strqry = "select count(*) sno from [Customer] order by sno desc"; SqlCommand cmd = new SqlCommand(strqry, con); SqlDataReader dr; dr = cmd.ExecuteReader(); while (dr.Read()) { a = Convert.ToInt32(dr[0].ToString()) + 1; } dr.Close(); dr.Dispose(); con.Close(); sno = Convert.ToString(a); if (sno.Length == 3) { sno = "0" + sno; string RegNo1 = nam + sno; return RegNo1; } else if (sno.Length == 2) { sno = "00" + sno; string RegNo1 = nam + sno; return RegNo1; } else if (sno.Length == 1) { sno = "000" + sno; string RegNo1 = nam + sno; return RegNo1; } else { string RegNo1 = nam + sno; return RegNo1; } } void clear() { chkTerms.Checked = false; txtReferID.Text = ""; txtRefName.Text = ""; //txtParentage.Text = ""; TextBox1.Text = ""; // TextBox2.Text = ""; //txtNominee.Text = ""; txtRelation.Text = ""; ddl1.SelectedIndex = 0; txtAddress.Text = ""; txtEmailID.Text = ""; txtName.Text = ""; txtPhNo.Text = ""; // txtBankAcc.Text = ""; txtBankName.Text = ""; txtAccName.Text = ""; txtIFSCCode.Text = ""; txtBranch.Text = ""; // txtDOB.Text = ""; } private static Random random = new Random(); void GetPassword() { var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; RandomPass = new string(Enumerable.Repeat(chars, 6).Select(s => s[random.Next(s.Length)]).ToArray()); } protected void btnSave_Click(object sender, EventArgs e) { if (txtRefName.Text == "") { message = "javascript: alert('Please Enter Valid Reference ID of the Customer.')"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", message, true); txtReferID.Focus(); } else { if (chkTerms.Checked == false) { message = "javascript: alert('Please check the terms of use checkbox.')"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", message, true); chkTerms.Focus(); } else { Session["uid"] = GenRegNo(txtName.Text.Trim()); //Session["spid"] = txtReferID.Text; GetPassword(); getallactivemembers(); if (Session["pid"].ToString() != "NULL") { if (con.State == ConnectionState.Closed) { con.Open(); } try { string insQuery = "insert into Customer" + "( " + "name " + ",emailID " + ",phone_no " + ",address " + ",refer_id " + ",password " + ",date " + ",parentage " + ",nominee " + ",n_relation " + ",n_DOB " + ",p_rltion " + ",accountNo " + ",holderName " + ",bankName " + ",IFSCCode " + ",branchName " + ",panno " + ",livestatus " + ",aadharnumber " + ",sponserid " + ",userid " + ",paytm " + ",phonepe " + ",googlepay " + ",whatsapp " + ")" + "values " + "(" + "@name " + ",@emailID " + ",@phone_no " + ",@address " + ",@refer_id " + ",@password " + ",@date " + ",@parentage " + ",@nominee " + ",@n_relation " + ",@n_DOB " + ",@p_rltion " + ",@accountNo " + ",@holderName " + ",@bankName " + ",@IFSCCode " + ",@branchName " + ",@panno " + ",@lstatus " + ",@aadharnumber " + ",@sid " + ",@uid " + ",@paytm " + ",@phonepe " + ",@googlepay " + ",@whatsapp " + ")"; SqlCommand cmd_insert = new SqlCommand(insQuery, con); cmd_insert.Parameters.AddWithValue("@name", txtName.Text.Trim()); cmd_insert.Parameters.AddWithValue("@emailID", txtEmailID.Text.Trim()); cmd_insert.Parameters.AddWithValue("@phone_no", txtPhNo.Text.Trim()); cmd_insert.Parameters.AddWithValue("@address", txtAddress.Text.Trim()); cmd_insert.Parameters.AddWithValue("@refer_id", Session["pid"].ToString()); cmd_insert.Parameters.AddWithValue("@password", RandomPass); Session["password"] = RandomPass; Session["Name"] = txtName.Text; DateTime datenow = System.DateTime.Now.Date; string dd = datenow.ToString("dd/MM/yyyy"); cmd_insert.Parameters.AddWithValue("@date", DateTime.ParseExact(dd, "dd/MM/yyyy", null)); cmd_insert.Parameters.AddWithValue("@parentage", ""); cmd_insert.Parameters.AddWithValue("@nominee", ""); cmd_insert.Parameters.AddWithValue("@n_relation", ""); cmd_insert.Parameters.AddWithValue("@n_DOB", DateTime.ParseExact(dd, "dd/MM/yyyy", null)); cmd_insert.Parameters.AddWithValue("@p_rltion", ""); cmd_insert.Parameters.AddWithValue("@accountNo", ""); cmd_insert.Parameters.AddWithValue("@holderName", ""); cmd_insert.Parameters.AddWithValue("@bankName", ""); cmd_insert.Parameters.AddWithValue("@IFSCCode", ""); cmd_insert.Parameters.AddWithValue("@branchName", ""); cmd_insert.Parameters.AddWithValue("@panno", ""); cmd_insert.Parameters.AddWithValue("@aadharnumber", ""); cmd_insert.Parameters.AddWithValue("@lstatus", '0'); cmd_insert.Parameters.AddWithValue("@sid", txtReferID.Text.Trim()); cmd_insert.Parameters.AddWithValue("@uid", Session["uid"].ToString()); cmd_insert.Parameters.AddWithValue("@paytm", ""); cmd_insert.Parameters.AddWithValue("@phonepe", ""); cmd_insert.Parameters.AddWithValue("@googlepay", ""); cmd_insert.Parameters.AddWithValue("@whatsapp", ""); cmd_insert.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { } finally { } clear(); Response.Redirect("thanks.aspx"); } else { message = "javascript: alert('Please Contact The Administrator of Website.')"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", message, true); } } } } void SendMSG(string mno, string sms) { try { string url = "http://smsservicejammu.inertit.com/index.php/smsapi/httpapi/?uname=amazesrg&password=amazejk&sender=ACFUND&receiver=" + mno + "&route=TA&msgtype=1&sms=" + sms + ""; HttpWebRequest request = (HttpWebRequest)WebRequest .Create(url); request.MaximumAutomaticRedirections = 4; request.Credentials = CredentialCache.DefaultCredentials; HttpWebResponse response = (HttpWebResponse)request .GetResponse(); Stream receiveStream = response.GetResponseStream( ); StreamReader readStream = new StreamReader(receiveStream, System.Text.Encoding.UTF8); string sResponse = readStream.ReadToEnd(); response.Close(); readStream.Close(); } catch (Exception ex) { //Response.Write(ex.ToString()); } } private void MessageBox(string msg) { message = "javascript: alert('" + msg + "')"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", message, true); } protected void btnReset_Click(object sender, EventArgs e) { clear(); } protected void txtReferID_TextChanged(object sender, EventArgs e) { txtRefName.Text = ""; try { if (con.State == ConnectionState.Closed) { con.Open(); } strqry = "select * from [Customer] where [userid]='" + txtReferID.Text + "'"; cmd = new SqlCommand(strqry, con); dr = cmd.ExecuteReader(); if (dr.HasRows) { dr.Read(); txtRefName.Text = dr["name"].ToString(); dr.Close(); } else { dr.Close(); message = "javascript: alert('INVALID REFERENCE ID ?')"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", message, true); txtReferID.Text = ""; txtReferID.Focus(); } } catch { } finally { con.Close(); } } protected void txtEmailID_TextChanged(object sender, EventArgs e) { strqry = "select count(*) from customer where emailID='" + txtEmailID.Text + "'"; con.Open(); cmd = new SqlCommand(strqry, con); int count = Convert.ToInt32(cmd.ExecuteScalar()); if (count == 0) { con.Close(); } else { message = "javascript: alert('Email ID Already Registred !')"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", message, true); txtEmailID.Text = ""; txtEmailID.Focus(); con.Close(); } } protected void txtPhNo_TextChanged(object sender, EventArgs e) { if (txtPhNo.Text.Length == 10) { strqry = "select count(*) from customer where phone_no='" + txtPhNo.Text + "'"; con.Open(); cmd = new SqlCommand(strqry, con); int count = Convert.ToInt32(cmd.ExecuteScalar()); if (count == 0) { con.Close(); } else { message = "javascript: alert('Phone Number Already Registred !')"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", message, true); txtPhNo.Text = ""; txtPhNo.Focus(); con.Close(); } } else { message = "javascript: alert('Phone Number Invalid !')"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertScript", message, true); txtPhNo.Text = ""; txtPhNo.Focus(); } } public void getallactivemembers() { SqlConnection conn = new SqlConnection(connectionString); if (conn.State != ConnectionState.Open) { conn.Open(); } string query = "select customer.userid,livestatus from customer where livestatus='1' order by sno"; SqlCommand cmd = new SqlCommand(query, conn); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { allnodes.Add(dr[0].ToString()); allnodesstatus.Add(dr[1].ToString()); alllnode = alllnode + 1; } conn.Close(); if (allnodes.Count < 4) { Session["pid"] = allnodes[0].ToString(); } else { for (int i = 1; i < allnodes.Count; i++) { int dt = countdownmembers(allnodes[i]); if (dt == 1) { Session["pid"] = "NULL"; } else { break; } } } } public int countdownmembers(string userid) { SqlConnection conn = new SqlConnection(connectionString); if (conn.State != ConnectionState.Open) { conn.Open(); } string query = "select count(*) from customer where livestatus!='2' and refer_id='"+userid+"'"; SqlCommand cmd = new SqlCommand(query, conn); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { dr.Read(); int mem = Convert.ToInt32(dr[0].ToString()); if (mem < 3) { Session["pid"] = userid.ToString(); conn.Close(); return 0; } else { conn.Close(); return 1; } } else { conn.Close(); return 1; } } }