コード例 #1
0
        public void Bus_Serialize(string path, bsl obj)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(bsl));

            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("Bus",
                                              new XElement("Name", obj.buslist[0].busname),
                                              new XElement("Departure", obj.buslist[0].departure),
                                              new XElement("From", obj.buslist[0].from),
                                              new XElement("To", obj.buslist[0].to),
                                              new XElement("Fare", obj.buslist[0].fare),
                                              new XElement("Seat", obj.buslist[0].seatcount)
                                              );
                doc.Element("BusDetails").Add(newElement);
                doc.Save(path);
            }
        }
コード例 #2
0
        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;
        }