Friday 24 October 2014

Star Pattern Programs Cplusplus

Program To Print Following Star Pattern in Cpluplus


Star Pattern in Cpluplus


#include<iostream.h>
void main()
{
   int i,j,k,n;
   cout<<"\Enter the number of lines to be printed: ";
    cin>>n;
   for(i=0;i<n;i++)
   {
      for(j=0;j<(n-i-1);j++)
 cout<<" ";
      for(k=0;k<(2*i+1);k++)
 cout<<"*";
      cout<<endl;
   }
      for(i=0;i<n-1;i++)
   {
      for(j=0;j<=i;j++)
cout<<" ";
      for(k=(2*n-2*i-3);k>0;k--)
   cout<<"*";
      cout<<endl;
   }
}

 

Program To Print Following Star Pattern in Cpluplus

Star Pattern in Cpluplus

Star Pattern in Cpluplus



#include<iostream.h>
void main()
{
 int i,j,k,n;
 cout<<"\Enter the number of lines to be printed: ";
 cin>>n;
 for(i=0;i<n;i++)
 {
       for(j=n-i-1;j>0;j--)
     cout<<" ";
       cout<<"*";
       for(k=2*i-1;k>0;k--)
     cout<<" ";             //code for upper triangle
       if(i!=0)
     cout<<"*";
       cout<<endl;
  }
  for(i=n-1;i>0;i--)
  {
       for(j=0;j<n-i;j++)
     cout<<" ";
       cout<<"*";                  //code for lower triangle
for(k=2*i-3;k>0;k--)
    cout<<" ";
       if(i!=1)
     cout<<"*";
       cout<<"\n";
    }
}

 

Program To Create Circular Loading Bar using Graphics.h


#include<graphics.h>

#include<dos.h>

void main()
{
int gd=DETECT,gm; 
              // variable to detect graphics driver and graphic mode

 int counter;   

//Below is code to initialize the graphics with parameters for graphics initgraph(&gd,&gm,"c:\\turboc3\\bgi");

//Loop to show the loading circle for(counter=0;counter<=360;++counter)
{
circle(300,200,80);
pieslice(300,200,0,counter,80);
outtextxy(200,320,"Loading....Please Wait!");
delay(20);
}
closegraph();
}

OUTPUT :
Program To Create Circular Loading Bar graphics.h cplusplus
Program To Create Circular Loading Bar graphics.h cplusplus




Program To Create Loading Bar using Graphics.h


#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>

void main()
{
 int x=170,i,gdriver=DETECT,gmode;
  // variable to detect graphics driver and graphic mode

//Below is code to initialize the graphics with parameters for graphics
 initgraph(&gdriver,&gmode,"c:\\tc\\bgi");

 settextstyle(DEFAULT_FONT,HORIZ_DIR,2);

//Outtextxy is used to print the given text at specified x and y pixel position 
//It will print given text at pixel position 170,180
 outtextxy(170,180,"LOADING,PLEASE WAIT");

  for(i=0;i<300;++i)
 {
  delay(30);
  line(x,200,x,220);
  x++;
 }
 getch();

//close the graph that was initialized
 closegraph();  

}

OUTPUT :
Program To Create Loading Bar using Graphics.h Cplusplus
Program To Create Loading Bar using Graphics.h Cplusplus


Program To Print Star Triangle Pattern in Cplusplus


#include<iostream.h>
#include<conio.h>

void main()
{
clrscr(); //to clear the screen
int i,j,k,num;

cout<<"Tell How many lines you want";
cin>>num;

num*=2;
for(i=0;i<num;i+=2)
{
cout<<"\n";

for ( j = num; j > i; j -= 2 )
cout<<" ";

for( k=0; k<=i; ++k )
cout<<"*";
}
getch(); //to stop the screen
}
OUTPUT


Program To Print Star Triangle Pattern Cplusplus
Program To Print Star Triangle Pattern Cplusplus

Program To Print Alphabets in Cplusplus ( I have printed A to H ) 


