tweet coding
tweet coding
CODING
AdminReg.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
public partial class adminreg : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void btnreg_Click(object sender, EventArgs e)
{
Try
{
conn.Open();
string uname = txtuname.Text;
String pwd = Encryptdata(txtpwd.Text);
String name = txtname.Text;
String email = txtemail.Text;
String mno = txtmno.Text;
String place = txtplace.Text;
string sq = DropDownsq.Text;
string ans = txtans.Text;
string dpwd = Decryptdata(pwd);
string date = DateTime.Now.ToString();
SqlCommand cmd = new SqlCommand("Insert into adminReg1
values(@uname,@pwd,@name,@email,@mobile,@place,@sq,@answer,@dpwd)", conn);
cmd.Parameters.AddWithValue("@uname", uname);
cmd.Parameters.AddWithValue("@pwd", pwd);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@email", email);
cmd.Parameters.AddWithValue("@mobile", mno);
cmd.Parameters.AddWithValue("@place", place);
cmd.Parameters.AddWithValue("@sq", sq);
cmd.Parameters.AddWithValue("@answer", ans);
cmd.Parameters.AddWithValue("@dpwd", dpwd);
cmd.ExecuteNonQuery();
conn.Close();
txtuname.Text = " ";
txtpwd.Text = " ";
txtname.Text = " ";
txtemail.Text = " ";
txtmno.Text = " ";
txtplace.Text = " ";
txtans.Text = "";
lblmsg.Text = " Registration completed successfully ";}
catch (Exception ex)
{
lblmsg.Text = "This User Name is Already Taken.Pleas Take Another User Name";
}
}
private string Encryptdata(string password)
{
string strmsg = string.Empty;
byte[] encode = new byte[password.Length];
encode = Encoding.UTF8.GetBytes(password);
strmsg = Convert.ToBase64String(encode);
return strmsg;}
private string Decryptdata(string encryptpwd)
{
string decryptpwd = string.Empty;
UTF8Encoding encodepwd = new UTF8Encoding();
Decoder Decode = encodepwd.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
decryptpwd = new String(decoded_char);
return decryptpwd;
}
}
AdminUserSearch.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class asearchuser : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
string uname = (string)Session["d"];
conn.Open();
SqlCommand cmd = new SqlCommand("select uname,name,email,mobile,place from
userreg1 where uname=@uname", conn);
cmd.Parameters.AddWithValue("@uname", uname);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
lbluname.Text = dr["uname"].ToString();
lblname.Text = dr["name"].ToString();
lblemail.Text = dr["email"].ToString();
lblmobile.Text = dr["mobile"].ToString();
lblplace.Text = dr["place"].ToString();}
conn.Close();
string query2 = "select imagepath from ImagesPath where uname='" + uname + "'order by
date desc";
SqlDataAdapter da1 = new SqlDataAdapter(query2, conn);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "a");
int k = ds1.Tables["a"].Rows.Count;
if (k > 0){
Image2.ImageUrl = ds1.Tables["a"].Rows[0][0].ToString();}}
protected void btback_Click(object sender, EventArgs e)
{Response.Redirect("auserdetails.aspx");}
protected void btndelete_Click(object sender, EventArgs e)
{string uname = lbluname.Text;
Session["dt"] = uname;
Response.Redirect("adeleteuser.aspx");
}}
Adeleteuser.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class adeleteuser : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void Page_Load(object sender, EventArgs e)
{delete();}
protected void btndelete_Click(object sender, EventArgs e){
conn.Open();
string id = txtuname.Text;
SqlCommand cmd1 = new SqlCommand("select uname from userreg1 where
uname=@uname", conn);
cmd1.Parameters.AddWithValue("@uname", id);
string id1 = (string)cmd1.ExecuteScalar();conn.Close();
try{
if (txtuname.Text == id1.ToString()){
conn.Open();
string uname = txtuname.Text;
SqlCommand cmd = new SqlCommand("delete from userreg1 where
uname=@uname",conn);
cmd.Parameters.AddWithValue("@uname", uname);
cmd.ExecuteNonQuery();
conn.Close();
txtuname.Text = "";
lblmsg.Text = "User Record Is Deleted";}
else
{lblmsg.Text = "No Matching records";}}
catch (NullReferenceException nr){
string uname = txtuname.Text;
lblmsg.Text = "No Matching records with User Name " + uname + " In Server";
txtuname.Text = "";}}
protected void delete(){
string uname = (string)Session["dt"];
conn.Open();
SqlCommand cmd = new SqlCommand("select * from userreg where uname="+uname+"",
conn);
//cmd.Parameters.AddWithValue("@uname", uname);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{txtuname.Text = dr["uname"].ToString();}conn.Close();}}
Aearth.aspx
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.Data;
using System.Configuration;
public partial class aearth : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
string aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, ll;
protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack)
{BindContrydropdown();}
conn.Open();
SqlCommand cmd = new SqlCommand("select * from earth ", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
GridViewsearch.DataSource = ds;
GridViewsearch.DataBind();
conn.Open();
SqlCommand cmd1 = new SqlCommand("select * from earth order by date desc", conn);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
conn.Close();
if (ds1.Tables[0].Rows.Count > 0)
{GridViewsearch.DataSource = ds;
GridViewsearch.DataBind();}
else{
ds1.Tables[0].Rows.Add(ds1.Tables[0].NewRow());
GridViewsearch.DataSource = ds1;
GridViewsearch.DataBind();
int columncount = GridViewsearch.Rows[0].Cells.Count;
GridViewsearch.Rows[0].Cells.Clear();
GridViewsearch.Rows[0].Cells.Add(new TableCell());
GridViewsearch.Rows[0].Cells[0].ColumnSpan = columncount;
GridViewsearch.Rows[0].Cells[0].Text = "No Records Found";}}
protected void GridViewsearch_RowCommand(object sender,
GridViewCommandEventArgs e){
if (e.CommandName == "Select"){
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = GridViewsearch.Rows[index];
string report = GridViewsearch.Rows[index].Cells[0].Text;
Session["r"] = report;
conn.Open();
string status = "yes";
SqlCommand cmd1 = new SqlCommand("UPDATE earth SET status = @status WHERE
report=@report", conn);
cmd1.Parameters.AddWithValue("@status", status);
cmd1.Parameters.AddWithValue("@report", report);
cmd1.ExecuteNonQuery();
conn.Close();
if (DropDownList1.SelectedItem.Text == "--Select--")
{Response.Write("please select any one value in dropdownlist");}
else{
conn.Open();
SqlDataAdapter sdd = new SqlDataAdapter("select uname,email from userreg where
uname='" + DropDownList1.SelectedItem.Text + "'", conn);
DataSet dss = new DataSet();
sdd.Fill(dss);
if (dss.Tables[0].Rows.Count > 0)
{aa = dss.Tables[0].Rows[0]["email"].ToString();}
conn.Close();
GridViewRow selectedRow1 = GridViewsearch.Rows[index];
string bb = GridViewsearch.Rows[index].Cells[0].Text;
string dd = GridViewsearch.Rows[index].Cells[2].Text;
string cc = GridViewsearch.Rows[index].Cells[3].Text;
Session["report"] = bb;
Session["date"] = cc;
Session["emaillid"] = aa;
Session["place"] = dd;
Response.Redirect("earthreport.aspx");}}
else{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = GridViewsearch.Rows[index];
string report = GridViewsearch.Rows[index].Cells[0].Text;
conn.Open();
SqlCommand cmd = new SqlCommand("delete from earth where report=@report", conn);
cmd.Parameters.AddWithValue("@report", report);
cmd.ExecuteNonQuery();
conn.Close();
Response.Redirect("aearth.aspx");}}
protected void BindContrydropdown()
{//conenction path for databaseconn.Open();
SqlCommand cmd = new SqlCommand("Select uname FROM userreg", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "uname";// DropDownList1.DataValueField = "UserId";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("--Select--", "0"));
conn.Close();}
Aforget.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.master"
AutoEventWireup="true" CodeFile="aforget.aspx.cs" Inherits="aforget" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style2
{
color: #FFFF66;
font-weight: 700;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<form id="form1" runat="server">
<p>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br
/><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<div style="position:absolute; top: 244px; left: 403px; width: 532px; height: 365px; color:
#6600FF;">
</span>
<asp:TextBox ID="txtuname" runat="server" CssClass="style2"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtuname" CssClass="style2"
ErrorMessage="Plase Fill User Name"></asp:RequiredFieldValidator>
<span class="style2"><br /><br />
&nbs
p; Sec Question </span>
<asp:DropDownList ID="DropDownsq" runat="server" CssClass="style2"
Width="128px" ForeColor="Blue">
<asp:ListItem>What is Your Pet Name</asp:ListItem>
<asp:ListItem>Who is Your Favorite Teacher</asp:ListItem>
<asp:ListItem>Your Favorite Place</asp:ListItem>
<asp:ListItem>Your Favorite Food</asp:ListItem>
</asp:DropDownList>
<span class="style2"> </span>
<span class="style2"><br />
<br />Answer </span>
<asp:TextBox ID="txtans" runat="server" CssClass="style2"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtans" CssClass="style2" ErrorMessage="Please Fill
Answer"></asp:RequiredFieldValidator>
<br class="style2" /> <br /><br />
<asp:Button ID="btnsubmit" runat="server" onclick="btnsubmit_Click"
style="position:absolute; top: 203px; left: 167px;"
Text="submit" /><br /><br />
<asp:Label ID="lblmsg" runat="server" Font-Size="X-Large" ForeColor="Maroon"
style="font-size: medium; color: #009933; font-weight: 700;"></asp:Label>
<br /></div></p></form></asp:Content>
Aforget.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class aforget : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void btnsubmit_Click(object sender, EventArgs e)
{
conn.Open();
string uname = txtuname.Text;
String sq = DropDownsq.Text;
string ans = txtans.Text;
SqlCommand cmd = new SqlCommand("select decryptpwd from adminreg1 where
uname=@uname and sq=@sq and answer=@answer", conn);
cmd.Parameters.AddWithValue("@uname", uname);
cmd.Parameters.AddWithValue("@sq", sq);
cmd.Parameters.AddWithValue("@answer", ans);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
if (ds.Tables[0].Rows.Count > 0)
{
lblmsg.Text = "Your Password is: " + ds.Tables[0].Rows[0]["decryptpwd"].ToString();
}
else
{
lblmsg.Text = "Details Not Matching";
}
}
}
Alogin.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class alogin : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void btnlogin_Click(object sender, EventArgs e)
{
Session["uname"] = txtuname.Text;
conn.Open();
string uname = txtuname.Text;
String pwd = txtpwd.Text;
SqlCommand cmd = new SqlCommand("select count(*) from adminreg1 where
uname=@uname and decryptpwd=@pwd", conn);
cmd.Parameters.AddWithValue("@uname", uname);
cmd.Parameters.AddWithValue("@pwd", pwd);
int i = (int)cmd.ExecuteScalar();
conn.Close();
if (i == 0)
{
lblmsg.Text = "invalid user";
}
else
{
Server.Transfer("aearth.aspx");
}
}
}
Auserdetails.aspx
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.Data;
using System.Configuration;
public partial class ausertweets : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void btnsearch_Click(object sender, EventArgs e)
{
string uname= txtuname.Text;
conn.Open();
SqlCommand cmd = new SqlCommand("select * from tweets where username=@uname ",
conn);
cmd.Parameters.AddWithValue("@uname", uname);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
GridViewsearch.DataSource = ds;
GridViewsearch.DataBind();
txtuname.Text = "";
}
protected void GridViewsearch_RowCommand(object sender,
GridViewCommandEventArgs e)
{
if (e.CommandName == "Select"){
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = GridViewsearch.Rows[index];
string tweet = GridViewsearch.Rows[index].Cells[0].Text;
conn.Open();
SqlCommand cmd = new SqlCommand("delete from tweets where tweet=@tweet", conn);
cmd.Parameters.AddWithValue("@tweet", tweet);
cmd.ExecuteNonQuery();
conn.Close();
Response.Redirect("atweetd.aspx");
}}
protected void GridViewsearch_PageIndexChanging(object sender, GridViewPageEventArgs
e)
{
GridViewsearch.PageIndex = e.NewPageIndex;
GridViewsearch.DataBind();
}}
Earthreport.aspx
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Globalization;
using System.Net;
using System.IO;
using System.Xml.Linq;
using System.Net.Mail;
using System.Security.Cryptography;
using System.Text;
public partial class earthreport : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
string gMailAccount = "[email protected]";
string password = "sundaychennai";
string to;
string subject = "Welcome";
string message,yes;
protected void Page_Load(object sender, EventArgs e){
message = "REPORT"+"---->"+(string)Session["report"]+"PLACE"+"---->"+
(string)Session["place"]+"DATE"+"--->"+(string)Session["place"];
to = (string)Session["emaillid"];
NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
MailMessage msg = new MailMessage();
msg.From = new MailAddress(gMailAccount);
msg.To.Add(new MailAddress(to));
msg.Subject = subject; msg.Body = message; msg.IsBodyHtml = true;
try{
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true; client.UseDefaultCredentials = false; client.Credentials = loginInfo;
client.Send(msg);}
catch (Exception ex){
//console.WriteLine(ex);
//Label3.Text = "OFFLINE : Failure Sending Mail !";}
yes = "yes";conn.Close();
lblmsg.Text = "Report Sended Successfull to Users";}
protected void Button1_Click(object sender, EventArgs e)
{Response.Redirect("aearth.aspx");}}
Follow.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class follow : System.Web.UI.Page
{SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void Page_Load(object sender, EventArgs e)
{followers();
followed();}
protected void followers()
{string uname = (string)Session["uname"];
conn.Open();
SqlCommand cmd = new SqlCommand("select username from follow where
following=@uname", conn);
cmd.Parameters.AddWithValue("@uname", uname);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds); conn.Close();
GridView1.DataSource = ds;
GridView1.DataBind();
conn.Open();
SqlCommand cmd1 = new SqlCommand("select count(username) from follow where
following=@uname", conn);
cmd1.Parameters.AddWithValue("@uname", uname);
string count = cmd1.ExecuteScalar().ToString();
lblfr.Text = "Your Followers " +count.ToString() + " Members";
conn.Close();}
protected void followed()
{ string uname = (string)Session["uname"]; conn.Open();
SqlCommand cmd = new SqlCommand("select following from follow where
username=@uname", conn);
cmd.Parameters.AddWithValue("@uname", uname);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds); conn.Close();
GridView3.DataSource = ds; GridView3.DataBind(); conn.Open();
SqlCommand cmd1 = new SqlCommand("select count(following) from follow where
username=@uname", conn);
cmd1.Parameters.AddWithValue("@uname", uname);
string count = cmd1.ExecuteScalar().ToString();
lblfd.Text = "Your Followed " + count.ToString() + " Members";
conn.Close();}}
Home.aspx
Home.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ string a = DateTime.Now.Year.ToString();
}}
Profile.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Drawing;
public partial class profile : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnget_Click(object sender, EventArgs e)
{
string uname = (string)Session["uname"];
conn.Open();
SqlCommand cmd = new SqlCommand("select name,email,mobile,place from userreg1
where uname=@uname", conn);
cmd.Parameters.AddWithValue("@uname", uname);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
txtname.Text = dr["name"].ToString();
txtemail.Text = dr["email"].ToString();
txtmobile.Text = dr["mobile"].ToString();
txtplace.Text = dr["place"].ToString();
}
conn.Close();
}
protected void btnupdate_Click(object sender, EventArgs e)
{
conn.Open();
string uname = (string)Session["uname"];
string name = txtname.Text;
string email = txtemail.Text;
string mobile = txtmobile.Text;
string place = txtplace.Text;
SqlCommand cmd = new SqlCommand("update userreg1 set
name=@name,email=@email,mobile=@mobile,place=@place where uname=@uname",
conn);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@email", email);
cmd.Parameters.AddWithValue("@mobile", mobile);
cmd.Parameters.AddWithValue("@place", place);
cmd.Parameters.AddWithValue("@uname", uname);
cmd.ExecuteNonQuery();
conn.Close();
lblmsg.Text = "Details Updated Successfully";
txtname.Text = "";
txtemail.Text = "";
txtmobile.Text = "";
txtplace.Text = "";
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string uname = (string)Session["uname"];
//Get Filename from fileupload control
string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
//Save images into Images folder
fileuploadimages.SaveAs(Server.MapPath("Images1/" + filename));
//string id = txtid.Text;
//string details = txtdetails.Text;
//string date = DateTime.Now.ToString();
//string status = "Avilable";
//Getting dbconnection from web.config connectionstring
//SqlConnection con = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
//Open the database connection
conn.Open();
//Query to insert images path and name into database
string date = DateTime.Now.ToString();
SqlCommand cmd = new SqlCommand("Insert into
ImagesPath(ImageName,ImagePath,uname,date)
values(@ImageName,@ImagePath,@uname)", conn);
//Passing parameters to query
//cmd.Parameters.AddWithValue("@id", id);
//cmd.Parameters.AddWithValue("@details", details);
//cmd.Parameters.AddWithValue("@date", date);
//cmd.Parameters.AddWithValue("@status", status);
cmd.Parameters.AddWithValue("@uname", uname);
cmd.Parameters.AddWithValue("@ImageName", filename);
cmd.Parameters.AddWithValue("@ImagePath", "Images1/" + filename);
//cmd.Parameters.AddWithValue("@date", date);
cmd.ExecuteNonQuery();
//Close dbconnection
conn.Close();
lblmsg.Text = "Photo Uploaded successfully";
//Response.Redirect("aitemupload.aspx");
}
}
Search.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class search : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void Page_Load(object sender, EventArgs e)
{btnfollow.Visible = false;}
protected void btnsearch_Click(object sender, EventArgs e)
{
//string uname = (string)Session["uname"];
string uname = txtuname.Text; conn.Open();
SqlCommand cmd = new SqlCommand("select uname,name,email,mobile,place from
userreg1 where uname=@uname", conn);
cmd.Parameters.AddWithValue("@uname", uname);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{ lbluname.Text = dr["uname"].ToString();
lblname.Text = dr["name"].ToString();
lblemail.Text = dr["email"].ToString();
lblmobile.Text = dr["mobile"].ToString();
lblplace.Text = dr["place"].ToString(); }
conn.Close(); btnfollow.Visible = true;
string query2 = "select imagepath from ImagesPath where uname='" + uname + "' ";
SqlDataAdapter da1 = new SqlDataAdapter(query2, conn);
DataSet ds1 = new DataSet(); da1.Fill(ds1, "a");
int k = ds1.Tables["a"].Rows.Count;
if (k > 0){
Image2.ImageUrl = ds1.Tables["a"].Rows[0][0].ToString();}}
protected void btnfollow_Click(object sender, EventArgs e)
{
string uname = (string)Session["uname"];
conn.Open(); string fname = txtuname.Text;
string date = DateTime.Now.ToString();
SqlCommand cmd = new SqlCommand("Insert into follow values(@following,@username)",
conn);
cmd.Parameters.AddWithValue("@following", fname);
cmd.Parameters.AddWithValue("@username", uname);
cmd.ExecuteNonQuery(); conn.Close();
lblmsg.Text = "Your Followed " + txtuname.Text + " Successfully";
txtuname.Text = ""; }}
Sendtweet.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class sendtweet : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btntweet_Click(object sender, EventArgs e)
{
try
{
string uname = (string)Session["uname"];
conn.Open();
string tweet = txttweet.Text;
string date = DateTime.Now.ToString();
SqlCommand cmd = new SqlCommand("Insert into tweets values(@tweet,@username)",
conn);
cmd.Parameters.AddWithValue("@username", uname);
cmd.Parameters.AddWithValue("@tweet", tweet);
//cmd.Parameters.AddWithValue("@time", date);
cmd.ExecuteNonQuery();
conn.Close();
txttweet.Text = " ";
lblmsg.Text = " Tweet Successfully Sended ";
}
catch (Exception ex)
{
lblmsg.Text = "Tweet Charecters Must 140 Only";
}
}
}
Tweet.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class tweet : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from tweets order ", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds); conn.Close();
GridView1.DataSource = ds; GridView1.DataBind(); //replay();
}
protected void replay()
{conn.Open();
SqlCommand cmd = new SqlCommand("select * from tweets ", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet(); da.Fill(ds); conn.Close();
GridView1.DataSource = ds; GridView1.DataBind(); }
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{ if (e.CommandName == "Select") {
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = GridView1.Rows[index];
string tweet = GridView1.Rows[index].Cells[0].Text;
// string cname = GridView1.Rows[index].Cells[1].Text;
// DateTime sellerdate =Convert.ToDateTime( GridView1.Rows[index].Cells[2].Text);
// string product = GridView1.Rows[index].Cells[3].Text;
// string productcode = GridView1.Rows[index].Cells[4].Text;
//float price =Convert.ToSingle( GridView1.Rows[index].Cells[5].Text);
// string quantity =GridView1.Rows[index].Cells[6].Text;
//decimal cyp =Convert.ToDecimal( GridView1.Rows[index].Cells[7].Text);
// decimal lyp =Convert.ToDecimal( GridView1.Rows[index].Cells[8].Text);
// string termperiod = GridView1.Rows[index].Cells[9].Text;
// string soldshare = GridView1.Rows[index].Cells[10].Text;
Session["r"] = tweet;
Response.Redirect("sendtweet.aspx");}}}
Uearth.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class earth : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void Page_Load(object sender, EventArgs e) {
lblplace.Visible = false; conn.Open();
SqlCommand cmd = new SqlCommand("select report,place,date from earth where
status='yes'", conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();da.Fill(ds); conn.Close();
GridView1.DataSource = ds; GridView1.DataBind(); }
protected void btnearth_Click(object sender, EventArgs e)
{
lblplace.Visible = false;
string uname = (string)Session["uname"]; conn.Open();
SqlCommand cmd1 = new SqlCommand("select place from userreg1 where
uname=@uname", conn);
cmd1.Parameters.AddWithValue("@uname", uname);
SqlDataAdapter da = new SqlDataAdapter(cmd1);
DataSet ds = new DataSet(); da.Fill(ds); conn.Close();
if (ds.Tables[0].Rows.Count > 0)
{ lblplace.Text = ds.Tables[0].Rows[0]["place"].ToString();} conn.Open();
string report = txtearth.Text;
string place = lblplace.Text;
string date = DateTime.Now.ToString();
string status = "no";
string earth = "Earthquake Alert";
SqlCommand cmd = new SqlCommand("Insert into earth
values(@report,@uname,@place,@status,@earth)", conn);
cmd.Parameters.AddWithValue("@report", report);
cmd.Parameters.AddWithValue("@uname", uname);
cmd.Parameters.AddWithValue("@place", place);
//cmd.Parameters.AddWithValue("@date", date);
cmd.Parameters.AddWithValue("@status", status);
cmd.Parameters.AddWithValue("@earth", earth);
cmd.ExecuteNonQuery(); conn.Close();
txtearth.Text = " ";
lblmsg.Text = " Report Sended to Admin ";
}}
Uforgot.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class Home : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnlogin_Click(object sender, EventArgs e)
{
Session["uname"] = txtuname.Text;
conn.Open();
string uname = txtuname.Text;
String pwd = txtpwd.Text;
SqlCommand cmd = new SqlCommand("select count(*) from userreg1 where
uname=@uname and decryptpwd=@pwd", conn);
cmd.Parameters.AddWithValue("@uname", uname);
cmd.Parameters.AddWithValue("@pwd", pwd);
int i = (int)cmd.ExecuteScalar();
conn.Close();
if (i == 0)
{
lblmsg.Text = "invalid user";
}
else
{
Server.Transfer("sendtweet.aspx");
}
}
}
Ureg.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
public partial class userreg : System.Web.UI.Page
{
SqlConnection conn = new
SqlConnection(ConfigurationManager.ConnectionStrings["cs"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnreg_Click(object sender, EventArgs e)
{
// try
// {
conn.Open();
string uname = txtuname.Text;
string pwd = Encryptdata(txtpwd.Text);
string name = txtname.Text;
string email = txtemail.Text;
string mno = txtmno.Text;
string place = txtplace.Text;
string sq = DropDownsq.Text;
string ans = txtans.Text;
string dpwd = Decryptdata(pwd);
//string date = DateTime.Now.ToString();
SqlCommand cmd = new SqlCommand("Insert into userreg1
values(@uname,@pwd,@name,@email,@mobile,@place,@sq,@answer,@decryptpwd)" ,
conn);
cmd.Parameters.AddWithValue("@uname", uname);
cmd.Parameters.AddWithValue("@pwd", pwd);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@email", email);
cmd.Parameters.AddWithValue("@mobile", mno);
cmd.Parameters.AddWithValue("@place", place);
cmd.Parameters.AddWithValue("@sq", sq);
cmd.Parameters.AddWithValue("@answer", ans);
cmd.Parameters.AddWithValue("@decryptpwd", dpwd);
//cmd.Parameters.AddWithValue("@date", date);
cmd.ExecuteNonQuery();
conn.Close();
txtuname.Text = " ";
txtpwd.Text = " ";
txtname.Text = " ";
txtemail.Text = " ";
txtmno.Text = " ";
txtplace.Text = " ";
txtans.Text = " ";
lblmsg.Text = " Registration completed successfully ";
//}
//catch (Exception ex)
//{
// lblmsg.Text = "This User Name is Already Taken.Pleas Take Another User Name";
//}
}
private string Encryptdata(string password)
{
string strmsg = string.Empty;
byte[] encode = new byte[password.Length];
encode = Encoding.UTF8.GetBytes(password);
strmsg = Convert.ToBase64String(encode);
return strmsg;
}
private string Decryptdata(string encryptpwd)
{
string decryptpwd = string.Empty;
UTF8Encoding encodepwd = new UTF8Encoding();
Decoder Decode = encodepwd.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
char[] decoded_char = new char[charCount];
Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
decryptpwd = new String(decoded_char);
return decryptpwd;
}
}