Tuesday, 31 July 2012

News Title image an gridview display

BAL:

public class BAL
{
    public string _NewsTitle, _NewMsg, _Image, _ThumbImg;
public BAL()
{
//
// TODO: Add constructor logic here
//
}
    public string newstitle
    {
        get
        {
            return _NewsTitle;

        }
        set
        {
            _NewsTitle = value;
        }
    }
    public string newmsg
    {
        get
        {
            return _NewMsg;
        }
        set
        {
            _NewMsg = value;
        }
    }
    public string image
    {
        get
        {
            return _Image;
        }
        set
        {
            _Image = value;
        }
    }
    public string thumbimg
    {
        get
        {
            return _ThumbImg;
        }
        set
        {
            _ThumbImg = value;
        }
    }
    public int insertimg()
    {
        SqlParameter[] p = new SqlParameter[4];
        p[0] = new SqlParameter("@NewsTitle", newstitle);
        p[1] = new SqlParameter("@NewMsg", newmsg);
        p[2] = new SqlParameter("Image", image);
        p[3] = new SqlParameter("Thumbimage", thumbimg);
        int result = DAL.executeNonquerynews("Insert_new", p);
        return result;  
    }
    public DataSet display()
    {
        string query = ("select * from dbo.news");
        DataSet ds = DAL.displayload(query);
        return ds;
    }
}
DAL://insert,load same procedure

Default.aspx:

BAL b = new BAL();
    protected void Page_Load(object sender, EventArgs e)
    {
        load();
    }
    protected void btnsave_Click(object sender, EventArgs e)
    {
        string fileName = FileUpload1.PostedFile.FileName;
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(Server.MapPath("~/images/" + fileName));
        }
        string thumb = FileUpload2.PostedFile.FileName;
        if (FileUpload2.HasFile)
        {
            FileUpload2.SaveAs(Server.MapPath("~/thumb img/" + thumb));
        }
        b._NewsTitle = TextBox1.Text;
        b. _NewMsg = TextBox2.Text;
        b._Image= FileUpload1.FileName;
        b._ThumbImg = FileUpload2.FileName;
        int result=b.insertimg();
        load();


    }
    public void load()
    {
        DataSet ds = b.display();
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
}
Design.aspx:


 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:TemplateField HeaderText="Image">
    <ItemTemplate>
        <asp:Image ID="Image1" ImageUrl='<%#"~/images/"+Eval("Image")%>' runat="server"  Width="50px" Height="50px"/>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
  </asp:GridView>


       

Sunday, 29 July 2012

3 tier insert,update,delete gridview using c#

BAL:

 public int insert()
    {
        try
        {
            SqlParameter[] p = new SqlParameter[3];
            // p[0]=new  SqlParameter("Id",id);
            p[0] = new SqlParameter("UserName", username);
            p[1] = new SqlParameter("Email", email);
            p[2] = new SqlParameter("Image", image);
            int result = DAL.executeNonQuery_sam("insselect", p);
            return result;
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
            return 0;
        }
    }
    public DataSet load()
    {
        string query = ("select * from dbo.tbl_select");
        DataSet ds = DAL.load(query);
        return ds;
    }
   
    public int update()
    {
        try
        {
            SqlParameter[] p = new SqlParameter[3];
            p[0] = new SqlParameter("@Id", id);
            p[1] = new SqlParameter("@UserName", username);
            p[2] = new SqlParameter("@Email", email);
            int result = DAL.executeNonQueryupdate("Updateselect", p);
            return result;
        }
        catch (Exception ex)
        {
            ex.Message.ToString();
            return 0;
        }
    }
    
    public int delete()
    {
        SqlParameter[] p=new SqlParameter[1];
        p[0]=new SqlParameter("Id",id);

        int ds = DAL.executeNonQuery_sam("Delete_grid", p);
        return ds;
     }
   

}

DAL:

 static SqlConnection con;
    static SqlCommand cmd;
