Example #1
0
        public void saveDiaryEntry(HeroDiaryEntry DiaryEntry)
        {
            try
            {
                using (SQLiteConnection conn = new SQLiteConnection(@"Data Source=" + dbPath + @"\gv.db;Version=3;New=False;Compress=True;"))
                {
                    conn.Open();
                    using (SQLiteCommand cmd = conn.CreateCommand())
                    {
                        string commandText = "select count(*) as diarycount from Diary where HeroName=@HeroName and EntryTime=@EntryTime and Entry=@Entry and Updated >= @Updated";
                        cmd.Parameters.AddWithValue("@HeroName", this.Name);
                        cmd.Parameters.AddWithValue("@EntryTime", DiaryEntry.TimeStamp);
                        cmd.Parameters.AddWithValue("@Entry", DiaryEntry.Content);
                        cmd.Parameters.AddWithValue("@Updated", DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss"));

                        cmd.CommandText = commandText;
                        cmd.CommandType = CommandType.Text;
                        object ret = cmd.ExecuteScalar();
                        if (int.Parse((ret == null) ? "0" : ret.ToString()) == 0)
                        {
                            cmd.Parameters.Clear();
                            commandText = "insert into Diary (HeroName, Updated, EntryTime, Entry) values (@HeroName, @Updated, @EntryTime, @Entry)";
                            cmd.Parameters.AddWithValue("@HeroName", this.Name);
                            cmd.Parameters.AddWithValue("@Updated", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                            cmd.Parameters.AddWithValue("@EntryTime", DiaryEntry.TimeStamp);
                            cmd.Parameters.AddWithValue("@Entry", DiaryEntry.Content);

                            cmd.CommandText = commandText;
                            cmd.CommandType = CommandType.Text;
                            cmd.ExecuteNonQuery();
                        }
                        DiaryEntry.Saved = true;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                throw;
            }
        }
Example #2
0
        public void saveDiaryEntry(HeroDiaryEntry DiaryEntry)
        {
            try
            {
                using (SQLiteConnection conn = new SQLiteConnection(@"Data Source=" + dbPath + @"\gv.db;Version=3;New=False;Compress=True;"))
                {
                    conn.Open();
                    using (SQLiteCommand cmd = conn.CreateCommand())
                    {
                        string commandText = "select count(*) as diarycount from Diary where HeroName=@HeroName and EntryTime=@EntryTime and Entry=@Entry and Updated >= @Updated";
                        cmd.Parameters.AddWithValue("@HeroName", this.Name);
                        cmd.Parameters.AddWithValue("@EntryTime", DiaryEntry.TimeStamp);
                        cmd.Parameters.AddWithValue("@Entry", DiaryEntry.Content);
                        cmd.Parameters.AddWithValue("@Updated", DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss"));

                        cmd.CommandText = commandText;
                        cmd.CommandType = CommandType.Text;
                        object ret = cmd.ExecuteScalar();
                        if (int.Parse((ret == null) ? "0" : ret.ToString()) == 0)
                        {
                            cmd.Parameters.Clear();
                            commandText = "insert into Diary (HeroName, Updated, EntryTime, Entry) values (@HeroName, @Updated, @EntryTime, @Entry)";
                            cmd.Parameters.AddWithValue("@HeroName", this.Name);
                            cmd.Parameters.AddWithValue("@Updated", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                            cmd.Parameters.AddWithValue("@EntryTime", DiaryEntry.TimeStamp);
                            cmd.Parameters.AddWithValue("@Entry", DiaryEntry.Content);

                            cmd.CommandText = commandText;
                            cmd.CommandType = CommandType.Text;
                            cmd.ExecuteNonQuery();
                        }
                        DiaryEntry.Saved = true;
                    }
                }

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                throw;
            }
        }
Example #3
0
        public void getHero(string heroName)
        {
            try
            {
                using (SQLiteConnection conn = new SQLiteConnection(@"Data Source=" + dbPath + @"\gv.db;Version=3;New=False;Compress=True;"))
                {
                    conn.Open();
                    using (SQLiteCommand cmd = conn.CreateCommand())
                    {
                        string commandText = "select * from Hero where Name=@HeroName order by id desc limit 1";
                        cmd.Parameters.AddWithValue("@HeroName", !String.IsNullOrEmpty(heroName) ? heroName : this.Name);
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = commandText;

                        SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
                        DataSet ds = new DataSet();
                        da.Fill(ds);

                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                DataRow row = ds.Tables[0].Rows[0];

                                this.Updated = DateTime.Parse(row["Updated"].ToString());
                                this.Name = row["Name"].ToString();
                                this.Motto = row["Motto"].ToString();
                                this.Personality = row["Personality"].ToString();
                                this.Guild = row["Guild"].ToString();
                                this.GuildRank = row["GuildRank"].ToString();
                                this.Level = int.Parse(row["Level"].ToString());
                                this.Inventory = int.Parse(row["Inventory"].ToString());
                                this.MaxInventory = int.Parse(row["MaxInventory"].ToString());
                                this.Quest = row["Quest"].ToString();
                                this.QuestPercent = int.Parse(row["QuestPercent"].ToString());
                                this.Gold = int.Parse(row["Gold"].ToString());
                                this.MonstersKilled = int.Parse(row["MonstersKilled"].ToString());
                                this.DeathCount = int.Parse(row["DeathCount"].ToString());
                                this.Wins = int.Parse(row["Wins"].ToString());
                                this.Losses = int.Parse(row["Losses"].ToString());
                                this.Bricks = row["Bricks"].ToString();
                                this.TownName = row["TownName"].ToString();
                                this.MilestonesPassed = int.Parse(row["MilestonesPassed"].ToString());
                                this.GodPower = int.Parse(row["GodPower"].ToString());
                                this.Weapon = row["Weapon"].ToString();
                                this.Shield = row["Shield"].ToString();
                                this.Head = row["Head"].ToString();
                                this.Body = row["Body"].ToString();
                                this.Arms = row["Arms"].ToString();
                                this.Legs = row["Legs"].ToString();
                                this.Talisman = row["Talisman"].ToString();

                                this.Gratitude = int.Parse(row["Gratitude"].ToString());
                                this.Unity = int.Parse(row["Unity"].ToString());
                                this.Might = int.Parse(row["Might"].ToString());
                                this.Greed = int.Parse(row["Greed"].ToString());
                                this.Construction = int.Parse(row["Construction"].ToString());
                                this.Taming = int.Parse(row["Taming"].ToString());
                                this.Gladiatorship = int.Parse(row["Gladiatorship"].ToString());
                                this.Creation = int.Parse(row["Creation"].ToString());
                                this.Destruction = int.Parse(row["Destruction"].ToString());
                            }
                        }
                        //and Updated >= @Updated

                        cmd.Parameters.Clear();
                        cmd.CommandText = "select * from Diary where HeroName=@HeroName order by Diary_ID limit 10";
                        cmd.Parameters.AddWithValue("@HeroName", this.Name);
                        //cmd.Parameters.AddWithValue("@Updated", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

                        da = new SQLiteDataAdapter(cmd);
                        ds = new DataSet();
                        da.Fill(ds);

                        if (ds.Tables.Count > 0)
                        {
                            foreach (DataRow row in ds.Tables[0].Rows)
                            {
                                HeroDiaryEntry entry = new HeroDiaryEntry();
                                entry.TimeStamp = row["EntryTime"].ToString();
                                entry.Content = row["Entry"].ToString();
                                entry.Saved = true;
                                this.DiaryEntries.Insert(0, entry);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                throw;
            }
        }
        private bool heroDiary()
        {
            // Parse the Hero's diary
            bool newestAtTop = false;

            try
            {
                HtmlElement elem = webBrowser1.Document.GetElementById("news");
                if (elem != null)
                {
                    if (elem.Children.Count > 1)
                    {

                        HtmlElementCollection spans = webBrowser1.Document.GetElementsByTagName("SPAN");
                        foreach (HtmlElement span in spans)
                        {
                            if (span.Title().Equals("Change diary sort order", StringComparison.InvariantCultureIgnoreCase))
                            {
                                string temp = span.InnerText;
                                newestAtTop = (temp == "▼");
                                break;
                            }
                        }

                        HtmlElementCollection items = webBrowser1.Document.GetElementById("diary").Children[1].Children[0].Children[0].Children;
                        bool itemAdded = false;
                        int insertionPoint = hero.DiaryEntries.Count;
                        foreach (HtmlElement item in items)
                        {
                            HeroDiaryEntry entry = new HeroDiaryEntry();
                            entry.TimeStamp =item.Children[0].InnerText;
                            entry.Content = item.Children[1].InnerText;
                            entry.Saved = true;
                            if (!hero.DiaryEntries.Contains(entry))
                            {
                                entry.Saved = false;
                                if (newestAtTop)
                                    hero.DiaryEntries.Insert(insertionPoint, entry);
                                else
                                    hero.DiaryEntries.Add(entry);

                                itemAdded = true;
                            }
                        }

                        if (itemAdded)
                        {
                            for (int i = 0; i < hero.DiaryEntries.Count; i++)
                            {
                                HeroDiaryEntry diaryItem = hero.DiaryEntries[i];
                                if (!diaryItem.Saved)
                                {
                                    hero.saveDiaryEntry(diaryItem);
                                    diaryItem.Saved = true;
                                    hero.DiaryEntries[i] = diaryItem;
                                }
                            }
                        }
                        if (hero.DiaryEntries.Count > 0)
                            tbxDiary.Text = hero.DiaryEntries[hero.DiaryEntries.Count - 1].Content;
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                throw;
            }
        }
 private void syncDiaryAndNews()
 {
     // Sync the existing diary entries from the Old Hero to the current hero
     if (hero.DiaryEntries.Count == 0)
     {
         foreach (HeroDiaryEntry oldEntry in oldHero.DiaryEntries)
         {
             HeroDiaryEntry newEntry = new HeroDiaryEntry();
             newEntry.Content = oldEntry.Content;
             newEntry.Saved = true;
             newEntry.TimeStamp = oldEntry.TimeStamp;
             hero.DiaryEntries.Add(newEntry);
         }
     }
 }
Example #6
0
        public void getHero(string heroName)
        {
            try
            {
                using (SQLiteConnection conn = new SQLiteConnection(@"Data Source=" + dbPath + @"\gv.db;Version=3;New=False;Compress=True;"))
                {
                    conn.Open();
                    using (SQLiteCommand cmd = conn.CreateCommand())
                    {
                        string commandText = "select * from Hero where Name=@HeroName order by id desc limit 1";
                        cmd.Parameters.AddWithValue("@HeroName", !String.IsNullOrEmpty(heroName) ? heroName : this.Name);
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = commandText;

                        SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
                        DataSet           ds = new DataSet();
                        da.Fill(ds);

                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                DataRow row = ds.Tables[0].Rows[0];

                                this.Updated          = DateTime.Parse(row["Updated"].ToString());
                                this.Name             = row["Name"].ToString();
                                this.Motto            = row["Motto"].ToString();
                                this.Personality      = row["Personality"].ToString();
                                this.Guild            = row["Guild"].ToString();
                                this.GuildRank        = row["GuildRank"].ToString();
                                this.Level            = int.Parse(row["Level"].ToString());
                                this.Inventory        = int.Parse(row["Inventory"].ToString());
                                this.MaxInventory     = int.Parse(row["MaxInventory"].ToString());
                                this.Quest            = row["Quest"].ToString();
                                this.QuestPercent     = int.Parse(row["QuestPercent"].ToString());
                                this.Gold             = int.Parse(row["Gold"].ToString());
                                this.MonstersKilled   = int.Parse(row["MonstersKilled"].ToString());
                                this.DeathCount       = int.Parse(row["DeathCount"].ToString());
                                this.Wins             = int.Parse(row["Wins"].ToString());
                                this.Losses           = int.Parse(row["Losses"].ToString());
                                this.Bricks           = row["Bricks"].ToString();
                                this.TownName         = row["TownName"].ToString();
                                this.MilestonesPassed = int.Parse(row["MilestonesPassed"].ToString());
                                this.GodPower         = int.Parse(row["GodPower"].ToString());
                                this.Weapon           = row["Weapon"].ToString();
                                this.Shield           = row["Shield"].ToString();
                                this.Head             = row["Head"].ToString();
                                this.Body             = row["Body"].ToString();
                                this.Arms             = row["Arms"].ToString();
                                this.Legs             = row["Legs"].ToString();
                                this.Talisman         = row["Talisman"].ToString();

                                this.Gratitude     = int.Parse(row["Gratitude"].ToString());
                                this.Unity         = int.Parse(row["Unity"].ToString());
                                this.Might         = int.Parse(row["Might"].ToString());
                                this.Greed         = int.Parse(row["Greed"].ToString());
                                this.Construction  = int.Parse(row["Construction"].ToString());
                                this.Taming        = int.Parse(row["Taming"].ToString());
                                this.Gladiatorship = int.Parse(row["Gladiatorship"].ToString());
                                this.Creation      = int.Parse(row["Creation"].ToString());
                                this.Destruction   = int.Parse(row["Destruction"].ToString());
                            }
                        }
                        //and Updated >= @Updated

                        cmd.Parameters.Clear();
                        cmd.CommandText = "select * from Diary where HeroName=@HeroName order by Diary_ID limit 10";
                        cmd.Parameters.AddWithValue("@HeroName", this.Name);
                        //cmd.Parameters.AddWithValue("@Updated", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

                        da = new SQLiteDataAdapter(cmd);
                        ds = new DataSet();
                        da.Fill(ds);

                        if (ds.Tables.Count > 0)
                        {
                            foreach (DataRow row in ds.Tables[0].Rows)
                            {
                                HeroDiaryEntry entry = new HeroDiaryEntry();
                                entry.TimeStamp = row["EntryTime"].ToString();
                                entry.Content   = row["Entry"].ToString();
                                entry.Saved     = true;
                                this.DiaryEntries.Insert(0, entry);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                throw;
            }
        }