Exemplo n.º 1
0
        public bool InitializeSQL()
        {
            //FactoryMain.Password = "******";
            if (FactoryMain.Initialize() == false)
            {
                HelperMsg.Error("Fehler beim öffnen der MySQL Verbindung!\nDies kann verschiedene Ursachen haben.\nSollte das Problem längerfristig bestehen, kontaktiere GodLesZ.", "SQL Fehler");
                return(false);
            }

            using (frmLogin frm = new frmLogin(FactoryMain.Mysql)) {
                frm.ShowDialog();
                MapControl.CanEdit = frm.HasAccess;
            }

            // disable menu Buttons
            if (MapControl.CanEdit == false)
            {
                MenuProgrammSave.Enabled        = false;
                MenuProgrammLocalBackup.Enabled = false;

                MenuProgrammSave.Visible        = false;
                MenuProgrammLocalBackup.Visible = false;
                MenuProgrammSep2.Visible        = false;
            }

            return(true);
        }
Exemplo n.º 2
0
        private void MenuProgrammReload_Click(object sender, EventArgs e)
        {
            if (MapControl.CanEdit == true && HelperMsg.Ask("Alle Änderungen gehen dadurch verloren!\n\nListe aktualisiern/neuladen?", "Änderungen gehen verloren!") == false)
            {
                return;
            }

            MapControl.RefreshAll();
        }