#include<iostream>

using namespace std;

int main()
{
int i,j,k=1;
char ch;
cout<<"Input an Alphabet in capital letters that you want to print:";
cin>>ch;
cout<<"\n\n\n\n";
switch(ch)
{
case 'A':
cout<<"\t\t\t    ";
for(i=1;i<=40;++i)
{
for(j=0;j<=22;++j)
{
if(i==1||i==2||i==21||i==20)
cout<<"*";
else
{
if(j==0||j==20)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t    ";

}
break;



case 'B':
cout<<"\t\t\t\t";

while(k<=2)
{
for(i=1;i<=9;++i)
{
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}

cout<<"\n\t\t\t\t";

}
for(i=1;i<=10;++i)
{
if(i==1||i==10)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";

for(i=1;i<=10;++i)
{
if(i==1||i==10)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";

for(i=9;i>=1;--i)
{
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";
}
++k;
}
 break;

 case'C':
cout<<"\t\t\t    ";

for(i=1;i<=40;++i)
{
for(j=0;j<=22;++j)
{
if(i==1||i==2||i==39||i==40)
cout<<"*";
else
{
if(j==0)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t    ";

}
break;

 case'D':
 cout<<"\t\t\t\t";
 for(i=1;i<=18;++i)
 {
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";
 }
 while(k<=4)
 {
for(i=1;i<=19;++i)
{
if(i==1||i==19)
cout<<"**";
else
cout<<" ";
}
cout<<"\n\t\t\t\t";
 ++k;
 }
 for(i=18;i>=1;--i)
 {
for(j=0;j<=i;++j)
{
if(j==0||j==i)
cout<<"**";
else
cout<<" ";
}
 cout<<"\n\t\t\t\t";
 }
 break;

 case'E':

 cout<<"\t\t\t\t";
 for(i=1;i<=39;++i)
 {
for(j=1;j<=20;++j)
{
if(i==1||i==2||i==20||i==21||i==38||i==39)
cout<<"*";
else
{
if(j==1)
cout<<"**";
else
cout<<" ";
}
}
 cout<<"\n\t\t\t\t";
 }
 break;

 case'F':

 cout<<"\t\t\t\t";

for(i=1;i<=40;++i)
{
for(j=1;j<=20;++j)
{
if(i==1||i==2||i==18||i==19)
cout<<"*";
else
{
if(j==1)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t\t";
}
break;

 case'G':

cout<<"\t\t\t";
for(i=1;i<=25;++i)
{
for(j=1;j<=20;++j)
{
if(i==1||i==2)
cout<<"*";
else
{
if(j==1)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t";
}
for(i=1;i<=10;++i)
{
for(j=1;j<=20;++j)
{
if(i==1||i==2)
{ if(j==1||j==14||j==15||j==16)
cout<<"**";
  else
  cout<<" ";
}
else
{
if(i==9||i==10)
cout<<"*";
else
{  if(j==1||j==18)
  cout<<"**";
  else
  cout<<" ";
}
}
}
cout<<"\n\t\t\t";
}
break;


 case'H':

cout<<"\t\t\t";
for(i=1;i<=40;++i)
{
for(j=1;j<=21;++j)
{
if(i==20||i==21)
cout<<"*";
else
{
if(j==1||j==19)
cout<<"**";
else
cout<<" ";
}
}
cout<<"\n\t\t\t";
}
break;

return 0;
}

OUTPUT :



Tuesday 14 October 2014

How To Create Printable Bootstrap Page



Every Day Is a New Learning Day . Today, I learnt a new thing with bootstrap When We use the page becomes responsive it will adapt its width and height and change it accordingly to the screen on which we are viewing that webpage that's the magic of Bootstrap .

 BUT there is one thing need to be noticed that is When we print that page . Like i needed to give one functionality in my web application to the client . Client wants a button when client click on that button a print preview of current page is given to client and page will be downloaded as .PDF file 
But Now you may face some problem as below :-

Bootstrap - Print layout and breaks after each grid column

Grid stacks when printing Bootstrap page

you may search How to Create Printable bootstrap page So solution is below


when you see in your print preview or .PDF file you can see bootstrap  layout will be not there . This is because bootstrap make the columns and rows by using some inbuilt classes these classes are by default included in bootstrap.min.css file but you have to set them to be allowed in all media As bydefault it is set to screen only


When you try code below in your html page you can see it is not printing your page with bootstrap enabled 

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
   <div class="container">
  <div class="row">
  <div class="col-md-6">Column1</div>
    <div class="col-md-6">Column2</div>
  </div>
</div>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

Steps To Create your Bootstrap Webpage Printable


1. Replace every col-md- with col-xs-
 e.g. :- replace every col-md-6 to col-xs-6 This is the thing that worked for me to get me rid of this problem you can see what you have to replace

Replace following code

   <div class="container">
  <div class="row">
    <div class="col-md-6">Column1</div>
    <div class="col-md-6">Column2</div>
  </div>
</div>

With this code in our given example

<div class="container"> <div class="row"> <div class="col-xs-6">Column1</div> <div class="col-xs-6">Column2</div> </div> </div>

Saturday 4 October 2014

\adt-bundle-windows-x86_64-20130219\sdk\platform-tools\aapt.exe is invalid

When your are using Android with Csharp or when you are using Monoandroid you will be facing some some error related to aapt.exe missing or aapt.exe invalid . These are common error to Monoandroid developer that almost every one that uses Monoandroid will face .

So Today I decided to get the actual reason of this problem and I sit on my chair to find out the reason and possible solution to this error that may work for everyone . I suffered from this error number of times before but i tried the ways to get rid of it But not today this is the day to get solution of this error .

What are Possible Errors :



  • Error MSB6004: The specified task executable location "C:\Program


  • Files\adt-bundle-windows-x86_64-20130219\sdk\platform-tools\aapt.exe" is 


invalid. (MSB6004) (TaskyAndroid)

The specified task executable location "D:\android-sdk\platform-tools

\aapt.exe" is invalid.


Reason of Above Errors 




This issue is caused by Google changing around the directory structure of the Android SDK with their latest updates and due to these updates old directory structures are creating problem Most probably these error comes after you update your android So when you update your android-sdk then it update the directory structure of android-sdk to new structure of google that allows
aapt.exe to be must present in android-sdk/platform-tools/ but that will be not there because in old directory structure that monoandroid is using aapt.exe is in android-sdk/build-tools/ that's why this error is coming and MonoAndroid Team is applying these changes so  before that we need to figure out this issue to continue our development

Error Solution aapt.exe Invalid


Steps :-

1.  Copy the aapt.exe file from folder \android-sdk\build-tools\17.0.0 to \android-sdk\platform-tools . Here 17.0.0 is your android api you have installed in your sdk it will be what version you installed like :- 8.0.0, 18.0.0

2. Now Also Copy \android-sdk\build-tools\17.0.0\lib folder to \android-sdk\platform-tools\ As there is a file in that directory dx.jar which is also Needed by xamarin

3. Now Everything will be fine ........Cheers!


There is one more error which can let you suffer it is :-

java exited with code 1


Reason of Error java exited with code 1

The reason of this error is in our previous error solution When you copy the aapt.exe file from  \android-sdk\build-tools\17.0.0 to \android-sdk\platform-tools .  and forger to copy or don't copy folder  \android-sdk\build-tools\17.0.0\lib folder to \android-sdk\platform-tools\ then this error comes this is main reason of this error

Error Solution java exited with code 1



 Also Copy \android-sdk\build-tools\17.0.0\lib folder to \android-sdk\platform-tools\ As there is a file in that directory dx.jar which is also Needed by xamarin after copying aapt.exe file

Wednesday 1 October 2014

Error : Failed To Update Android SDK

Every Android update contains some tools and advance features . Today I need To update my Andorid SDK to include Google Glass Services in it and enable it to use Google Maps in Andorid Application . In android to use google maps you must have google glass services in your android sdk

Some times it may be possible you sdk not having google glass services . Generally google glass services are available under Extras folder in android sdk Check that folder and click on Install update

But when we update Android SDK we may have an error while updating android sdk . You may have following like error :-

Failed to rename directory 
C:\Media\adt-bundle-windows-x86_64-20130522\sdk\platforms\android-19 to 
C:\Media\adt-bundle-windows-x86_64-20130522\sdk\temp\PlatformPackage.old01.
[find_lock] Directory locked by javaw.exe
And then, a window appears with this message:

-=Warning!=-
The following processes:
- javaw.exe
are locking the following directory:
C:\Media\adt-bundle-windows-x86_64-20130522\sdk\platforms\android-19
Please close these aplications so that the installation can continue.

The main cause of these errors are while we are updating android sdk on one side and on other side our android tools are running or hold by some other background process and we cannot kill that process at it will be automatically started so don't try to do that so the solution to this problem is :-

Follow these simple steps: There are two possible solutions to this problem that may definately solve your problem these both worked for me

Solution1

1. Open your android sdk folder

2. Under that folder you will find temp folder if you are using android studio then path is: C:\Users\<username>\AppData\Local\Android\android-studio\sdk\temp
3. Cut everything and paste it in some other new folder
4. Rerun the sdk and now and update

Solution2

1. First Make a copy of the \tools folder, name it something like \copy. So you should have c:\android-sdk-windows\copy.
2. Now run android.bat from the \copy folder with Admin privileges.
3. This should prevent the issue with items currently being open in the \tools folder.
4. Now cheers..

Saturday 27 September 2014

BootStrap Technology For Responsive Websites

Bootstrap is very good  and simple to use technology for making your website Mobile Compatible . It helps to make your website compatible with every you open it . Regardless of the screen size where we opens the website it provides full Responsiveness

Bootstrap File Structure

bootstrap/
├── css/
│   ├── bootstrap.css
│   ├── bootstrap.min.css
│   ├── bootstrap-theme.css
│   └── bootstrap-theme.min.css
├── js/
│   ├── bootstrap.js
│   └── bootstrap.min.js
└── fonts/
    ├── glyphicons-halflings-regular.eot
    ├── glyphicons-halflings-regular.svg
    ├── glyphicons-halflings-regular.ttf
    └── glyphicons-halflings-regular.woff


BootStrap Online File Links

 For Making your website Responsive using Bootstrap Technology You require some css , js coded files you can then use classes defined in these files to make your website responsive  you can either download these files from links below or you can directly provide these links in <head > </head> Tag of your Html or jsp or aspx file .
 For using Offline files :- 
 Go to links below one by one and this will open css code save the files with their respective names and then reference them in your page <head></head> Tag
For using Online Files :- 
Just include the following code lines in your page's <head></head> Tag
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" ref="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

A Simple Sample of Bootstrap Html Page Below :-


<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <h1>Hello, world!</h1>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

Grid System In Bootstrap

Grid systems are used for creating page layouts through a series of rows and columns that house your content. Bootstrap's Grid system has done a lot of ease for developers Instead of doing calculations for div's like they do before bootstrap technology they can easily divide the page into columns and rows and design the page according to it .

Here's how the Bootstrap grid system works:

  • Rows must be placed within a .container (fixed-width) or .container-fluid (full-width) for proper alignment and padding. A container will contain all your divs
  • Use rows to create horizontal groups of columns.
  • Content should be placed within columns, and only columns may be immediate children of rows.
  • Predefined grid classes like .row and .col-xs-4 are available for quickly making grid layouts. Less mixins can also be used for more semantic layouts.
  • Columns create gutters (gaps between column content) via padding. That padding is offset in rows for the first and last column via negative margin on .rows.
  • The negative margin is why the examples below are outdented. It's so that content within grid columns is lined up with non-grid content.
  • Grid columns are created by specifying the number of twelve available columns you wish to span. For example, three equal columns would use three .col-xs-4.
  • If more than 12 columns are placed within a single row, each group of extra columns will, as one unit, wrap onto a new line.
  • Grid classes apply to devices with screen widths greater than or equal to the breakpoint sizes, and override grid classes targeted at smaller devices. Therefore, applying any .col-md- class to an element will not only affect its styling on medium devices but also on large devices if a .col-lg- class is not present.
Reference Links

1. http://getbootstrap.com/
2. http://getbootstrap.com/css/

Monday 1 September 2014

How To Create Re-sizable Popup Windows using Jquery

CODE FOR HOW TO CREATE RE-SIZABLE POPUPS USING JQUERY


Try the code written below to create resizable popups for your websites you must have internet connection to use jquery files in the code below other wise you can download these files and give them static paths according to your directory structure

CODE

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Dialog - Modal confirmation</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height:140,
      modal: true,
      buttons: {
        "Delete all items": function() {
          $( this ).dialog( "close" );
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      }
    });
  });
  </script>
</head>
<body>

<div id="dialog-confirm" title="Empty the recycle bin?">
  <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>

<p>Sed vel diam id libero <a href="http://example.com">rutrum convallis</a>. Donec aliquet leo vel magna. Phasellus rhoncus faucibus ante. Etiam bibendum, enim faucibus aliquet rhoncus, arcu felis ultricies neque, sit amet auctor elit eros a lectus.</p>


</body>
</html>

Wednesday 20 August 2014

save to google drive button javascript code

This is a simple javascript code to upload file from your computer to google drive using google drive api

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
   <script src='https://apis.google.com/js/platform.js'></script>
<div class="g-savetodrive"   data-src="/images/attendance.png" data-filename="ppupload1.jpg" data-sitename="Pictures of "    >
</div>
    </form>
</body>
</html>


Sunday 3 August 2014

Mixed mode assembly is built against version 'v2.0.50727' of the runtime


Error :- Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information

Error Explanation -
During using Sqlite Database with Csharp Applications you may suffer from this error Don't fear from it this is simple error

This problem is seen often . The main reasonof this problems  is that, because of the support for side-by-side runtimes in .Net Technology , .NET framework 4.0 has changed its way of binding  to older framework mixed-mode assemblies. These assemblies are those that are compiled from old  C++\CLI. Currently available DirectX assemblies are mixed mode. If you see a message like this then you know you have run into the issue:

Mixed mode assembly is built against version 'v1.1.4322' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

SOLUTION :
Add the Following code in App.config file . App.config file will be available in Solution Explorer . If App.config is not available then you can add it by :-

  1. Right click on Project's folder in Solution Explorer 
  2. Click on Add then click on New
  3. Now scroll and find Application Configuration file and Click ok
  4. Now App.config will be successfully added .
  5. Now make the code of your App.config file similar to the following code or the replace the <startup> tag with tag given below

    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
     <requiredRuntime version="v4.0.20506" />
    </startup>
  6. Now All errors Will be gone and continue your code with SQlite Csharp using link below :-

    How To Use Sqlite Database With Csharp





How To Use Sqlite Database With Csharp

Sqlite Database is the best way of providing portability to our database . Sqlite database is well know for the conditions when developers don't want to mess up with installation of database on the client machine . In case of Desktop applications or Web Applications We often require database . It does not matter any database we use We need to install it .

We can use database for application by install it on Client's machine that may be some messy work that take some time and could be problematic and The Second condition is to host the database to Database Server and client is given the access to that Database But that may include some Usage or disk cost of Database Server that could be costly as the database goes on increasing day by day

So solution to these type of problems is SQLite Database . Actually Sqlite Database is very popular database used in Handheld or mobile applications . The main purpose of using Sqlite Database for these conditions is that Sqlite Database Simply includes the All sql queries that are used to create table in between the application source code and it create a file of database with .mdf extension on client's machine in given location and all data is saved to that location so it can be easily backed up by employee by using simple method of uploading this database file to his / her Mail Account or save it in somewhere else .

Download the Sqlite DLL And sourcecode that will be required in this Application 

Download System.Data.Sqlite Dll File
DOWNLOAD SOURCECODE ZIP FILE


 
Adding System.Data.Sqlite Dll File To Visual Studio


  1. Open Visual Studio and Create a New C# Desktop Application Project by giving it a legal name .
  2. Now In Right Side you can see Solution Explorer 
  3. In Solution Explorer Right Click on Reference and Click on Add Reference

  4. Now Click on Browse and then Click on Browse button to choose Dll file from your computer where you have downloaded it .

  5. Now click on OK after adding dll file .

  6. Now Dll file is successfully Added
  7. Now Finally Add Namespace Using System.Data.Sqlite in top line of your form's .Cs file


Adding Data_Connection Class

Data_connection class will be used to give location where the Sqlite Database .mdf file will be created We are creating class for this as it will be used in number of location that is called code reuse

Steps To Add Class :- 

  1. Right click on Project's folder in solution explorer 
  2. In pop-up menu click on Add Then click on Class
  3. Now a Window appear give a name like Data_connection.cs and Hit ok
  4. Now add the code similar to following code to the class :-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SQLite;
using System.Data;
using System.Windows.Forms;
namespace useSqlitecsharp
{
    class Data_connection
    {
        public string datalocation()
        {
            string dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            return "Data Source=" + dir + "\\DBgeeksprogrammings.mdf;";
        }

    }
}
5. Now Save all

Adding Code for Creating Table , Inserting Data and Showing Inserted Data

Now we are going to create table using csharp code by passing queries into the code then we pass insert query then we show the result
Add the code similar to following code to your form  :-

Main Terms Used in Code

1. SQLiteConnection :- This is class that is used to establish connection to the sqlite database for creating table , inserting data or to pass any query to database we must first establish connection to database and open the port for connection this is accomplished by making object of this class

2. SQLcommand :- This class is used to pass the sql queries . This requires the Sqlconnect object to be passed also to open to tell the command which instance of database is used for executing the queries that are passed to it .

3. SqlDataAdapter :- This class is used to store the result of executed query and hold to put it in some other variable or datatable


ERROR INFORMATION :- It may be possible that you may go through an error that always exist when we you are attempting first time with sqlite database The error details is shown in image below and Its solution is given in link below


CLICK HERE FOR ERROR SOLUTION
ERROR SOLUTION

Csharp ( C# ) CODE  :-


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;

namespace useSqlitecsharp
{
    public partial class Form1 : Form
    {
        Data_connection dbobject = new Data_connection();
        SQLiteConnection SQLconnect = new SQLiteConnection();
        public Form1()
        {
            InitializeComponent();
        }
     
        private void button1_Click(object sender, EventArgs e)
        {
            SQLiteCommand SQLcommand = new SQLiteCommand();
            SQLcommand = SQLconnect.CreateCommand();
            SQLcommand.CommandText = "CREATE TABLE IF NOT EXISTS "+textBox1.Text+"( Username TEXT, Password TEXT);";
            SQLcommand.ExecuteNonQuery();
            SQLcommand.Dispose();

            MessageBox.Show("Table Created");
        }



        private void Form1_Load(object sender, EventArgs e)
        {
            SQLconnect.ConnectionString = dbobject.datalocation();
            SQLconnect.Open();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SQLiteCommand cmd = new SQLiteCommand();
            cmd = SQLconnect.CreateCommand();
            cmd.CommandText = "insert into " + textBox1.Text + " (Username,Password)  values (@username,@password)";
            cmd.Parameters.AddWithValue("@username", textBox2.Text);
            cmd.Parameters.AddWithValue("@password", textBox3.Text);
            cmd.ExecuteNonQuery();
            cmd.Dispose();

            MessageBox.Show("Data Inserted");
        }



        private void button3_Click(object sender, EventArgs e)
        {
            SQLiteCommand cmd = new SQLiteCommand("select * from "+textBox1.Text , SQLconnect);
            SQLiteDataAdapter da = new SQLiteDataAdapter();
            DataTable dt = new DataTable();
            da.SelectCommand = cmd;
            da.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                dataGridView1.DataSource = dt;
            }
            else
            {
                MessageBox.Show("No Data Exist in Table");
            }
        }

    }
}

































Friday 1 August 2014

How To use Crystal Reports in Asp.net


Download zip code file  for Crystal Report Demo App
Download Code For How To use Crystal Reports in Asp.net

Setting Up Sql Server Database 

  1. Open you Sql Server Management Studio
  2. Connect to SQl Server
  3. Then  in Right panel Right click on Databases and Click on New Database
  4. Now A New Dialog Box Appears 
  5. Fill Database name: TestReports and Hit Enter . Now Table will be successfully created

  6. Now in the Query window execute the following scripts to create table

  7. After successfull creation of tables insert some dummy data in tables using following query code

  8. Now Our Database work is over Now we go to Visual Studio for code

Now Do Code in Visual Studio
Start your Visual Studio .Click on New project choose Asp.net Web Form  Application and Give a appropriate name and choose location and Hit Enter .


Getting Dataset Ready For Report

  1. Right click on Project Folder in solution Explorer and click on Add then in further sub-menu click on New item

  2. Now a Popup window appears scroll and choose DataSet give name "Customers" and Click on Ok to add DataSet
  3. Now Customers Dataset will be added in solution explorer . Now Double click on it 
  4. It will open DataSet Designer Now right click on and create new DataTable 
  5. After Creating DataTable it will be empty by default now we will add column to it similar to our column in table in database 
  6. Right click on DataTable that we have created and Create new Column and give it name try to give the name similar to name of columns in Table in Database


Adding Crystal Report

  1. Right click on Project Folder in solution Explorer and click on Add then in further sub-menu click on New item 
  2. Now a Popup window appears scroll and choose Crystal Report give it name and Click on Ok

  3. Now Crystal Report Gallery window popup after some time 
  4. Now choose "Using the Report Wizard"  and click ok

  5. Now a window will popup and tell you to choose your dataset that we have created in above steps
  6. Choose your Datatable under Customers DataSet and Click ok
  7. Now your Dataset fields will be added on Field Explorer . Field explorer is available on left side of visual studio window
  8. In Field explorer under Database Expert you all datatable fields will be available

  9. you can drag these fields to crystal Report Details Section When you add them in  Details Section Its Header will automatically added to Page Header Section
  10. you can do some design of your Crystal Report like shown below :-


Designing Form

  1. Now  we will add a Aspx form that will be used to view our Crystal Report
  2. Right click on Project Folder in solution Explorer and click on Add then in further sub-menu click on New item 
  3. Now a Popup window appears scroll and choose WebForm give it name and Click on Ok  
  4. Now delete the existing code Add Following Code To Aspx Form


<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <center>
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" Width="1000" />
            </center>
    </form>
</body>
</html>



Adding Csharp ( C# ) Code


  1. Now go to Csharp code of New Added Webform and Add code similar to code below :-
  2. Add this code under your partial class -- 


protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument crystalReport = new ReportDocument();
        crystalReport.Load(Server.MapPath("~/CustomerReport.rpt"));
        Customers dsCustomers = GetData("select * from Testtable");
        crystalReport.SetDataSource(dsCustomers);
        CrystalReportViewer1.ReportSource = crystalReport;
    }

    private Customers GetData(string query)
    {
        string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        SqlCommand cmd = new SqlCommand(query);
        using (SqlConnection con = new SqlConnection(conString))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;

                sda.SelectCommand = cmd;
                using (Customers dsCustomers = new Customers())
                {
                    sda.Fill(dsCustomers, "DataTable1");
                    return dsCustomers;
                }
            }
        }
    }