Page

How to Sort Datalist Using Dropdownlist in ASP.Net


// Example.aspx //

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Example.aspx.cs" Inherits="_Example" %>  
  
<!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> Sort Datalist Using Dropdownlist</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  

<asp:DropDownList ID="DDLSorting" runat="server" AutoPostBack="True" onselectedindexchanged="DDLSorting_SelectedIndexChanged">
                        <asp:ListItem>Best Match</asp:ListItem>
                        <asp:ListItem>New Arrivals</asp:ListItem>
                        <asp:ListItem Value="3" Text="Price: Low to High"></asp:ListItem>
                        <asp:ListItem>Price: High to Low</asp:ListItem>
                        </asp:DropDownList>
              </div>  
        </form>  
    </body>  
</html>  


// Example.aspx.cs //


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

public partial class Example : System.Web.UI.Page
{

  protected void Page_Load(object sender, EventArgs e)
    {
    }

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    bindDropDownList();
}

private void bindDropDownList()
{
    DropDownList1.DataTextField = "price";
    DataList1.DataSourceID = null;
    DataList1.DataSource = getReader();
    DropDownList1.DataBind();

}

private SqlDataReader getReader()
{
    SqlDataReader reader = null;

    if(DropDownList1.Text == "-Select-")
    {
      string strConnectionString =
            ConfigurationManager.ConnectionStrings["Pubs"].ConnectionString;
        SqlConnection myConnect = new SqlConnection(strConnectionString);

        string strCommandText ="SELECT * FROM [Category ] WHERE ID<= 20";

        SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
        myConnect.Open();

   reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

    }
    else if (DropDownList1.SelectedValue == "Price - Highest to Lowest")
    {
        string strConnectionString =
            ConfigurationManager.ConnectionStrings["Pubs"].ConnectionString;
        SqlConnection myConnect = new SqlConnection(strConnectionString);

        string strCommandText = "SELECT ID, packageName, price, description1, description2, image1, image2 FROM Category WHERE ID <= 20 ORDER BY price desc";

        SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
        myConnect.Open();

   reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

    }

    else if (DropDownList1.DataTextField == "Price - Lowest to Highest")
    {
        string strConnectionString =
            ConfigurationManager.ConnectionStrings["Pubs"].ConnectionString;
        SqlConnection myConnect = new SqlConnection(strConnectionString);

        string strCommandText = "SELECT ID, packageName, price, description1, description2, image1, image2 FROM Category WHERE ID <= 20 ORDER BY price";

        SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
        myConnect.Open();

   reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

    }
    return reader;
   }
}

Programe to Sparse Matrix in C/C++

//*******************************************************************
// SPARSE MATRIX
//********************************************************************
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<process.h>
#include<graphics.h>
void insert(int [][100],int,int);
void display(int [][100],int ,int);
void check(int [][100],int,int);
void main()
{
int gd,gm;
int a[100][100],ch,n,m,k;
char cho;

s:
clrscr();
printf("\t\t\t_________________________________\n\n");
printf("\t\t\t********SPARSE MATRIX *********");
printf("\n\n\t\t\t_________________________________");
printf("\n\n\t\t\t*******ENTER THE CHOICE*********");
printf("\n\t\t\t________________________________");
printf("\n\t\t\t INTER THE MATRIX      [1]");
printf("\n\t\t\t CHECKING  THE MATRIX  [2]");
printf("\n\t\t\t DISPLAY               [3]");
printf("\n\t\t\t EXIT                  [4]\n\n");
printf("\t\t\t\t.......");
fflush(stdin);
scanf("%d",&ch);


clrscr();

switch(ch)
{

case 1:
clrscr();
k=1;
printf("\n\n\t\t\t_____________________________________");
printf("\n\n\t\t\t***INSERTION PART*****\n");
printf("\t\t\t________________________________________\n\n");

printf("\n\n\t\t\tENTER THE SIZE OF MATRIX\n\n");
printf("\t\t\t\tROW:=");
scanf("%d",&n);
printf("\t\t\t\tCOLLUMN:=");
scanf("%d",&m);

insert(a,n,m);           //call the insert function
goto s;



case 2:
clrscr();
printf("\n\n\t\t\t_____________________________________");
printf("\n\n\t\t\t\t***MATRIX CHACKING PART*****\n");
printf("\t\t\t________________________________________\n\n");

 if(k==1)
{
check(a,n,m);              //call the check function
}
else
{
printf("\n\n\t\t\tPLEASE INSERT THE MATRIX");
}

getch();
goto s;

case 3:
clrscr();
printf("\n\n\t\t\t\t___________________________________");
printf("\n\n\t\t\t\t\t******DISPLAY PART***********");
printf("\n\t\t______________________________________\n\n");
if(k==1)
{

display(a,n,m); //call the display function
}
else
{

printf("\n\n\t\t\tPLEASE INSERT THE MATRIX");
}
getch();
goto s;

case 4:
clrscr();

printf("\n\n\t\t\t____________________________________");
printf("\n\n\t\t\t\t***EXIT PART*****\n");
printf("\n\n\t\t\t\t__________________________________");
getch();
exit(0);



//*********************************************************************
//                               DEFAULT
//*********************************************************************
default:
clrscr();
printf("\n\n\n\t\t\t U R ENTER THE WRONG CHOICE");
delay(1000);
goto s;
}
 //***************END OF THE SWITCH STATEMENT***************
 //*********************************************************




getch();
}








