Tuesday, 29 January 2013

3- tier architecture for asp.net begginers


firstly we have to take data access layer for interact with database

next we are going to business logic layer for interact with DAL

next interact with ASPX page of ur actual UI design page

DAL -->BLL -->UI


How to Show rdlc report file into pdf format

 string MimeType = "";
    string Encoding = "";
    string strExtension = "";
    string[] streamIds = null;
    Warning[] warnings = null;


protected void Page_Load(object sender, EventArgs e)
    {
        ds = objBll.reportuser();
      
        ReportDataSource rds = new ReportDataSource();
        rds.Name = "userreportsDS_DataTable1";
        rds.Value = ds.Tables[0];
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(rds);
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("Reports/")+"useruploadReport.rdlc";

        byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out MimeType, out Encoding, out strExtension, out streamIds, out warnings);
        Response.Buffer = true;
        Response.Clear();
        Response.ContentType = MimeType;
        Response.AddHeader("content-position", bytes.Length.ToString());
        Response.BinaryWrite(bytes); // create the file
     

    }

Thursday, 24 January 2013

usage of datalist and repeater control with example

gridview is a web control. datalist and repeater are additional web controls.
these three web controls have some similarities are as follows

1.datalist and repeater are used to display data like gridview.
for ex: gridview have datasource property and databind() mathods. the datalist and repeaters also have these two properties.

2. datalist and repeater are composed of no.of dataitems of datalistitems and the repeater of repeateritems


further reference and for examples plz check the below link...

http://chikkanti.wordpress.com/2012/05/12/datalist-control-example-in-asp-net/

display images fom folder in gridview code for source code using asp.net c#

<asp:GridView ID="gdvfileupload" runat="server" AutoGenerateColumns="False" style="text-align: center"
                            Width="500px">
                            <Columns>
                                <asp:TemplateField HeaderText="imageid">
                                    <ItemTemplate>
                                        <asp:Label ID="lblimageid" runat="server" Text='<%#Eval("imageid") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="image name">
                                    <ItemTemplate>
                                        <asp:Label ID="lblimage" runat="server" Text='<%#Eval("imagename") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField>
                                    <ItemTemplate>                                     
                                       <asp:Image ID="image1" runat="server" ImageUrl='<%#Eval("imagepath") %>' Width="100" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>

code for how to count votes regarding their symbols using asp.net c#

    
    protected void BtnVote_Click(object sender, EventArgs e)
    {
        if (Rbtbjp.Checked == true || Rbtcongress.Checked == true || RbtTDP.Checked == true)
        {
            string value;
            string strr = "select partyname from votescount where partyname like '%" + name + "%'";
            NpgsqlDataAdapter da = new NpgsqlDataAdapter(strr, con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            if (ds.Tables[0].Rows.Count == 0)
            {
                value = "";
            }
            else
            {
                value = ds.Tables[0].Rows[0][0].ToString();
            }

            if (value == name)
            {
                string qrr = "select vote from votescount where partyname ='" + name + "'";
                con.Open();
                NpgsqlDataAdapter da1 = new NpgsqlDataAdapter(qrr, con);
                DataSet ds1 = new DataSet();
                da1.Fill(ds1);
                count = Convert.ToInt32(ds1.Tables[0].Rows[0][0].ToString());
                count = count + 1;
                string str = "update votescount set partyname='" + name + "',vote='" + count + "' where partyname ='" + name + "' ";

                NpgsqlCommand cmd = new NpgsqlCommand(str, con);
                cmd.ExecuteNonQuery();
                con.Close();
                Response.Write("<script>alert('Inserted Successfully........')</script>");
                gridfill();
            }
            else
            {
                count = 1;
                string str = "Insert into votescount(partyname,vote,partysymbol) values('" + name + "','" + count + "','" + imgurl + "')";
                con.Open();
                NpgsqlCommand cmd = new NpgsqlCommand(str, con);
                cmd.ExecuteNonQuery();
                con.Close();
                Response.Write("<script>alert('Inserted Successfully........')</script>");
                gridfill();
            }
            Btnclear_Click(sender, e);
        }
        else
        {
            Response.Write("<script>alert('plz select party........')</script>");
        }
    }





code for upload image using file upload control in asp.net c#

code for upload image using  file upload control  in asp.net c#



 protected void griddata()
    {
        string qry = "select imageid,imagename,imagepath from fileupload";
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
        NpgsqlDataAdapter da = new NpgsqlDataAdapter(qry, con);
        DataSet   ds = new DataSet();
        da.Fill(ds);
        gdvfileupload.DataSource = ds;
        gdvfileupload.DataBind();
        con.Close();
    }
 
    protected void btnSaveImage_Click1(object sender, EventArgs e)
    {
       
        if (FileuploadImg.PostedFile != null)
        {
            string fileExt = System.IO.Path.GetExtension(FileuploadImg.FileName);

            if (fileExt == ".jpeg" || fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png")
            {
                string imgName = FileuploadImg.FileName;
                string imgPath = FileuploadImg.PostedFile.FileName;

                FileuploadImg.SaveAs(Server.MapPath("images/" + imgName));

                filePath = Server.MapPath("~/Files/images/" + imgName);
                string filename1 = Path.GetFileName(filePath);
                //filename1 = Path.GetFileNameWithoutExtension(myFile);
                string str = "insert into fileupload(imagename,imagepath) values('" + filename1 + "','" + imgPath + "')";
                con.Open();
                NpgsqlCommand cmd = new NpgsqlCommand(str, con);
                cmd.ExecuteNonQuery();
                con.Close();
                Response.Write("<script>alert('Uploaded Successfully....')</script>");
                griddata();
               
            }
            else               
            {
                Response.Write("<script>alert('Invalid file....')</script>");
            }
        }
    }

Thursday, 16 February 2012

Converting RTF to HTML


Posted on September 28, 2009 by Matthew
Have you ever had the desire to convert some RTF text into HTML? Probably not. But if you do, then you are in luck! I recently had the need to do this conversion and after some searching found out a way to do it by enhancing a sample distributed in the MSDN library.  The sample is called:XAML to HTML Conversion Demo


The sample has code which converts HTML to and from a XAML Flow Document.  But this doesn’t make things easier until you realize that there is a way to convert RTF to XAML easily. The key is to use System.Windows.Controls.RichTextBox which can load RTF from a stream and save it as XAML.  This conversion is shown below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
private static string ConvertRtfToXaml(string rtfText)
{
    var richTextBox = new RichTextBox();
    if (string.IsNullOrEmpty(rtfText)) return "";
    var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
    using (var rtfMemoryStream = new MemoryStream())
    {
        using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))
        {
            rtfStreamWriter.Write(rtfText);
            rtfStreamWriter.Flush();
            rtfMemoryStream.Seek(0, SeekOrigin.Begin);
            textRange.Load(rtfMemoryStream, DataFormats.Rtf);
        }
    }
    using (var rtfMemoryStream = new MemoryStream())
    {
        textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
        textRange.Save(rtfMemoryStream, DataFormats.Xaml);
        rtfMemoryStream.Seek(0, SeekOrigin.Begin);
        using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
        {
            return rtfStreamReader.ReadToEnd();
        }
    }
}

