Beispiel #1
0
        internal void Aktualizace(bool force = false)
        {
            if (!InvokeRequired)
            {
                timer_ClearInfo.Stop();
            }
            else
            {
                this.BeginInvoke(new Action(() => timer_ClearInfo.Stop()));
            }

            infoBox.Text = jazyk.Message_VyhledavamAktualizace;
            try
            {
                XmlDocument updates = new XmlDocument();
                //updates.Load(Properties.Settings.Default.updateCesta + "\\ticketnik.xml");
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

                try
                {
                    //výchozí cesta v síti
                    if (!Properties.Settings.Default.pouzivatZalozniUpdate)
                    {
                        updates.Load(Properties.Settings.Default.updateCesta + "\\ticketnik.xml");
                        Logni("Kontroluji updaty na " + Properties.Settings.Default.updateCesta + "\\ticketnik.xml", LogMessage.INFO);
                    }
                    else
                    {
                        try
                        {
                            WebClient wc = new WebClient();
                            wc.DownloadFile(Properties.Settings.Default.ZalozniUpdate + "/ticketnik.xml", Path.GetTempPath() + "\\ticketnik.xml");
                            updates.Load(Path.GetTempPath() + "\\ticketnik.xml");
                            Logni("Kontroluji updaty na " + Properties.Settings.Default.ZalozniUpdate + "/ticketnik.xml", LogMessage.INFO);
                        }
                        catch (Exception e)
                        {
                            if (Properties.Settings.Default.pouzivatZalozniUpdate)
                            {
                                try
                                {
                                    updates.Load(Properties.Settings.Default.updateCesta + "\\ticketnik.xml");
                                    Logni("Kontroluji updaty na " + Properties.Settings.Default.updateCesta + "\\ticketnik.xml", LogMessage.INFO);
                                }
                                catch { Logni("Nelze načíst aktualizační zdroj v síti.", LogMessage.WARNING); }
                            }
                            Logni("Nelze načíst žádný zdroj aktualizací.\r\n" + e.Message, LogMessage.WARNING);
                            //why? Lepší je return. throw new Exception("Nelze vyhledat žádný zdroj aktualizací");
                            return;
                        }
                    }
                }
                catch
                {
                    //backup download z netu
                    try
                    {
                        WebClient wc = new WebClient();
                        wc.DownloadFile(Properties.Settings.Default.ZalozniUpdate + "/ticketnik.xml", Path.GetTempPath() + "\\ticketnik.xml");
                        updates.Load(Path.GetTempPath() + "\\ticketnik.xml");
                        Logni("Kontroluji updaty na " + Properties.Settings.Default.ZalozniUpdate + "/ticketnik.xml", LogMessage.INFO);
                    }
                    catch (Exception e)
                    {
                        if (Properties.Settings.Default.pouzivatZalozniUpdate)
                        {
                            try
                            {
                                updates.Load(Properties.Settings.Default.updateCesta + "\\ticketnik.xml");
                                Logni("Kontroluji updaty na " + Properties.Settings.Default.updateCesta + "\\ticketnik.xml", LogMessage.INFO);
                            }
                            catch { Logni("Nelze načíst aktualizační zdroj v síti.", LogMessage.WARNING); }
                        }
                        Logni("Nelze načíst žádný zdroj aktualizací.\r\n" + e.Message, LogMessage.WARNING);
                        //why? Lepší je return. throw new Exception("Nelze vyhledat žádný zdroj aktualizací");
                        return;
                    }
                }

                if (verze < int.Parse(updates.DocumentElement.SelectSingleNode("Zakosi").InnerText) || force)
                {
                    //DoCommand("copy " + Properties.Settings.Default.updateCesta + "\\zakaznici " + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\_zakaznici");
                    try
                    {
                        //výchozí cesta v síti
                        if (!Properties.Settings.Default.pouzivatZalozniUpdate)
                        {
                            File.Copy(Properties.Settings.Default.updateCesta + "\\zakaznici", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\_zakaznici", true);

                            Logni("Stahuji soubor zakaznici z " + Properties.Settings.Default.updateCesta + "\\zakaznici", LogMessage.INFO);
                        }
                        else
                        {
                            try
                            {
                                WebClient wc = new WebClient();
                                wc.DownloadFile(Properties.Settings.Default.ZalozniUpdate + "/zakaznici", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\_zakaznici");

                                Logni("Stahuji soubor zakaznici z " + Properties.Settings.Default.ZalozniUpdate + "/zakaznici", LogMessage.INFO);
                            }
                            catch (Exception e)
                            {
                                Logni("Stažení souboru zakaznici selhalo.\r\n" + e.Message, LogMessage.WARNING);
                            }
                        }
                    }
                    catch
                    {
                        //backup download na netu
                        try
                        {
                            WebClient wc = new WebClient();
                            wc.DownloadFile(Properties.Settings.Default.ZalozniUpdate + "/zakaznici", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\_zakaznici");

                            Logni("Stahuji soubor zakaznici z " + Properties.Settings.Default.ZalozniUpdate + "/zakaznici", LogMessage.INFO);
                        }
                        catch (Exception e)
                        {
                            Logni("Stažení souboru zakaznici selhalo.\r\n" + e.Message, LogMessage.WARNING);
                        }
                    }
                    NbtFile tmpZak = new NbtFile();
                    tmpZak.LoadFromFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\_zakaznici");

                    NbtFile zak = new NbtFile();
                    zak.LoadFromFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\zakaznici");

                    foreach (NbtTag ncz in tmpZak.RootTag)
                    {
                        if (vcl.IsCancellationRequested)
                        {
                            return;
                        }
                        if (ncz.TagType == NbtTagType.Compound)
                        {
                            if (!zak.RootTag.Contains(ncz.Name))
                            {
                                zak.RootTag.Add((NbtCompound)ncz.Clone());
                            }
                            else if (zak.RootTag.Get <NbtCompound>(ncz.Name).Get <NbtByte>("Velikost").Value != tmpZak.RootTag.Get <NbtCompound>(ncz.Name).Get <NbtByte>("Velikost").Value)
                            {
                                zak.RootTag.Get <NbtCompound>(ncz.Name).Get <NbtByte>("Velikost").Value = tmpZak.RootTag.Get <NbtCompound>(ncz.Name).Get <NbtByte>("Velikost").Value;
                            }

                            if (tmpZak.RootTag.Get <NbtCompound>(ncz.Name).Get <NbtString>("Terp") != null)
                            {
                                if (zak.RootTag.Get <NbtCompound>(ncz.Name).Get <NbtString>("Terp") == null)
                                {
                                    zak.RootTag.Get <NbtCompound>(ncz.Name).Add(new NbtString("Terp", tmpZak.RootTag.Get <NbtCompound>(ncz.Name).Get <NbtString>("Terp").Value));
                                }
                                else
                                {
                                    zak.RootTag.Get <NbtCompound>(ncz.Name).Get <NbtString>("Terp").Value = tmpZak.RootTag.Get <NbtCompound>(ncz.Name).Get <NbtString>("Terp").Value;
                                }
                            }
                        }
                        else if (ncz.TagType == NbtTagType.List)
                        {
                            if (!zak.RootTag.Contains(ncz.Name))
                            {
                                zak.RootTag.Add((NbtList)ncz.Clone());
                            }
                            else
                            {
                                ((NbtCompound)zak.RootTag.Get <NbtList>("Terpy")[0]).Remove("Task");
                                ((NbtCompound)zak.RootTag.Get <NbtList>("Terpy")[0]).Add((NbtCompound)((NbtCompound)tmpZak.RootTag.Get <NbtList>("Terpy")[0]).Get <NbtCompound>("Task").Clone());
                                ((NbtCompound)zak.RootTag.Get <NbtList>("Terpy")[0]).Remove("Typ");
                                ((NbtCompound)zak.RootTag.Get <NbtList>("Terpy")[0]).Add((NbtCompound)((NbtCompound)tmpZak.RootTag.Get <NbtList>("Terpy")[0]).Get <NbtCompound>("Typ").Clone());
                                ((NbtCompound)zak.RootTag.Get <NbtList>("Terpy")[0]).Remove("Velikost");
                                ((NbtCompound)zak.RootTag.Get <NbtList>("Terpy")[0]).Add((NbtCompound)((NbtCompound)tmpZak.RootTag.Get <NbtList>("Terpy")[0]).Get <NbtCompound>("Velikost").Clone());

                                if (zak.RootTag["Terpy"][0]["Custom"] == null)
                                {
                                    ((NbtCompound)zak.RootTag["Terpy"][0]).Add(new NbtCompound("Custom"));
                                }
                                if (zak.RootTag["Terpy"][0]["Custom"]["Task"] == null)
                                {
                                    ((NbtCompound)zak.RootTag["Terpy"][0]["Custom"]).Add(new NbtList("Task", NbtTagType.String));
                                }
                                foreach (NbtString nbs in (NbtList)tmpZak.RootTag["Terpy"][0]["Custom"]["Task"])
                                {
                                    if (vcl.IsCancellationRequested)
                                    {
                                        return;
                                    }
                                    bool nal = false;
                                    foreach (NbtString nbss in (NbtList)zak.RootTag["Terpy"][0]["Custom"]["Task"])
                                    {
                                        if (vcl.IsCancellationRequested)
                                        {
                                            return;
                                        }
                                        if (nbss.Value == nbs.Value)
                                        {
                                            nal = true;
                                            break;
                                        }
                                    }
                                    if (!nal)
                                    {
                                        ((NbtList)zak.RootTag["Terpy"][0]["Custom"]["Task"]).Add(new NbtString(nbs.Value));
                                    }
                                }

                                if (zak.RootTag["Terpy"][0]["Custom"]["Terp"] == null)
                                {
                                    ((NbtCompound)zak.RootTag["Terpy"][0]["Custom"]).Add(new NbtList("Terp", NbtTagType.String));
                                }
                                foreach (NbtString nbs in (NbtList)tmpZak.RootTag["Terpy"][0]["Custom"]["Terp"])
                                {
                                    if (vcl.IsCancellationRequested)
                                    {
                                        return;
                                    }
                                    bool nal = false;
                                    foreach (NbtString nbss in (NbtList)zak.RootTag["Terpy"][0]["Custom"]["Terp"])
                                    {
                                        if (vcl.IsCancellationRequested)
                                        {
                                            return;
                                        }
                                        if (nbss.Value == nbs.Value)
                                        {
                                            nal = true;
                                            break;
                                        }
                                    }
                                    if (!nal)
                                    {
                                        ((NbtList)zak.RootTag["Terpy"][0]["Custom"]["Terp"]).Add(new NbtString(nbs.Value));
                                    }
                                }

                                if (zak.RootTag["Terpy"][0]["Custom"]["TerpPopis"] == null)
                                {
                                    ((NbtCompound)zak.RootTag["Terpy"][0]["Custom"]).Add(new NbtCompound("TerpPopis"));
                                }
                                foreach (NbtString nbs in (NbtCompound)tmpZak.RootTag["Terpy"][0]["Custom"]["TerpPopis"])
                                {
                                    if (vcl.IsCancellationRequested)
                                    {
                                        return;
                                    }
                                    if (zak.RootTag["Terpy"][0]["Custom"]["TerpPopis"][nbs.Name] == null)
                                    {
                                        ((NbtCompound)zak.RootTag["Terpy"][0]["Custom"]["TerpPopis"]).Add(new NbtString(nbs.Name, nbs.Value));
                                    }
                                    else
                                    {
                                        ((NbtString)zak.RootTag["Terpy"][0]["Custom"]["TerpPopis"][nbs.Name]).Value = nbs.Value;
                                    }
                                }
                                if (zak.RootTag["Terpy"][0]["Custom"]["TaskPopis"] == null)
                                {
                                    ((NbtCompound)zak.RootTag["Terpy"][0]["Custom"]).Add(new NbtCompound("TaskPopis"));
                                }
                                foreach (NbtString nbs in (NbtCompound)tmpZak.RootTag["Terpy"][0]["Custom"]["TaskPopis"])
                                {
                                    if (vcl.IsCancellationRequested)
                                    {
                                        return;
                                    }
                                    if (zak.RootTag["Terpy"][0]["Custom"]["TaskPopis"][nbs.Name] == null)
                                    {
                                        ((NbtCompound)zak.RootTag["Terpy"][0]["Custom"]["TaskPopis"]).Add(new NbtString(nbs.Name, nbs.Value));
                                    }
                                    else
                                    {
                                        ((NbtString)zak.RootTag["Terpy"][0]["Custom"]["TaskPopis"][nbs.Name]).Value = nbs.Value;
                                    }
                                }
                            }
                        }
                    }

                    zak.RootTag.Get <NbtInt>("verze").Value = tmpZak.RootTag.Get <NbtInt>("verze").Value;

                    byte pokusy = 0;

aktul:
                    if (pokusy < 10)
                    {
                        if (vcl.IsCancellationRequested)
                        {
                            return;
                        }
                        try
                        {
                            pokusy++;
                            zak.SaveToFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\zakaznici", NbtCompression.GZip);
                            list = new Zakaznici(this);
                            Logni(jazyk.Message_ZakazniciUpd + " " + zak.RootTag.Get <NbtInt>("verze").Value, LogMessage.INFO);
                        }
                        catch
                        {
                            Thread.Sleep(500);
                            goto aktul;
                        }
                    }
                    File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\_zakaznici");

                    if (!InvokeRequired)
                    {
                        LoadFile();
                    }
                    else
                    {
                        this.BeginInvoke(new Action(() => LoadFile()));
                    }
                }

                foreach (XmlNode Njazyk in updates.DocumentElement.SelectSingleNode("Lang").ChildNodes)
                {
                    if (vcl.IsCancellationRequested)
                    {
                        return;
                    }
                    if (File.Exists(System.Reflection.Assembly.GetEntryAssembly().Location.Replace("Ticketnik.exe", "") + "lang\\" + Njazyk.Name + ".xml"))
                    {
                        string[]    jverze  = Njazyk.InnerText.Split('.');
                        XmlDocument preklad = new XmlDocument();
                        preklad.Load(System.Reflection.Assembly.GetEntryAssembly().Location.Replace("Ticketnik.exe", "") + "lang\\" + Njazyk.Name + ".xml");

                        if ((int.Parse(preklad.DocumentElement.Attributes.GetNamedItem("version").InnerText) < int.Parse(jverze[0])) ||
                            (int.Parse(preklad.DocumentElement.Attributes.GetNamedItem("version").InnerText) == int.Parse(jverze[0]) &&
                             int.Parse(preklad.DocumentElement.Attributes.GetNamedItem("revision").InnerText) < int.Parse(jverze[1])))
                        {
                            try
                            {
                                //výchozí cesta v síti
                                if (!Properties.Settings.Default.pouzivatZalozniUpdate)
                                {
                                    File.Copy(Properties.Settings.Default.updateCesta + "\\lang\\" + Njazyk.Name + ".xml", System.Reflection.Assembly.GetEntryAssembly().Location.Replace("Ticketnik.exe", "") + "lang\\" + Njazyk.Name + ".xml", true);

                                    Logni("Stahuji soubor jazyka z " + Properties.Settings.Default.updateCesta + "\\lang\\" + Njazyk.Name + ".xml", LogMessage.INFO);
                                }
                                else
                                {
                                    try
                                    {
                                        WebClient wc = new WebClient();
                                        wc.DownloadFile(Properties.Settings.Default.ZalozniUpdate + "/lang/" + Njazyk.Name + ".xml", System.Reflection.Assembly.GetEntryAssembly().Location.Replace("Ticketnik.exe", "") + "lang\\" + Njazyk.Name + ".xml");
                                        Logni("Stahuji soubor jazyka z " + Properties.Settings.Default.ZalozniUpdate + "/lang/" + Njazyk.Name + ".xml", LogMessage.INFO);
                                    }
                                    catch (Exception e)
                                    {
                                        Logni("Stažení aktualizací jazyka selhalo.\r\n" + e.Message, LogMessage.WARNING);
                                    }
                                }
                            }
                            catch
                            {
                                //backup download z netu
                                try
                                {
                                    WebClient wc = new WebClient();
                                    wc.DownloadFile(Properties.Settings.Default.ZalozniUpdate + "/lang/" + Njazyk.Name + ".xml", System.Reflection.Assembly.GetEntryAssembly().Location.Replace("Ticketnik.exe", "") + "lang\\" + Njazyk.Name + ".xml");
                                    Logni("Stahuji soubor jazyka z " + Properties.Settings.Default.ZalozniUpdate + "/lang/" + Njazyk.Name + ".xml", LogMessage.INFO);
                                }
                                catch (Exception e)
                                {
                                    Logni("Stažení aktualizací jazyka selhalo.\r\n" + e.Message, LogMessage.WARNING);
                                }
                            }
                            jazyk = new Jazyk();
                            if (!InvokeRequired)
                            {
                                jazyk.Reload(this);
                            }
                            else
                            {
                                this.BeginInvoke(new Action(() => jazyk.Reload(this)));
                            }
                            Logni("Jazyk " + Njazyk.Name + " byl updatován.", LogMessage.INFO);
                        }
                    }
                }

                if (program < int.Parse(updates.DocumentElement.SelectSingleNode("App").InnerText))
                {
                    if (DialogResult.Yes == MessageBox.Show(jazyk.Message_NovaVerze, jazyk.Message_Aktualizace, MessageBoxButtons.YesNo))
                    {
                        try
                        {
                            //výchozí cesta v síti
                            if (!Properties.Settings.Default.pouzivatZalozniUpdate)
                            {
                                File.Copy(Properties.Settings.Default.updateCesta + "\\Ticketnik.exe", System.Reflection.Assembly.GetEntryAssembly().Location.Replace("Ticketnik.exe", "_Ticketnik.exe"), true);
                                Logni("Stahuji Ticketnik z " + Properties.Settings.Default.updateCesta + "\\Ticketnik.exe", LogMessage.INFO);
                            }
                            else
                            {
                                try
                                {
                                    WebClient wc = new WebClient();
                                    wc.DownloadFile(Properties.Settings.Default.ZalozniUpdate + "/Ticketnik.txt", System.Reflection.Assembly.GetEntryAssembly().Location.Replace("Ticketnik.exe", "_Ticketnik.exe"));
                                    Logni("Stahuji Ticketnik z " + Properties.Settings.Default.ZalozniUpdate + "\\Ticketnik.exe", LogMessage.INFO);
                                }
                                catch (Exception e)
                                {
                                    Logni("Stažení aktualizace programu selhalo.\r\n" + e.Message, LogMessage.WARNING);
                                }
                            }
                        }
                        catch
                        {
                            //backup download z netu
                            try
                            {
                                WebClient wc = new WebClient();
                                wc.DownloadFile(Properties.Settings.Default.ZalozniUpdate + "/Ticketnik.txt", System.Reflection.Assembly.GetEntryAssembly().Location.Replace("Ticketnik.exe", "_Ticketnik.exe"));
                                Logni("Stahuji Ticketnik z " + Properties.Settings.Default.ZalozniUpdate + "\\Ticketnik.exe", LogMessage.INFO);
                            }
                            catch (Exception e)
                            {
                                Logni("Stažení aktualizace programu selhalo.\r\n" + e.Message, LogMessage.WARNING);
                            }
                        }

                        Process.Start("_Ticketnik.exe", "/update");

                        if (!InvokeRequired)
                        {
                            this.Close();
                        }
                        else
                        {
                            this.BeginInvoke(new Action(() => this.Close()));
                        }
                    }
                }
                infoBox.Text = jazyk.Message_AktualizaceHotova;
            }
            catch (Exception e)
            {
                infoBox.Text = jazyk.Message_AktualizaceSeNezdarila;
                Logni("Aktualizace se nezdařila\r\n\r\n" + e.Message, LogMessage.WARNING);
            }

            if (vlaknoTerp != null && vlaknoTerp.IsAlive)
            {
                if (!InvokeRequired)
                {
                    timer_ClearInfo.Start();
                }
                else
                {
                    this.BeginInvoke(new Action(() => timer_ClearInfo.Start()));
                }
            }
        }
Beispiel #2
0
        public Ticket(long id, string mesic, DateTime datum, DateTime odCas, DateTime doCas, List <DateTime> pauzyOd, List <DateTime> pauzyDo, Stav stav, string ID, string kontakt, string PC, string popis, string poznamky, TypTicketu typTicketu = TypTicketu.Normalni, string zakaznik = "", string customTerp = "", string customTask = "", string onlineTyp = "")
        {
            Mesic      = mesic;
            Datum      = datum;
            Od         = odCas;
            Do         = doCas;
            PauzyOd    = pauzyOd;
            PauzyDo    = pauzyDo;
            StavT      = stav;
            this.ID    = ID;
            Kontakt    = kontakt;
            this.PC    = PC;
            Popis      = popis;
            Poznamky   = poznamky;
            IDtick     = id;
            Zakaznik   = zakaznik;
            TypPrace   = (byte)typTicketu;
            CustomTask = customTask;
            CustomTerp = customTerp;
            OnlineTyp  = onlineTyp;

            if (Od > Do && Do.ToString("H:mm") != "0:00")
            {
                Od = Od.AddHours(-12);
                Do = Do.AddHours(12);
            }

            //udělat seznam velikostí zákazníků
            if (typTicketu == TypTicketu.OnlineTyp)
            {
                Terp  = TerpKod.OnlineTerp;
                TerpT = TerpTyp.OnlineTerpTask;
            }
            else if (typTicketu == TypTicketu.Normalni)
            {
                if (Zakaznici.DejVelikost(zakaznik) == 0)
                {
                    Terp  = TerpKod.VelkyNormal;
                    TerpT = TerpTyp.VelkyNormal;
                }
                else if (Zakaznici.DejVelikost(zakaznik) == 1)
                {
                    Terp  = TerpKod.StredniNormal;
                    TerpT = TerpTyp.StredniNormal;
                }
                else
                {
                    Terp  = TerpKod.MalyNormal;
                    TerpT = TerpTyp.MalyNormal;
                }
            }
            else if (typTicketu == TypTicketu.PraceOPrazdniny)
            {
                if (Zakaznici.DejVelikost(zakaznik) == 0)
                {
                    Terp  = TerpKod.VelkyHolyday;
                    TerpT = TerpTyp.VelkyHolyday;
                }
                else if (Zakaznici.DejVelikost(zakaznik) == 1)
                {
                    Terp  = TerpKod.StredniHolyday;
                    TerpT = TerpTyp.StredniHolyday;
                }
                else
                {
                    Terp  = TerpKod.MalyHolyday;
                    TerpT = TerpTyp.MalyHolyday;
                }
            }
            else if (typTicketu == TypTicketu.NahradniVolno)
            {
                if (Zakaznici.DejVelikost(zakaznik) == 0)
                {
                    Terp  = TerpKod.VelkyHolyday;
                    TerpT = TerpTyp.VelkyNormalNahradni;
                }
                else if (Zakaznici.DejVelikost(zakaznik) == 1)
                {
                    Terp  = TerpKod.StredniHolyday;
                    TerpT = TerpTyp.StredniNormalNahradni;
                }
                else
                {
                    Terp  = TerpKod.MalyHolyday;
                    TerpT = TerpTyp.MalyNormalNahradni;
                }
            }
            else if (typTicketu == TypTicketu.ProblemNahradniVolno)
            {
                if (Zakaznici.DejVelikost(zakaznik) == 0)
                {
                    Terp  = TerpKod.VelkyProblem;
                    TerpT = TerpTyp.VelkyProblemNahradni;
                }
                else if (Zakaznici.DejVelikost(zakaznik) == 1)
                {
                    Terp  = TerpKod.StredniProblem;
                    TerpT = TerpTyp.StredniProblemNahradni;
                }
                else
                {
                    Terp  = TerpKod.MalyProblem;
                    TerpT = TerpTyp.MalyProblemNahradni;
                }
            }
            else if (typTicketu == TypTicketu.Prescas)
            {
                if (Zakaznici.DejVelikost(zakaznik) == 0)
                {
                    Terp  = TerpKod.VelkyNormal;
                    TerpT = TerpTyp.VelkyNormalPrescas;
                }
                else if (Zakaznici.DejVelikost(zakaznik) == 1)
                {
                    Terp  = TerpKod.StredniNormal;
                    TerpT = TerpTyp.StredniNormalPrescas;
                }
                else
                {
                    Terp  = TerpKod.MalyNormal;
                    TerpT = TerpTyp.MalyNormalPrescas;
                }
            }
            else if (typTicketu == TypTicketu.ProblemOPrazdniny)
            {
                if (Zakaznici.DejVelikost(zakaznik) == 0)
                {
                    Terp  = TerpKod.VelkyProblem;
                    TerpT = TerpTyp.VelkyProblemHolyday;
                }
                else if (Zakaznici.DejVelikost(zakaznik) == 1)
                {
                    Terp  = TerpKod.StredniProblem;
                    TerpT = TerpTyp.StredniProblemHolyday;
                }
                else
                {
                    Terp  = TerpKod.MalyProblem;
                    TerpT = TerpTyp.MalyProblemHolyday;
                }
            }
            else if (typTicketu == TypTicketu.ProblemPrescas)
            {
                if (Zakaznici.DejVelikost(zakaznik) == 0)
                {
                    Terp  = TerpKod.VelkyProblem;
                    TerpT = TerpTyp.VelkyProblemPrescas;
                }
                else if (Zakaznici.DejVelikost(zakaznik) == 1)
                {
                    Terp  = TerpKod.StredniProblem;
                    TerpT = TerpTyp.StredniProblemPrescas;
                }
                else
                {
                    Terp  = TerpKod.MalyProblem;
                    TerpT = TerpTyp.MalyProblemPrescas;
                }
            }
            else if (typTicketu == TypTicketu.ProblemTicket)
            {
                if (Zakaznici.DejVelikost(zakaznik) == 0)
                {
                    Terp  = TerpKod.VelkyProblem;
                    TerpT = TerpTyp.VelkyProblem;
                }
                else if (Zakaznici.DejVelikost(zakaznik) == 1)
                {
                    Terp  = TerpKod.StredniProblem;
                    TerpT = TerpTyp.StredniProblem;
                }
                else
                {
                    Terp  = TerpKod.MalyProblem;
                    TerpT = TerpTyp.MalyProblem;
                }
            }
            else if (typTicketu == TypTicketu.Enkripce)
            {
                Terp  = TerpKod.Enkripce;
                TerpT = TerpTyp.Enkripce;
            }
            else if (typTicketu == TypTicketu.EnkripceNahradniVolno)
            {
                Terp  = TerpKod.Enkripce;
                TerpT = TerpTyp.EnkripceNahradni;
            }
            else if (typTicketu == TypTicketu.EnkripceOPrazdniny)
            {
                Terp  = TerpKod.EnkripceHoliday;
                TerpT = TerpTyp.EnkripceHoliday;
            }
            else if (typTicketu == TypTicketu.EnkripcePrescas)
            {
                Terp  = TerpKod.Enkripce;
                TerpT = TerpTyp.EnkripcePrescas;
            }
            else if (typTicketu == TypTicketu.EnkripceProblem)
            {
                Terp  = TerpKod.EnkripceProblem;
                TerpT = TerpTyp.EnkripceProblem;
            }
            else if (typTicketu == TypTicketu.EnkripceProblemNahradni)
            {
                Terp  = TerpKod.EnkripceProblem;
                TerpT = TerpTyp.EnkripceProblemNahradni;
            }
            else if (typTicketu == TypTicketu.EnkripceProblemOPrazdniny)
            {
                Terp  = TerpKod.EnkripceProblem;
                TerpT = TerpTyp.EnkripceProblemHoliday;
            }
            else if (typTicketu == TypTicketu.EnkripceProblemPrescas)
            {
                Terp  = TerpKod.EnkripceProblem;
                TerpT = TerpTyp.EnkripceProblemPrescas;
            }
            else if (typTicketu == TypTicketu.Mobility)
            {
                Terp  = TerpKod.Mobility;
                TerpT = TerpTyp.Mobility;
            }
            else if (typTicketu == TypTicketu.MobilityNahradniVolno)
            {
                Terp  = TerpKod.Mobility;
                TerpT = TerpTyp.MobilityNahradni;
            }
            else if (typTicketu == TypTicketu.MobilityOPrazdniny)
            {
                Terp  = TerpKod.MobilityHoliday;
                TerpT = TerpTyp.MobilityHoliday;
            }
            else if (typTicketu == TypTicketu.MobilityPrescas)
            {
                Terp  = TerpKod.Mobility;
                TerpT = TerpTyp.MobilityPrescas;
            }
            else if (typTicketu == TypTicketu.MobilityProblem)
            {
                Terp  = TerpKod.MobilityProblem;
                TerpT = TerpTyp.MobilityProblem;
            }
            else if (typTicketu == TypTicketu.MobilityProblemNahradni)
            {
                Terp  = TerpKod.MobilityProblem;
                TerpT = TerpTyp.MobilityProblemNahradni;
            }
            else if (typTicketu == TypTicketu.MobilityProblemOPrazdniny)
            {
                Terp  = TerpKod.MobilityProblem;
                TerpT = TerpTyp.MobilityProblemHoliday;
            }
            else if (typTicketu == TypTicketu.MobilityProblemPrescas)
            {
                Terp  = TerpKod.MobilityProblem;
                TerpT = TerpTyp.MobilityProblemPrescas;
            }
            else if (typTicketu == TypTicketu.Custom)
            {
                Terp  = TerpKod.Custom;
                TerpT = TerpTyp.Custom;
            }
            else if (typTicketu == TypTicketu.CustomNahradni)
            {
                Terp  = TerpKod.Custom;
                TerpT = TerpTyp.CustomNahradni;
            }
            else if (typTicketu == TypTicketu.CustomOPrazdniny)
            {
                Terp  = TerpKod.CustomHoliday;
                TerpT = TerpTyp.CustomHoliday;
            }
            else if (typTicketu == TypTicketu.CustomPrescas)
            {
                Terp  = TerpKod.Custom;
                TerpT = TerpTyp.CustomPrescas;
            }
            else
            {
                if (Zakaznici.DejVelikost(zakaznik) == 0)
                {
                    Terp = TerpKod.VelkyProblem;
                }
                else if (Zakaznici.DejVelikost(zakaznik) == 1)
                {
                    Terp = TerpKod.StredniProblem;
                }
                else
                {
                    Terp = TerpKod.MalyProblem;
                }
            }
        }
Beispiel #3
0
        private void Export_Novy()
        {
            if (!InvokeRequired)
            {
                form.timer_ClearInfo.Stop();
            }
            else
            {
                this.BeginInvoke(new Action(() => form.timer_ClearInfo.Stop()));
            }
            form.infoBox.Text = form.jazyk.Message_Exportuji;
            form.Update();

            DateTime start;
            DateTime konec;

            over = false;
            List <ExportRow> exportRadky = new List <ExportRow>();

            int odec = 0;

            if (DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek).DayOfWeek == DayOfWeek.Sunday && (int)DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek).DayOfWeek == 0)
            {
                odec = 1;
            }

            if (radioButton3.Checked)
            {
                start = dateTimePicker1.Value;
                konec = dateTimePicker2.Value;
            }
            else if (radioButton1.Checked)
            {
                konec = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

                //tohle zrevidovat, jestli by nestačilo jen to Add day v catch bez try
                try
                {
                    start = new DateTime(DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek).Year, DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek).Month, DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek).Day + odec);
                }
                catch
                {
                    start = new DateTime(DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek).Year, DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek).Month, DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek).Day);
                    start = start.AddDays(odec);
                }
            }
            else
            {
                start = DateTime.Now.AddDays(-7);
                start = start.AddDays(-(int)(start.DayOfWeek - 1));
                start = new DateTime(start.Year, start.Month, start.Day);

                konec = new DateTime(start.Year, start.Month, start.Day).AddDays(6);
            }

            //Projít tickety splňující podmínku a zařadit je správně do exportu
            for (DateTime d = start; d <= konec; d = d.AddDays(1))
            {
                if (form.poDnech.ContainsKey(d))
                {
                    foreach (string s in form.poDnech[d].Keys)
                    {
                        foreach (Ticket t in form.poDnech[d][s])
                        {
                            DateTime pauzaDohromady = new DateTime();
                            DateTime cas            = new DateTime();
                            DateTime hrubyCas       = new DateTime();

                            for (int i = 0; i < t.PauzyDo.Count; i++)
                            {
                                if (t.PauzyDo[i].ToString("H:mm") != "0:00")
                                {
                                    pauzaDohromady = pauzaDohromady.AddHours(t.PauzyDo[i].Hour - t.PauzyOd[i].Hour).AddMinutes(t.PauzyDo[i].Minute - t.PauzyOd[i].Minute);
                                }
                            }

                            try
                            {
                                cas      = cas.AddHours((t.Do.Hour - t.Od.Hour) - pauzaDohromady.Hour).AddMinutes((t.Do.Minute - t.Od.Minute) - pauzaDohromady.Minute);
                                hrubyCas = form.RoundUp(cas, TimeSpan.FromMinutes(30));

                                //dny[d][t.TerpT].Add(t, hrubyCas);
                                string den = "";
                                switch (d.DayOfWeek)
                                {
                                case DayOfWeek.Monday: den = "Pondělí";
                                    break;

                                case DayOfWeek.Tuesday: den = "Úterý";
                                    break;

                                case DayOfWeek.Wednesday: den = "Středa";
                                    break;

                                case DayOfWeek.Thursday: den = "Čtvrtek";
                                    break;

                                case DayOfWeek.Friday: den = "Pátek";
                                    break;

                                case DayOfWeek.Saturday: den = "Sobota";
                                    break;

                                case DayOfWeek.Sunday: den = "Neděle";
                                    break;
                                }

                                ExportTyp et;
                                if (t.TypPrace == 0 || t.TypPrace == 2 || t.TypPrace == 8 || t.TypPrace == 12 || t.TypPrace == 16 || t.TypPrace == 20 || t.TypPrace == 24)
                                {
                                    et = ExportTyp.Normal;
                                }
                                else if (t.TypPrace == 1 || t.TypPrace == 6 || t.TypPrace == 10 || t.TypPrace == 15 || t.TypPrace == 18 || t.TypPrace == 23 || t.TypPrace == 27)
                                {
                                    et = ExportTyp.Holiday;
                                }
                                else if (t.TypPrace == 3 || t.TypPrace == 5 || t.TypPrace == 9 || t.TypPrace == 13 || t.TypPrace == 17 || t.TypPrace == 21 || t.TypPrace == 25)
                                {
                                    et = ExportTyp.Prescas;
                                }
                                else if (t.TypPrace == 4 || t.TypPrace == 7 || t.TypPrace == 11 || t.TypPrace == 14 || t.TypPrace == 19 || t.TypPrace == 22 || t.TypPrace == 26)
                                {
                                    et = ExportTyp.Compens;
                                }
                                else
                                {
                                    et = ExportTyp.Normal;
                                }

                                if (exportRadky.Count == 0)
                                {
                                    exportRadky.Add(new ExportRow());
                                }

                                List <int> toSkip = new List <int>();
                                if (t.CustomTerp == "")
                                {
                                    t.CustomTerp = Zakaznici.GetTerp(t.Zakaznik);
                                }
                                //když není task, tak defaultně incident 1.2.1 - nová verze by neměla umět uložit bez tasku
                                if (t.CustomTask == "")
                                {
                                    t.CustomTask = Zakaznici.Terpy.Get <NbtCompound>("Task").Get <NbtString>("Incident").Value;
                                }

                                //přiřazení ticketu ke správnému řádku a dni
                                for (int i = 0; i < exportRadky.Count; i++)
                                {
                                    if (exportRadky[i].Terp == null)
                                    {
                                        exportRadky[i].Terp = t.CustomTerp;
                                        exportRadky[i].Task = t.CustomTask;
                                        exportRadky[i].Typ  = et;
                                        exportRadky[i].Radek[den].Koment = t.ID + " " + t.Zakaznik + " " + t.Popis + "\r\n";
                                        decimal tCas = hrubyCas.Hour;
                                        if (hrubyCas.Minute == 30)
                                        {
                                            tCas += 0.5m;
                                        }
                                        exportRadky[i].Radek[den].Cas = tCas;
                                        break;
                                    }
                                    else if (exportRadky[i].Terp == t.CustomTerp && exportRadky[i].Task == t.CustomTask && exportRadky[i].Typ == et)
                                    {
                                        if ((exportRadky[i].Radek[den].Koment.Length + (t.ID + " " + t.Zakaznik + " " + t.Popis + "\r\n").Length < 240))
                                        {
                                            exportRadky[i].Radek[den].Koment += t.ID + " " + t.Zakaznik + " " + t.Popis + "\r\n";
                                            decimal tCas = hrubyCas.Hour;
                                            if (hrubyCas.Minute == 30)
                                            {
                                                tCas += 0.5m;
                                            }
                                            exportRadky[i].Radek[den].Cas += tCas;
                                            break;
                                        }
                                        else
                                        {
                                            exportRadky.Add(new ExportRow());
                                            continue;
                                        }
                                    }
                                    else if (i < exportRadky.Count - 1)
                                    {
                                        continue;
                                    }
                                    exportRadky.Add(new ExportRow());
                                }
                            }
                            catch
                            {
                                MessageBox.Show(form.jazyk.Windows_Export_Ticket + " " + t.ID + " - " + t.Zakaznik + ", " + form.jazyk.Windows_Export_NaKteremJsiPracoval + " " + t.Datum.ToString("d.MM.yyyy") + ", " + form.jazyk.Windows_Export_Neukoncen);
                            }
                        }
                    }
                }
            }

            //přepočet času na 8h
            //celkový čas normálních ticketů (statní se neupravují)
            Dictionary <string, decimal> casy = new Dictionary <string, decimal> {
                { "Pondělí", 0 }, { "Úterý", 0 }, { "Středa", 0 }, { "Čtvrtek", 0 }, { "Pátek", 0 }, { "Sobota", 0 }, { "Neděle", 0 }
            };

            foreach (ExportRow s in exportRadky)
            {
                if (s.Typ == ExportTyp.Normal)
                {
                    casy["Pondělí"] += s.Radek["Pondělí"].Cas;
                    casy["Úterý"]   += s.Radek["Úterý"].Cas;
                    casy["Středa"]  += s.Radek["Středa"].Cas;
                    casy["Čtvrtek"] += s.Radek["Čtvrtek"].Cas;
                    casy["Pátek"]   += s.Radek["Pátek"].Cas;
                    casy["Sobota"]  += s.Radek["Sobota"].Cas;
                    casy["Neděle"]  += s.Radek["Neděle"].Cas;
                }
            }

            //výběr řádků, co se upraví čas
            foreach (string cs in casy.Keys)
            {
                if (casy[cs] == 8 || casy[cs] == 0)
                {
                    continue;
                }
                else if (casy[cs] < 8)
                {
                    Dictionary <int, decimal> pridat = new Dictionary <int, decimal>();

                    for (int i = 0; i < exportRadky.Count; i++)
                    {
                        if (exportRadky[i].Typ == ExportTyp.Normal && exportRadky[i].Radek[cs].Cas > 0)
                        {
                            pridat.Add(i, exportRadky[i].Radek[cs].Cas);
                        }
                    }

                    pridat = pridat.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

                    decimal zbyva         = 8 - casy[cs];
                    decimal prumerNaRadek = Math.Ceiling((zbyva / pridat.Count) / 0.5m) * 0.5m;

                    //úprava času
                    int index = 0;
                    for (decimal d = zbyva; d > 0; d -= prumerNaRadek)
                    {
                        if (d - prumerNaRadek < 0)
                        {
                            prumerNaRadek = d;
                        }

                        pridat[pridat.Keys.ElementAt(index)] += prumerNaRadek;

                        index++;
                        zbyva -= prumerNaRadek;
                    }
                    foreach (int newI in pridat.Keys)
                    {
                        exportRadky[newI].Radek[cs].Cas = pridat[newI];
                    }
                }
                else if (casy[cs] > 8)
                {
                    Dictionary <int, decimal> ubrat = new Dictionary <int, decimal>();

                    for (int i = 0; i < exportRadky.Count; i++)
                    {
                        if (exportRadky[i].Typ == ExportTyp.Normal && exportRadky[i].Radek[cs].Cas > 0.5m)
                        {
                            ubrat.Add(i, exportRadky[i].Radek[cs].Cas);
                        }
                    }

                    ubrat = ubrat.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
                    decimal zbyva         = casy[cs] - 8;
                    decimal prumerNaRadek = Math.Ceiling((zbyva / ubrat.Count) / 0.5m) * 0.5m;

                    //úprava času
                    int index = 0;
                    for (decimal d = zbyva; d > 0; d -= prumerNaRadek)
                    {
                        if (d - prumerNaRadek < 0)
                        {
                            prumerNaRadek = d;
                        }

                        ubrat[ubrat.Keys.ElementAt(index)] -= prumerNaRadek;

                        index++;
                        zbyva -= prumerNaRadek;
                    }
                    foreach (int newI in ubrat.Keys)
                    {
                        exportRadky[newI].Radek[cs].Cas = ubrat[newI];
                    }
                }
            }

            //export do souboru
            //pro excel
            File.WriteAllBytes(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\tmp_export.xlsx", Properties.Resources.mytime_template);

            Excel.XLWorkbook   export      = new Excel.XLWorkbook(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ticketnik\\tmp_export.xlsx");
            Excel.IXLWorksheet exportSheet = export.Worksheet(1);

            NumberFormatInfo nfi = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";

            int row = 2;

            foreach (ExportRow s in exportRadky)
            {
                if (s.Terp != null)
                {
                    //project
                    exportSheet.Cell(row, 1).Value = s.Terp;
                    //project name
                    exportSheet.Cell(row, 2).Value = "najdiSiSam";
                    //task
                    exportSheet.Cell(row, 3).SetValue(s.Task);
                    //task name
                    exportSheet.Cell(row, 4).Value = "TyVisCo";
                    //type
                    exportSheet.Cell(row, 5).Value = s.GetTyp();
                    //pondělí (čas, comment)
                    exportSheet.Cell(row, 6).Value = s.Radek["Pondělí"].Cas.ToString() == "0" ? "" : s.Radek["Pondělí"].Cas.ToString(nfi);
                    exportSheet.Cell(row, 7).Value = s.Radek["Pondělí"].Koment.Replace("\t", " ").Replace("\"", "");
                    //úterý
                    exportSheet.Cell(row, 10).Value = s.Radek["Úterý"].Cas.ToString() == "0" ? "" : s.Radek["Úterý"].Cas.ToString(nfi);
                    exportSheet.Cell(row, 11).Value = s.Radek["Úterý"].Koment.Replace("\t", " ").Replace("\"", "");
                    //středa
                    exportSheet.Cell(row, 14).Value = s.Radek["Středa"].Cas.ToString() == "0" ? "" : s.Radek["Středa"].Cas.ToString(nfi);
                    exportSheet.Cell(row, 15).Value = s.Radek["Středa"].Koment.Replace("\t", " ").Replace("\"", "");
                    //čtvrtek
                    exportSheet.Cell(row, 18).Value = s.Radek["Čtvrtek"].Cas.ToString() == "0" ? "" : s.Radek["Čtvrtek"].Cas.ToString(nfi);
                    exportSheet.Cell(row, 19).Value = s.Radek["Čtvrtek"].Koment.Replace("\t", " ").Replace("\"", "");
                    //pátek
                    exportSheet.Cell(row, 22).Value = s.Radek["Pátek"].Cas.ToString() == "0" ? "" : s.Radek["Pátek"].Cas.ToString(nfi);
                    exportSheet.Cell(row, 23).Value = s.Radek["Pátek"].Koment.Replace("\t", " ").Replace("\"", "");
                    //sobota
                    exportSheet.Cell(row, 26).Value = s.Radek["Sobota"].Cas.ToString() == "0" ? "" : s.Radek["Sobota"].Cas.ToString(nfi);
                    exportSheet.Cell(row, 27).Value = s.Radek["Sobota"].Koment.Replace("\t", " ").Replace("\"", "");
                    //neděle
                    exportSheet.Cell(row, 30).Value = s.Radek["Neděle"].Cas.ToString() == "0" ? "" : s.Radek["Neděle"].Cas.ToString(nfi);
                    exportSheet.Cell(row, 31).Value = s.Radek["Neděle"].Koment.Replace("\t", " ").Replace("\"", "");

                    row++;
                }
            }

            export.Save();
            export.Dispose();

            form.infoBox.Text = "";

            saveFileDialog1.AddExtension = true;
            saveFileDialog1.DefaultExt   = "xlsx";
            saveFileDialog1.Filter       = "Excel|*.xlsx";
            saveFileDialog1.FileName     = "MyTime Info.xlsx";
            saveFileDialog1.ShowDialog();
        }
Beispiel #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            listView1.BeginUpdate();
            listView1.Items.Clear();

            if (!pouzitRegex)
            {
                //hledání
                if (form.file.RootTag.Get <NbtInt>("verze").Value < 10100)
                {
                    foreach (NbtTag c in form.file.RootTag.Get <NbtCompound>("Zakaznici"))
                    {
                        if (c.TagType != NbtTagType.Compound)
                        {
                            continue;
                        }
                        if (c.Name.ToLower().Contains(zakaznik.Text.ToLower()))
                        {
                            foreach (NbtCompound cc in (NbtCompound)c)
                            {
                                int mesic = 0;
                                switch (cc.Name)
                                {
                                case "leden":
                                    mesic = 1;
                                    break;

                                case "unor":
                                    mesic = 2;
                                    break;

                                case "brezen":
                                    mesic = 3;
                                    break;

                                case "duben":
                                    mesic = 4;
                                    break;

                                case "kveten":
                                    mesic = 5;
                                    break;

                                case "cerven":
                                    mesic = 6;
                                    break;

                                case "cervenec":
                                    mesic = 7;
                                    break;

                                case "srpen":
                                    mesic = 8;
                                    break;

                                case "zari":
                                    mesic = 9;
                                    break;

                                case "rijen":
                                    mesic = 10;
                                    break;

                                case "listopad":
                                    mesic = 11;
                                    break;

                                case "prosinec":
                                    mesic = 12;
                                    break;
                                }
                                foreach (NbtCompound ti in cc.Get <NbtList>("Tickety"))
                                {
                                    if (ti.Get <NbtString>("ID").Value.ToLower().Contains(id.Text.ToLower()) &&
                                        ti.Get <NbtString>("Kontakt").Value.ToLower().Contains(kontakt.Text.ToLower()) &&
                                        ti.Get <NbtString>("PC").Value.ToLower().Contains(pc.Text.ToLower()) &&
                                        ti.Get <NbtString>("Popis").Value.ToLower().Contains(popis.Text.ToLower()) &&
                                        ti.Get <NbtString>("Poznamky").Value.ToLower().Contains(poznamka.Text.ToLower())
                                        )
                                    {
                                        string stst = "";
                                        Color  barvaP;

                                        switch (ti.Get <NbtByte>("Stav").Value)
                                        {
                                        case (byte)Ticket.Stav.Probiha:
                                            stst   = form.jazyk.Windows_Search_Probiha;
                                            barvaP = Properties.Settings.Default.probiha;
                                            break;

                                        case (byte)Ticket.Stav.Ceka_se:
                                            stst   = form.jazyk.Windows_Search_CekaSe;
                                            barvaP = Properties.Settings.Default.ceka;
                                            break;

                                        case (byte)Ticket.Stav.RDP:
                                            stst   = form.jazyk.Windows_Search_RDP;
                                            barvaP = Properties.Settings.Default.rdp;
                                            break;

                                        case (byte)Ticket.Stav.Ceka_se_na_odpoved:
                                            stst   = form.jazyk.Windows_Search_CekaSeNa;
                                            barvaP = Properties.Settings.Default.odpoved;
                                            break;

                                        case (byte)Ticket.Stav.Vyreseno:
                                            stst = form.jazyk.Windows_Search_Hotovo;
                                            if (ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.Prescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.CustomPrescas ||
                                                ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.EnkripcePrescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.EnkripceProblemPrescas ||
                                                ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.MobilityPrescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.MobilityProblemPrescas ||
                                                ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.ProblemPrescas)
                                            {
                                                barvaP = Properties.Settings.Default.prescas;
                                            }
                                            else
                                            {
                                                barvaP = Properties.Settings.Default.vyreseno;
                                            }
                                            break;

                                        default:
                                            stst   = form.jazyk.Windows_Search_Probiha;
                                            barvaP = Properties.Settings.Default.probiha;
                                            break;
                                        }
                                        string casDoString = "";
                                        if ((new DateTime(1, 1, 1, ti.Get <NbtByte>("Do h").Value, ti.Get <NbtByte>("Do m").Value, 0)).ToString("H:mm") != "0:00")
                                        {
                                            casDoString = (new DateTime(1, 1, 1, ti.Get <NbtByte>("Do h").Value, ti.Get <NbtByte>("Do m").Value, 0)).ToString("H:mm");
                                        }

                                        string terp = "";
                                        if (ti["Terp"] != null && ti["Terp"].StringValue != "")
                                        {
                                            terp = ti["Terp"].StringValue;
                                        }
                                        else
                                        {
                                            terp = Zakaznici.GetTerp(c.Name);
                                        }

                                        if (ti["Task"] != null && ti["Task"].StringValue != "")
                                        {
                                            terp += " | " + ti["Task"].StringValue;
                                        }
                                        else
                                        {
                                            terp += " | " + DejTask(ti["ID"].StringValue);
                                        }

                                        ListViewItem lvi = new ListViewItem(new string[] { "", ti.Get <NbtString>("PC").Value, ti.Get <NbtString>("ID").Value, c.Name, ti.Get <NbtString>("Popis").Value, ti.Get <NbtString>("Kontakt").Value, new DateTime(ti.Get <NbtShort>("Rok").Value, mesic, ti.Get <NbtByte>("Den").Value).ToString("dd.M.yyyy"), terp, stst, ti.Get <NbtString>("Poznamky").Value });
                                        lvi.BackColor = barvaP;
                                        lvi.ForeColor = form.ContrastColor(barvaP);
                                        lvi.Tag       = new Tag(new DateTime(ti.Get <NbtShort>("Rok").Value, mesic, ti.Get <NbtByte>("Den").Value), ti.Get <NbtLong>("IDlong").Value);
                                        listView1.Items.Add(lvi);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (NbtCompound rok in form.file.RootTag.Get <NbtCompound>("Zakaznici"))
                    {
                        foreach (NbtTag c in rok)
                        {
                            if (c.TagType != NbtTagType.Compound)
                            {
                                continue;
                            }
                            if (c.Name.ToLower().Contains(zakaznik.Text.ToLower()))
                            {
                                foreach (NbtCompound cc in (NbtCompound)c)
                                {
                                    int mesic = 0;
                                    switch (cc.Name)
                                    {
                                    case "leden":
                                        mesic = 1;
                                        break;

                                    case "unor":
                                        mesic = 2;
                                        break;

                                    case "brezen":
                                        mesic = 3;
                                        break;

                                    case "duben":
                                        mesic = 4;
                                        break;

                                    case "kveten":
                                        mesic = 5;
                                        break;

                                    case "cerven":
                                        mesic = 6;
                                        break;

                                    case "cervenec":
                                        mesic = 7;
                                        break;

                                    case "srpen":
                                        mesic = 8;
                                        break;

                                    case "zari":
                                        mesic = 9;
                                        break;

                                    case "rijen":
                                        mesic = 10;
                                        break;

                                    case "listopad":
                                        mesic = 11;
                                        break;

                                    case "prosinec":
                                        mesic = 12;
                                        break;
                                    }
                                    foreach (NbtCompound ti in cc.Get <NbtList>("Tickety"))
                                    {
                                        if (ti.Get <NbtString>("ID").Value.ToLower().Contains(id.Text.ToLower()) &&
                                            ti.Get <NbtString>("Kontakt").Value.ToLower().Contains(kontakt.Text.ToLower()) &&
                                            ti.Get <NbtString>("PC").Value.ToLower().Contains(pc.Text.ToLower()) &&
                                            ti.Get <NbtString>("Popis").Value.ToLower().Contains(popis.Text.ToLower()) &&
                                            ti.Get <NbtString>("Poznamky").Value.ToLower().Contains(poznamka.Text.ToLower())
                                            )
                                        {
                                            string stst = "";
                                            Color  barvaP;

                                            switch (ti.Get <NbtByte>("Stav").Value)
                                            {
                                            case (byte)Ticket.Stav.Probiha:
                                                stst   = form.jazyk.Windows_Search_Probiha;
                                                barvaP = Properties.Settings.Default.probiha;
                                                break;

                                            case (byte)Ticket.Stav.Ceka_se:
                                                stst   = form.jazyk.Windows_Search_CekaSe;
                                                barvaP = Properties.Settings.Default.ceka;
                                                break;

                                            case (byte)Ticket.Stav.RDP:
                                                stst   = form.jazyk.Windows_Search_RDP;
                                                barvaP = Properties.Settings.Default.rdp;
                                                break;

                                            case (byte)Ticket.Stav.Ceka_se_na_odpoved:
                                                stst   = form.jazyk.Windows_Search_CekaSeNa;
                                                barvaP = Properties.Settings.Default.odpoved;
                                                break;

                                            case (byte)Ticket.Stav.Vyreseno:
                                                stst = form.jazyk.Windows_Search_Hotovo;
                                                if (ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.Prescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.CustomPrescas ||
                                                    ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.EnkripcePrescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.EnkripceProblemPrescas ||
                                                    ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.MobilityPrescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.MobilityProblemPrescas ||
                                                    ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.ProblemPrescas)
                                                {
                                                    barvaP = Properties.Settings.Default.prescas;
                                                }
                                                else
                                                {
                                                    barvaP = Properties.Settings.Default.vyreseno;
                                                }
                                                break;

                                            default:
                                                stst   = form.jazyk.Windows_Search_Probiha;
                                                barvaP = Properties.Settings.Default.probiha;
                                                break;
                                            }
                                            string casDoString = "";
                                            if ((new DateTime(1, 1, 1, ti.Get <NbtByte>("Do h").Value, ti.Get <NbtByte>("Do m").Value, 0)).ToString("H:mm") != "0:00")
                                            {
                                                casDoString = (new DateTime(1, 1, 1, ti.Get <NbtByte>("Do h").Value, ti.Get <NbtByte>("Do m").Value, 0)).ToString("H:mm");
                                            }
                                            string terp = "";
                                            if (ti["Terp"] != null && ti["Terp"].StringValue != "")
                                            {
                                                terp = ti["Terp"].StringValue;
                                            }
                                            else
                                            {
                                                terp = Zakaznici.GetTerp(c.Name);
                                            }

                                            if (ti["Task"] != null && ti["Task"].StringValue != "")
                                            {
                                                terp += " | " + ti["Task"].StringValue;
                                            }
                                            else
                                            {
                                                terp += " | " + DejTask(ti["ID"].StringValue);
                                            }

                                            ListViewItem lvi = new ListViewItem(new string[] { "", ti.Get <NbtString>("PC").Value, ti.Get <NbtString>("ID").Value, c.Name, ti.Get <NbtString>("Popis").Value, ti.Get <NbtString>("Kontakt").Value, new DateTime(ti.Get <NbtShort>("Rok").Value, mesic, ti.Get <NbtByte>("Den").Value).ToString("dd.M.yyyy"), terp, stst, ti.Get <NbtString>("Poznamky").Value });
                                            lvi.BackColor = barvaP;
                                            lvi.ForeColor = form.ContrastColor(barvaP);
                                            lvi.Tag       = new Tag(new DateTime(ti.Get <NbtShort>("Rok").Value, mesic, ti.Get <NbtByte>("Den").Value), ti.Get <NbtLong>("IDlong").Value);
                                            listView1.Items.Add(lvi);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                try
                {
                    //regexy tu
                    Regex regexPC       = new Regex(pc.Text, RegexOptions.IgnoreCase);
                    Regex regexID       = new Regex(id.Text, RegexOptions.IgnoreCase);
                    Regex regexZakaznik = new Regex(zakaznik.Text, RegexOptions.IgnoreCase);
                    Regex regexKontakt  = new Regex(kontakt.Text, RegexOptions.IgnoreCase);
                    Regex regexPopis    = new Regex(popis.Text, RegexOptions.IgnoreCase);
                    Regex regexPoznamka = new Regex(poznamka.Text, (RegexOptions.IgnoreCase | RegexOptions.Multiline));

                    if (form.file.RootTag.Get <NbtInt>("verze").Value < 10100)
                    {
                        foreach (NbtTag c in form.file.RootTag.Get <NbtCompound>("Zakaznici"))
                        {
                            if (c.TagType != NbtTagType.Compound)
                            {
                                continue;
                            }

                            Match matchZakaznik = regexZakaznik.Match(c.Name);

                            if (matchZakaznik.Success)
                            {
                                foreach (NbtCompound cc in (NbtCompound)c)
                                {
                                    int mesic = 0;
                                    switch (cc.Name)
                                    {
                                    case "leden":
                                        mesic = 1;
                                        break;

                                    case "unor":
                                        mesic = 2;
                                        break;

                                    case "brezen":
                                        mesic = 3;
                                        break;

                                    case "duben":
                                        mesic = 4;
                                        break;

                                    case "kveten":
                                        mesic = 5;
                                        break;

                                    case "cerven":
                                        mesic = 6;
                                        break;

                                    case "cervenec":
                                        mesic = 7;
                                        break;

                                    case "srpen":
                                        mesic = 8;
                                        break;

                                    case "zari":
                                        mesic = 9;
                                        break;

                                    case "rijen":
                                        mesic = 10;
                                        break;

                                    case "listopad":
                                        mesic = 11;
                                        break;

                                    case "prosinec":
                                        mesic = 12;
                                        break;
                                    }
                                    foreach (NbtCompound ti in cc.Get <NbtList>("Tickety"))
                                    {
                                        Match matchPC       = regexPC.Match(ti.Get <NbtString>("PC").Value);
                                        Match matchKontakt  = regexKontakt.Match(ti.Get <NbtString>("Kontakt").Value);
                                        Match matchID       = regexID.Match(ti.Get <NbtString>("ID").Value);
                                        Match matchPopis    = regexPopis.Match(ti.Get <NbtString>("Popis").Value);
                                        Match matchPoznamka = regexPoznamka.Match(ti.Get <NbtString>("Poznamky").Value);

                                        if (matchPC.Success && matchKontakt.Success && matchID.Success && matchPopis.Success && matchPoznamka.Success)
                                        {
                                            string stst = "";
                                            Color  barvaP;

                                            switch (ti.Get <NbtByte>("Stav").Value)
                                            {
                                            case (byte)Ticket.Stav.Probiha:
                                                stst   = form.jazyk.Windows_Search_Probiha;
                                                barvaP = Properties.Settings.Default.probiha;
                                                break;

                                            case (byte)Ticket.Stav.Ceka_se:
                                                stst   = form.jazyk.Windows_Search_CekaSe;
                                                barvaP = Properties.Settings.Default.ceka;
                                                break;

                                            case (byte)Ticket.Stav.RDP:
                                                stst   = form.jazyk.Windows_Search_RDP;;
                                                barvaP = Properties.Settings.Default.rdp;
                                                break;

                                            case (byte)Ticket.Stav.Ceka_se_na_odpoved:
                                                stst   = form.jazyk.Windows_Search_CekaSeNa;
                                                barvaP = Properties.Settings.Default.odpoved;
                                                break;

                                            case (byte)Ticket.Stav.Vyreseno:
                                                stst = form.jazyk.Windows_Search_Hotovo;
                                                if (ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.Prescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.CustomPrescas ||
                                                    ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.EnkripcePrescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.EnkripceProblemPrescas ||
                                                    ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.MobilityPrescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.MobilityProblemPrescas ||
                                                    ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.ProblemPrescas)
                                                {
                                                    barvaP = Properties.Settings.Default.prescas;
                                                }
                                                else
                                                {
                                                    barvaP = Properties.Settings.Default.vyreseno;
                                                }
                                                break;

                                            default:
                                                stst   = form.jazyk.Windows_Search_Probiha;
                                                barvaP = Properties.Settings.Default.probiha;
                                                break;
                                            }
                                            string casDoString = "";
                                            if ((new DateTime(1, 1, 1, ti.Get <NbtByte>("Do h").Value, ti.Get <NbtByte>("Do m").Value, 0)).ToString("H:mm") != "0:00")
                                            {
                                                casDoString = (new DateTime(1, 1, 1, ti.Get <NbtByte>("Do h").Value, ti.Get <NbtByte>("Do m").Value, 0)).ToString("H:mm");
                                            }
                                            string terp = "";
                                            if (ti["Terp"] != null && ti["Terp"].StringValue != "")
                                            {
                                                terp = ti["Terp"].StringValue;
                                            }
                                            else
                                            {
                                                terp = Zakaznici.GetTerp(c.Name);
                                            }

                                            if (ti["Task"] != null && ti["Task"].StringValue != "")
                                            {
                                                terp += " | " + ti["Task"].StringValue;
                                            }
                                            else
                                            {
                                                terp += " | " + DejTask(ti["ID"].StringValue);
                                            }
                                            ListViewItem lvi = new ListViewItem(new string[] { "", ti.Get <NbtString>("PC").Value, ti.Get <NbtString>("ID").Value, c.Name, ti.Get <NbtString>("Popis").Value, ti.Get <NbtString>("Kontakt").Value, new DateTime(ti.Get <NbtShort>("Rok").Value, mesic, ti.Get <NbtByte>("Den").Value).ToString("dd.M.yyyy"), terp, stst, ti.Get <NbtString>("Poznamky").Value });
                                            lvi.BackColor = barvaP;
                                            lvi.ForeColor = form.ContrastColor(barvaP);
                                            lvi.Tag       = new Tag(new DateTime(ti.Get <NbtShort>("Rok").Value, mesic, ti.Get <NbtByte>("Den").Value), ti.Get <NbtLong>("IDlong").Value);
                                            listView1.Items.Add(lvi);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (NbtCompound rok in form.file.RootTag.Get <NbtCompound>("Zakaznici"))
                        {
                            foreach (NbtTag c in rok)
                            {
                                if (c.TagType != NbtTagType.Compound)
                                {
                                    continue;
                                }

                                Match matchZakaznik = regexZakaznik.Match(c.Name);

                                if (matchZakaznik.Success)
                                {
                                    foreach (NbtCompound cc in (NbtCompound)c)
                                    {
                                        int mesic = 0;
                                        switch (cc.Name)
                                        {
                                        case "leden":
                                            mesic = 1;
                                            break;

                                        case "unor":
                                            mesic = 2;
                                            break;

                                        case "brezen":
                                            mesic = 3;
                                            break;

                                        case "duben":
                                            mesic = 4;
                                            break;

                                        case "kveten":
                                            mesic = 5;
                                            break;

                                        case "cerven":
                                            mesic = 6;
                                            break;

                                        case "cervenec":
                                            mesic = 7;
                                            break;

                                        case "srpen":
                                            mesic = 8;
                                            break;

                                        case "zari":
                                            mesic = 9;
                                            break;

                                        case "rijen":
                                            mesic = 10;
                                            break;

                                        case "listopad":
                                            mesic = 11;
                                            break;

                                        case "prosinec":
                                            mesic = 12;
                                            break;
                                        }
                                        foreach (NbtCompound ti in cc.Get <NbtList>("Tickety"))
                                        {
                                            Match matchPC       = regexPC.Match(ti.Get <NbtString>("PC").Value);
                                            Match matchKontakt  = regexKontakt.Match(ti.Get <NbtString>("Kontakt").Value);
                                            Match matchID       = regexID.Match(ti.Get <NbtString>("ID").Value);
                                            Match matchPopis    = regexPopis.Match(ti.Get <NbtString>("Popis").Value);
                                            Match matchPoznamka = regexPoznamka.Match(ti.Get <NbtString>("Poznamky").Value);

                                            if (matchPC.Success && matchKontakt.Success && matchID.Success && matchPopis.Success && matchPoznamka.Success)
                                            {
                                                string stst = "";
                                                Color  barvaP;

                                                switch (ti.Get <NbtByte>("Stav").Value)
                                                {
                                                case (byte)Ticket.Stav.Probiha:
                                                    stst   = form.jazyk.Windows_Search_Probiha;
                                                    barvaP = Properties.Settings.Default.probiha;
                                                    break;

                                                case (byte)Ticket.Stav.Ceka_se:
                                                    stst   = form.jazyk.Windows_Search_CekaSe;
                                                    barvaP = Properties.Settings.Default.ceka;
                                                    break;

                                                case (byte)Ticket.Stav.RDP:
                                                    stst   = form.jazyk.Windows_Search_RDP;;
                                                    barvaP = Properties.Settings.Default.rdp;
                                                    break;

                                                case (byte)Ticket.Stav.Ceka_se_na_odpoved:
                                                    stst   = form.jazyk.Windows_Search_CekaSeNa;
                                                    barvaP = Properties.Settings.Default.odpoved;
                                                    break;

                                                case (byte)Ticket.Stav.Vyreseno:
                                                    stst = form.jazyk.Windows_Search_Hotovo;
                                                    if (ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.Prescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.CustomPrescas ||
                                                        ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.EnkripcePrescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.EnkripceProblemPrescas ||
                                                        ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.MobilityPrescas || ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.MobilityProblemPrescas ||
                                                        ti.Get <NbtByte>("Prace").Value == (byte)Ticket.TypTicketu.ProblemPrescas)
                                                    {
                                                        barvaP = Properties.Settings.Default.prescas;
                                                    }
                                                    else
                                                    {
                                                        barvaP = Properties.Settings.Default.vyreseno;
                                                    }
                                                    break;

                                                default:
                                                    stst   = form.jazyk.Windows_Search_Probiha;
                                                    barvaP = Properties.Settings.Default.probiha;
                                                    break;
                                                }
                                                string casDoString = "";
                                                if ((new DateTime(1, 1, 1, ti.Get <NbtByte>("Do h").Value, ti.Get <NbtByte>("Do m").Value, 0)).ToString("H:mm") != "0:00")
                                                {
                                                    casDoString = (new DateTime(1, 1, 1, ti.Get <NbtByte>("Do h").Value, ti.Get <NbtByte>("Do m").Value, 0)).ToString("H:mm");
                                                }
                                                string terp = "";
                                                if (ti["Terp"] != null && ti["Terp"].StringValue != "")
                                                {
                                                    terp = ti["Terp"].StringValue;
                                                }
                                                else
                                                {
                                                    terp = Zakaznici.GetTerp(c.Name);
                                                }

                                                if (ti["Task"] != null && ti["Task"].StringValue != "")
                                                {
                                                    terp += " | " + ti["Task"].StringValue;
                                                }
                                                else
                                                {
                                                    terp += " | " + DejTask(ti["ID"].StringValue);
                                                }
                                                ListViewItem lvi = new ListViewItem(new string[] { "", ti.Get <NbtString>("PC").Value, ti.Get <NbtString>("ID").Value, c.Name, ti.Get <NbtString>("Popis").Value, ti.Get <NbtString>("Kontakt").Value, new DateTime(ti.Get <NbtShort>("Rok").Value, mesic, ti.Get <NbtByte>("Den").Value).ToString("dd.M.yyyy"), terp, stst, ti.Get <NbtString>("Poznamky").Value });
                                                lvi.BackColor = barvaP;
                                                lvi.ForeColor = form.ContrastColor(barvaP);
                                                lvi.Tag       = new Tag(new DateTime(ti.Get <NbtShort>("Rok").Value, mesic, ti.Get <NbtByte>("Den").Value), ti.Get <NbtLong>("IDlong").Value);
                                                listView1.Items.Add(lvi);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch { MessageBox.Show(form.jazyk.Error_RegexError); }
            }
            listView1.EndUpdate();
        }