//************************************************
//  ****INSERTION  function***
//*************************************************



void insert (int a[][100],int n,int m)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("\n\n\t\t\tENTER THE VALUE of [%d][%d]:==",i,j);
scanf("%d",&a[i][j]);
}
}

      printf("\n\n\t\t\t*******MATRIX IS FULL*********");
      delay(1000);
}





//****************************************************************
//      DISPLAY   function
//****************************************************************/*



void display(int a[][100],int n,int m)
{
int i,j,k;
printf("\n\t\t\tROW:=%d\n\n\t\t\tCOLUMN:=%d\n",n,m);
printf("\n\n\n\t\t\tMATRIX IS ......\n\n\t\t");

for(k=0;k<m;k++)
{
printf("\tcolumn %d",k);
}

printf("\n\n\n");

for(i=0;i<n;i++)
{
printf("\trow %d\t",i);
for(j=0;j<m;j++)
{
printf("\t%d\t",a[i][j]);
}

printf("\n\n\n");

}

}





//*************************************************************
//     ******** CHECKING function *******
//***************************************************************/*

void check(int a[][100],int n ,int m)
{

int i,j,ut=0,lt=0,d=0,ire=0,k=0,re=0,ir=0;



for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
if(a[i][j]==0)
{
lt=1;
break;
}
}
}


if(lt==1)
{
for(i=0;i<n;i++)
{
for(j=i;j<m;j++)
{
if(a[i][j]==0)
{
ut=1;
break;
}
}
}
}

 if((ut==1)&&(lt==1))
 {
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(i==j)
{
if(a[i][j]==0)
{
d=1;
break;
}
}
else if(i!=j)
{
if(a[i][j]!=0)
{
d=1;
break;
}
}
}
}
}

if(lt==0)
{
re=1;
printf("\t\t\tmatrix is lower traingler");
}
else if(ut==0)
{
re=1;
printf("\t\t\tmatrix is upper triangular");
}
else if(d==0)
{
re=1;
printf("\t\t\tmatrix is daigonal");
}
else
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]==0)
{
ire++;
}
}
}

if(ir>1)
{
ire=1;
printf("matrix is iregular");
}
else
{
printf("matrix is not sparse matrix");
}
}
}



