Пример #1
0
        private void delete_Click(object sender, RoutedEventArgs e)
        {
            var custjson = File.ReadAllText(@"Customers.json");

            try
            {
                var    jObject = JObject.Parse(custjson);
                JArray custArr = (JArray)jObject["Customers"];

                Button            button = sender as Button;
                Classes.Customers custId = button.CommandParameter as Classes.Customers;
                int cId = custId.Id;

                var CustomerName = string.Empty;
                var CustToDelete = custArr.FirstOrDefault(obj => obj["Id"].Value <int>() == cId);

                custArr.Remove(CustToDelete);

                string output = Newtonsoft.Json.JsonConvert.SerializeObject(jObject, Newtonsoft.Json.Formatting.Indented);
                File.WriteAllText(@"Customers.json", output);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                MessageBox.Show("Customer Deleted");
                GetCustomersList();
            }
        }
Пример #2
0
        private void btnView_Click(object sender, RoutedEventArgs e)
        {
            Button b = sender as Button;

            Classes.Customers cust = b.CommandParameter as Classes.Customers;

            id      = cust.Id;
            name    = cust.FullName;
            email   = cust.Email;
            phone   = cust.Phone;
            address = cust.Address;
            city    = cust.City;
            country = cust.Country;

            SingleCustomer sc = new SingleCustomer();

            sc.Show();
            this.Close();
        }