示例#1
0
        private void SaveClickCables(object sender, RoutedEventArgs e)
        {
            string Name = CableName.Text.Trim();
            float  length;
            Cables cable = new Cables();

            if (Name.Trim() == "")
            {
                MessageBox.Show("please make sure the item has a name");
            }
            else if (!float.TryParse(CableLength.Text.Trim(), out length))
            {
                if (CableLength.Text.Trim() == "")
                {
                    MessageBox.Show("please add the length of the cable");
                }
                else
                {
                    MessageBox.Show("make sure the lenght only contains numbers and \".\" ");
                }
            }
            else
            {
                /// adds cable
                cable.length = length;
                cable.name   = Name;
                ItemLists lists = fileHandeleralive.Load();
                cable.id = lists.cabels.Count();
                lists.cabels.Add(cable);
                fileHandeleralive.Save(lists);

                //MessageBox.Show("sucsessfully saved \"" + cable.name + "\"");



                //refreshes list
                cablelistshow.ItemsSource = fileHandeleralive.Load().cabels;
            }
        }