Esempio n. 1
0
        public Vehical ShowForm(Vehical CurrentVehical)
        {
            mCurrentVehical = CurrentVehical;
            DialogResult dr = this.ShowDialog();

            return mCurrentVehical;
        }
Esempio n. 2
0
        private void LoadOfflineStorage()
        {
            XmlDocument XmlDocument_ = new XmlDocument();

            try
            {
                XmlDocument_.Load(OfflineStorageLocation);

                XmlNodeList XmlNodeList_root = XmlDocument_.GetElementsByTagName("root");

                // Validate Document
                if (XmlNodeList_root.Count == 1)
                {
                    string ProductName = "", ProductVersion = "";
                    uint VehicalCount, CustomerCount;
                    XmlAttributeCollection Attributes = XmlNodeList_root.Item(0).Attributes;
                    foreach (XmlAttribute attribute in Attributes)
                    {
                        if (attribute.Name == "ProductName")
                        {
                            ProductName = attribute.Value;
                        }
                        if (attribute.Name == "ProductVersion")
                        {
                            ProductVersion = attribute.Value;
                        }
                    }

                    if (ProductName == Application.ProductName && ProductVersion == Application.ProductVersion)
                    {
                        // Document should be valid (Fingers crossed)
                        XmlNodeList XmlNodeList_Vehicals = XmlDocument_.GetElementsByTagName("vehicals");
                        XmlNodeList XmlNodeList_Customers = XmlDocument_.GetElementsByTagName("customers");
                        if(XmlNodeList_Vehicals.Count == 1 )
                        {
                            Attributes = XmlNodeList_Vehicals.Item(0).Attributes;
                            foreach (XmlAttribute attribute in Attributes)
                            {
                                if (attribute.Name == "VehicalCount")
                                {
                                    VehicalCount = Convert.ToUInt32(attribute.Value);
                                }
                            }
                        }
                        if (XmlNodeList_Customers.Count == 1)
                        {
                            Attributes = XmlNodeList_Customers.Item(0).Attributes;
                            foreach (XmlAttribute attribute in Attributes)
                            {
                                if (attribute.Name == "CustomerCount")
                                {
                                    CustomerCount = Convert.ToUInt32(attribute.Value);
                                }
                            }
                        }
                        // Set load all vehicals and customers
                        XmlNodeList_Vehicals = XmlDocument_.GetElementsByTagName("vehical");
                        foreach (XmlNode node in XmlNodeList_Vehicals)
                        {
                            Vehical CurrentVehical = new Vehical();
                            Attributes = node.Attributes;
                            foreach (XmlAttribute attribute in Attributes)
                            {
                                if (attribute.Name == "RegistrationNumber")
                                {
                                    CurrentVehical.RegistrationNumber = attribute.Value;
                                }
                                if (attribute.Name == "Make")
                                {
                                    CurrentVehical.Make = attribute.Value;
                                }
                                if (attribute.Name == "Model")
                                {
                                    CurrentVehical.Model = attribute.Value;
                                }
                                if (attribute.Name == "Colour")
                                {
                                    CurrentVehical.Colour = attribute.Value;
                                }
                                if (attribute.Name == "Available")
                                {
                                    CurrentVehical.Available = Convert.ToBoolean( attribute.Value );
                                }
                                if (attribute.Name == "HiredByCustomerID")
                                {
                                    CurrentVehical.HiredByCustomerID = (int) Convert.ToInt32(attribute.Value);
                                }
                            }
                            if (CurrentVehical.RegistrationNumber != "" && CurrentVehical.RegistrationNumber != null)
                            {
                                Vehicals.Add(CurrentVehical);
                            }
                        }
                        XmlNodeList_Customers = XmlDocument_.GetElementsByTagName("customer");
                        foreach (XmlNode node in XmlNodeList_Customers)
                        {
                            Customer CurrentCustomer = new Customer();
                            Attributes = node.Attributes;
                            foreach (XmlAttribute attribute in Attributes)
                            {
                                if (attribute.Name == "ID")
                                {
                                    CurrentCustomer.ID = (int)Convert.ToInt32(attribute.Value);
                                }
                                if (attribute.Name == "FirstName")
                                {
                                    CurrentCustomer.FirstName = attribute.Value;
                                }
                                if (attribute.Name == "LastName")
                                {
                                    CurrentCustomer.LastName = attribute.Value;
                                }
                                if (attribute.Name == "ContactNumber")
                                {
                                    CurrentCustomer.ContactNumber = attribute.Value;
                                }
                                if (attribute.Name == "ContactAddress")
                                {
                                    CurrentCustomer.ContactAddress = attribute.Value;
                                }
                                if (attribute.Name == "DOB")
                                {
                                    CurrentCustomer.DOB = Convert.ToDateTime(attribute.Value);
                                }
                                if (attribute.Name == "IsHiring")
                                {
                                    CurrentCustomer.IsHiring = Convert.ToBoolean(attribute.Value);
                                }
                            }
                            if (CurrentCustomer.ID > 0)
                            {
                                Customers.Add(CurrentCustomer);
                            }
                        }

                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message); // write exception to console
            }
        }
Esempio n. 3
0
        private void importToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormImport Import = new FormImport();
            if (Import.ShowDialog()== DialogResult.OK)
            {
                OpenFileDialog OpenFile = new OpenFileDialog();
                OpenFile.AddExtension = true;
                OpenFile.DefaultExt = "xml";
                OpenFile.Filter = "XML File(*.xml)|*.xml*";
                if (OpenFile.ShowDialog() == DialogResult.OK)
                {
                    XmlDocument XmlDocument_ = new XmlDocument();

                    try
                    {
                        XmlDocument_.Load(OpenFile.FileName);

                        XmlNodeList XmlNodeList_root = XmlDocument_.GetElementsByTagName("root");

                        // Validate Document
                        if (XmlNodeList_root.Count == 1)
                        {
                            string ProductName = "", ProductVersion = "";
                            uint VehicalCount, CustomerCount;
                            XmlAttributeCollection Attributes = XmlNodeList_root.Item(0).Attributes;
                            foreach (XmlAttribute attribute in Attributes)
                            {
                                if (attribute.Name == "ProductName")
                                {
                                    ProductName = attribute.Value;
                                }
                                if (attribute.Name == "ProductVersion")
                                {
                                    ProductVersion = attribute.Value;
                                }
                            }

                            if (ProductName == Application.ProductName && ProductVersion == Application.ProductVersion)
                            {
                                // Document should be valid (Fingers crossed)
                                XmlNodeList XmlNodeList_Vehicals = XmlDocument_.GetElementsByTagName("vehicals");
                                XmlNodeList XmlNodeList_Customers = XmlDocument_.GetElementsByTagName("customers");
                                if (XmlNodeList_Vehicals.Count == 1)
                                {
                                    Attributes = XmlNodeList_Vehicals.Item(0).Attributes;
                                    foreach (XmlAttribute attribute in Attributes)
                                    {
                                        if (attribute.Name == "VehicalCount")
                                        {
                                            VehicalCount = Convert.ToUInt32(attribute.Value);
                                        }
                                    }
                                }
                                if (XmlNodeList_Customers.Count == 1)
                                {
                                    Attributes = XmlNodeList_Customers.Item(0).Attributes;
                                    foreach (XmlAttribute attribute in Attributes)
                                    {
                                        if (attribute.Name == "CustomerCount")
                                        {
                                            CustomerCount = Convert.ToUInt32(attribute.Value);
                                        }
                                    }
                                }
                                // Set load all vehicals and customers
                                if (Import.import_vehicals)
                                {
                                    Vehicals.Clear();
                                    XmlNodeList_Vehicals = XmlDocument_.GetElementsByTagName("vehical");
                                    foreach (XmlNode node in XmlNodeList_Vehicals)
                                    {
                                        Vehical CurrentVehical = new Vehical();
                                        Attributes = node.Attributes;
                                        foreach (XmlAttribute attribute in Attributes)
                                        {
                                            if (attribute.Name == "RegistrationNumber")
                                            {
                                                CurrentVehical.RegistrationNumber = attribute.Value;
                                            }
                                            if (attribute.Name == "Make")
                                            {
                                                CurrentVehical.Make = attribute.Value;
                                            }
                                            if (attribute.Name == "Model")
                                            {
                                                CurrentVehical.Model = attribute.Value;
                                            }
                                            if (attribute.Name == "Colour")
                                            {
                                                CurrentVehical.Colour = attribute.Value;
                                            }
                                            if (attribute.Name == "Available")
                                            {
                                                CurrentVehical.Available = Convert.ToBoolean(attribute.Value);
                                            }
                                            if (attribute.Name == "HiredByCustomerID")
                                            {
                                                CurrentVehical.HiredByCustomerID = (int)Convert.ToInt32(attribute.Value);
                                            }
                                        }
                                        if (CurrentVehical.RegistrationNumber != "" && CurrentVehical.RegistrationNumber != null)
                                        {
                                            Vehicals.Add(CurrentVehical);
                                        }
                                    }
                                }
                                if (Import.import_customers)
                                {
                                    Customers.Clear();
                                    XmlNodeList_Customers = XmlDocument_.GetElementsByTagName("customer");
                                    foreach (XmlNode node in XmlNodeList_Customers)
                                    {
                                        Customer CurrentCustomer = new Customer();
                                        Attributes = node.Attributes;
                                        foreach (XmlAttribute attribute in Attributes)
                                        {
                                            if (attribute.Name == "ID")
                                            {
                                                CurrentCustomer.ID = (int)Convert.ToInt32(attribute.Value);
                                            }
                                            if (attribute.Name == "FirstName")
                                            {
                                                CurrentCustomer.FirstName = attribute.Value;
                                            }
                                            if (attribute.Name == "LastName")
                                            {
                                                CurrentCustomer.LastName = attribute.Value;
                                            }
                                            if (attribute.Name == "ContactNumber")
                                            {
                                                CurrentCustomer.ContactNumber = attribute.Value;
                                            }
                                            if (attribute.Name == "ContactAddress")
                                            {
                                                CurrentCustomer.ContactAddress = attribute.Value;
                                            }
                                            if (attribute.Name == "DOB")
                                            {
                                                CurrentCustomer.DOB = Convert.ToDateTime(attribute.Value);
                                            }
                                            if (attribute.Name == "IsHiring")
                                            {
                                                CurrentCustomer.IsHiring = Convert.ToBoolean(attribute.Value);
                                            }
                                        }
                                        if (CurrentCustomer.ID > 0)
                                        {
                                            Customers.Add(CurrentCustomer);
                                        }
                                    }
                                }

                            }
                        }
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc.Message); // write exception to console
                    }

                }
            }
            UpdateCustomerList();
            UpdateVehicalList();
        }