Ejemplo n.º 1
0
        public static void SaveCustomer(Customer c)
        {
            CustomerDataLayer cDL = GetDataLayer();

            cDL.SaveCustomer(c);
        }
Ejemplo n.º 2
0
 public static void DeleteCustomer(Customer c)
 {
     DeleteCustomer(c.CustomerNo);
 }
Ejemplo n.º 3
0
        public Customer LoadCustomer(String number)
        {
            Customer customer = null;

            XDocument xDoc = XDocument.Load(this.DataSource);

            var dbElement = (from item in xDoc.Descendants("Customers").Descendants("Customer")
                             where item.Attribute("number").Value == number
                             select item).FirstOrDefault();

            if (dbElement != null)
            {
                customer = new Customer
                {
                    CustomerNo = number,
                    Firstname = dbElement.Element("Firstname").Value,
                    Lastname = dbElement.Element("Lastname").Value,
                    Address = dbElement.Element("Address").Value,
                    ZipCode = dbElement.Element("ZipCode").Value,
                    City = dbElement.Element("City").Value,
                    Country = dbElement.Element("Country").Value
                };
            }

            return customer;
        }
Ejemplo n.º 4
0
 public Boolean DeleteCustomer(Customer c)
 {
     return DeleteCustomer(c.CustomerNo);
 }
Ejemplo n.º 5
0
        public Boolean SaveCustomer(Customer c)
        {
            if (c == null)
            {
                throw new NullReferenceException("Customer is null");
            }

            XDocument xDoc = XDocument.Load(this.DataSource);

            var dbElement = (from item in xDoc.Descendants("Customers").Descendants("Customer")
                             where item.Attribute("number").Value == c.CustomerNo
                             select item).FirstOrDefault();

            if (dbElement != null)
            {
                dbElement.Element("Firstname").Value = c.Firstname;
                dbElement.Element("Lastname").Value = c.Lastname;
                dbElement.Element("Address").Value = c.Address;
                dbElement.Element("ZipCode").Value = c.ZipCode;
                dbElement.Element("City").Value = c.City;
                dbElement.Element("Country").Value = c.Country;
            }
            else
            {
                dbElement = new XElement("Customer",
                new XElement("Firstname", c.Firstname),
                new XElement("Lastname", c.Lastname),
                new XElement("Address", c.Address),
                new XElement("ZipCode", c.ZipCode),
                new XElement("City", c.City),
                new XElement("Country", c.Country),
                new XElement("Activities"));

                dbElement.Add(new XAttribute("number", c.CustomerNo));

                xDoc.Element("Customers").Add(dbElement);
            }

            xDoc.Save(".\\DataSource.Xml");

            return true;
        }
Ejemplo n.º 6
0
        private void SaveCustomer()
        {
            Boolean isEdit = (txtCustomerNo.Enabled == false);

            Customer c = new Customer();
            c.CustomerNo = txtCustomerNo.Text;
            c.Firstname = txtFirstname.Text;
            c.Lastname = txtLastname.Text;
            c.Address = txtAddress.Text;
            c.ZipCode = txtZip.Text;
            c.City = txtCity.Text;
            c.Country = txtCountry.Text;

            if(isEdit == true)
            {
                CustomerManager.SaveCustomer(c);
            }
            else
            {
                CustomerManager.CreateNewCustomer(c);
            }

            ClearAll();

            ShowAllCustomers();
        }