Esempio n. 1
0
        public void contact_Serialize(string path, tickets obj)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(tickets));

            if (!File.Exists(path))
            {
                FileStream read = new FileStream(path, FileMode.Append, FileAccess.Write, FileShare.None);
                using (read)
                {
                    serializer.Serialize(read, obj);
                    read.Close();
                }
            }
            else
            {
                XDocument doc = XDocument.Load(path);


                var newElement = new XElement("Contacts",
                                              new XElement("Name", obj.contactlist[0].Customername),
                                              new XElement("BusName", obj.contactlist[0].BusName),
                                              new XElement("From", obj.contactlist[0].From),
                                              new XElement("To", obj.contactlist[0].to),
                                              new XElement("Contact", obj.contactlist[0].number),
                                              new XElement("Date", obj.contactlist[0].Date),
                                              new XElement("Seat", obj.contactlist[0].seat),
                                              new XElement("Fare", obj.contactlist[0].fare),
                                              new XElement("Departure", obj.contactlist[0].dep)
                                              );
                doc.Element("Tickets").Add(newElement);
                doc.Save(path);
            }
        }
        private void Searchbtn_Click(object sender, EventArgs e)
        {
            string chfrom = fromInput.Text;
            string chto   = ToInput.Text;

            if (fromInput.SelectedIndex < 0 || ToInput.SelectedIndex < 0)
            {
                MessageBox.Show("Field Can't Be Empty");
                return;
            }


            bookuser bookobj = new bookuser();
            tickets  tobj    = bookobj.get_details(Resources.Resource1.FilePathTickets, bookobj);



            dataGridView1.Visible = true;

            var dateAndTime = Date.Value;
            var date        = dateAndTime.Date;

            senddate = Convert.ToString(date.ToString("dd/MM/yyyy"));



            bookuser bobj = new bookuser();
            tickets  obj  = bobj.get_details(Resources.Resource1.FilePathTickets, bobj);

            DataTable dt = new DataTable();

            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Departure", typeof(string));
            dt.Columns.Add("Fare", typeof(int));
            dt.Columns.Add("Seat", typeof(int));


            busdetials myobj   = new busdetials();
            bsl        tempobj = myobj.getbus_detials(Resources.Resource1.FilePathBus, myobj);

            for (var i = 0; i < tempobj.buslist.Count; i++)
            {
                if (tempobj.buslist[i].from == fromInput.Text && tempobj.buslist[i].to == ToInput.Text)
                {
                    int tempseat = 0;
                    if (obj != null)
                    {
                        for (int j = 0; j < obj.contactlist.Count; j++)
                        {
                            if (obj.contactlist[j].BusName == tempobj.buslist[i].busname && obj.contactlist[j].From == tempobj.buslist[i].from && obj.contactlist[j].to == tempobj.buslist[i].to && obj.contactlist[j].Date == senddate)
                            {
                                tempseat = obj.contactlist[j].seat;
                            }
                        }
                    }
                    DataRow dr = dt.NewRow();
                    dr["Name"]      = tempobj.buslist[i].busname;
                    dr["Departure"] = tempobj.buslist[i].departure;
                    dr["Fare"]      = tempobj.buslist[i].fare;
                    dr["Seat"]      = tempobj.buslist[i].seatcount - tempseat;
                    dt.Rows.Add(dr);
                }
            }



            dataGridView1.DataSource = dt;

            col.Visible = true;
            dataGridView1.Columns["Name"].DisplayIndex      = 0;
            dataGridView1.Columns["Departure"].DisplayIndex = 1;
            dataGridView1.Columns["Fare"].DisplayIndex      = 2;
            dataGridView1.Columns["Seat"].DisplayIndex      = 3;
            dataGridView1.Columns["Book"].DisplayIndex      = 4;
        }