public static string connection = (ConfigurationManager.ConnectionStrings["constr"].ConnectionString);


    public static int executeNonQuery_sam(String CommandText, SqlParameter[] Parameters)
    {
        try
        {
            con = new SqlConnection(connection);
            cmd = new SqlCommand(CommandText, con);
            cmd.CommandType = CommandType.StoredProcedure;
            foreach (SqlParameter p in Parameters)
            {
                if (p.Value == null)
                {

                }
                cmd.Parameters.Add(p);
            }
            con.Open();
            return cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw new ArgumentException(ex.Message);
        }

        finally
        {
            con.Close();
        }
    }
    public static DataSet load(String CommandText)
    {

        con = new SqlConnection(connection);
        cmd = new SqlCommand(CommandText, con);
        con.Open();
        cmd.CommandType = CommandType.Text;
        SqlDataAdapter adb=new SqlDataAdapter(cmd);
        DataSet ds=new DataSet();
        adb.Fill(ds);
        con.Close();
        return ds;
    }
    
    
    public static int executeNonQueryupdate(String CommandText, SqlParameter[] Parameters)
    {
        try
        {
            con = new SqlConnection(connection);
            cmd = new SqlCommand(CommandText, con);
            cmd.CommandType = CommandType.StoredProcedure;
            foreach (SqlParameter p in Parameters)
            {
               
                cmd.Parameters.Add(p);
            }
            con.Open();
            return cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw new ArgumentException(ex.Message);
        }

        finally
        {
            con.Close();
        }
    }
   
}
Default.aspx:

int id6;
    string name1, email2;
    BAL b = new BAL();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {  
            load();
        }
    }
    protected void btninsert_Click(object sender, EventArgs e)
    {
        try
        {

            b._Username = TextBox1.Text;
            b._Email = TextBox2.Text;
            int result = b.insert();
            load();
            Label1.Text = "save";

        }
        catch (Exception ex)
        {
            ex.Message.ToString();

        }
       
    }

    public void load()
    {
        DataSet ds = b.load();
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
    protected void btnupdate_Click(object sender, EventArgs e)
    {
        
         Button btn = sender as Button;
        TextBox id = (TextBox)btn.FindControl("TextBox4");
        TextBox name = (TextBox)btn.FindControl("TextBox5");
        TextBox email = (TextBox)btn.FindControl("TextBox6");
        b._Id = Convert.ToInt32(id.Text.ToString());
        b._Username = name.Text;
        b._Email = email.Text;
        int result = b.update();
        DataSet ds = new DataSet();
        GridView1.DataBind();
        GridView1.DataSource = ds;
      
        load();
    }

    protected void Button3_Click(object sender, EventArgs e)//sample update code 
    {
        int a = Convert.ToInt32(TextBox3.Text.ToString());
        b._Id = a;
       
        b._Username = TextBox1.Text;
        b._Email = TextBox2.Text;
        int result=b.update();
        load();

    }
    
    protected void btndelete_Click(object sender, EventArgs e)//gridview
    {
        Button btn = (Button)sender; //find control
        Label ltn = (Label)btn.FindControl("Label1");
        b._Id = Convert.ToInt32(ltn.Text.ToString());
        int result = b.delete();
        load();
    }
}


Design template:

<asp:GridView ID="GridView1" runat="server" 
        AutoGenerateColumns="false">       
        <Columns>
       
                <asp:TemplateField HeaderText="Select">
                    <ItemTemplate>
                        <asp:CheckBox ID="chk" runat="server" onclick="ChangecheckboxStateToTrue()" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Id">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%#Eval("Id") %>' Visible="false"></asp:Label>
                        <asp:TextBox ID="TextBox4" runat="server" Text='<%#Eval("Id") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="UserName">
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%#Eval("UserName") %>' Visible="false"></asp:Label>
                        <asp:TextBox ID="TextBox5" runat="server" Text='<%#Eval("UserName") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Email">
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%#Eval("Email") %>' Visible="false"></asp:Label>
                        <asp:TextBox ID="TextBox6" runat="server" Text='<%#Eval("Email") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Update">
                <ItemTemplate>
                    <asp:Button ID="btnupdate" runat="server" Text="update" 
                        onclick="btnupdate_Click"/>
                </ItemTemplate>
                </asp:TemplateField>
               <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Button ID="btndelete" runat="server" onclick="btndelete_Click" 
                            Text="Delete" />
                    </ItemTemplate>
                </asp:TemplateField>
               
            </Columns>
        </asp:GridView>