Bus Ticket Booking System In C/C++

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
#include<dos.h>
#include<string.h>
void seat_av();
void graph_init();
void add_new_she();
void main_menu();
void ticket_book();
void user_bus_list();
void admin_menu();
void user_menu();
void del_record();
void add_bus();
void list_of_bus();
void update_records();
void rev_list();
void search();
void admin_login();
void user_login();
typedef struct
{
char bus_name[40];
char org[30];
char dest[30];
char a_time[10];
char d_time[10];
int bus_no;
int seat;
int fare;
} bus;
typedef struct
{
char bus_name[30];
char p_name[30];
char j_date[15];
int seat_no;
int bus_no;
int age;
}book;
typedef struct
{
int bus_no;
char dt[15];
int t_seat;
}seat;
FILE *fb,*fr,*ft,*fs;
char another;
void main()
{
int i;
clrscr();
textcolor(4);
gotoxy(25,3);
cprintf("sourcecodernp.blogspot.com");
gotoxy(35,5);
cprintf("Project On");
gotoxy(27,7);
cprintf("Bus Ticket Booking System");
gotoxy(40,9);

cprintf("Please Wait File is Loding................");
textcolor(12);
gotoxy(10,24);
for(i=0;i<65;i++)
{
delay(100);
cprintf("%c",219);
}
main_menu();
getch();
}
void main_menu()
{
int ch;
clrscr();
graph_init();
setbkcolor(8);
rectangle(140,100,500,300);
setcolor(4);
gotoxy(35,6);
printf("Main Menu");
gotoxy(30,8);
printf("Adminstrator Mode [1]");
gotoxy(30,10);
printf("User Mode         [2]");
gotoxy(30,12);
printf("Exit              [3]");
gotoxy(30,14);
printf("Enter your choice : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
admin_login();
break;
case 2:
user_login();
break;
case 3:
exit(1);
break;
default:
main_menu();
break;
}
}
void admin_menu()
{
int ch;
clrscr();
graph_init();
setbkcolor(8);
rectangle(40,70,600,400);
setcolor(BLUE);
setfillstyle(SOLID_FILL,RED);
bar(40,70,600,120);
settextstyle(1,0,2);
outtextxy(170,85,"Welcome to Administrator Menu");
gotoxy(13,12);
printf("Add New Bus         [1]");
gotoxy(45,12);
printf("Update Records      [2]");
gotoxy(13,14);
printf("Delete Record       [3]");
gotoxy(45,14);
printf("List of Records     [4]");
gotoxy(13,16);
printf("Reservation List    [5]");
gotoxy(45,16);
printf("Add New Schedual    [6]");
gotoxy(13,18);
printf("Back Previous Menu  [7]");
gotoxy(13,20);
printf("Enter Your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
add_bus();
break;
case 2:
update_records();
break;
case 3:
del_record();
break;
case 4:
list_of_bus();
break;
case 5:
rev_list();
break;
case 6:
add_new_she();
case 7:
main_menu();
default:
printf("Wrong Input");
}
}
void add_bus()
{
bus b;
clrscr();
graph_init();
another='Y';
setbkcolor(8);
fb=fopen("bus.dat","ab");
while(another=='Y'||another=='y')
{
fflush(stdin);
printf("\nEnter bus No:");
scanf("%d",&b.bus_no);
fflush(stdin);
printf("\nEnter Bus Name:");
gets(b.bus_name);
fflush(stdin);
printf("\nEnter origin:");
gets(b.org);
fflush(stdin);
printf("\nEnter distination:");
gets(b.dest);
fflush(stdin);
printf("\nEnter Departure Time:");
gets(b.d_time);
fflush(stdin);
printf("\nEnter Arrival Time:");
gets(b.a_time);
fflush(stdin);
printf("\nEnter Total Seat : ");
scanf("%d",&b.seat);
fflush(stdin);
printf("\nEnter Fare : ");
scanf("%d",&b.fare);
fwrite(&b,sizeof(b),1,fb);
printf("\nRecord is added");
printf("\nAdd another record(Y/N):");
fflush(stdin);
another=getche();
}
fclose(fb);
admin_menu();
closegraph();
restorecrtmode();
}
void list_of_bus()
{
int i=1,p=3;
bus b;
clrscr();
graph_init();
setbkcolor(8);
gotoxy(1,1);
printf("Bus No");
gotoxy(10,1);
printf("Bus Name");
gotoxy(25,1);
printf("Origin");
gotoxy(35,1);
printf("Destination");
gotoxy(50,1);
printf("Departure Time");
gotoxy(67,1);
printf("Arrival Time");
fb=fopen("bus.dat","rb");
if(fb==NULL)
{
printf("\n\nError-File Cannot Open");
}
while(fread(&b,sizeof(b),1,fb)==1)
{
gotoxy(1,p);
printf("%d",b.bus_no);
gotoxy(10,p);
printf("%s",b.bus_name);
gotoxy(25,p);
printf("%s",b.org);
gotoxy(35,p);
printf("%s",b.dest);
gotoxy(50,p);
printf("%s",b.d_time);
gotoxy(67,p);
printf("%s",b.a_time);
if(i%10==0)
{
printf("\nPress any key to continue............!");
fflush(stdin);
getch();
clrscr();
p=3;
}
i++;
p+=2;
}
printf("\n\nPress any key to back to Menu.........!");
getch();
admin_menu();
}
void update_records()
{
long int resize;
int b_no;
bus b;
clrscr();
graph_init();
resize=sizeof(b);
another='Y';
fb=fopen("bus.dat","rb+");
while(another=='Y' || another=='y')
{
printf("Enter Bus No :");
scanf("%d",&b_no);
rewind(fb);
while(fread(&b,resize,1,fb)==1)
{
if(b.bus_no==b_no)
{
fflush(stdin);
printf("Enter Bus name:");
gets(b.bus_name);
fflush(stdin);
printf("\nEnter origin:");
gets(b.org);
fflush(stdin);
printf("\nEnter distination:");
gets(b.dest);
fflush(stdin);
printf("\nEnter total seat:");
scanf("%d",&b.seat);
fflush(stdin);
printf("\nEnter Fare:");
scanf("%d",&b.fare);
fseek(fb,-resize,SEEK_CUR);
fwrite(&b,sizeof(b),1,fb);
}
}
printf("\n\nData is Updated");
printf("\n\nModify another Data(Y/N);");
fflush(stdin);
another=getche();
}
fclose(fb);
getch();
admin_menu();
closegraph();
restorecrtmode();
}
void search()
{
int b_no;
bus b;
clrscr();
graph_init();
fb=fopen("bus.dat","rb");
another='Y';
printf("\nEnter bus no:");
scanf("%d",&b_no);
while(fread(&b,sizeof(b),1,fb)==1)
{
if(b.bus_no==b_no)
{
printf("\n\nBus is found");
printf("\n\n\tBus No         :  %d",b.bus_no);
printf("\n\n\tBus Name       :  %s",b.bus_name);
printf("\n\n\tDeparture      :  %s",b.org);
printf("\n\n\tDestination    :  %s",b.dest);
printf("\n\n\tDeparture Time :  %s",b.d_time);
printf("\n\n\tArrival Time   :  %s",b.a_time);
printf("\n\n\tSeat           :  %d",b.seat);
printf("\n\n\tFare           :  %d",b.fare);
printf("\n\nAnother search(Y/N) :");
fflush(stdin);
another=getchar();
if(another=='y'||another=='Y')
search();
else
{
fclose(fb);
user_menu();
}
}
}
printf("\n\nBus is Not Fount");
printf("\n\nDo you want to Search another Bus(Y/N) :");
fflush(stdin);
another=getchar();
if(another=='Y'||another=='y')
search();
else
{
fclose(fb);
user_menu();
}
closegraph();
restorecrtmode();
}
void del_record()
{
int c=1,z;
bus b;
int bno;
clrscr();
graph_init();
another='Y';
while(another=='Y' || another=='y')
{
printf("\nEnter Bus No for Deletion :");
scanf("%d",&bno);
ft=fopen("temp.dat","ab");
fb=fopen("bus.dat","rb");
while(fread(&b,sizeof(b),1,fb)==1)
{
if(b.bus_no==bno)
{
c++;
}
else
{
fwrite(&b,sizeof(b),1,ft);
}
}
fclose(fb);
fclose(ft);
remove("bus.dat");
rename("temp.dat","bus.dat");
fb=fopen("bus.dat","rb+");
setcolor(WHITE);
outtextxy(40,370,"THE RECORD IS DELETING");
rectangle(40,380,580,405);
for(z=40;z<=580;z++)
{
setfillstyle(SOLID_FILL,BLACK);
floodfill(0,0,BLACK);
rectangle(40,380,z,405);
delay(10);
setfillstyle(SOLID_FILL,BLUE);
floodfill(42,392,WHITE);
}
clrscr();
cleardevice();
printf("\n\nDelete another Records(Y/N) : ");
fflush(stdin);
another=getche();
}
fclose(fb);
getch();
admin_menu();
closegraph();
restorecrtmode();
}

