Sunteți pe pagina 1din 25

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 vpAssignment2;

namespace VPAssignment3
{
public partial class AssignDriver : Form
{
public AssignDriver()
{
InitializeComponent();
}
public string VEHICLESEARCHBOX
{
get { return vSEARCHBOX.Text; }

set { vSEARCHBOX.Text = value; }


}
public string DRIVERSEARCHBOX
{
get { return dSEARCHBOX.Text; }

set { dSEARCHBOX.Text = value; }


}

public void driverException()


{
MessageBox.Show("Driver not found !", "Error");
}
public void vehicleException()
{
MessageBox.Show("Vehicle not found or already assigned!", "Error");
}

private void AssignButton_Click(object sender, EventArgs e)


{
if(DRIVERSEARCHBOX==""||VEHICLESEARCHBOX=="")
{
MessageBox.Show("Field left empty!", "Error");
}
Vehicle v = new Vehicle();
v.ADTV(this);
MessageBox.Show("Driver assigned !","Success");
DRIVERSEARCHBOX = "";
VEHICLESEARCHBOX = "";
}

private void backButton_Click(object sender, EventArgs e)


{
this.Hide();
Form1 f = new Form1();
f.ShowDialog();
this.Close();
f.Focus();
}

private void AssignDriver_Load(object sender, EventArgs e)


{

}
}
}

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 vpAssignment2;