Wednesday, 25 July 2012

UPDATE USING 3 TIER ARCHITECTURE (CASCADING DROPDOWN)

Appropriate coding for tat file is:

Update.cs

public partial class member_updateprofile : System.Web.UI.Page
{
    BAL b = new BAL();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {

            ddlState.DataSource = b.GetState();
            ddlState.DataBind();
            ddlState.Items.Insert(0, new ListItem("Select", "0"));
            System.Data.DataTable dt = b.selectupdate();
            foreach (System.Data.DataRow r in dt.Rows)
            {
                lbl_Username.Text = dt.Rows[0][0].ToString();
                lbl_Email.Text = dt.Rows[0][1].ToString();
                txt_Name.Text = dt.Rows[0][2].ToString();
                ddlState.Items.FindByValue(dt.Rows[0][7].ToString());
                ddlState.DataBind();
                ddl_City.DataSource = b.GetCitiesByStateId(Convert.ToInt32(ddlState.SelectedValue));
                ddl_City.DataBind();
                ddlState.Items.Insert(0, new ListItem("Select", "0"));
                ddl_City.Items.FindByValue(dt.Rows[0][8].ToString());
                ddl_City.Items.Insert(0, new ListItem("Select", "0"));
                txt_Phone.Text = dt.Rows[0][4].ToString();
                txt_About.Text = dt.Rows[0][5].ToString();
                txt_Interest.Text = dt.Rows[0][6].ToString();
                rb_Individual.Checked = dt.Rows[0][3].ToString() == "1" ? true : false;
                rb_Business.Checked = dt.Rows[0][3].ToString() == "2" ? true : false;
            }


            b.username = lbl_Username.Text;
            b.email = lbl_Email.Text;
            b.name = txt_Name.Text;
            b.stateid = Convert.ToInt32(ddlState.SelectedValue);
            b.cityid = Convert.ToInt32(ddl_City.SelectedValue);

            b.phone1 = Convert.ToInt32(txt_Phone.Text);
            b.aboutMe = txt_About.Text;
            b.interests = txt_Interest.Text;

        }

    }


    protected void btnSave_Click(object sender, EventArgs e)
    {

        b.name = txt_Name.Text;
        b.stateid = Convert.ToInt32(ddlState.SelectedValue);
        b.cityid = Convert.ToInt32(ddl_City.SelectedValue);
        if (rb_Business.Checked == true)
        {
            b.type = 2;
        }
        else
            b.type = 1;
        b.phone1 = Convert.ToInt32(txt_Phone.Text);
        b.aboutMe = txt_About.Text;
        b.interests = txt_Interest.Text;
        b.updateprofile();
    }


    protected void ddlState_SelectedIndexChanged1(object sender, EventArgs e)
    {
        DataTable dt = b.GetCitiesByStateId(Convert.ToInt32(ddlState.SelectedValue));
        ddl_City.DataSource = dt;
        ddl_City.DataBind();
        ddl_City.Items.Insert(0, new ListItem("Select", "0"));
    }

    protected void btnReset_Click(object sender, EventArgs e)
    {
        ClearData();
    }

    private void ClearData()
    {

        txt_Name.Text = "";
        ddlState.SelectedIndex = -1;
        ddl_City.SelectedIndex = -1;
        txt_Phone.Text = "";
        txt_About.Text = "";
        txt_Interest.Text = "";
        rb_Business.Checked = false;
        rb_Individual.Checked = false;
        
    }
}


In BAL.cs following code:

public class BAL
{

    public string _uname, _email;
    public int _type;
    public int _stateId, _cityId,_phone;
    public string _name, _aboutme, _interests;

    public BAL()
    {

    }
    public string username
    {
        get { return _uname; }
        set { _uname = value; }
    }
    
    public string email
    {
        get { return _email; }
        set { _email = value; }
    }

    public int type
    {
        get { return _type; }
        set { _type = value; }

    }
   
    public int stateid
    {
        get { return _stateId; }
        set { _stateId = value; }
    }

    public int cityid
    {
        get { return _cityId; }
        set { _cityId = value; }
    }
   