void user_menu()
{
int ch;
clrscr();
graph_init();
setbkcolor(8);
rectangle(40,70,600,400);
setcolor(BLUE);
setfillstyle(SOLID_FILL,RED);
bar(40,70,600,120);
settextstyle(1,0,2);
outtextxy(170,85,"Welcome to User Menu");
gotoxy(13,12);
printf("Search Bus         [1]");
gotoxy(45,12);
printf("Booking Ticket     [2]");
gotoxy(13,14);
printf("Show List of Bus   [3]");
gotoxy(45,14);
printf("Seat Availability  [4]");
gotoxy(13,16);
printf("Back Previous Menu [5]");
gotoxy(13,18);
printf("Enter your choice : ");
scanf("%d",&ch);
while(1)
{
switch(ch)
{
case 1:
search();
break;
case 2:
ticket_book();
break;
case 3:
user_bus_list();
break;
case 4:
seat_av();
break;
case 5:
main_menu();
break;
default:
user_menu();
break;
}
}
}
void ticket_book()
{
int resize;
book b1;
seat s;
clrscr();
graph_init();
another='Y';
resize=sizeof(s);
rewind(fr);
fs=fopen("seat.dat","rb+");
fr=fopen("booking.dat","wb");
fseek(fr,0,SEEK_END);
while(another=='Y'|| another=='y')
{
fflush(stdin);
printf("\nEnter Bus No:");
scanf("%d",&b1.bus_no);
fflush(stdin);
printf("\nBus Name:");
gets(b1.bus_name);
fflush(stdin);
printf("\nEnter Passenger Name:");
gets(b1.p_name);
fflush(stdin);
printf("\nEnter age:");
scanf("%d",&b1.age);
fflush(stdin);
printf("\nEnter Journey Date(D/M/Y) :");
gets(b1.j_date);
fflush(stdin);
printf("\nEnter seat No:");
scanf("%d",&b1.seat_no);
fseek(fs,0,SEEK_SET);
while(fread(&s,sizeof(s),1,fs)==1)
{
if((s.bus_no==b1.bus_no) && (strcmp(s.dt,b1.j_date)==0))
{
s.t_seat=s.t_seat-1;
fseek(fs,-resize,SEEK_CUR);
fwrite(&s,sizeof(s),1,fs);
}
fclose(fs);
}
fwrite(&b1,sizeof(b1),1,fr);
printf("\nBook Another ticket(Y/N) : ");
fflush(stdin);
another=getche();
}
fclose(fr);
user_menu();
}
void rev_list()
{
book b2;
int i=1,p=3;
clrscr();
graph_init();
gotoxy(1,1);
printf("Bus No");
gotoxy(13,1);
printf("Bus Name");
gotoxy(27,1);
printf("Passenger Name");
gotoxy(50,1);
printf("Age");
gotoxy(57,1);
printf("Seat No");
gotoxy(68,1);
printf("Journey Date");
fr=fopen("booking.dat","rb");
while(fread(&b2,sizeof(b2),1,fr)==1)
{
gotoxy(1,p);
printf("%d",b2.bus_no);
gotoxy(13,p);
printf("%s",b2.bus_name);
gotoxy(27,p);
printf("%s",b2.p_name);
gotoxy(50,p);
printf("%d",b2.age);
gotoxy(57,p);
printf("%d",b2.seat_no);
gotoxy(68,p);
printf("%s",b2.j_date);
if(i%10==0)
{
printf("\nPress any key to continue............!");
fflush(stdin);
getch();
clrscr();
p=3;
}
i++;
p+=2;
}
printf("\n\nPress any key to back to Menu.........!");
getch();
admin_menu();
}
void admin_login()
{
int i,x=38,j;
char pwd[20];
char *pass="chandan";
clrscr();
graph_init();
setfillstyle(SOLID_FILL,4);
bar(0,0,640,480);
setfillstyle(SOLID_FILL,BLACK);
bar(10,10,625,430);
line (130,180,500,180);
rectangle ( 130,150,500,300);
setfillstyle ( SOLID_FILL, 7 );
bar (130,150,500,180);
setfillstyle ( SOLID_FILL, 8 );
bar (130,180,500,300 );
setcolor(4);
outtextxy(140,165, " P A S S W O R D   V E R I F I C A T I O N  " );
setfillstyle ( SOLID_FILL, 0 );
bar(290,222,450,245);
outtextxy ( 160, 229, "ENTER PASSWORD " );
for(i=0;i<20;i++)
{
pwd[i]=getch();
if(pwd[i]=='\r')
{
pwd[i]='\0';
break;
}
else
{
gotoxy(x,15);
printf("*");
x++;
}
}
if(strcmp(pass,pwd)==0)
{
clrscr();
cleardevice();
setbkcolor(12);
setcolor(BLUE);
settextstyle(1,0,4);
outtextxy(100,100,"Pls Wait File is in Process........");
gotoxy(15,14);
for(j=0;j<50;j++)
{
delay(200);
printf("%c",219);
}
admin_menu();
}
else
{
clrscr();
cleardevice();
setcolor(2);
settextstyle(1,0,4);
setbkcolor(12);
outtextxy(145,190,"Invalid Password");
sound(700);
delay(1000);
nosound();
admin_login();
}
closegraph();
restorecrtmode();
}
void graph_init()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"..\\bgi");
}
void user_login()
{
int x=37,i,j;
char user[20];
char *username="chandan";
char pwd[20];
char *pass="123456";
graph_init();
setfillstyle(SOLID_FILL,4);
bar(0,0,640,480);
setfillstyle(SOLID_FILL,BLACK);
bar(10,10,625,430);
line(130,180,500,180);
rectangle(130,150,500,300);
setfillstyle(SOLID_FILL, 7 );
bar(130,150,500,180);
setfillstyle ( SOLID_FILL, 8 );
bar(130,180,500,300);
setcolor(4);
outtextxy(140,165," P A S S W O R D   V E R I F I C A T I O N  " );
setfillstyle ( SOLID_FILL, 0 );
bar(280, 200, 450, 230 );
bar(280, 247, 450, 277 );
outtextxy(135,210,"Enter User Name :" );
outtextxy(135,258,"Enter Password  :");
gotoxy(37,14);
fflush(stdin);
gets(user);
for(i=0;i<20;i++)
{
pwd[i]=getch();
if(pwd[i]=='\r')
{
pwd[i]='\0';
break;
}
else
{
gotoxy(x,17);
printf("*");
x++;
}
}
if((strcmp(username,user)==0) && (strcmp(pass,pwd)==0))
{
clrscr();
cleardevice();
setbkcolor(12);
setcolor(BLUE);
settextstyle(1,0,4);
outtextxy(100,100,"Pls Wait File is in Process........");
gotoxy(14,14);
for(j=0;j<50;j++)
{
delay(200);
printf("%c",219);
}
user_menu();
}
else
{
clrscr();
cleardevice();
setcolor(14);
settextstyle(1,0,3);
setbkcolor(12);
outtextxy(145,190,"Invalid User or Password");
sound(700);
delay(1000);
nosound();
user_login();
}
closegraph();
restorecrtmode();
}
void user_bus_list()
{
int i=1;
bus b;
clrscr();
graph_init();
setbkcolor(12);
fb=fopen("bus.dat","rb");
if(fb==NULL)
{
printf("\n\nError-File Cannot Open");
}
while(fread(&b,sizeof(b),1,fb)==1)
{
setcolor(BLUE);
settextstyle(4,0,3);
outtextxy(200,10,"All Bus Information");
printf("\n\n\n\n\t************************************************************");
printf("\n\n\t\t\tBus No         :   %d",b.bus_no);
printf("\n\n\t\t\tBus Name       :   %s",b.bus_name);
printf("\n\n\t\t\tOrigin         :   %s",b.org);
printf("\n\n\t\t\tDestination    :   %s",b.dest);
printf("\n\n\t\t\tDeparture Time :   %s",b.d_time);
printf("\n\n\t\t\tArrival Time   :   %s",b.a_time);
printf("\n\n\t\t\tTotal Seat     :   %d",b.seat);
printf("\n\n\t\t\tTotal Fare     :   %d",b.fare);
if(i%1==0)
{
printf("\n\n\t\tPress any key to continue............!");
fflush(stdin);
getch();
clrscr();
}
i++;
}
printf("\n\nPress any key to back to Menu.........!");
getch();
user_menu();
closegraph();
restorecrtmode();
}
void add_new_she()
{
seat s;
clrscr();
graph_init();
cleardevice();
another='y';
fs=fopen("seat.dat","wb");
while(another=='y'||another=='Y')
{
printf("Enter Bus No  :");
scanf("%d",&s.bus_no);
fflush(stdin);
printf("Date of Departure  :");
gets(s.dt);
fflush(stdin);
printf("Enter Seat :");
scanf("%d",&s.t_seat);
fwrite(&s,sizeof(s),1,fs);
printf("Record is added");
printf("\nAdd another record:");
fflush(stdin);
another=getche();
}
fclose(fs);
getch();
admin_menu();
}
void seat_av()
{
int b_no;
char dat[15];
seat s;
clrscr();
graph_init();
cleardevice();
another='y';
fs=fopen("seat.dat","rb");
printf("\nEnter Bus No :");
scanf("%d",&b_no);
fflush(stdin);
printf("Enter Date   :");
gets(dat);
while(another=='y'||another=='Y')
{
while(fread(&s,sizeof(s),1,fs)==1)
{
if((s.bus_no==b_no) && (strcmp(s.dt,dat)==0))
{
printf("\n\nBus No :%d",s.bus_no);
printf("\n\nDate   :%s",s.dt);
printf("\n\nAvailable Seat :%d",s.t_seat);
printf("\n\nSearch Another Record:");
fflush(stdin);
another=getchar();
if(another=='y'||another=='Y')
seat_av();
else
{
fclose(fs);
user_menu();
}
}
}
printf("\n\nBus is Not Fount");
printf("\n\nDo you want to Search another Bus(Y/N) :");
fflush(stdin);
another=getchar();
if(another=='Y'||another=='y')
seat_av();
else
{
fclose(fs);
user_menu();
}
closegraph();
restorecrtmode();
}
}


