예제 #1
0
 protected void btnlogin_Click(object sender, EventArgs e)
 {
     try
     {
         string username = Regex.Replace(txtusername.Text, @"[^\w]", "");
         string password = Regex.Replace(txtpassword.Text, @"[^\w]", "");
         if (username == "")
         {
             lblmsg.Visible           = true;
             lblmsg.Text              = "Username must not be empty.";
             mtop.Style["margin-top"] = "40px";
         }
         else if (password == "")
         {
             lblmsg.Visible           = true;
             lblmsg.Text              = "Password must not be empty.";
             mtop.Style["margin-top"] = "40px";
         }
         else
         {
             ProjectDatasetTableAdapters.usersTableAdapter ta = new ProjectDatasetTableAdapters.usersTableAdapter();
             string ucheck = ta.checkbyusername(username).ToString();
             string pcheck = ta.passwordcheck(username, password).ToString();
             if (Convert.ToInt32(ucheck) == 0)
             {
                 lblmsg.Visible           = true;
                 lblmsg.Text              = "Username doesn't Exist.";
                 mtop.Style["margin-top"] = "40px";
             }
             else if (Convert.ToInt32(pcheck) == 0)
             {
                 lblmsg.Visible           = true;
                 lblmsg.Text              = "Username/Password Is incorrect.";
                 mtop.Style["margin-top"] = "40px";
             }
             else if (username == "admin")
             {
                 Session["username"]  = username;
                 Session["logintype"] = "admin";
                 Response.Redirect("dashboard.aspx");
             }
             else
             {
                 Session["username"]  = username;
                 Session["logintype"] = "user";
                 Response.Redirect("dashboard.aspx");
             }
         }
     }
     catch (Exception ex)
     {
         lblmsg.Visible           = true;
         lblmsg.Text              = ex.ToString();
         mtop.Style["margin-top"] = "40px";
     }
 }
 protected void btnregister_Click(object sender, EventArgs e)
 {
     try
     {
         string username        = Regex.Replace(txtusername.Text, @"[^\w]", "");
         string fullname        = Regex.Replace(txtfullname.Text, @"[^\w]", "");
         string email           = txtemail.Text.ToString();
         string password        = Regex.Replace(txtpassword.Text, @"[^\w]", "");
         string password_repeat = Regex.Replace(txtrepeatpassword.Text, @"[^\w]", "");
         string mobileno        = Regex.Replace(txtmobile.Text, @"[^\w]", "");
         if (username == "")
         {
             lblmsg.Visible           = true;
             lblmsg.Text              = "Username must not be empty.";
             mtop.Style["margin-top"] = "40px";
         }
         else if (fullname == "")
         {
             lblmsg.Visible           = true;
             lblmsg.Text              = "Real name must not be empty.";
             mtop.Style["margin-top"] = "40px";
         }
         else if (email == "")
         {
             lblmsg.Visible           = true;
             lblmsg.Text              = "Email must not be empty.";
             mtop.Style["margin-top"] = "40px";
         }
         else if (password == "")
         {
             lblmsg.Visible           = true;
             lblmsg.Text              = "Password must not be empty.";
             mtop.Style["margin-top"] = "40px";
         }
         else if (password_repeat == "")
         {
             lblmsg.Visible           = true;
             lblmsg.Text              = "Password Repeat Feild must not be empty.";
             mtop.Style["margin-top"] = "40px";
         }
         else if (mobileno == "")
         {
             lblmsg.Visible           = true;
             lblmsg.Text              = "Mobile no must not be empty.";
             mtop.Style["margin-top"] = "40px";
         }
         else if (password != password_repeat)
         {
             lblmsg.Visible           = true;
             lblmsg.Text              = "Passwords Donot Match.";
             mtop.Style["margin-top"] = "40px";
         }
         else
         {
             ProjectDatasetTableAdapters.usersTableAdapter ta = new ProjectDatasetTableAdapters.usersTableAdapter();
             string ucount = ta.checkbyusername(username).ToString();
             string ecount = ta.checkbyemail(email).ToString();
             if (Convert.ToInt32(ucount) > 0)
             {
                 lblmsg.Visible           = true;
                 lblmsg.Text              = "Username Already Exists";
                 mtop.Style["margin-top"] = "40px";
             }
             else if (Convert.ToInt32(ecount) > 0)
             {
                 lblmsg.Visible           = true;
                 lblmsg.Text              = "Email Already Exists";
                 mtop.Style["margin-top"] = "40px";
             }
             else
             {
                 ta.InsertQuery(username, email, password, fullname);
                 lblmsg.Visible             = true;
                 lblmsg.Text                = "You are Registered Successfully!";
                 lblmsg.Style["background"] = "#4CAF50!important";
                 mtop.Style["margin-top"]   = "40px";
             }
         }
     }
     catch (Exception ex)
     {
         lblmsg.Visible           = true;
         lblmsg.Text              = ex.ToString();
         mtop.Style["margin-top"] = "40px";
     }
 }
        protected void btnsend_Click(object sender, EventArgs e)
        {
            try
            {
                string username = (string)(Session["username"]);
                String receiver = Regex.Replace(txtreceiver.Text, @"[^\w]", "");
                String amount   = Regex.Replace(txtamount.Text, @"[^\w]", "");
                if (receiver == "")
                {
                    lblmsg.Visible           = true;
                    lblmsg.Text              = "Receiver Username Must not be empty.";
                    mtop.Style["margin-top"] = "40px";
                }
                else if (amount == "")
                {
                    lblmsg.Visible           = true;
                    lblmsg.Text              = "Amount Must not be empty";
                    mtop.Style["margin-top"] = "40px";
                }
                else
                {
                    if (Convert.ToInt32(amount) < 100)
                    {
                        lblmsg.Visible           = true;
                        lblmsg.Text              = "Minimum amount you can send is, RS100";
                        mtop.Style["margin-top"] = "40px";
                    }
                    else
                    {
                        ProjectDatasetTableAdapters.usersTableAdapter ta = new ProjectDatasetTableAdapters.usersTableAdapter();
                        String rcount = ta.checkbyusername(receiver).ToString();
                        if (Convert.ToInt32(rcount) == 0)
                        {
                            lblmsg.Visible           = true;
                            lblmsg.Text              = "User is not registered";
                            mtop.Style["margin-top"] = "40px";
                        }
                        else
                        {
                            ProjectDataset.usersDataTable td = new ProjectDataset.usersDataTable();
                            td = ta.GetDataByusername(username);
                            String sid = td.Rows[0]["user_id"].ToString();

                            String sbalance = td.Rows[0]["balance"].ToString();
                            if (Convert.ToInt32(sbalance) < Convert.ToInt32(amount))
                            {
                                lblmsg.Visible           = true;
                                lblmsg.Text              = "You Do not Have Enough Balance";
                                mtop.Style["margin-top"] = "40px";
                            }
                            else
                            {
                                ta.updatesenderbalance(Convert.ToInt32(amount), username);
                                ta.updatereceiverbalance(Convert.ToInt32(amount), receiver);
                                td = ta.GetDataByusername(receiver);
                                string rid = td.Rows[0]["user_id"].ToString();
                                lblmsg.Visible             = true;
                                lblmsg.Text                = "Amount successfully Transferred!";
                                lblmsg.Style["background"] = "#4CAF50!important";
                                mtop.Style["margin-top"]   = "40px";
                                ProjectDatasetTableAdapters.transfersTableAdapter tta = new ProjectDatasetTableAdapters.transfersTableAdapter();
                                tta.Insert(Convert.ToInt32(sid), Convert.ToInt32(rid), Convert.ToInt32(amount), DateTime.Now);
                            }
                        }
                    }
                }
            } catch (Exception ex)
            {
                lblmsg.Visible           = true;
                lblmsg.Text              = ex.ToString();
                mtop.Style["margin-top"] = "40px";
            }
        }