77 lines
3.1 KiB
C#
77 lines
3.1 KiB
C#
using MySql.Data.MySqlClient;
|
|
using Newtonsoft.Json;
|
|
using PoEco.Net.DB;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.Metrics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
using static PoEco.Net.JSON.Stash;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
|
|
namespace PoEco.Net.JSON
|
|
{
|
|
internal class Currency
|
|
{
|
|
public static MySqlConnection MxPoEDB()
|
|
{
|
|
MySqlConnection conn;
|
|
string myConnectionString;
|
|
|
|
myConnectionString = $"server={JSON.Settings.GetdbHost()};port={JSON.Settings.GetdbPort()};uid={JSON.Settings.GetdbUser()};pwd={JSON.Settings.GetdbPass()};database={JSON.Settings.GetdbName()};";
|
|
conn = new MySqlConnection();
|
|
conn.ConnectionString = myConnectionString;
|
|
return conn;
|
|
}
|
|
public static void GenCurrencyTab(string user, int tab, string columnname, string table)
|
|
{
|
|
int uid = DB.User.GetUserID(user);
|
|
double chaosValue = 0;
|
|
string curName = "";
|
|
StashRoot stash = JsonConvert.DeserializeObject<StashRoot>(File.ReadAllText($@"data/stash/{user}.tab.{tab}.json"));
|
|
foreach (Stash.Item i in stash.items)
|
|
{
|
|
if (columnname == "divvalue")
|
|
{
|
|
//Console.WriteLine(MySqlHelper.EscapeString(i.typeLine)+" "+GetCurrencyValueByName(MySqlHelper.EscapeString(curName), table));
|
|
MySqlConnection cond = MxPoEDB();
|
|
string cmdTextd = $"INSERT INTO poeco_tab_div(uid, uiid, name, stack, cvalue) VALUES ('{uid}','{i.id}','{MySqlHelper.EscapeString(i.typeLine)}','{i.stackSize}','{GetCurrencyValueByName(MySqlHelper.EscapeString(curName), table)}')";
|
|
MySqlCommand cmdd = new MySqlCommand(cmdTextd, cond);
|
|
cond.Open();
|
|
cmdd.ExecuteNonQuery();
|
|
cond.Close();
|
|
}
|
|
curName = i.typeLine;
|
|
chaosValue = chaosValue + (GetCurrencyValueByName(MySqlHelper.EscapeString(curName), table) * i.stackSize);
|
|
}
|
|
MySqlConnection con = MxPoEDB();
|
|
string cmdText = $"UPDATE poeco_user SET {columnname} = '{chaosValue}' WHERE account = '{user}'";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
cmd.ExecuteNonQuery();
|
|
con.Close();
|
|
}
|
|
public static double GetCurrencyValueByName(string name, string table)
|
|
{
|
|
using (var con = MxPoEDB())
|
|
{
|
|
string cmdText = $"SELECT * FROM {table} WHERE name = '{name}'";
|
|
MySqlCommand cmd = new MySqlCommand(cmdText, con);
|
|
con.Open();
|
|
var row = cmd.ExecuteReader();
|
|
if (name == "Chaos Orb")
|
|
{
|
|
return 1.0;
|
|
} else
|
|
{
|
|
if (row.HasRows) { row.Read(); return Convert.ToDouble(row["vchaos"]); } else { return 0; }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|