Movie Booking System In C/C++

#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
void search();
void current_movie();
void main_menu();
void book();
void print_ticket();
void add_hall();
void list_movie();
void ticket_cancel();
void screen();
typedef struct
{
int mid;
int hid;
char hname[40];
char mname[30];
char actor[30];
char actoress[30];
char r_date[30];
}movie;
typedef struct
{
char hname[30];
char area[30];
int id;
int a_seat;
int d_seat;
}hall;
typedef struct
{
char name[30];
char gender;
char c_type[10];
int age;
int amount;
int seat_no;
int tno;
}ticket;
FILE *fm,*ft,*fh;
void main()
{
clrscr();
screen();
delay(7000);
main_menu();
getch();
}
void screen()
{
textcolor(BLUE);
gotoxy(20,4);
cprintf("sourcecodernp.blogspot.com");
gotoxy(30,6);
cprintf("Project on");
gotoxy(25,8);
cprintf("Movie Booking System");
gotoxy(20,10);
}
void main_menu()
{
int ch;
clrscr();
gotoxy(30,2);
cprintf("Main Menu");
gotoxy(30,4);
cprintf("Add Hall Information  [1] ");
gotoxy(30,6);
cprintf("Add Current Movie     [2]");
gotoxy(30,8);
cprintf("Book Ticket           [3]");
gotoxy(30,10);
cprintf("List of Current Movie [4]");
gotoxy(30,12);
cprintf("Ticket Cancel         [5]");
gotoxy(30,14);
cprintf("Search Movie          [6]");
gotoxy(30,16);
cprintf("Exit                  [7]");
gotoxy(30,18);
cprintf("Enter Your Choice : ");
scanf("%d",&ch);
while(1)
{
switch(ch)
{
case 1:
add_hall();
break;
case 2:
current_movie();
break;
case 3:
book();
break;
case 4:
list_movie();
break;
case 5:
ticket_cancel();
break;
case 6:
search();
break;
case 7:
exit(1);
break;
default:
main_menu();
}
}
}
void current_movie()
{
char another='Y';
movie m;
fm=fopen("movie.dat","ab");
while(another=='Y'||another=='y')
{
fflush(stdin);
printf("\nEnter Movie ID:");
scanf("%d",&m.mid);
fflush(stdin);
printf("Enter Hall ID  :");
scanf("%d",&m.hid);
fflush(stdin);
printf("Enter Hall Name :");
gets(m.hname);
fflush(stdin);
printf("\nEnter Movie Name:");
gets(m.mname);
fflush(stdin);
printf("\nEnter Actor Name:");
gets(m.actor);
fflush(stdin);
printf("\nEnter Actoress Name:");
gets(m.actoress);
fflush(stdin);
printf("\nEnter Releas Year:");
gets(m.r_date);
fwrite(&m,sizeof(m),1,fm);
printf("\n\nRecords is Added");
printf("\n\nAdd record(Y/N) : ");
another=getche();
}
fclose(fm);
main_menu();
}
void book()
{
int ch;
char another='Y';
ticket t;
clrscr();
ft=fopen("ticket.dat","wb");
while(another=='Y'||another=='y')
{
fflush(stdin);
printf("Enter Name:");
gets(t.name);
fflush(stdin);
printf("Enter Gender(M/F):");
scanf("%c",&t.gender);
fflush(stdin);
printf("Enter age");
scanf("%d",&t.age);
fflush(stdin);
printf("\nEnter Class Type");
printf("1.AC");
printf("2.DC");
scanf("%d",&ch);
switch(ch)
{
case 1:
t.amount=400;
break;
case 2:
t.amount=200;
break;
default:
printf("Input is in Valid");
break;
}
printf("Class Type : %s",t.c_type);
printf("Total Amount : %d",t.amount);
fflush(stdin);
printf("\n\nEnter Seat No:");
scanf("%d",&t.seat_no);
printf("\n\nEnter ticket No:");
scanf("%d",&t.tno);
fwrite(&t,sizeof(t),1,ft);
printf("\n\nRecords is Updated");
printf("\n\nAdd another Record : ");
fflush(stdin);
another=getche();
}
fclose(fm);
}
void add_hall()
{
char another='Y';
hall h;
clrscr();
fh=fopen("hall.dat","wb");
while(another=='Y'||another=='y')
{
fflush(stdin);
printf("\nEnter Hall ID:");
scanf("%d",&h.id);
fflush(stdin);
printf("\nEnter Hall Name:");
gets(h.hname);
fflush(stdin);
printf("\nEnter Area Name:");
gets(h.area);
fflush(stdin);
printf("\nEnter Total AC Seat:");
scanf("%d",&h.a_seat);
fflush(stdin);
printf("\nEnter Total DC Seat  : ");
scanf("%d",&h.d_seat);
fwrite(&h,sizeof(h),1,fh);
printf("\n\nRecords is Added");
printf("\n\nAdd record(Y/N) : ");
another=getche();
}
fclose(fh);
main_menu();
}
void list_movie()
{
int i=1;
movie m;
clrscr();
fm=fopen("movie.dat","rb");
while(fread(&m,sizeof(m),1,fm)==1)
{
gotoxy(30,3);
printf("All Movie Information");
printf("\n\t\t*********************************************");
printf("\n\n\t\tMovie ID        :  %d",m.mid);
printf("\n\n\t\tHall ID         :  %d",m.hid);
printf("\n\n\t\tMovie Name      :  %s",m.mname);
printf("\n\n\t\tHall Name       :  %s",m.hname);
printf("\n\n\t\tActor Name      :  %s",m.actor);
printf("\n\n\t\tActoress Name   :  %s",m.actoress);
printf("\n\n\t\tRealse Year     :  %s",m.r_date);
if(i%1==0)
{
printf("\n\n\n\t\tPress any key to continue");
fflush(stdin);
getch();
clrscr();
}
i++;
}
printf("\n\nPress any key to back Main menu");
getch();
main_menu();
fclose(fm);
}
void ticket_cancel()
{
int t_id,c=1;
ticket t;
FILE *ftd;
char another='y';
clrscr();
while(another=='y'||another=='Y')
{
ftd=fopen("temp.dat","wb");
ft=fopen("ticket.dat","rb");
printf("\n\nEnter Ticket No For Cancelation     :");
scanf("%d",&t_id);
while(fread(&t,sizeof(t),1,ft)==1)
{
if(t.tno==t_id)
{
c++;
}
else
{
fwrite(&t,sizeof(t),1,ftd);
}
}
fclose(ftd);
fclose(ft);
remove("ticket.dat");
rename("temp.dat","ticket.dat");
if(c);
{
printf("\n\nBook is Deleted");
printf("You want to delete another record :");
}
fflush(stdin);
another=getche();
}
main_menu();
}
void search()
{
int hid;
movie m;
char another;
clrscr();
fm=fopen("movie.dat","rb");
another='y';
printf("\nEnter Hall Id No:");
scanf("%d",&hid);
while(fread(&m,sizeof(m),1,fm)==1)
{
if(m.hid==hid)
{
printf("\n\nHall is found");
printf("\n\n\t\tHall ID                 :  %d",m.hid);
printf("\n\n\t\tMovie ID                :  %d",m.mid);
printf("\n\n\t\tMovie Name              :  %s",m.mname);
printf("\n\n\t\tHall Name               :  %s",m.hname);
printf("\n\n\t\tActor Name              :  %s",m.actor);
printf("\n\n\t\tActoress Name           :  %s",m.actoress);
printf("\n\n\t\tRealse Year             :  %s",m.r_date);
printf("\n\nYou want to search another flight(Y/N) :");
fflush(stdin);
another=getchar();
if(another=='y'||another=='Y')
search();
else
{
fclose(fm);
main_menu();
}
}
}
printf("\n\nHall is not available");
printf("\n\nDo you want to Search another medicine(Y/N) :");
fflush(stdin);
another=getchar();
if(another=='Y'||another=='y')
search();
else
{
fclose(fm);
}
getch();
main_menu();
}