namespace VPAssignment3
{
public partial class AssignStudent : Form
{
public AssignStudent()
{
InitializeComponent();
}

private void AssignStudent_Load(object sender, EventArgs e)


{

}
public string Enrollment
{
get{ return enrl.Text; }
set{ enrl.Text += value; }
}
public string VSEARCHBOX
{
get { return vSEARCHBOX.Text; }
set { vSEARCHBOX.Text += value; }
}
public void capException()
{
MessageBox.Show("The Vehicle is full ", "Error");
}
public void vehexception()
{
MessageBox.Show("Vehicle not found ", "Error");
}
public void stuException()
{
MessageBox.Show("Student not found ", "Error");
}
private void AssignButton_Click(object sender, EventArgs e)
{
if (Enrollment == "" || VSEARCHBOX == "")
{
MessageBox.Show("Field left empty!", "Error");
}
Vehicle v = new Vehicle();
v.ASTV(this);
MessageBox.Show("Student assigned to this vehicle","SUCCESS");
Enrollment = "";
VSEARCHBOX = "";

private void backButton_Click(object sender, EventArgs e)


{
this.Hide();
Form1 f = new Form1();
f.ShowDialog();
this.Close();
f.Focus();
}
}
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VPAssignment3;

namespace vpAssignment2
{
class Driver
{
string driverId;
string dName;
string cnic;
string dContact;
string dAddress;
List<Driver> dlist = new List<Driver>();

public Driver() { }
public Driver(string dId, string dNm, string cnc, string dCt, string dAdd)
{
this.driverId = dId;
this.dName = dNm;
this.dContact = dCt;
this.cnic = cnc;
this.dAddress = dAdd;
}
public string driverID
{
get { return driverId; }
set { driverId = value; }
}
public void NewDriver(DriverForm df)
{

this.driverId = "D-"+df.DID;
this.dName = df.DNAME;
this.cnic = df.DCNIC;
this.dContact = df.DCONTACT;
this.dAddress = df.DADDRESS;
Driver d = new Driver(driverId, dName, cnic, dContact, dAddress);
dlist.Add(d);
dToFile(dlist);
dlist.Clear();

}
private void dToFile(List<Driver> dobj)
{
FileStream f = new FileStream("drivers.txt", FileMode.Append,
FileAccess.Write);
StreamWriter s = new StreamWriter(f);
for (int i = 0; i < dobj.Count; i++)
{
Driver d = dobj[i] as Driver;
s.WriteLine(d.driverId);
s.WriteLine(d.dName);
s.WriteLine(d.cnic);
s.WriteLine(d.dContact);
s.WriteLine(d.dAddress);
s.Close();
}
f.Close();

}
public List<Driver> findDriver(DriverForm df)
{
List<Driver> list = new List<Driver>();
FileStream fr = new FileStream("drivers.txt", FileMode.Open,
FileAccess.Read);
StreamReader s = new StreamReader(fr);
string temp;
string f = df.DRIVERSEARCHBOX;
bool test = false;
while (!s.EndOfStream)
{
temp = s.ReadLine();
string di, dn, cn, ct, ad;
if (temp == f)
{
test = true;
di = f;
dn = s.ReadLine();
cn = s.ReadLine();
ct = s.ReadLine();
ad = s.ReadLine();
Driver driver = new Driver(di, dn, cn, ct, ad);
list.Add(driver);

}
}
if(test!=true)
{
df.DRIVERDETAILS = "DRIVER WITH ID ( " + f + " ) NOT FOUND !";
df.DRIVERDETAILS = "ID is case sensistive and mostly written in
UPPERCASE letters";
}
s.Close();
fr.Close();
return list;

public List<Driver> findDriver2(AssignDriver ad)


{
List<Driver> list = new List<Driver>();
FileStream fr = new FileStream("drivers.txt", FileMode.Open,
FileAccess.Read);
StreamReader s = new StreamReader(fr);
string temp;
bool test = false;
string f = ad.DRIVERSEARCHBOX;
while (!s.EndOfStream)
{
temp = s.ReadLine();
string di, dn, cn, ct, add;
if (temp == f)
{
test = true;
di = f;
dn = s.ReadLine();
cn = s.ReadLine();
ct = s.ReadLine();
add = s.ReadLine();
Driver driver = new Driver(di, dn, cn, ct, add);
list.Add(driver);

}
}
if (test != true)
{
ad.driverException();
}
s.Close();
fr.Close();
return list;

}
public void printDObj(List<Driver> dl,DriverForm df)
{
foreach (Driver d in dl)
{
df.DRIVERDETAILS = "Driver's ID : "+d.driverId+"\n";
df.DRIVERDETAILS = "Driver's Name : " + d.dName + "\n";
df.DRIVERDETAILS = "Driver's CNIC : " + d.cnic + "\n";
df.DRIVERDETAILS = "Driver's Contact : " + d.dContact + "\n";
df.DRIVERDETAILS = "Driver's Address : " + d.dAddress + "\n";
}
dl.Clear();
}
public Driver readDObj(List<Driver> dl)
{
string a, b, c, d, e;
Driver dri = dl[0] as Driver;
for (int i=0;i<dl.Count;i++)
{
a =dri.driverId;
b =dri.dName;
c =dri.cnic;
d =dri.dContact;
e =dri.dAddress;
}

dl.Clear();
return dri;

}
public string getiD(List<Driver> dl)
{
string s = dl[0].driverId;
return s;
}
}
}

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 vpAssignment2;

namespace VPAssignment3
{
public partial class DriverForm : Form
{
public DriverForm()
{
InitializeComponent();
}

public string DRIVERSEARCHBOX


{
get { return driverSearchBox.Text; }

set { driverSearchBox.Text = value; }


}
public string DRIVERDETAILS
{
get { return driverDetails.Text; }

set { driverDetails.Text += value; }


}
public string DID
{
get { return dIDbox.Text; }

set { dIDbox.Text += value; }


}
public string DNAME
{
get { return dNamebox.Text; }

set { dNamebox.Text += value; }


}
public string DCNIC
{
get { return dCNICbox.Text; }

set { dCNICbox.Text += value; }


}
public string DCONTACT
{
get { return dContactbox.Text; }

set { dContactbox.Text += value; }


}
public string DADDRESS
{
get { return dAddressbox.Text; }

set { dAddressbox.Text += value; }


}

private void DriverForm_Load(object sender, EventArgs e)


{

private void driverSearchButton_Click(object sender, EventArgs e)


{
Driver d = new Driver();
List<Driver> dl = new List<Driver>();
driverDetails.Text = "";
dl=d.findDriver(this);
d.printDObj(dl, this);
}

private void addDriver_Click(object sender, EventArgs e)


{
if (dIDbox.Text == "" || dNamebox.Text == "" || dCNICbox.Text == "" ||
dContactbox.Text == "" || dAddressbox.Text == "")
{
MessageBox.Show("Fill all fields", "ERROR");
}
else
{
Driver d = new Driver();
List<Driver> dl = new List<Driver>();
d.NewDriver(this);
MessageBox.Show("Driver Added","Success");
dIDbox.Text = "";
dNamebox.Text = "";
dCNICbox.Text = "";
dContactbox.Text = "";
dAddressbox.Text = "";
}

private void clearButton_Click(object sender, EventArgs e)


{
DRIVERSEARCHBOX = "";
}

private void backButton_Click(object sender, EventArgs e)


{
this.Hide();
Form1 f = new Form1();
f.ShowDialog();
this.Close();
f.Focus();
}
}
}

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 vpAssignment2;

namespace VPAssignment3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Focus();
}

private void driverButton_Click(object sender, EventArgs e)


{
this.Hide();
DriverForm df = new DriverForm();
df.ShowDialog();
this.Close();
df.Focus();
}

private void vehicleButton_Click(object sender, EventArgs e)


{
this.Hide();
VehicleForm vf = new VehicleForm();
vf.ShowDialog();
this.Close();
vf.Focus();
}

private void studentButton_Click(object sender, EventArgs e)


{
this.Hide();
StudentForm sf = new StudentForm();
sf.ShowDialog();
this.Close();
sf.Focus();
}

private void reportButton_Click(object sender, EventArgs e)


{
this.Hide();
ReportForm rf = new ReportForm();
rf.ShowDialog();
this.Close();
rf.Focus();
}

private void assignDriver_Click(object sender, EventArgs e)


{
this.Hide();
AssignDriver rf = new AssignDriver();
rf.ShowDialog();
this.Close();
rf.Focus();
}

private void assignStudent_Click(object sender, EventArgs e)


{
this.Hide();
AssignStudent rf = new AssignStudent();
rf.ShowDialog();
this.Close();
rf.Focus();
}

private void exit_Click(object sender, EventArgs e)


{
Application.Exit();
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VPAssignment3
{
static class Program
{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 vpAssignment2;

namespace VPAssignment3
{
public partial class ReportForm : Form
{
public ReportForm()
{
InitializeComponent();
}

public string VSEARCHBOX


{
get { return vsearchBox.Text; }
set { vsearchBox.Text += value; }
}
public string REPORTBOX
{
get { return reportbox.Text; }
set { reportbox.Text += value; }
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Hide();
Form1 f = new Form1();
f.ShowDialog();
this.Close();
f.Focus();
}
public void vehException()
{
MessageBox.Show("Error", "Error");
}
private void submitButton_Click(object sender, EventArgs e)
{
Vehicle v = new Vehicle();
v.generateReport(this);
}
}
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VPAssignment3;
namespace vpAssignment2
{
class Student
{
string enrollment;
string sName;
string dept;
string sContact;
string sAddress;
List<Student> slist = new List<Student>();
public Student() { }
public Student(string en, string sNm, string dp,string sCt, string sAdd)
{
this.enrollment=en;
this.sName=sNm;
this.dept=dp;
this.sContact=sCt;
this.sAddress=sAdd;
}

public void NewStudent(StudentForm sf)


{
this.enrollment = sf.SID;
this.sName = sf.SNAME;
this.dept = sf.SDEPT;
this.sContact = sf.SCONTACT;
this.sAddress = sf.SADDRESS;
Student s = new Student(enrollment, sName, dept, sContact, sAddress);
slist.Add(s);
sToFile(slist);
slist.Clear();

}
private void sToFile(List<Student> sobj)
{
FileStream f = new FileStream("students.txt", FileMode.Append,
FileAccess.Write);
StreamWriter s = new StreamWriter(f);
for (int i = 0; i < sobj.Count; i++)
{
Student st= sobj[i] as Student;
s.WriteLine(st.enrollment);
s.WriteLine(st.sName);
s.WriteLine(st.dept);
s.WriteLine(st.sContact);
s.WriteLine(st.sAddress);
s.Close();
}
f.Close();
}
public List<Student> findStudent(StudentForm sf)
{
List<Student> list = new List<Student>();
FileStream fr = new FileStream("students.txt", FileMode.Open,
FileAccess.Read);
StreamReader s = new StreamReader(fr);
string temp;
string f = sf.STUDENTSEARCHBOX;
bool test = false;
while (!s.EndOfStream)
{
temp = s.ReadLine();
string di, dn, cn, ct, ad;
if (temp == f)
{
test = true;
di = f;
dn = s.ReadLine();
cn = s.ReadLine();
ct = s.ReadLine();
ad = s.ReadLine();
Student st = new Student(di, dn, cn, ct, ad);
list.Add(st);

}
}
if (test != true)
{
sf.STUDENTDETAILS= "STUDENT WITH ID ( " + f + " ) NOT FOUND !";
sf.STUDENTDETAILS = "Follow the format: e.g 01-134171-095";
}
s.Close();
fr.Close();
return list;

}
public List<Student> findStudent2(AssignStudent ast)
{
List<Student> list = new List<Student>();
FileStream fr = new FileStream("students.txt", FileMode.Open,
FileAccess.Read);
StreamReader s = new StreamReader(fr);
string temp;
string f = ast.Enrollment;
bool test = false;
while (!s.EndOfStream)
{
temp = s.ReadLine();
string di, dn, cn, ct, ad;
if (temp == f)
{
test = true;
di = f;
dn = s.ReadLine();
cn = s.ReadLine();
ct = s.ReadLine();
ad = s.ReadLine();
Student st = new Student(di, dn, cn, ct, ad);
list.Add(st);

}
}
if (test != true)
{
ast.stuException();
}
s.Close();
fr.Close();
return list;

public void print(List<Student> sl,StudentForm sf)


{
foreach (Student s in sl)
{
sf.STUDENTDETAILS = "Student's ID : " + s.enrollment + "\n";
sf.STUDENTDETAILS = "Student's Name : " + s.sName+ "\n";
sf.STUDENTDETAILS = "Student's Dept. : " + s.dept + "\n";
sf.STUDENTDETAILS = "Student's Contact : " + s.sContact + "\n";
sf.STUDENTDETAILS = "Student's Address : " + s.sAddress + "\n";
}
sl.Clear();
}

public string getiD(List<Student> sl)


{
string s = sl[0].enrollment;
return s;
}
}
}

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 vpAssignment2;

namespace VPAssignment3
{
public partial class StudentForm : Form
{
public StudentForm()
{
InitializeComponent();
}
public string STUDENTSEARCHBOX
{
get { return studentSearchBox.Text; }

set { studentSearchBox.Text = value; }


}
public string STUDENTDETAILS
{
get { return studentDetails.Text; }

set { studentDetails.Text += value; }


}
public string SID
{
get { return sIDbox.Text; }

set { sIDbox.Text += value; }


}
public string SNAME
{
get { return sNamebox.Text; }

set { sNamebox.Text += value; }


}
public string SDEPT
{
get { return sDeptbox.Text; }

set { sDeptbox.Text += value; }


}
public string SCONTACT
{
get { return sContactbox.Text; }

set { sContactbox.Text += value; }


}
public string SADDRESS
{
get { return sAddressbox.Text; }

set { sAddressbox.Text += value; }


}

private void clearButton_Click(object sender, EventArgs e)


{
STUDENTSEARCHBOX = "";
}

private void studentSearchButton_Click(object sender, EventArgs e)


{
Student s = new Student();
List<Student> sl = new List<Student>();
studentDetails.Text = "";
sl = s.findStudent(this);
s.print(sl, this);
}

private void backButton_Click(object sender, EventArgs e)


{
this.Hide();
Form1 f = new Form1();
f.ShowDialog();
this.Close();
f.Focus();
}

private void addStudent_Click(object sender, EventArgs e)


{
if (sIDbox.Text == "" || sNamebox.Text == "" || sDeptbox.Text == "" ||
sContactbox.Text == "" || sAddressbox.Text == "")
{
MessageBox.Show("Fill all fields", "ERROR");
}
else
{
Student s = new Student();
List<Student> sl = new List<Student>();
s.NewStudent(this);
MessageBox.Show("Student Added", "Success");
sIDbox.Text = "";
sNamebox.Text = "";
sDeptbox.Text = "";
sContactbox.Text = "";
sAddressbox.Text = "";
}
}
}
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VPAssignment3;

namespace vpAssignment2
{
class Vehicle
{
string vName;
string vNo;
string color;
string chasis;
int capacity;
string drivId;
string studId;
Driver driver;
Student student;
List<Driver> dlist = new List<Driver>();
List<Vehicle> vlist = new List<Vehicle>();
List<Student> slist = new List<Student>();
public Vehicle() { }
public Vehicle(string vn,string vnm,string cl,string ch,int cp)
{
this.vNo = vn;
this.vName = vnm;
this.color = cl;
this.chasis = ch;
this.capacity = cp;

}
public Vehicle(string vn, string vnm, string cl, string ch, int cp,string
did)
{
this.vNo = vn;
this.vName = vnm;
this.color = cl;
this.chasis = ch;
this.capacity = cp;
this.drivId = did;

}
public Vehicle(string vn, string vnm, string cl, string ch, int cp, string
did, string sid)
{
this.vNo = vn;
this.vName = vnm;
this.color = cl;
this.chasis = ch;
this.capacity = cp;
this.drivId = did;
this.studId = sid;

}
public void newVehicle(VehicleForm vf)
{

this.vNo = vf.VID;
this.vName = vf.VNAME;
this.color = vf.VCOLOR;
this.chasis = vf.VCHASIS;
this.capacity = int.Parse(vf.VCAPACITY);
Vehicle v = new Vehicle(vNo, vName, color, chasis, capacity);
vlist.Add(v);
vToFile(vlist);
vlist.Clear();
}
public void ADTV(AssignDriver ad)
{
vlist = findVehicle2(ad);
Driver d = new Driver();
dlist=d.findDriver2(ad);
string s = ad.DRIVERSEARCHBOX;
vTovd(vlist, s);

public void ASTV(AssignStudent ast)


{
vlist = findVehicleinVD(ast);
Vehicle v = new Vehicle();
v = vlist[0];
int cap = Convert.ToInt32(v.capacity);
if (cap == 0)
{
ast.capException();
}
else
{
FileStream f = new FileStream("sList.txt", FileMode.Append,
FileAccess.Write);
StreamWriter s = new StreamWriter(f);
s.WriteLine(v.vNo);
for (int i = 0; i < 1; i++)
{
Student st = new Student();
slist = st.findStudent2(ast);
string id = st.getiD(slist);
s.WriteLine(id);
cap--;
}
s.Close();
f.Close();

int count = linecounter(v.vNo);


lineChanger(Convert.ToString(cap), "VD.txt", count);
}
}

public void generateReport(ReportForm rf) //REPORT


{
vlist=findVehicleinVDreport(rf);
printrepobject(vlist, rf);

}
public void printrepobject(List<Vehicle> vl, ReportForm vf)
{
foreach (Vehicle v in vl)
{
vf.REPORTBOX = "Vehicle ID: " + v.vNo + "\n";
vf.REPORTBOX = "Vehicle Name: " + v.vName + "\n";
vf.REPORTBOX = "Vehicle Color: " + v.color + "\n";
vf.REPORTBOX = "Vehicle Chasis: " + v.chasis + "\n";
vf.REPORTBOX = "Vehicle Capacity: " + v.capacity + "\n\n";
vf.REPORTBOX = "Driver ID: " + v.drivId+ "\n";
vf.REPORTBOX = "STUDENTS : \n" +v.studId;

}
vl.Clear();
}
public List<Vehicle> findVehicleinVDreport(ReportForm ast)
{
string vi, vn, cl, ch, did, enrl;
int cp;
List<Vehicle> list = new List<Vehicle>();
string f = ast.VSEARCHBOX;
FileStream fr = new FileStream("VD.txt", FileMode.Open,
FileAccess.Read);
StreamReader s = new StreamReader(fr);
string temp;

bool test = false;


while (!s.EndOfStream)
{
temp = s.ReadLine();
if (temp == f)
{
test = true;
vi = temp;
vn = s.ReadLine();
cl = s.ReadLine();
ch = s.ReadLine();
cp = Convert.ToInt32(s.ReadLine());
did = s.ReadLine();
Vehicle vehicle = new Vehicle(vi,vn,cl,ch,cp,did);
vlist.Add(vehicle)
}
}
if (test != true)
{
ast.vehException();
}
s.Close();
fr.Close();
FileStream fs = new FileStream("sList.txt", FileMode.Open,
FileAccess.Read);
StreamReader sf = new StreamReader(fs);
string temp2;
bool test2 = false;
while (!s.EndOfStream)
{
temp2 = s.ReadLine();
if (temp2 == f)
{
test2 = true;
enrl = s.ReadLine();
Vehicle vehicle = new Vehicle();
vehicle.studId = enrl;
list.Add(vehicle);
}
}
if (test2 != true)
{
ast.vehException();
}

sf.Close();
fs.Close();

return list;

}
static void lineChanger(string newText, string fileName, int line)
{
string[] arrLine = File.ReadAllLines(fileName);
arrLine[line - 1] = newText;
File.WriteAllLines(fileName, arrLine);
}

private void vToFile(List<Vehicle> vl)


{
FileStream f = new FileStream("vehicles.txt", FileMode.Append,
FileAccess.Write);
StreamWriter s = new StreamWriter(f);
for (int i = 0; i < vl.Count; i++)
{
Vehicle v = vl[i] as Vehicle;
s.WriteLine(v.vNo);
s.WriteLine(v.vName);
s.WriteLine(v.color);
s.WriteLine(v.chasis);
s.WriteLine(v.capacity);
s.Close();
}
f.Close();
}

private void vTovd(List<Vehicle> vl,string d)


{
FileStream f = new FileStream("VD.txt", FileMode.Append,
FileAccess.Write);
StreamWriter s = new StreamWriter(f);
for (int i = 0; i < vl.Count; i++)
{
Vehicle v = vl[i] as Vehicle;
s.WriteLine(v.vNo);
s.WriteLine(v.vName);
s.WriteLine(v.color);
s.WriteLine(v.chasis);
s.WriteLine(v.capacity);
s.WriteLine(d);
}
s.Close();
f.Close();
}

public List<Vehicle> findVehicle2(AssignDriver ad)


{
List<Vehicle> list = new List<Vehicle>();
string f = ad.VEHICLESEARCHBOX;
bool t = findVehicleinVD(ad);
if (t == true)
{
FileStream fr = new FileStream("vehicles.txt", FileMode.Open,
FileAccess.Read);
StreamReader s = new StreamReader(fr);
bool test = false;
string temp;
while (!s.EndOfStream)
{
temp = s.ReadLine();
string vi, vn, cl, ch;
int cp;
if (temp == f)
{
test = true;
vi = temp;
vn = s.ReadLine();
cl = s.ReadLine();
ch = s.ReadLine();
cp = Convert.ToInt32(s.ReadLine());
Vehicle vehicle = new Vehicle(vi, vn, cl, ch, cp);
list.Add(vehicle);
}
}

if (test != true)
{
ad.vehicleException();
}

s.Close();
fr.Close();
return list;
}
else
ad.vehicleException();
return null;

}
public bool findVehicleinVD(AssignDriver ad)
{
List<Vehicle> list = new List<Vehicle>();
string f = ad.VEHICLESEARCHBOX;
FileStream fr = new FileStream("VD.txt", FileMode.Open,
FileAccess.Read);
StreamReader s = new StreamReader(fr);
string temp;
while (!s.EndOfStream)
{
temp = s.ReadLine();
string vi, vn, cl, ch, did;
int cp;
if (temp == f)
{
vi = temp;
vn = s.ReadLine();
cl = s.ReadLine();
ch = s.ReadLine();
cp = Convert.ToInt32(s.ReadLine());
did = s.ReadLine();
s.Close();
fr.Close();
}
return false;
}
return true;
}
public List<Vehicle> findVehicle(VehicleForm vf)
{
List<Vehicle> list = new List<Vehicle>();
string f=vf.VEHICLESEARCHBOX;
FileStream fr = new FileStream("vehicles.txt", FileMode.Open,
FileAccess.Read);
StreamReader s = new StreamReader(fr);
string temp;
bool test = false;
while (!s.EndOfStream)
{
temp = s.ReadLine();
string vi, vn, cl, ch;
int cp;
if (temp == f)
{
test = true;
vi = temp;
vn = s.ReadLine();
cl = s.ReadLine();
ch = s.ReadLine();
cp = Convert.ToInt32(s.ReadLine());
Vehicle vehicle = new Vehicle(vi, vn, cl, ch, cp);
list.Add(vehicle);
}
}
if (test != true)
{
vf.VEHICLEDETAILS="VEHICLE WITH ID ( " + f + " ) NOT FOUND !\n";
vf.VEHICLEDETAILS = "ID is case sensistive and mostly written in
UPPERCASE letters";
}
s.Close();
fr.Close();
return list;

}
public int linecounter(string id)
{
List<Vehicle> list = new List<Vehicle>();
string f=id;
int counter=0;
FileStream fr = new FileStream("VD.txt", FileMode.Open,
FileAccess.Read);
StreamReader s = new StreamReader(fr);
string temp;
while (!s.EndOfStream)
{
temp = s.ReadLine();
counter++;
string vi, vn, cl, ch, did;
int cp;
if (temp == f)
{

vi = temp;
counter++;
vn = s.ReadLine();
counter++;
cl = s.ReadLine();
counter++;
ch = s.ReadLine();
counter++;
cp = Convert.ToInt32(s.ReadLine());
did = s.ReadLine();
}
}

s.Close();
fr.Close();
return counter;

public List<Vehicle> findVehicleinVD(AssignStudent ast)


{
List<Vehicle> list = new List<Vehicle>();
string f = ast.VSEARCHBOX;
FileStream fr = new FileStream("VD.txt", FileMode.Open,
FileAccess.Read);
StreamReader s = new StreamReader(fr);
string temp;
bool test = false;
while (!s.EndOfStream)
{
temp = s.ReadLine();
string vi, vn, cl, ch,did;
int cp;
if (temp == f)
{
test = true;
vi = temp;
vn = s.ReadLine();
cl = s.ReadLine();
ch = s.ReadLine();
cp = Convert.ToInt32(s.ReadLine());
did = s.ReadLine();
Vehicle vehicle = new Vehicle(vi, vn, cl, ch, cp,did);
list.Add(vehicle);
}
}
if (test != true)
{
ast.vehexception();
}
s.Close();
fr.Close();
return list;

public void printVObj(List<Vehicle> vl,VehicleForm vf)


{
foreach (Vehicle v in vl)
{
vf.VEHICLEDETAILS="Vehicle ID: "+v.vNo+"\n";
vf.VEHICLEDETAILS = "Vehicle Name: " + v.vName + "\n";
vf.VEHICLEDETAILS = "Vehicle Color: " + v.color + "\n";
vf.VEHICLEDETAILS = "Vehicle Chasis: " + v.chasis + "\n";
vf.VEHICLEDETAILS = "Vehicle Capacity: " + v.capacity + "\n";
}
vl.Clear();
}
public Vehicle readVObj(List<Vehicle> vl)
{
string a, b, c, d;
int e;
Vehicle veh = vl[0] as Vehicle;
for (int i = 0; i <= vl.Count; i++)
{
a = veh.vNo;
b = veh.vName;
c = veh.color;
d = veh.chasis;
e = veh.capacity;
}

vl.Clear();
return veh;
}
}
}

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 vpAssignment2;

namespace VPAssignment3
{
public partial class VehicleForm : Form
{
public VehicleForm()
{
InitializeComponent();
}

public string VEHICLESEARCHBOX


{
get { return vehicleSearchBox.Text; }

set { vehicleSearchBox.Text = value; }


}
public string VEHICLEDETAILS
{
get { return vehicleDetails.Text; }

set { vehicleDetails.Text += value; }


}
public string VID
{
get { return vIDbox.Text; }

set { vIDbox.Text += value; }


}
public string VNAME
{
get { return vNamebox.Text; }

set { vNamebox.Text += value; }


}
public string VCOLOR
{
get { return vColorbox.Text; }

set { vColorbox.Text += value; }


}
public string VCAPACITY
{
get { return vCapacitybox.Text; }
set { vCapacitybox.Text += value; }
}
public string VCHASIS
{
get { return vChasisbox.Text; }

set { vChasisbox.Text += value; }


}

private void backButton_Click(object sender, EventArgs e)


{
this.Hide();
Form1 f = new Form1();
f.ShowDialog();
this.Close();
f.Focus();
}

private void clearButton_Click(object sender, EventArgs e)


{
VEHICLESEARCHBOX = "";
}

private void vehicleSearchButton_Click(object sender, EventArgs e)


{
Vehicle v = new Vehicle();
List<Vehicle> vl = new List<Vehicle>();
vehicleDetails.Text = "";
vl = v.findVehicle(this);
v.printVObj(vl, this);
}

private void addVehicle_Click(object sender, EventArgs e)


{
if (vIDbox.Text == "" || vNamebox.Text == "" || vColorbox.Text == "" ||
vChasisbox.Text == "" || vCapacitybox.Text == "")
{
MessageBox.Show("Fill all fields", "ERROR");
}
else
{
Vehicle v = new Vehicle();
List<Vehicle> vl = new List<Vehicle>();
v.newVehicle(this);
MessageBox.Show("Vehicle Added", "Success");
vIDbox.Text = "";
vNamebox.Text = "";
vColorbox.Text = "";
vChasisbox.Text = "";
vCapacitybox.Text = "";
}

}
}
}

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

S-ar putea să vă placă și