Beispiel #1
0
        public static Dictionary <string, DayAva> ReadAllDefault()
        {
            var all        = DayAva.ReadAll();
            var allDefault = new Dictionary <string, DayAva>();

            foreach (var ava in all.Values)
            {
                var copy = new DayAva(
                    ava.DirsID,
                    ava.Date,
                    RoomCount.GetCount(ava.DirsID)
                    );

                allDefault.Add(
                    copy.Id,
                    copy
                    );
            }

            return(allDefault);
        }
Beispiel #2
0
        public static void RunWrite()
        {
            try
            {
                StatusInfo.StatusRunning = true;

                DateTime lastUpdate = DateTime.Parse((string)Program.AddIn.Query("SELECT MAX(updated_on) FROM b_buchungen").Rows[0][0]);

                if (lastUpdate == _lastUpdate)
                {
                    _thread = null;
                    StatusInfo.StatusRunning = false;
                    StatusInfo.WriteLine("Verfügbarkeiten senden: Keine veränderten Buchungen");

                    return;
                }
                _lastUpdate = lastUpdate;

                Dictionary <string, DayAva> avaNew    = DayAva.ReadAllDefault();
                Dictionary <string, DayAva> avaOnline = DayAva.ReadAll();

                DataTable table = _query();

                StatusInfo.StatusGroup = "Errechnen der neuen Verfügbarkeiten...";

                int c = 0, p = 0, a = table.Rows.Count;
                foreach (DataRow row in table.Rows)
                {
                    int      dirsId   = Int16.Parse(row["dirsid"].ToString());
                    DateTime arrival  = DateTime.Parse(row["arrival"].ToString());
                    DateTime depature = DateTime.Parse(row["depature"].ToString());

                    for (DateTime date = arrival; date < depature; date = date.AddDays(1))
                    {
                        string id = DayAva.GetID(date, dirsId);

                        if (!avaNew.ContainsKey(id))
                        {
                            var day = new DayAva(dirsId, date, RoomCount.GetCount(dirsId));

                            avaNew.Add(
                                day.Id,
                                day
                                );
                        }

                        avaNew[id].Value -= 1;
                    }

                    p = (int)((100.0f / a) * c);

                    StatusInfo.StatusLabel    = String.Format("Buchung: {0} von {1}", c, a);
                    StatusInfo.StatusProgress = p;

                    c++;
                }

                StatusInfo.StatusGroup = "Differenzen senden...";

                var dirs21 = new dirs21.DIRS21PMSInterface();
                var knr    = Settings.GetSetting <int>("dirs21.knr");
                var pwd    = Settings.GetSetting <string>("dirs21.pwd");

                int send = 0;
                c = 0;
                a = avaNew.Count;
                foreach (var id in avaNew.Keys.ToArray())
                {
                    if (!avaOnline.ContainsKey(id) || avaNew[id].Value != avaOnline[id].Value)
                    {
                        var ava = avaNew[id];

                        try
                        {
                            dirs21.WriteAvailabilities(
                                knr,
                                pwd,
                                ava.DirsID,
                                ava.Date.ToString("dd.MM.yyyy"),
                                ava.Date.ToString("dd.MM.yyyy"),
                                ava.Value
                                );

                            send++;
                        }
                        catch
                        {
                            MessageBox.Show(
                                String.Format(
                                    "Datensatz konnte nicht an Dirs21 gesendet werden. Bitte tragen Sie die Werte manuell ein.\n\nDirsID: {0}\nDatum: {1}\nWert: {2}",
                                    ava.DirsID,
                                    ava.Date.ToString("dd.MM.yyyy"),
                                    ava.Value
                                    ),
                                "Fehler",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error
                                );
                        }
                    }

                    p = (int)((100.0f / a) * c);

                    StatusInfo.StatusLabel    = String.Format("Datensatz: {0} von {1}", c, a);
                    StatusInfo.StatusProgress = p;

                    c++;
                }
                dirs21.Dispose();

                StatusInfo.StatusGroup    = "Speichern der Daten...";
                StatusInfo.StatusLabel    = "Bitte Warten";
                StatusInfo.StatusProgress = -1;

                DayAva.SaveAll(avaNew);

                StatusInfo.StatusRunning = false;
                StatusInfo.WriteLine("Verfügbarkeiten senden: " + send + " Veränderungen gesendet.");
            }
            finally
            {
                _thread = null;
            }
        }