Exemplo n.º 3
0
        public void SavePoints(bool Backup)
        {
            bool backUped = false;

            // delete all?
            if (Points.Points.Count == 0)
            {
                string mName = Points.Map.ToName().MysqlEscape();
                if (CountMobsOnMap(mName) == 0)
                {
                    return;
                }
                if (HelperMsg.Ask("ACHTUNG\nAlle Monster der Map \"" + Points.Map.ToName() + "\" werden gelöscht!\n\nMöchtest du das tun?", "Alle Monster löschen?") != true)
                {
                    return;
                }

                if (Backup == true)
                {
                    CreateBackup();
                }
                Mysql.QuerySimple("DELETE FROM `shaiya_mob_db` WHERE mapname = '{0}'", mName);
                return;
            }

            foreach (SMobPoint p in Points.Points)
            {
                if (p.ID > 0 && p.Changed == false)
                {
                    continue;
                }

                if (Backup == true && backUped == false)
                {
                    CreateBackup();
                    backUped = true;
                }

                if (p.ID > 0)
                {
                    Mysql.QuerySimple("UPDATE `shaiya_mob_db` SET `pos_x` = {0}, `pos_y` = {1}, `name` = '{2}', `mapname` = '{3}', `level` = '{4}', `anzahl` = '{5}', `element` = '{6}', `boss` = {7}, `info` = '{8}' WHERE `id` = {9}", p.X, p.Y, p.Name.MysqlEscape(), Points.Map.ToName().MysqlEscape(), p.Level.MysqlEscape(), p.Anzahl.MysqlEscape(), p.Element.ToString(), (p.IsBoss ? 1 : 0), p.InfoDesc.MysqlEscape(), p.ID);
                }
                else
                {
                    if (PointExists(p) == false)
                    {
                        Mysql.QuerySimple("INSERT INTO `shaiya_mob_db` VALUES( NULL, {0}, {1}, '{2}', '{3}', '{4}', '{5}', '{6}', {7}, '{8}' );", p.X, p.Y, p.Name.MysqlEscape(), Points.Map.ToName().MysqlEscape(), p.Level.MysqlEscape(), p.Anzahl.MysqlEscape(), p.Element.ToString(), (p.IsBoss ? 1 : 0), p.InfoDesc.MysqlEscape());
                    }
                    else
                    {
                        HelperMsg.Error("Mob \"" + p.Name + "\" existiert schon in der Datenbank an der selben Position!\nFalls dies nicht beabsichtigt war, wende dich bitte an GodLesZ", "SQL Warnung");
                    }
                }
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> UpdateStatusAsync(IEnumerable <SmsResultJsonModel> statusSms)
        {
            List <int> notFindSms = new List <int>();

            try
            {
                bool flgUpdate = false;

                if (statusSms != null)
                {
                    foreach (var sms in statusSms)
                    {
                        var smsFromDb = await _context.JournalSms.SingleOrDefaultAsync(i => i.Id == sms.Id);

                        if (smsFromDb != null)
                        {
                            smsFromDb.Status = sms.State;

                            smsFromDb.DateSent = sms.Date;

                            flgUpdate = true;
                        }
                        else
                        {
                            notFindSms.Add(sms.Id);
                        }
                    }
                }
                else
                {
                    return(new ObjectResult("Request contains no data.")
                    {
                        StatusCode = 400
                    });
                }

                if (flgUpdate)
                {
                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                return(new ObjectResult(
                           $"{HelperMsg.GetAllMessages(ex, $"Error has occurred in {GetType().FullName} UpdateStatusAsync(statusSms)")}")
                {
                    StatusCode = 500
                });
            }

            if (notFindSms.Any())
            {
                StringBuilder notFind = new StringBuilder("SMS not found in the Database Id: ");
                foreach (var id in notFindSms)
                {
                    notFind.Append($"{id}, ");
                }

                return(new ObjectResult(notFind.ToString().TrimEnd().TrimEnd(','))
                {
                    StatusCode = 400
                });
            }


            return(new ObjectResult("Statuses have updated.")
            {
                StatusCode = 200
            });
        }
Exemplo n.º 5
0
        private async Task <IActionResult> GetSmsAsync(string date = null)
        {
            List <SmsJsonModel> result = new List <SmsJsonModel>();

            try
            {
                var smsResendOnFailures =
                    await _context.GlobalSettings.AsNoTracking().SingleOrDefaultAsync(s => s.paramName == "SmsResendOnFailures");

                if (smsResendOnFailures != null &&
                    smsResendOnFailures.paramValue == "true")
                {
                    result.AddRange(await GetSmsForResendAsync());
                }

                var maxId = await _context.JournalSms.MaxAsync(x => (int?)x.EDDSMsgId) ?? 0;

                List <EDDSMsg> eddMsgNew;

                if (string.IsNullOrEmpty(date))
                {
                    eddMsgNew = await _context.EDDSMsg
                                .AsNoTracking()
                                .Where(i => i.idMsg > maxId && (i.idMsgType == 1 || i.idMsgType == 2))
                                .ToListAsync();
                }
                else
                {
                    if (DateTime.TryParse(date, out DateTime dt))
                    {
                        eddMsgNew = await _context.EDDSMsg.AsNoTracking().Where(i =>
                                                                                i.idMsg > maxId && i.DateIn >= dt && (i.idMsgType == 1 || i.idMsgType == 2)).ToListAsync();
                    }
                    else
                    {
                        return(new ObjectResult($"The date in request is not in a valid format: {date}")
                        {
                            StatusCode = 400
                        });                     // throw new ArgumentException(nameof(date));
                    }
                }


                var phones = await _context.Phone
                             .AsNoTracking()
                             .Include(t => t.PhoneTypeStatusSmis)
                             .ThenInclude(c => c.TypeStatusSmis)
                             .Select(p => new { p.Id, p.PhoneTypeStatusSmis })
                             .ToListAsync();

                List <JournalSms> listSmsNew = new List <JournalSms>();

                foreach (var smsNew in eddMsgNew)
                {
                    var smsXml = GetSmsXml(smsNew.MsgText);

                    if (smsXml == null)
                    {
                        continue;
                    }

                    foreach (var phone in phones)
                    {
                        var status = phone.PhoneTypeStatusSmis.SingleOrDefault(s =>
                                                                               s.TypeStatusSmis.Code == smsXml.IncidentStatus);


                        if (status == null)
                        {
                            continue;
                        }

                        listSmsNew.Add(new JournalSms
                        {
                            Text      = GetTextSms(status, smsXml),
                            PhoneId   = phone.Id,
                            DateSent  = DateTime.Now,
                            EDDSMsgId = smsNew.idMsg,
                            Status    = -1
                        });
                    }
                }

                // Save to DB
                if (listSmsNew.Any())
                {
                    await _context.JournalSms.AddRangeAsync(listSmsNew);

                    await _context.SaveChangesAsync();


                    foreach (var sms in listSmsNew)
                    {
                        result.Add(new SmsJsonModel
                        {
                            Id      = sms.Id,
                            Message = sms.Text,
                            Phone   = sms.Phone.PhoneNumber
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new ObjectResult(
                           $"{HelperMsg.GetAllMessages(ex, $"Error has occurred in {GetType().FullName} GetSmsAsync(date)")}")
                {
                    StatusCode = 500
                });
            }

            return(new ObjectResult(result)
            {
                StatusCode = 200
            });
        }