CSEians
cuz we rockzz
Monday, July 11, 2011
Tuesday, August 3, 2010
use of trigger for updating a column
CREATE OR REPLACE TRIGGER isrert_bill BEFORE INSERT OR UPDATE ON system.bill
FOR EACH ROW
BEGIN
IF :NEW.unit=0 THEN
:NEW.bill:=0;
elsif :new.unit>0 and :new.unit<100 then
:NEW.bill:=:NEW.unit*2.5;
elsif :new.unit>=100 and :new.unit<250 then
:new.bill:=:NEW.unit*3;
elsif :NEW.unit>=250 and :NEW.unit<500 then
:NEW.bill:=:NEW.unit*4.5;
else
:NEW.bill:=:NEW.unit*6;
END IF;
END;
/
--it will update a column of no values named bill calculating the unit column
Enjoy SQL..
FOR EACH ROW
BEGIN
IF :NEW.unit=0 THEN
:NEW.bill:=0;
elsif :new.unit>0 and :new.unit<100 then
:NEW.bill:=:NEW.unit*2.5;
elsif :new.unit>=100 and :new.unit<250 then
:new.bill:=:NEW.unit*3;
elsif :NEW.unit>=250 and :NEW.unit<500 then
:NEW.bill:=:NEW.unit*4.5;
else
:NEW.bill:=:NEW.unit*6;
END IF;
END;
/
--it will update a column of no values named bill calculating the unit column
Enjoy SQL..
A simple project of Library management in C++ with file
#include
#include
#include
#include
#include
#include
#include
class with_file
{
public:
char name[20];
char w_name[20];
char acc_no[7];
int k,i,l_c_n;
char string[10];
int file_id;
char c;
char dept_name[10];
int count;
int pos;
char choice;
public:
with_file(){ //call of constructor
k=0;
file_id=1;
choice='\0';
}
void sitting();
};
void with_file::sitting(){
cout<<"\t\t..WELCOME TO LIBRARY MANAGEMENT SOFTWARE.."<
cout<<"\n\nWhat type of work do you want"<
cout<<"\t01.Log in as Student."<
cout<<"\t02.Log in as Librarian."<
cout<<"\t03.Back"<
cin>>i;
if(i==1)
{
count=1;
while(count){
clrscr();
cout<<"To borrow book press b"<<<"To see books press r"<<<"Exit e"<<<"Choice: ";
cin>>choice;
switch(choice){
case 'b':
clrscr();
cout<<"Enter your library card no.:"<
cin>>l_c_n;
if((l_c_n>1000 && l_c_n<1121) || (l_c_n>3000 && l_c_n<3121)|| (l_c_n>5000 && l_c_n<5121) || (l_c_n>7000 && l_c_n<7061) || (l_c_n>9000 && l_c_n<9061))
{
pos=1;
while(pos){
clrscr();
cout<<"To take book press 1"<<<"To do nothing press 0"<<<"Choice: ";
cin>>pos;
if(pos==1){
clrscr();
itoa(l_c_n,string,10);
strcat(string,".txt");
ofstream file(string,ios::ate);
int loop;
cout<<"How many book will you take?(1 to 3)? ";
cin>>loop;
while(loop)
{
cout<<"Name of the book: ";
gets(name);
cout<<"Accession no: ";
gets(acc_no);
int p=0;
file<
while(name[p]){
file<
p++;
}
while(p<20){
file<<'\0';
p++;
}
int q=0;
while(acc_no[q]){
file<
q++;
}
while(q<7){
file<<' ';
q++;
}
loop--;
}
file.close();
}
}
break;
case 'r':
clrscr();
cout<<"Give Department Name: ";
cin>>dept_name;
strcat(dept_name,".txt");
ifstream open_file(dept_name);
if(!open_file){
cout<<"There is no information about this department"<
}
else{
while(!open_file.eof()){
open_file.get(c);
if(c=='\0'){
cout<<" ";
}
else{
cout<
}
}
}
open_file.close();
getch();
break;
case 'e':
count=0;
break;
}
else {cout<<"Sorry!! You are not a valid student.";}
getch();
}
}
}
if(i==2){
int pass;
cout<<"Enter the librarian password:";
cin>>pass;
if(pass==1234)
{
count=1;
while(count){
int i;
clrscr();
cout<<"To insert new book info press i"<<<"To read file press r"<
cout<<"To create library card press a"<<<"To remove file press c"<<<"Otherwise e"<<<"Choice: ";
cin>>choice;
switch(choice){
case 'i':
clrscr();
pos=1;
while(pos){
clrscr();
cout<<"To give book info press 1"<<<"To do nothing press 0"<<<"Choice: ";
cin>>pos;
if(pos==1){
clrscr();
cout<<"Give Department Name: ";
cin>>dept_name;
strcat(dept_name,".txt");
ofstream file(dept_name,ios::ate);
int loop;
cout<<"How many book info will be given? ";
cin>>loop;
while(loop){
cout<<"Name of the book: ";
gets(name);
cout<<"Name of the Author: ";
gets(w_name);
cout<<"Accession no: ";
gets(acc_no);
int i=0;
file<
while(name[i]){
file<
i++;
}
while(i<20){
file<<'\0';
i++;
}
int j=0;
while(w_name[j]){
file<
j++;
}
while(j<20){
file<<'\0';
j++;
}
i=0;
while(acc_no[i]){
file<
i++;
}
while(i<7){
file<<' ';
i++;
}
loop--;
}
file.close();
}
}
break;
case 'r':
clrscr();
cout<<"Give Department Name: ";
cin>>dept_name;
strcat(dept_name,".txt");
ifstream open_file(dept_name);
if(!open_file){
cout<<"There is no information about this department"<
}
else{
while(!open_file.eof()){
open_file.get(c);
if(c=='\0'){
cout<<" ";
}
else{
cout<
}
}
}
open_file.close();
getch();
break;
case 'a':
clrscr();
ofstream fout;
fout.open("card.txt",ios::out) ;
char sname[20],dept[5];
long int roll;
cout<<"Enter ur Full Name:";
gets(sname);
cout<<"\nDepartment name:" ;
gets(dept);
cout<<"\nEnter roll by presing 1:: ";
cin>>roll;
fout<<<" "<<<" " <
cout<<"\n\nName Dept. Roll\n\n";
cout<<<" "<<<" " <<<"\n\n";
cout<<"\n\nur library card No:"<
fout.close();
getch();
break;
case 'c':
clrscr();
char file[80];
cout<<"File to delete:";
gets(file);
if (remove(file) == 0)
cout<<"Removed..."<
else
perror("remove");
getch();
break;
case 'e':
count=0;
break;
}
}
}
}
}
void main()
{
clrscr();
int i,j;
with_file ob2;
ob2.sitting();
}
#include
#include
#include
#include
#include
#include
class with_file
{
public:
char name[20];
char w_name[20];
char acc_no[7];
int k,i,l_c_n;
char string[10];
int file_id;
char c;
char dept_name[10];
int count;
int pos;
char choice;
public:
with_file(){ //call of constructor
k=0;
file_id=1;
choice='\0';
}
void sitting();
};
void with_file::sitting(){
cout<<"\t\t..WELCOME TO LIBRARY MANAGEMENT SOFTWARE.."<
cout<<"\n\nWhat type of work do you want"<
cout<<"\t01.Log in as Student."<
cout<<"\t02.Log in as Librarian."<
cout<<"\t03.Back"<
cin>>i;
if(i==1)
{
count=1;
while(count){
clrscr();
cout<<"To borrow book press b"<
cin>>choice;
switch(choice){
case 'b':
clrscr();
cout<<"Enter your library card no.:"<
cin>>l_c_n;
if((l_c_n>1000 && l_c_n<1121) || (l_c_n>3000 && l_c_n<3121)|| (l_c_n>5000 && l_c_n<5121) || (l_c_n>7000 && l_c_n<7061) || (l_c_n>9000 && l_c_n<9061))
{
pos=1;
while(pos){
clrscr();
cout<<"To take book press 1"<
cin>>pos;
if(pos==1){
clrscr();
itoa(l_c_n,string,10);
strcat(string,".txt");
ofstream file(string,ios::ate);
int loop;
cout<<"How many book will you take?(1 to 3)? ";
cin>>loop;
while(loop)
{
cout<<"Name of the book: ";
gets(name);
cout<<"Accession no: ";
gets(acc_no);
int p=0;
file<
while(name[p]){
file<
p++;
}
while(p<20){
file<<'\0';
p++;
}
int q=0;
while(acc_no[q]){
file<
q++;
}
while(q<7){
file<<' ';
q++;
}
loop--;
}
file.close();
}
}
break;
case 'r':
clrscr();
cout<<"Give Department Name: ";
cin>>dept_name;
strcat(dept_name,".txt");
ifstream open_file(dept_name);
if(!open_file){
cout<<"There is no information about this department"<
}
else{
while(!open_file.eof()){
open_file.get(c);
if(c=='\0'){
cout<<" ";
}
else{
cout<
}
}
}
open_file.close();
getch();
break;
case 'e':
count=0;
break;
}
else {cout<<"Sorry!! You are not a valid student.";}
getch();
}
}
}
if(i==2){
int pass;
cout<<"Enter the librarian password:";
cin>>pass;
if(pass==1234)
{
count=1;
while(count){
int i;
clrscr();
cout<<"To insert new book info press i"<
cout<<"To create library card press a"<
cin>>choice;
switch(choice){
case 'i':
clrscr();
pos=1;
while(pos){
clrscr();
cout<<"To give book info press 1"<
cin>>pos;
if(pos==1){
clrscr();
cout<<"Give Department Name: ";
cin>>dept_name;
strcat(dept_name,".txt");
ofstream file(dept_name,ios::ate);
int loop;
cout<<"How many book info will be given? ";
cin>>loop;
while(loop){
cout<<"Name of the book: ";
gets(name);
cout<<"Name of the Author: ";
gets(w_name);
cout<<"Accession no: ";
gets(acc_no);
int i=0;
file<
while(name[i]){
file<
i++;
}
while(i<20){
file<<'\0';
i++;
}
int j=0;
while(w_name[j]){
file<
j++;
}
while(j<20){
file<<'\0';
j++;
}
i=0;
while(acc_no[i]){
file<
i++;
}
while(i<7){
file<<' ';
i++;
}
loop--;
}
file.close();
}
}
break;
case 'r':
clrscr();
cout<<"Give Department Name: ";
cin>>dept_name;
strcat(dept_name,".txt");
ifstream open_file(dept_name);
if(!open_file){
cout<<"There is no information about this department"<
}
else{
while(!open_file.eof()){
open_file.get(c);
if(c=='\0'){
cout<<" ";
}
else{
cout<
}
}
}
open_file.close();
getch();
break;
case 'a':
clrscr();
ofstream fout;
fout.open("card.txt",ios::out) ;
char sname[20],dept[5];
long int roll;
cout<<"Enter ur Full Name:";
gets(sname);
cout<<"\nDepartment name:" ;
gets(dept);
cout<<"\nEnter roll by presing 1:: ";
cin>>roll;
fout<
cout<<"\n\nName Dept. Roll\n\n";
cout<
cout<<"\n\nur library card No:"<
fout.close();
getch();
break;
case 'c':
clrscr();
char file[80];
cout<<"File to delete:";
gets(file);
if (remove(file) == 0)
cout<<"Removed..."<
else
perror("remove");
getch();
break;
case 'e':
count=0;
break;
}
}
}
}
}
void main()
{
clrscr();
int i,j;
with_file ob2;
ob2.sitting();
}
Sunday, July 18, 2010
Use of role in SQL
CREATE USER u_asst_gm identified by asst_gm;
CREATE USER u_operator identified by operator;
//here create two users u_asst_gm and u_operator
CREATE ROLE r_asst_gm;
CREATE ROLE r_operator;
GRANT CREATE SESSION,CREATE TABLE,UNLIMITED TABLESPACE to r_asst_gm;
GRANT CREATE SESSION,UNLIMITED TABLESPACE to r_operator;
//here creates the role and grant privileges to the role
GRANT r_asst_gm to u_asst_gm;
GRANT r_operator to u_operator;
//here grant role to users
GRANT SELECT,INSERT,DELETE,UPDATE on customer to u_asst_gm;
GRANT SELECT,INSERT,DELETE,UPDATE on bill to u_asst_gm;
GRANT SELECT,INSERT,DELETE,UPDATE on payee to u_asst_gm;
GRANT SELECT,INSERT,UPDATE on bill to u_operator;
commit;
//grant table accessing privileges to users.
Enjoy SQL
Tuesday, July 6, 2010
How to define global variable in c# windows form
It is easy to use global like variable in web based application but quite hard to use it in windows form. Here the solution:
Add a new class.cs file to the project and then
static class GlobalClass
{
private string m_globalVar = "";
public static string GlobalVar
{
get { return m_globalVar; }
set { m_globalVar = value; }
}
}
Use it anywhere like this
GlobalClass.GlobalVar = "the_value_you_waant_to_put";
Access it anywhere like this
myFormLabel.Text = GlobalClass.GlobalVar;
Enjoy C#
Monday, July 5, 2010
Text to speech conversion in C#
In visual studio
Add reference: System.Speechthen header
system.speech.synthesizer;
then inside the button_click:
SpeechSynthesizer s = new SpeechSynthesizer();
s.Speak("The speech goes here whatever you like");
or,
you can use a textbox. Suppose it is textBox1 then,
s.Speak(textBox1.Text);
Enjoy C#
How to generate captcha in C#
The code below generates randomly captcha. You can access it in another page using session in C#.
Add using System.IO
the code is :
protected void Page_Load(object sender, EventArgs e)
{
System.Drawing.Bitmap objBmp = new System.Drawing.Bitmap(90, 25); System.Drawing.Graphics objGraphics = System.Drawing.Graphics.FromImage(objBmp); objGraphics.Clear(System.Drawing.Color.Green); objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; System.Drawing.Font objFont = new System.Drawing.Font("Acoustic Light", 11, System.Drawing.FontStyle.Bold);
string strRandom = "";
string[] strArray = new string[36];
strArray = new string[] { "a", "b", "c" , "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","A","R","S","F"};
Random autoRand = new Random();
int x;
for (x = 0; x < i =" Convert.ToInt32(autoRand.Next(0,">
}
Session.Add("strRandom", strRandom);
objGraphics.DrawString(strRandom, objFont, System.Drawing.Brushes.White, 3, 3); Response.ContentType = "image/GIF";
objBmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); objFont.Dispose(); objGraphics.Dispose(); objBmp.Dispose();
}
Enjoy C#
Subscribe to:
Posts (Atom)