Пример #1
0
        private void buttonAddPackage_Click(object sender, EventArgs e)
        {
            var packages      = new XMLProvider().XMLToPackages();
            var packageNumber = textBoxPackageNumber.Text;
            var clientID      = textBoxClientID.Text;
            var status        = textBoxStatus.Text;
            var time          = DateTime.Now;

            if (packages.FirstOrDefault(n => n.PackageNumber == packageNumber) == null)
            {
                packages.Add(new Package()
                {
                    ID_User           = Int32.Parse(clientID),
                    PackageNumber     = packageNumber,
                    Status            = status,
                    StatusChangedDate = time
                });
            }
            else
            {
                packages.FirstOrDefault(n => n.PackageNumber == packageNumber).Status            = status;
                packages.FirstOrDefault(n => n.PackageNumber == packageNumber).StatusChangedDate = time;
            }
            new XMLProvider().PackageToXML(packages);
            this.Close();
        }
Пример #2
0
        private void buttonDeletePackage_Click(object sender, EventArgs e)
        {
            if (!File.Exists("packages.xml"))
            {
                File.Create("packages.xml");
            }
            var            usersInXml      = File.ReadAllText("packages.xml");
            List <Package> packagesFromXML = new XMLProvider().XMLToPackages();
            int            selectedRow;

            try
            {
                selectedRow = dataGridViewPackages.SelectedRows[0].Index;
            }
            catch (Exception)
            {
                return;
            }

            if (selectedRow >= packagesFromXML.Count || selectedRow < 0)
            {
                return;
            }
            var packageToRemove = packagesFromXML.FirstOrDefault(i => i.PackageNumber == dataGridViewPackages.Rows[selectedRow].Cells[0].Value.ToString());

            packagesFromXML.Remove(packageToRemove);
            new XMLProvider().PackageToXML(packagesFromXML);
            Reload();
        }