using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
/// Summary description for class1
/// </summary>
public class class1
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["privacycloudconnection"]);
SqlConnection con1 = new SqlConnection(ConfigurationManager.AppSettings["cloudconnection"]);
SqlCommand cmd, cmd1, cmd2, cmd3, cmd4, cmd5, cmd6, cmd7, cmd8,cmd9;
int fid, fid1,fid2;
string id, id1,id2, logid, prky, len1, len2,ad1,ad2,ad3,ad4,ad5,ad6,ad7;
public class1()
{
//
// TODO: Add constructor logic here
//
}
public void userregister(int uid, string nm, string usrnam, string paswrd, string Email, string addrs, string city, string dob, string mobile, string logid, string prikey)
{
try
{
con.Open();
cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "registerform";
cmd.Parameters.Add("@usrid", SqlDbType.Int, 0);
cmd.Parameters["@usrid"].Value = uid;
cmd.Parameters.Add("@nam", SqlDbType.VarChar, 50);
cmd.Parameters["@nam"].Value = nm;
cmd.Parameters.Add("@username", SqlDbType.VarChar, 50);
cmd.Parameters["@username"].Value = usrnam;
cmd.Parameters.Add("@password", SqlDbType.VarChar, 50);
cmd.Parameters["@password"].Value = paswrd;
cmd.Parameters.Add("@email", SqlDbType.VarChar, 50);
cmd.Parameters["@email"].Value = Email;
cmd.Parameters.Add("@address", SqlDbType.VarChar, 50);
cmd.Parameters["@address"].Value = addrs;
cmd.Parameters.Add("@city", SqlDbType.VarChar, 50);
cmd.Parameters["@city"].Value = city;
cmd.Parameters.Add("@dob", SqlDbType.VarChar, 50);
cmd.Parameters["@dob"].Value = dob;
cmd.Parameters.Add("@mobileno", SqlDbType.VarChar, 50);
cmd.Parameters["@mobileno"].Value = mobile;
cmd.Parameters.Add("@loginid", SqlDbType.VarChar, 50);
cmd.Parameters["@loginid"].Value = logid;
cmd.Parameters.Add("@privacykey", SqlDbType.VarChar, 50);
cmd.Parameters["@privacykey"].Value = prikey;
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MsgBox.Show(ex.Message);
}
}
public void uploadfile(byte[] fibytes, string fityp,string dattim, string uid, string nam, string fiid, string fnam)
{
try
{
con.Open();
// int n = finam.Length;
cmd2 = new SqlCommand("insert into uploadfiles values('" + uid + "','" + fiid + "',@uploadfiles,'" + fityp + "','" + dattim + "')", con);
cmd6 = new SqlCommand("insert into commnfile values('" + uid + "','" + nam + "','" + fiid + "',@uploadfiles,'" + fnam + "','" + fityp + "','" + dattim + "')", con);
cmd2.Parameters.AddWithValue("@uploadfiles", fibytes);
cmd6.Parameters.AddWithValue("@uploadfiles", fibytes);
cmd2.ExecuteNonQuery();
cmd6.ExecuteNonQuery();
con.Close();
//MsgBox.Show("Your file is successfully secured by the cloud server");
}
catch (Exception ex)
{
MsgBox.Show(ex.Message);
}
}
public void uploadimg(byte[] fibytes, string fityp1, string dattim ,string uid, string nam, string fiid, string fnam)
{
try
{
con1.Open();
con.Open();
// int n = finam.Length;
cmd4 = new SqlCommand("insert into uploadimg values('" + uid + "','" + fiid + "',@uploadimg,'" + fityp1 + "','" + dattim + "')", con1);
cmd7 = new SqlCommand("insert into commnfile values('" + uid + "','" + nam + "','" + fiid + "',@uploadimg,'" + fnam + "','" + fityp1 + "','" + dattim + "')", con);
cmd4.Parameters.AddWithValue("@uploadimg", fibytes);
cmd7.Parameters.AddWithValue("@uploadimg", fibytes);
cmd4.ExecuteNonQuery();
cmd7.ExecuteNonQuery();
con1.Close();
con.Close();
//MsgBox.Show("Your image is successfully secured by the cloud server");
}
catch (Exception ex)
{
MsgBox.Show(ex.Message);
}
}
public int imgid()
{
con1.Open();
cmd5 = new SqlCommand("select max(imgid) from uploadimg", con1);
id2 = Convert.ToString(cmd5.ExecuteScalar());
if (id2 == "")
{
fid2 = 1;
}
else
{
fid2 = Convert.ToInt16(id2);
fid2 = fid2 + 1;
}
con1.Close();
return fid2;
}
public int fileid()
{
con.Open();
cmd1 = new SqlCommand("select max(fid) from commnfile", con);
id = Convert.ToString(cmd1.ExecuteScalar());
if (id == "")
{
fid = 1;
}
else
{
fid = Convert.ToInt16(id);
fid = fid + 1;
}
con.Close();
return fid;
}
public int userid()
{
con.Open();
cmd3 = new SqlCommand("select max(usrid) from register", con);
id1 = Convert.ToString(cmd3.ExecuteScalar());
if (id1 == "")
{
fid1 = 1;
}
else
{
fid1 = Convert.ToInt16(id1);
fid1 = fid1 + 1;
}
con.Close();
return fid1;
}
public string createloginid(string n1, string n2, string n3)
{
len1 = Convert.ToString(n2.Length);
logid = Convert.ToString(n2 + n1 + len1 + n3);
return logid;
}
public string createprivacykey(string s1, string s2, string s3)
{
len2 = Convert.ToString(s3.Length);
prky = Convert.ToString(s3 + s1 + len2);
return prky;
}
public void insertintologin(string usid,string unm,string pswd,string date)
{
con.Open();
SqlCommand cmd7 = new SqlCommand("insert into logindetails values('" + usid + "','" + unm + "','" + pswd + "','" + date + "')", con);
cmd7.ExecuteNonQuery();
con.Close();
}
public DataSet fillgridview(string uid)
{
con.Open();
con1.Open();
SqlDataAdapter ad1 = new SqlDataAdapter("select fid,date,filetyp,fname from commnfile where usrid='" + uid + "'", con);
DataSet set = new DataSet();
ad1.Fill(set);
con.Close();
con1.Close();
return set;
}
public DataSet selectddl()
{
con.Open();
SqlDataAdapter cmd8 = new SqlDataAdapter("select distinct usrid from commnfile", con);
DataSet dt1 = new DataSet();
cmd8.Fill(dt1);
con.Close();
return dt1;
}
public DataSet showgrid(string ddl)
{
con.Open();
SqlDataAdapter ad3 = new SqlDataAdapter("select fid,date,filetyp,fname from commnfile where usrid='"+ddl+"'", con);
DataSet dt = new DataSet();
ad3.Fill(dt);
con.Close();
return dt;
}
public DataSet viewusers(string unam)
{
con.Open();
SqlDataAdapter ad4 = new SqlDataAdapter("select username from register where nam='" + unam + "'", con);
DataSet set1 = new DataSet();
ad4.Fill(set1);
con.Close();
return set1;
}
public DataSet listusers()
{
con.Open();
SqlDataAdapter ad5 = new SqlDataAdapter("select nam from register", con);
DataSet set2 = new DataSet();
ad5.Fill(set2);
con.Close();
return set2;
}
public DataSet viewdetails(string uname)
{
con.Open();
SqlDataAdapter ad6 = new SqlDataAdapter("select nam,mobileno,email,city,dob from register where nam='" + uname + "'", con);
DataSet set1 = new DataSet();
ad6.Fill(set1);
con.Close();
return set1;
}
public DataSet selectdd2()
{
con.Open();
SqlDataAdapter cmd9 = new SqlDataAdapter("select distinct filetyp from commnfile", con);
DataSet dt2 = new DataSet();
cmd9.Fill(dt2);
con.Close();
return dt2;
}
public DataSet showgrid1(string ddl)
{
con.Open();
SqlDataAdapter ad7 = new SqlDataAdapter("select usrid,nam,fid,date,filetyp,fname from commnfile where filetyp='" + ddl + "'", con);
DataSet dt3 = new DataSet();
ad7.Fill(dt3);
con.Close();
return dt3;
}
}
..........hi in above code i am getting error .....invalidoperationexception was enabled by user code
the connectionstring property has not been intialized.....error showing place is
con.Open();
cmd3 = new SqlCommand("select max(usrid) from register", con);
id1 = Convert.ToString(cmd3.ExecuteScalar());
if (id1 == "")
{
...............any body plz help me