public Customer ShowCustomerDialog(Customer CurrentCustomer) { mCurrentCustomer = new Customer(); mCurrentCustomer = CurrentCustomer; DialogResult dr = this.ShowDialog(); return mCurrentCustomer; }
private void addToolStripMenuItem1_Click(object sender, EventArgs e) { Customer newCustomer = new Customer(); newCustomer = CustomerForm.ShowCustomerDialog(new Customer()); if (newCustomer.Updated) { // UPDATE Customer List LastCustomerID++; newCustomer.ID = LastCustomerID; Customers.Add(newCustomer); Customers[Customers.Count - 1].Updated = false; UpdateCustomerList(); } }
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 } }
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(); }
private void hiringToolStripMenuItem_Click(object sender, EventArgs e) { if (CustomerList.SelectedItems.Count <= 0) { MessageBox.Show("Please select a customer first. Then click on \"Hiring Table\" Again."); return; } List<Vehical> vList = new List<Vehical>(); Customer CurrentCustomer = new Customer(); if (CustomerList.SelectedItems.Count > 0) { foreach (Vehical V in Vehicals) { if (V.HiredByCustomerID.ToString() == CustomerList.SelectedItems[0].Text) { vList.Add(V); } } foreach (Customer C in Customers) { if (C.ID.ToString() == CustomerList.SelectedItems[0].Text) { CurrentCustomer = C; } } if (vList.Count > 0) { if (CurrentCustomer.ID.ToString() != "") { /* * Disable all menues and add close table button * Show only hired vehicals of customer * show only customer * if close button is clicked then reset GUI. */ menuStrip1.Hide(); toolStrip1.Show(); // add customer CustomerList.Items.Clear(); ListViewItem Item = new ListViewItem(); Item = new ListViewItem(); Item.Text = CurrentCustomer.ID.ToString(); Item.SubItems.Add(CurrentCustomer.FirstName); Item.SubItems.Add(CurrentCustomer.LastName); Item.SubItems.Add(CurrentCustomer.ContactNumber.ToString()); Item.SubItems.Add("Yes"); CustomerList.Items.Add(Item); // add vehicals VehicalList.Items.Clear(); ListViewItem ListItem = new ListViewItem(); foreach (Vehical v in vList) { ListItem = new ListViewItem(); ListItem.Text = v.RegistrationNumber; ListItem.SubItems.Add(v.Make); ListItem.SubItems.Add(v.Model); ListItem.SubItems.Add(v.Colour); if (v.Available == false) { ListItem.SubItems.Add("No"); VehicalList.Items.Add(ListItem); } } } } } }
private void editToolStripMenuItem1_Click(object sender, EventArgs e) { if (CustomerList.SelectedItems.Count <= 0) { MessageBox.Show("Please select a customer first. Then click on \"View/Edit\" Again."); return; } if(CustomerList.SelectedItems.Count > 0) foreach (Customer C in Customers) { if (C.ID.ToString() == CustomerList.SelectedItems[0].Text) { Customer newCustomer = new Customer(); newCustomer = CustomerForm.ShowCustomerDialog(C); if (newCustomer.Updated) { C.FirstName = newCustomer.FirstName; C.LastName = newCustomer.LastName; C.DOB = newCustomer.DOB; C.ContactNumber = newCustomer.ContactNumber; C.ContactAddress = newCustomer.ContactAddress; C.Updated = false; } } } UpdateCustomerList(); }
private void editToolStripMenuItem1_Click(object sender, EventArgs e) { if(CustomerList.SelectedItems.Count > 0) foreach (Customer C in Customers) { if (C.ID.ToString() == CustomerList.SelectedItems[0].Text) { Customer newCustomer = new Customer(); newCustomer = CustomerForm.ShowCustomerDialog(C); if (newCustomer.Updated) { C.FirstName = newCustomer.FirstName; C.LastName = newCustomer.LastName; C.DOB = newCustomer.DOB; C.ContactNumber = newCustomer.ContactNumber; C.ContactAddress = newCustomer.ContactAddress; C.Updated = false; } } } UpdateCustomerList(); }