public Customer(Customer cust)
 {
     _age = cust._age;
     _name = cust._name;
     _prenume = cust._prenume;
     _telefon = cust._telefon;
     _oras = cust._oras;
     _email = cust._email;
     _masuri = cust._masuri.ToArray();
     pathDir = Globals.customer_path + "cData\\" + (_name + " " + _prenume);
 }
        public static void add_customer(Customer customer)
        {
            Customer newCustomer = new Customer(customer);
            _customers[_cN++] = newCustomer;
            if ((_cN - 10) > 0)
            {
                _mainForm._peopleManager.ressurect_scrollbar();
            }

            var doc = XDocument.Load(customer_path + @"cList\customers.xml");

            doc.Element("Customers").Add(new XElement("customer", 
                new XElement("Nume", customer._name),
                new XElement("Prenume", customer._prenume),
                new XElement("Telefon", customer._telefon),
                new XElement("Email", customer._email),
                new XElement("Oras", customer._oras),
                new XElement("Path",customer.pathDir)
                ));

            doc.Save(customer_path + @"cList\customers.xml");

            if (cundo_count == 0)
            {
                _cSteps[cundo_count] = new cUndo(customer, Globals._cN - 1, 2);

                string undoPath = hidden_path + @"\cust\" + 0;
                System.IO.Directory.CreateDirectory(undoPath);
                System.IO.Directory.CreateDirectory(undoPath + @"\Customers\");

                foreach (string dir in Directory.GetDirectories(template_path))
                {
                    string dirName = new DirectoryInfo(dir).Name;
                    Directory.CreateDirectory(undoPath + @"\Customers\" + dirName);
                    string fileDest = undoPath + @"\Customers\" + dirName;
                    foreach (string file in Directory.GetFiles(dir))
                    {
                        File.Copy(file, fileDest + @"\" + Path.GetFileName(file));
                    }
                }
                cundo_count += 1;
            }
            else if(cundo_count < 20)
            {
                _cSteps[cundo_count] = new cUndo(customer, Globals._cN - 1, 2);

                string undoPath = hidden_path + @"\cust\" + cundo_count;
                System.IO.Directory.CreateDirectory(undoPath);
                System.IO.Directory.CreateDirectory(undoPath + @"\Customers\");

                foreach (string dir in Directory.GetDirectories(template_path))
                {
                    string dirName = new DirectoryInfo(dir).Name;
                    Directory.CreateDirectory(undoPath + @"\Customers\" + dirName);
                    string fileDest = undoPath + @"\Customers\" + dirName;
                    foreach (string file in Directory.GetFiles(dir))
                    {
                        File.Copy(file, fileDest + @"\" + Path.GetFileName(file));
                    }
                }
                cundo_count += 1;
            }

        }
        } // basic template folders parsing FILE NAME (W/O EXTENSION) = FOLDER NAME

        public static void initCustomers()
        {
            _cSteps = new cUndo[20];
            _customers = new Customer[100];
            if(File.Exists(customer_path + @"cList\customers.xml"))
            {
                XDocument xDoc = XDocument.Load(customer_path + @"cList\customers.xml");


                foreach (XElement xEl in xDoc.Root.Elements("customer"))
                {
                    string name = xEl.Element("Nume").Value;
                    string prenume = xEl.Element("Prenume").Value;
                    string telefon = xEl.Element("Telefon").Value;
                    string email = xEl.Element("Email").Value;
                    string oras = xEl.Element("Oras").Value;
                    string path = xEl.Element("Path").Value;
                    Customer newCustomer = new Customer(1, name, prenume, telefon, email, oras,path);
                    _customers[_cN++] = newCustomer;
                }
            }
            else
            {
                XmlTextWriter xml = new XmlTextWriter(customer_path + @"cList\customers.xml", Encoding.UTF8);
               xml.Formatting = Formatting.Indented;
               xml.WriteStartDocument();
               xml.WriteStartElement("Customers");
               xml.WriteEndElement();
               xml.WriteEndDocument();
               // xml creation + root
               xml.Close();
            }

            for (int i = 0; i < _cN; i++)
            {
                for (int dirIndex = 1; dirIndex < 4; dirIndex++)
                {
                    string path = _customers[i].pathDir + @"\Masura " + dirIndex;

                    foreach (string dir in Directory.GetDirectories(path))
                    {
                        string dirName = Path.GetFileName(dir);
                        if (!dirName.Contains("Gol"))
                        {
                            int _fn = 0;
                            string[] fileN = new string[100];
                            string[] fileP = new string[100];
                            foreach (string file in Directory.GetFiles(dir))
                            {
                                fileN[_fn] = Path.GetFileName(file);
                                fileP[_fn] = file;
                                _fn++;
                            }
                            Masura newMasura = new Masura(dirName, fileN, fileP, _fn);
                            _customers[i].AddMasura(newMasura, dirIndex - 1);
                        }
                        else
                        {
                            Directory.CreateDirectory(path + @"\Gol");
                        }
                    }
                }
            }
        } // basic customer.xml parsing
        private void savep_Click(object sender, EventArgs e)
        {
            if (type == 0) //add customer
            {
                #region add customer
                Globals._dummy._name = t0.Text;
                Globals._dummy._prenume = t1.Text;
                Globals._dummy._telefon = t2.Text;
                Globals._dummy._email = t3.Text;
                Globals._dummy._oras = t4.Text;

                string path = Globals.customer_path + "cData\\" + (Globals._dummy._name + " " + Globals._dummy._prenume);
                Directory.CreateDirectory(path);
                Globals._dummy.pathDir = path;

                int mas_index = 1;
                for (int i = 0; i < 3; i++)
                {
                    string destPath = path + "\\Masura " + mas_index + "\\" + Globals._dummy._masuri[i]._nume;
                    Directory.CreateDirectory(destPath);
                    if (Globals._dummy._masuri[i]._nume != "Gol")
                    {
                        for (int f = 0; f < Globals._dummy._masuri[i].fN; f++)
                        {
                            string overwrite = ""; int ov = 0;
                            while (File.Exists(destPath + "\\" + Path.GetFileName(Globals._dummy._masuri[i].filesP[f]) + overwrite))
                            {
                                ov += 1;
                                overwrite = "(" + ov + ")";
                            }

                            File.Copy(Globals._dummy._masuri[i].filesP[f], destPath + "\\" + Path.GetFileName(Globals._dummy._masuri[i].filesP[f]) + overwrite);
                        }
                    }
                    if (!Directory.Exists(destPath))
                    {
                        Directory.CreateDirectory(destPath);
                    }
                    mas_index += 1;
                }

                for (int i = mas_index; i < 4; i++)
                {
                    Directory.CreateDirectory(path + "\\Masura " + i + "\\Gol");
                }

                Customer newCustomer = new Customer(Globals._dummy);
                Globals.add_customer(newCustomer);
                #endregion
            }
            else
            {
                #region edit customer
                Globals._dummy._name = t0.Text;
                Globals._dummy._prenume = t1.Text;
                Globals._dummy._telefon = t2.Text;
                Globals._dummy._email = t3.Text;
                Globals._dummy._oras = t4.Text;

                string newPath, oldPath;
                oldPath = Globals.customer_path + "cData\\" + (Globals.previous_dummy._name + " " + Globals.previous_dummy._prenume);
                newPath = Globals.customer_path + "cData\\" + (Globals._dummy._name + " " + Globals._dummy._prenume);
                string dummy_folder = Globals.hidden_path + "\\dummy\\";
                Directory.CreateDirectory(dummy_folder);

                int mas_index = 1;
                for (int i = 0; i < 3; i++)
                {
                    string destPath = dummy_folder + "\\Masura " + mas_index + "\\" + Globals._dummy._masuri[i]._nume;
                    Directory.CreateDirectory(destPath);
                    if (Globals._dummy._masuri[i]._nume != "Gol")
                    {
                        for (int f = 0; f < Globals._dummy._masuri[i].fN; f++)
                        {
                            string overwrite = ""; int ov = 0;
                            while (File.Exists(destPath + "\\" + Path.GetFileName(Globals._dummy._masuri[i].filesP[f]) + overwrite))
                            {
                                ov += 1;
                                overwrite = "(" + ov + ")";
                            }
                            File.Copy(Globals._dummy._masuri[i].filesP[f], destPath + "\\" + Path.GetFileName(Globals._dummy._masuri[i].filesP[f]) + overwrite);
                        }
                    }
                    if (!Directory.Exists(destPath))
                    {
                        Directory.CreateDirectory(destPath);
                    }
                    mas_index += 1;
                }
                Directory.Delete(oldPath, true);
                Directory.Move(dummy_folder, newPath);

                Customer newCustomer = new Customer(Globals._dummy);
                var doc = XDocument.Load(Globals.customer_path + "cList\\customers.xml");
                var Contact = (from customer in doc.Descendants("customer")
                               where (customer.Element("Nume").Value == Globals.previous_dummy._name &&
                                      customer.Element("Prenume").Value == Globals.previous_dummy._prenume)
                               select customer).FirstOrDefault();
                if (Contact != null)
                {
                    Contact.Element("Nume").Value = newCustomer._name;
                    Contact.Element("Prenume").Value = newCustomer._prenume;
                    Contact.Element("Telefon").Value = newCustomer._telefon;
                    Contact.Element("Email").Value = newCustomer._email;
                    Contact.Element("Oras").Value = newCustomer._oras;
                }
                doc.Save(Globals.customer_path + "cList\\customers.xml");
                Globals._customers[dummy_index] = new Customer(newCustomer);
                #endregion
            }
            this.DialogResult = System.Windows.Forms.DialogResult.Yes;
        }
 public void peep_load(Customer customer,int index)
 {
     Globals._dummy = new Customer(customer);
     Globals.previous_dummy = new Customer(customer);
     t0.Text = Globals._dummy._name;
     t1.Text = Globals._dummy._prenume;
     t2.Text = Globals._dummy._telefon;
     t3.Text = Globals._dummy._email;
     t4.Text = Globals._dummy._oras;
     type = 1;
     dummy_index = index;
     redraw_masuri();
 }
        //0 = add, 1 = modify, 2 = delete

        public cUndo(Customer c, int i,int t)
        {
            _customer = c;
            index = i;
            type = t;
        }