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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
void FileHandling::updateEmployee(int TEMP_NUM)//update given employee
{
int temp=0;
char TEMP;
Employee e;//create object of Employee class
fstream tempfile;//create object of fstream
tempfile.open("Employee_Details.txt",ios::in|ios::out|ios::ate|ios::app);//open the file for output
string CurrentLine;
std::string ap="#";
stringstream s;//create a string stream object s
s<<TEMP_NUM;//convert int to string
ap.append(s.str());//append new string to ap
tempfile.seekg(0,ios::beg);//get the file pointer to the begining of the file
try
{
if(tempfile.good())//if file is available
{
while(!tempfile.eof())//loop until end of file
{
while(getline(tempfile,CurrentLine) && !CurrentLine.empty())
{
int firstPos = CurrentLine.find(ap);//find empid in the current line
if(firstPos != string::npos)
{
std::string NO,NAME,NIC,GEN,DESIGNATION,DEPARTMENT,DATEJOINED,NATIONALITY,REG,DOB,STS,PASSWORD;//declare string variables
CurrentLine.clear();
//-----------------------------------------------------------------------
cout<<"Enter Full Name :";
//getline(cin,NAME);
cin>>NAME;
cin.ignore();
cout<<"Employee NIC Number: ";
cin>>NIC;
cin.ignore();
cout<<endl;
cout<<"Employee Gender (M/F) :";
cin>>TEMP;
//-----------------------------------------------------------------------
if(TEMP=='M')
{
GEN="Male";
}
else if(TEMP=='F')
{
GEN="Female";
//e.gender("Female");
}
else
{
GEN="Invalid-Entry";
//e.gender("Invalid Entry");
}
TEMP=' ';
cin.ignore();
cout<<endl<<endl;
cout<<"Employee Designation :";
cin>>DESIGNATION;
cin.ignore();
cout<<endl<<endl;
cout<<"Employee Department"<<endl;
cout<<setw(10)<<"========================="<<endl;
cout<<"1-Accounts\n"<<"2-Human-Resources\n"<<"3-Sales\n"<<"4-Production\n"<<"5-IT\n"<<"6-Other\n"<<endl;
cout<<setw(10)<<"========================="<<endl<<endl;
cout<<":=";
cin>>temp;
switch(temp)
{
case(1):
{
DEPARTMENT="Accounts";
temp=0;
break;
}
case(2):
{
DEPARTMENT="Human Resources";
temp=0;
break;
}
case(3):
{
DEPARTMENT="Sales";
temp=0;
break;
}
case(4):
{
DEPARTMENT="Production";
temp=0;
break;
}
case(5):
{
DEPARTMENT="IT";
temp=0;
break;
}
case(6):
{
DEPARTMENT="Other";
temp=0;
break;
}
default:
{
cout<<"Department Is Not Valid"<<endl;
DEPARTMENT="Invalid-Entry";
temp=0;
break;
}
}
cin.ignore();
cout<<"Employee Date Joined (DD-MM-YYYY):";
cin>>DATEJOINED;
cin.ignore();
cout<<endl;
cout<<"Employee Nationality :";
cin>>NATIONALITY;
cin.ignore();
cout<<endl;
temp=0;
cout<<"Employee Religion (1-Buddhist,2-Catholic,3-Hindu,4-Muslim,5-Other) :";
cin>>temp;
switch(temp)
{
case(1):
{
REG="Buddhist";
temp=0;
break;
}
case(2):
{
REG="Catholic";
temp=0;
break;
}
case(3):
{
REG="Hindu";
temp=0;
break;
}
case(4):
{
REG="Muslim";
temp=0;
break;
}
case(5):
{
REG="Other";
temp=0;
break;
}
default:
{
REG="Invalid-Entry";
temp=0;
break;
}
}
cout<<endl;
cout<<"Employee Date Of Birth (DD-MM-YYYY):";
cin>>DOB;
cin.ignore();
cout<<endl;
temp=0;
cout<<"Employee Marital Status (1-Married , 2-Single):";
cin>>temp;
if(temp=1)
STS="Married";
else
STS="Single";
cin.ignore();
cout<<endl;
cout<<"Employee Default Password: ";
cin>>PASSWORD;
cin.ignore();
/*CurrentLine.append(ap);*/
CurrentLine.push_back(tempfile.get());
tempfile.clear();//clear the temp file object
}
/* else
{
}*/
}
}
tempfile.close(); //close file
}
}
catch(...)
{
cout<<"Exception occurred-Record Is Not Available";
}
}
|