forked from Sagleft/utopia-custom-cryptocards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogic.cs
More file actions
111 lines (94 loc) · 2.68 KB
/
Copy pathLogic.cs
File metadata and controls
111 lines (94 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace UtopiaCryptocards
{
public partial class MainForm : Form
{
void showMessage(string info = "") {
MessageBox.Show(info, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
bool isClientConnected() {
bool is_connected;
if(client == null) {
is_connected = false;
} else {
is_connected = client.checkClientConnection();
}
if(!is_connected) {
printToLog("No active client connection");
}
return is_connected;
}
void updateCardsList() {
if(!isClientConnected()) { return; }
//int image_index = 0;
listBox1.Items.Clear();
JArray cards_arr = client.getCards();
for(int i=0; i < cards_arr.Count; i++) {
JObject card_info = cards_arr[i] as JObject;
string cardID = card_info["cardid"].ToString();
listBox1.Items.Add(cardID);
if(cards_arr.Count > 0) {
listBox1.SelectedIndex = 0;
loadCardInfo();
}
}
}
void loadCardInfo() {
int card_index = listBox1.SelectedIndex;
string cardID = listBox1.Items[card_index].ToString();
if(card_index >= 0) {
JObject card_info = client.getCardInfo(cardID);
cardDataID.Text = cardID;
cardDataBalance.Text = card_info["balance"].ToString() + " CRP";
cardDataCreated.Text = card_info["created"].ToString();
cardDataColor.Text = card_info["color"].ToString();
cardDataName.Text = card_info["name"].ToString();
}
}
void ListBox1SelectedIndexChanged(object sender, EventArgs e)
{
loadCardInfo();
}
void BtnChooseColorClick(object sender, EventArgs e)
{
Color new_color;
DialogResult result = colorDialog1.ShowDialog();
if(result == DialogResult.OK) {
new_color = colorDialog1.Color;
string hex = new_color.R.ToString("X2") + new_color.G.ToString("X2") + new_color.B.ToString("X2");
newCardColor.Text = hex;
}
}
void BtnColorsGoldClick(object sender, EventArgs e)
{
newCardColor.Text = "FFD700";
}
void BtnColorsBlackClick(object sender, EventArgs e)
{
newCardColor.Text = "000000";
}
void BtnColorsGreenClick(object sender, EventArgs e)
{
newCardColor.Text = "39db7f";
}
void BtnCreateCardClick(object sender, EventArgs e)
{
if(!isClientConnected()) {
showMessage("No active client connection");
return;
}
string result = client.addCard(newCardName.Text, newCardColor.Text, newCardCharacters.Text);
updateCardsList();
showMessage("OK! cardID: " + result);
}
void ButtonClearLogClick(object sender, EventArgs e)
{
textBox_connectionLog.Clear();
}
}
}