    public int phone1
    {
        get { return _phone; }
        set { _phone = value; }
    }

    public string name
    {
        get { return _name; }
        set { _name = value; }
    }

    public string aboutMe
    {
        get { return _aboutme; }
        set { _aboutme = value; }
    }

    public string interests
    {
        get { return _interests; }
        set { _interests = value; }
    }
   



 public int updateprofile()
    {
        SqlParameter[] p = new SqlParameter[9];
        p[0] = new SqlParameter("@Name", name);
        p[1] = new SqlParameter("@StateId", stateid);
        p[2] = new SqlParameter("@CityId", cityid);
        p[3] = new SqlParameter("@Type", type);
        p[4] = new SqlParameter("@Phone", phone1);
        p[5] = new SqlParameter("@AboutMe", aboutMe);
        p[6] = new SqlParameter("@Interest", interests);
        p[7] = new SqlParameter("@UserId", 2);
        p[8] = new SqlParameter("@Flag", 3);
        int update = DAL.executeNonquery_SP("edit_dt", p);
        return update;
    }
    
    public DataTable selectupdate()
    {
        SqlParameter[] p = new SqlParameter[2];
        p[0] = new SqlParameter("@userid",2);
         p[1] = new SqlParameter("@flag",2);
         DataTable selupdate = DAL.Ret_datatable("get_dt1", p);
         return selupdate;
    }
 public DataTable GetCitiesByStateId(int _stateid)
    {
        try
        {
            SqlParameter[] p = new SqlParameter[2];
            p[0] = new SqlParameter("@Flag", 8);
            p[1] = new SqlParameter("@stateid", _stateid);
            return DAL.Ret_datatable("Get_dt", p);
        }

        catch (ArgumentException ex)
        {
            throw new ArgumentException(ex.Message);
        }
    }
 public DataTable GetState()
    {
        try
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@Flag", 3);
            return DAL.Ret_datatable("Get_dt", p);
        }

        catch (ArgumentException ex)
        {
            throw new ArgumentException(ex.Message);
        }
    }


DAL.cs file

public class DAL
{
    static SqlConnection con;
    static SqlCommand cmd;
    public DAL()
    {

    }

    public static string connection = (ConfigurationManager.ConnectionStrings["classifiedsConnectionString1"].ConnectionString);

    public static int executeNonquery_SP(String CommandText, SqlParameter[] parameters)
    {
        using (SqlConnection con = new SqlConnection(connection))
        {
            try
            {
                cmd = new SqlCommand(CommandText, con);
                cmd.CommandType = CommandType.StoredProcedure;
                foreach (SqlParameter p in parameters)
                {
                    if (p.Value != null)
                    {
                        cmd.Parameters.Add(p);
                    }

                }
                con.Open();
                return cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message);
            }
            finally
            {
                con.Close();
            }
        }
    }


 public static DataTable Ret_datatable(String CommandText1, SqlParameter[] parameters)
    {

        con = new SqlConnection(connection);
        cmd = new SqlCommand(CommandText1, con);
        con.Open();
        cmd.CommandType = CommandType.StoredProcedure;
        foreach (SqlParameter c in parameters)
        {
            if (c.Value == null)
            {
            }
            cmd.Parameters.Add(c);
        }

        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        da.Fill(ds);
        dt = ds.Tables[0];
        con.Close();
        return dt;
    }


Stored procedure for update:

UPDATE dbo.tbl_User
SET    Name=@NAME,Stateid=@Stateid,Cityid=@CITYID,Type=@TYPE,Phone=@PHONE,Aboutme=@ABOUTME,Interest=@INTEREST
WHERE UserId =@USERID

Stored procedure to select:

SELECT STATE,STATEID
FROM DBO.TBL_STATE



PASSWORD CHECKING & CHANGE PASSWORD




Create  ChangePassword.cs:

public partial class member_ChangePassword : System.Web.UI.Page
{
    BAL b = new BAL();
    string curpass,newpass,conpass;
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();

            dt=b.selectupdate();