Interview questions in my interview

->What is Dot Net Architecture?
C# -->CSC(csharp compiler)-->IL Code(Data Type,Source Code)-->\
                                                                                                             \---->CTS(d.t)--->///}MSIL Code->
                                                                                                             /---->CSC(s.c)-->//}     Managed ->                              
VB-->VBC(vb compiler)------>IL Code(Data Type,Source Code)-->/


Code   --->JIT Compiler------>O.S  
   so dot net is Platform Independent because of JIT compiler......  



->What is the Use of Dot Net in Real Time?


->Tell Me about Sql Server?

->What is the Usage and Types of Joins?


->What is Object?


->What is the difference between Abstract and Interface?


->What is Stored Procedure?


 ->What is DDL command?

to display table on DataGrid


private void BtnDisplay_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = "select * from <Table Name>";
            conn.Open();
            SqlDataAdapter da = new SqlDataAdapter(str,conn);
            da.Fill(ds);
            GdvDisplay.DataSource = ds.Tables[0];
            conn.Close();
        }

Using Get Button to get a data from table in C#.net

  private void BtnGet_Click(object sender, EventArgs e)
        {
             string str1 = string.Empty;
            try
            {
            str1 = "select * FROM Registration WHERE SNO='" + TxtSno.Text + "'";

            con.Open();
            da = new SqlDataAdapter(str1, con);
            da.Fill(ds);
           
            TxtName.Text  =ds.Tables[0].Rows[0][1].ToString();
            TxtGender.Text=ds.Tables[0].Rows[0][2].ToString();
            TxtDob.Text   =ds.Tables[0].Rows[0][3].ToString();
            TxtAge.Text   =ds.Tables[0].Rows[0][4].ToString();
       
            }
            catch (Exception ex1)
            {
                MessageBox.Show(ex1.Message);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
           
           
            }


        }

Delete Record on delete button in sql server with C#.net


private void BtnDelete_Click(object sender, EventArgs e)
        {
            string str2 = string.Empty;
         
                try
                {
                    str2 = "delete from Registration where SNO='" + TxtSno.Text + "'";
                    con.Open();
                    SqlCommand cmd = new SqlCommand(str2, con);
                    cmd.ExecuteScalar();
                    TxtAge.Text = TxtDob.Text = TxtGender.Text = TxtName.Text = TxtSno.Text = "";

                }
               
            catch (Exception ex2)
            {
                MessageBox.Show(ex2.Message);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }

            }
        }
       

how to create Save,Delete And Clear Buttons in our appilication usin C#.net With Sql Server back End


Save Button Background Coding in easy way to get It...............

 private void BtnSave_Click(object sender, EventArgs e)
        {
            string str="Insert into Registration(SNO,NAME,GENDER,DOB,AGE) values('"+TxtSno.Text +"','"+TxtName.Text +"','"+TxtGender.Text +"','"+TxtDob.Text +"','"+TxtAge.Text +"')";
            try
            {
                con.Open();
               
                SqlCommand cmd = new SqlCommand(str, con);
                cmd.ExecuteNonQuery();
                TxtAge.Text = TxtDob.Text = TxtGender.Text = TxtName.Text = TxtSno.Text = "";

            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
           
           
            }
        }