            foreach (DataRow r in dt.Rows)
            {
                txt_Id.Text = dt.Rows[0][0].ToString();
                lbl_Id.Text = dt.Rows[0][1].ToString();
                lbl_Email.Text = dt.Rows[0][2].ToString();
            }
    }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        b._password = txt_CurPwd.Text;
        b._id = Convert.ToInt32(txt_Id.Text.ToString());
        b._newpass = txt_NewPwd.Text;
        newpass = b._newpass;
        b._conpass = txt_ConfPwd.Text;
        conpass = b._conpass;
        DataTable dt = new DataTable();
        dt = b.checkpassword();
        foreach (DataRow r in dt.Rows)
        {
         
            curpass = dt.Rows[0][0].ToString();
         
        }

        if (curpass != txt_CurPwd.Text)
        {
            Response.Write("Please Enter Valid Password");
        }

        else if (newpass == conpass)
        {

            int result = b.updatepassword();

         
            Response.Write("Updated");

        }
        else
            Response.Write("Not Updated");

    }

    protected void btn_Reset_Click(object sender, EventArgs e)
    {
     
        txt_ConfPwd.Text = "";
        txt_CurPwd.Text = "";
        txt_Id.Text = "";
        txt_NewPwd.Text = "";
     }
}


BAL.CS:

public string _password, _newpass, _conpass;
public int _id;
public BAL()
    {

    }

public int id
    {
        get { return _id; }
        set { _id = value; }
     }

public string password
    {
        get { return _password; }
        set { _password = value; }
    }
public string newpassword
    {
        get { return _newpass; }
        set { _newpass = value; }
    }

public string confirmpassword
    {
        get { return _conpass; }
        set { _conpass = value; }
    }


 public DataTable checkpassword()
    {
        SqlParameter[] d = new SqlParameter[3];
        d[0] = new SqlParameter("@UserId", id);
        d[1] = new SqlParameter("@Password", password);
        d[2] = new SqlParameter("@Flag", 5);
        DataTable chk = DAL.Ret_datatable("get_dt1", d);
        return chk;
    }

    public int updatepassword()
    {
        SqlParameter[] e = new SqlParameter[3];
        e[0] = new SqlParameter("@UserId", id);
        e[1] = new SqlParameter("@password", confirmpassword);
        e[2] = new SqlParameter("@Flag", 6);
        int passupd = DAL.executeNonquery_SP("edit_dt",e);
        return passupd;
    }

DAL.cs:

public class DAL
{
    static SqlConnection con;
    static SqlCommand cmd;
    public DAL()
    {

    }

    public static string connection = (ConfigurationManager.ConnectionStrings["classifiedsConnectionString1"].ConnectionString);

    public static int executeNonquery_SP(String CommandText, SqlParameter[] parameters)
    {
        using (SqlConnection con = new SqlConnection(connection))
        {
            try
            {
                 cmd = new SqlCommand(CommandText, con);
                cmd.CommandType = CommandType.StoredProcedure;
                foreach (SqlParameter p in parameters)
                {
                    if (p.Value != null)
                    {
                        cmd.Parameters.Add(p);
                    }

                }
                con.Open();
                return cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message);
            }
            finally
            {
                con.Close();
            }
        }
    }


STORED PROCEDURE:

Select:
SELECT UserId,USERNAME,EMAIL
FROM TBL_USER WHERE USERID=@USERID

Update:
UPDATE dbo.tbl_User SET PASSWORD=@PASSWORD
WHERE USERID=@USERID

Wednesday, 18 July 2012

Newsletter to single user and multiple users(email)


1.Insert_Emails.asp:


if (!IsPostBack)
        {

            BindCountry();

        }

 protected void btnsubmit_Click(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand("ins_NewsLetterEmails", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Email",txtemail.Text);
        cmd.Parameters.AddWithValue("@Country", ddlcountry.SelectedValue);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }
    protected void BindCountry()
    {

        con.Open();
        SqlCommand cmd = new SqlCommand("select * from tbl_country", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        ddlcountry.DataSource = ds;
        ddlcountry.DataTextField = "country";
        ddlcountry.DataValueField = "countryId";
        ddlcountry.DataBind();
        ddlcountry.Items.Insert(0, new ListItem("--SELECT--", "0"));

    }

2.sendNewsLetter.asp:


ArrayList area = new ArrayList();
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["NRICONNECTION"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
 
        if (!IsPostBack)
        {

            BindCountry();
                 
        }
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        if (chkAllusers.Checked == true)
        {
            string Email;
            SqlCommand cmd = new SqlCommand("Sel_Email", con);
            cmd.CommandType = CommandType.StoredProcedure;
            con.Open();
            SqlDataReader rd = cmd.ExecuteReader();
            if (rd.HasRows)
            {
                while (rd.Read())
                {
                    Email = rd[0].ToString();
                    area.Add(Email);
                }
            }

            con.Close();
            sendmail();
        }
        else
        {
            sendmail1();
        }

    }
    protected void chkAllusers_CheckedChanged(object sender, EventArgs e)
    {
     
            //ArrayList area = new ArrayList();
       

        }

    protected void rdb1_CheckedChanged(object sender, EventArgs e)
    {
        //if (rdb1.Checked == true)
        //{
        //  ("~/Admin/NewsLetter/1/59358209.html/");
        //}
        //string strRedirect;
        //strRedirect = "~/Admin/NewsLetter/1/59358209.html/?selected=" + rdb1.Checked;
        //Response.Redirect(strRedirect);
    }

    private void sendmail()
    {

            foreach (string a in area)
            {
                string htmlBody = "<html><body><h1>Picture</h1><br><img src=\"1:59358209.html\"></body></html>";

                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
                mail.To.Add(a);
                mail.From = new MailAddress("nrizune@gmail.com");
                StringBuilder sb = new StringBuilder();
                sb.Append(a);
                mail.Subject = "Welcome To NRI SocialNetworking";
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.Credentials = new System.Net.NetworkCredential("nrizune@gmail.com", "nrizu123@");
                smtp.EnableSsl = true;
                mail.Body = htmlBody;
                mail.Body = emo.ToString();
                smtp.Send(mail);
                if (rdb1.Checked == true)
                {


                    AlternateView av =
                              AlternateView.CreateAlternateViewFromString(htmlBody,
                              null, MediaTypeNames.Text.Html);
                    LinkedResource lr = new LinkedResource("D:/NewsLetter/1/59358209.gif", MediaTypeNames.Image.Gif);
                    av.LinkedResources.Add(lr);
                    mail.AlternateViews.Add(av);

                }
                else if (rdb2.Checked == true)
                {

                    AlternateView av =
                              AlternateView.CreateAlternateViewFromString(htmlBody,
                              null, MediaTypeNames.Text.Html);
                    LinkedResource lr = new LinkedResource("D:/NewsLetter/2/letter2_01.gif", MediaTypeNames.Image.Gif);
                    av.LinkedResources.Add(lr);
                    mail.AlternateViews.Add(av);
                }
                else
                {

                }
                con.Close();
            }

         
   
    }


    public void sendmail1()
    {
        string htmlBody = "";

                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();    
                mail.To.Add(txtsingleuser.Text);
                mail.From = new MailAddress("hariharan.vst10@gmail.com");
                StringBuilder sb = new StringBuilder();
                sb.Append(txtsingleuser.Text);
                mail.Subject = "Welcome To NRI SocialNetworking";
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.Credentials = new System.Net.NetworkCredential("hariharan.vst10@gmail.com", "*****");
                smtp.EnableSsl = true;
                mail.Body = htmlBody;
                if (rdb1.Checked == true)
                {


                    AlternateView av =
                              AlternateView.CreateAlternateViewFromString(htmlBody,
                              null, MediaTypeNames.Text.Html);
               
                    LinkedResource lr = new LinkedResource("E:/17-7-12/PROJECT MAIN news Letter/Admin/NewsLetter/1/59358209_01.gif", MediaTypeNames.Image.Gif);
                    //LinkedResource lr1 = new LinkedResource("E:/17-7-12/PROJECT MAIN news Letter/Admin/NewsLetter/1/images/59358209_01.gif", MediaTypeNames.Image.Gif);
                    av.LinkedResources.Add(lr);
         
                    //av.LinkedResources.Add(lr1);
                    mail.AlternateViews.Add(av);
                 

                }
                else if (rdb2.Checked == true)
                {

                    AlternateView av =
                              AlternateView.CreateAlternateViewFromString(htmlBody,
                              null, MediaTypeNames.Text.Html);
                    LinkedResource lr = new LinkedResource("D:/NewsLetter/2/letter2_01.gif", MediaTypeNames.Image.Gif);
                    av.LinkedResources.Add(lr);
                    mail.AlternateViews.Add(av);
                }
                else
                {

                }
                con.Close();

             
                smtp.Send(mail);
             
            }


     


    protected void BindCountry()
    {

        con.Open();
        SqlCommand cmd = new SqlCommand("select * from tbl_country", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        ddlcountry.DataSource = ds;
        ddlcountry.DataTextField = "country";
        ddlcountry.DataValueField = "countryId";
        ddlcountry.DataBind();
        ddlcountry.Items.Insert(0, new ListItem("--SELECT--", "0"));

    }

Monday, 16 July 2012

3-Tier using Single Query(Insert,Update)

Bal.cs:


public class bal
{
 public int insert(string name,string place,int Id,int mode)
    {
        DAL s = new DAL();
        return s.insert(name, place,Id,1);

    }
    public int update(string name, string place, int Id,int mode)
    {
        DAL s = new DAL();
        return s.update(name, place, Id,2);

    }
}
Dal.cs:
public int insert(string name, string place,int Id,int mode)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("Ins_data", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Name", name);
        cmd.Parameters.AddWithValue("@Place", place);
        cmd.Parameters.AddWithValue("@mode", mode);
        cmd.Parameters.AddWithValue("@Id", Id);
        return cmd.ExecuteNonQuery();
        con.Close();


    }
    public int update(string name, string place, int Id,int mode)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("Ins_data", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Name", name);
        cmd.Parameters.AddWithValue("@Place", place);
        cmd.Parameters.AddWithValue("@mode", mode);
        cmd.Parameters.AddWithValue("@Id", Id);
        return cmd.ExecuteNonQuery();
        con.Close();

    }
Default

 bal s = new bal(); //call in public

protected void Button1_Click(object sender, EventArgs e)
    {
       
        string name = TextBox1.Text;
        string place = TextBox2.Text;
        int Id = 0;
        s.insert(name, place,Id,1);


    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        string name = TextBox1.Text;
        string place = TextBox2.Text;
        int Id =Convert.ToInt16( TextBox3.Text);
        s.update(name, place, Id,2);
    }

stored pro:

ALTER procedure [dbo].[Ins_data](@Name varchar(50),@place varchar(50),@Id int,@mode int)
as
begin
if(@mode=1)
begin
insert into dbo.Table_1 (Name,Place) values(@Name,@place)
end
else if (@mode=2)
begin
update dbo.Table_1 set Name=@Name,Place=@place where Id=@Id
end
end




Sunday, 15 July 2012

Email and verification link


string strbody = "";
                strbody += "<tr><td>Thank you for registering into our site.<br /></td></tr><tr><td> To verify your account <a href='http://localhost:2976/Registration.aspx?UserID=" + u_id + "&SendId=" + s_id + "'>click here</a><br /><br /></td></tr>";
                // strbody += "Once verified, you can login with the following credentials:<br /></span><br /></td></tr><tr><td style=width: 163px>Username:" + txtEmail.Text + "</td></tr><tr><td style=width: 163px>Password:" + txtPassword.Text + "<br /><br /></td></tr>";

                MailMessage mail = new MailMessage();
                mail.To.Add(txtEmail.Text);
                mail.From = new MailAddress("hariharan.vst10@gmail.com");
                StringBuilder sb = new StringBuilder();
                sb.Append(txtEmail.Text);
                sb.Append(txtPassword.Text);
                mail.Subject = "Welcome";
                //  mail.Body = sb.ToString();
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.Credentials = new System.Net.NetworkCredential("hariharan.vst10@gmail.com", "jhj");
                smtp.EnableSsl = true;
                mail.Body = strbody;
                //mail.Body = "Your User Name is:" + txtemail.Text + "Password  :" + txtpassword.Text;
                //mail.Body = "http://Activationlink.aspx?id=";
                smtp.Timeout = 100;
                smtp.Send(mail);