/
RecordLootDialog.cs
489 lines (439 loc) · 20.6 KB
/
RecordLootDialog.cs
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace ES_DKP_Utils
{
public class RecordLootDialog : System.Windows.Forms.Form
{
#region Component Delcarations
private System.Windows.Forms.Label lblRaid;
private System.Windows.Forms.Label lblRaidName;
private System.Windows.Forms.Label lblRaidDate;
private System.Windows.Forms.Label lblDate;
private System.Windows.Forms.Label lblLoot;
private System.Windows.Forms.Label lblPerson;
private System.Windows.Forms.Label lblPrice;
private System.Windows.Forms.ComboBox cboPeople;
private System.Windows.Forms.ComboBox cboLoot;
private System.Windows.Forms.ComboBox cboPrice;
private System.Windows.Forms.Button btnRecord;
private System.Windows.Forms.Label lblStatus;
private System.Windows.Forms.Button btnClose;
private System.ComponentModel.Container components = null;
#endregion
#region Other Declarations
private OleDbConnection dbConnect;
private OleDbDataAdapter dkpDA;
private OleDbCommandBuilder cmdBld;
private DataTable dtPeople;
private DataTable dtLoot;
private int price;
private int looter;
private int loot;
private string lootName;
private string lootCost;
private bool lootEntered;
private bool nameEntered;
private bool priceEntered;
private frmMain owner;
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Constructors
public RecordLootDialog()
{
log.Debug("Begin Method: frmRecordLoot.frmRecordLoot()");
InitializeComponent();
log.Debug("End Method: frmRecordLoot.frmRecordLoot()");
}
public RecordLootDialog(frmMain owner, string name, string date)
{
log.Debug("Begin Method: frmRecordLoot.frmRecordLoot(frmMain,string,string) (" + owner.ToString()
+ "," + name.ToString() + "," + date.ToString() + ")");
InitializeComponent();
this.owner = owner;
lblRaidName.Text = name;
lblRaidDate.Text = date;
string connectionStr;
connectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + owner.DBString;
try { dbConnect = new OleDbConnection(connectionStr); }
catch (Exception ex)
{
log.Error("Failed to open data connection: " + ex.Message);
MessageBox.Show("Could not create data connection. \n(" + ex.Message + ")", "Error");
}
try
{
this.dtPeople = new DataTable("People");
this.dtLoot = new DataTable("Loot");
dkpDA = new OleDbDataAdapter("SELECT DISTINCT DKS.Name FROM DKS", dbConnect);
dbConnect.Open();
dkpDA.Fill(dtPeople);
dkpDA = new OleDbDataAdapter("SELECT * FROM LootDKP ORDER BY LootName ASC", dbConnect);
cmdBld = new OleDbCommandBuilder(dkpDA);
dkpDA.Fill(dtLoot);
}
catch (Exception ex)
{
log.Error("Failed to load loot tables: " + ex.Message);
MessageBox.Show("Could not open data connection. \n(" + ex.Message + ")", "Error");
}
finally { dbConnect.Close(); }
dtPeople.Rows.Add(new object[] { "*** Select" });
dtLoot.Rows.Add(new object[] { "*** Select", 0 });
DataView dvP = new DataView(dtPeople, "", "Name ASC", DataViewRowState.CurrentRows);
DataView dvL = new DataView(dtLoot, "", "LootName ASC", DataViewRowState.CurrentRows);
cboPrice.DataSource = dvL;
cboPrice.DisplayMember = "DKP";
cboPeople.DataSource = dvP;
cboPeople.DisplayMember = "Name";
cboLoot.DataSource = dvL;
cboLoot.DisplayMember = "LootName";
log.Debug("End Method: frmRecordLoot.frmLootRecord()");
}
#endregion
#region Events
private void cboLoot_SelectedIndexChanged(object sender, System.EventArgs e)
{
log.Debug("Begin Method: cboLoot_SelectedIndexChanged(object,EventArgs) (" + sender.ToString() + "," + e.ToString() + ")");
string s = "Changed cboPrice.Selected Index from " + cboPrice.SelectedIndex + " to ";
cboPrice.SelectedIndex = cboLoot.SelectedIndex;
log.Debug(s + cboPrice.SelectedIndex);
log.Debug("End Method: cboLoot_SelectedIndexChanged()");
}
private void cboPeople_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
log.Debug("Begin Method: cboPeople_KeyPress(object,KeyPressEventArgs) (" + sender.ToString() + "," + e.ToString() + ")");
if (e.KeyChar >= 'A' && e.KeyChar <= 'z')
{
cboPeople.DroppedDown = true;
}
if (e.KeyChar == 13)
{
string s = "Enter key pressed in cboPeople. cboPeople.SelectedIndex before = " + cboPeople.SelectedIndex;
cboPeople.SelectedIndex = cboPeople.FindString(cboPeople.Text);
s += ", after = " + cboPeople.SelectedIndex;
if (cboPeople.SelectedIndex == -1) { cboPeople.SelectedIndex = 0; s += ". Reset to 0"; }
log.Debug(s);
looter = cboPeople.SelectedIndex;
nameEntered = true;
cboPrice.Focus();
}
log.Debug("End Method: cboPeople_KeyPress()");
}
private void cboPeople_Leave(object sender, System.EventArgs e)
{
log.Debug("Begin Method: cboPeople_Leave(object,EventArgs) (" + sender.ToString() + "," + e.ToString() + ")");
if (!nameEntered)
{
string s = "cboPeople leaving focus, Text before = " + cboPeople.Text;
cboPeople.SelectedIndex = cboPeople.FindString(cboPeople.Text);
s += ", after = " + cboPeople.Text + " (" + cboPeople.SelectedIndex + ")";
if (cboPeople.SelectedIndex == -1) { cboPeople.SelectedIndex = 0; s += " Reset to 0"; }
log.Debug(s);
looter = cboPeople.SelectedIndex;
}
log.Debug("End Method: cboPeople_Leave()");
}
private void cboLoot_Leave(object sender, System.EventArgs e)
{
log.Debug("Begin Method: cboLoot_Leave(object,EventArgs) (" + sender.ToString() + "," + e.ToString() + ")");
if (!lootEntered)
{
string s = "cboLoot leaving focus, Text before = " + cboLoot.Text;
cboLoot.SelectedIndex = cboLoot.FindString(cboLoot.Text);
s += ", after = " + cboLoot.Text + " (" + cboLoot.SelectedIndex + ")";
loot = cboLoot.SelectedIndex;
log.Debug(s);
lootName = cboLoot.Text;
}
log.Debug("End Method: cboLoot_Leave()");
}
private void cboLoot_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
log.Debug("Begin Method: cboLoot_KeyPress(object,KeyPressEventArgs) (" + sender.ToString() + "," + e.ToString() + ")");
if (e.KeyChar >= 'A' && e.KeyChar <= 'z')
{
cboLoot.DroppedDown = true;
}
if (e.KeyChar == 13)
{
string s = "Enter key pressed in cboLoot. cboLoot.Text before = " + cboLoot.Text;
cboLoot.SelectedIndex = cboLoot.FindString(cboLoot.Text);
s += ", after = " + cboLoot.Text + " (" + cboLoot.SelectedIndex + ")";
loot = cboLoot.SelectedIndex;
log.Debug(s);
lootName = cboLoot.Text;
lootEntered = true;
cboPeople.Focus();
}
log.Debug("End Method: cboLoot_KeyPress()");
}
private void cboPrice_Leave(object sender, System.EventArgs e)
{
log.Debug("Begin Method: cboPrice_Leave(object,EventArgs) (" + sender.ToString() + "," + e.ToString() + ")");
if (!priceEntered) lootCost = cboPrice.Text;
log.Debug("End Method: cboPrice_Leave()");
}
private void cboPrice_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
log.Debug("Begin Method: cboPrice_KeyPress(object,KeyPressEventArgs) (" + sender.ToString() + "," + e.ToString() + ")");
if (e.KeyChar == 13)
{
log.Debug("Enter key pressed in cboPrice, Text = " + cboPrice.Text);
lootCost = cboPrice.Text;
priceEntered = true;
btnRecord.Focus();
}
log.Debug("Begin Method: cboPrice_KeyPress()");
}
private void btnRecord_Click(object sender, System.EventArgs e)
{
log.Debug("Begin Method: btnRecord_Click(object,EventArgs) (" + sender.ToString() + "," + e.ToString() + ")");
log.Info("Upon entering btnRecord_Click, looter = " + looter + ", loot = " + loot + "," +
"cboPeople.Text = " + cboPeople.Text + " (" + cboPeople.SelectedIndex + "), cboLoot.Text = " + cboLoot.Text + " (" + cboLoot.SelectedIndex + ")," +
"cboPrice.Text = " + cboPrice.Text + " (" + cboPrice.SelectedIndex + ")");
if (looter <= 0 || loot == 0)
{
MessageBox.Show("Enter name and/or loot.", "Error");
return;
}
cboPeople.SelectedIndex = looter;
cboLoot.SelectedIndex = loot;
if (loot != -1) lootName = cboLoot.Text;
if (lootCost == null) cboPrice_Leave(new object(), new EventArgs());
nameEntered = lootEntered = priceEntered = false;
DataRow r = null;
try {
price = System.Int32.Parse(lootCost);
}
catch (Exception ex) {
MessageBox.Show("Invalid Price.");
log.Error("Failed to parse price: " + ex.Message);
return;
}
try {
r = dtLoot.Select("LootName='" + lootName.Replace("'", "''") + "'")[0];
}
catch (Exception ex) {
log.Error("Failed to select loot from table: " + ex.Message);
}
if (r == null)
{
log.Debug("Item not found in Loot table: " + lootName);
dtLoot.Rows.Add(new object[] { lootName, price });
try
{
foreach (DataRow t in dtLoot.Select("LootName='*** Select'")) dtLoot.Rows.Remove(t);
dkpDA.Update(dtLoot);
}
catch (Exception ex) {
log.Error("Failed to update Loot table: " + ex.Message);
}
}
else
{
if ((r.ItemArray[1].GetType() == System.Type.GetType("System.DBNull")) || ((int)r["DKP"] != price))
{
log.Debug("Item price null or different in Loot table, updating");
try
{
r["DKP"] = price;
foreach (DataRow t in dtLoot.Select("LootName='*** Select'")) dtLoot.Rows.Remove(t);
dkpDA.Update(dtLoot);
}
catch (Exception ex) {
log.Error("Failed to update Loot table: " + ex.Message);
}
}
}
try
{
int cost = -1 * price;
object[] o = new object[] { cboPeople.Text, "#" + lblRaidDate.Text + "#", lootName, cost.ToString(), null, lblRaidName.Text };
owner.CurrentRaid.AddRowToLocalTable(o);
lblStatus.Text = "Awarded " + cboPeople.Text + " " + lootName + " for a cost of " + price + " DKP.";
}
catch (Exception ex) {
log.Error("Failed to add loot row: " + ex.Message);
}
}
private void btnClose_Click(object sender, System.EventArgs e)
{
log.Debug("Begin Method: btnClose_Click(object,EventArgs) (" + sender.ToString() + "," + e.ToString() + ")");
this.Close();
log.Debug("Begin Method: btnClose_Click()");
}
#endregion
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblRaid = new System.Windows.Forms.Label();
this.lblRaidName = new System.Windows.Forms.Label();
this.lblRaidDate = new System.Windows.Forms.Label();
this.lblDate = new System.Windows.Forms.Label();
this.lblLoot = new System.Windows.Forms.Label();
this.lblPerson = new System.Windows.Forms.Label();
this.lblPrice = new System.Windows.Forms.Label();
this.cboPeople = new System.Windows.Forms.ComboBox();
this.cboLoot = new System.Windows.Forms.ComboBox();
this.cboPrice = new System.Windows.Forms.ComboBox();
this.btnRecord = new System.Windows.Forms.Button();
this.lblStatus = new System.Windows.Forms.Label();
this.btnClose = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// lblRaid
//
this.lblRaid.Location = new System.Drawing.Point(8, 16);
this.lblRaid.Name = "lblRaid";
this.lblRaid.Size = new System.Drawing.Size(32, 16);
this.lblRaid.TabIndex = 0;
this.lblRaid.Text = "Raid:";
//
// lblRaidName
//
this.lblRaidName.Font = new System.Drawing.Font("Comic Sans MS", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblRaidName.Location = new System.Drawing.Point(56, 16);
this.lblRaidName.Name = "lblRaidName";
this.lblRaidName.Size = new System.Drawing.Size(112, 24);
this.lblRaidName.TabIndex = 1;
//
// lblRaidDate
//
this.lblRaidDate.Font = new System.Drawing.Font("Comic Sans MS", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblRaidDate.Location = new System.Drawing.Point(56, 40);
this.lblRaidDate.Name = "lblRaidDate";
this.lblRaidDate.Size = new System.Drawing.Size(112, 24);
this.lblRaidDate.TabIndex = 3;
//
// lblDate
//
this.lblDate.Location = new System.Drawing.Point(8, 40);
this.lblDate.Name = "lblDate";
this.lblDate.Size = new System.Drawing.Size(40, 15);
this.lblDate.TabIndex = 2;
this.lblDate.Text = "Date:";
//
// lblLoot
//
this.lblLoot.Location = new System.Drawing.Point(8, 64);
this.lblLoot.Name = "lblLoot";
this.lblLoot.Size = new System.Drawing.Size(32, 24);
this.lblLoot.TabIndex = 4;
this.lblLoot.Text = "Loot: ";
//
// lblPerson
//
this.lblPerson.Location = new System.Drawing.Point(8, 96);
this.lblPerson.Name = "lblPerson";
this.lblPerson.Size = new System.Drawing.Size(48, 24);
this.lblPerson.TabIndex = 5;
this.lblPerson.Text = "Person:";
//
// lblPrice
//
this.lblPrice.Location = new System.Drawing.Point(8, 128);
this.lblPrice.Name = "lblPrice";
this.lblPrice.Size = new System.Drawing.Size(40, 24);
this.lblPrice.TabIndex = 6;
this.lblPrice.Text = "Price:";
//
// cboPeople
//
this.cboPeople.CausesValidation = false;
this.cboPeople.Location = new System.Drawing.Point(56, 96);
this.cboPeople.Name = "cboPeople";
this.cboPeople.Size = new System.Drawing.Size(387, 21);
this.cboPeople.TabIndex = 2;
this.cboPeople.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.cboPeople_KeyPress);
this.cboPeople.Leave += new System.EventHandler(this.cboPeople_Leave);
//
// cboLoot
//
this.cboLoot.DisplayMember = "LootName";
this.cboLoot.Location = new System.Drawing.Point(56, 64);
this.cboLoot.Name = "cboLoot";
this.cboLoot.Size = new System.Drawing.Size(387, 21);
this.cboLoot.TabIndex = 1;
this.cboLoot.SelectedIndexChanged += new System.EventHandler(this.cboLoot_SelectedIndexChanged);
this.cboLoot.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.cboLoot_KeyPress);
this.cboLoot.Leave += new System.EventHandler(this.cboLoot_Leave);
//
// cboPrice
//
this.cboPrice.Location = new System.Drawing.Point(56, 128);
this.cboPrice.Name = "cboPrice";
this.cboPrice.Size = new System.Drawing.Size(387, 21);
this.cboPrice.TabIndex = 3;
this.cboPrice.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.cboPrice_KeyPress);
this.cboPrice.Leave += new System.EventHandler(this.cboPrice_Leave);
//
// btnRecord
//
this.btnRecord.Location = new System.Drawing.Point(293, 155);
this.btnRecord.Name = "btnRecord";
this.btnRecord.Size = new System.Drawing.Size(72, 32);
this.btnRecord.TabIndex = 4;
this.btnRecord.Text = "Record";
this.btnRecord.Click += new System.EventHandler(this.btnRecord_Click);
//
// lblStatus
//
this.lblStatus.Location = new System.Drawing.Point(8, 160);
this.lblStatus.Name = "lblStatus";
this.lblStatus.Size = new System.Drawing.Size(279, 27);
this.lblStatus.TabIndex = 7;
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(371, 155);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(72, 32);
this.btnClose.TabIndex = 5;
this.btnClose.Text = "Close";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// RecordLootDialog
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(455, 194);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.lblStatus);
this.Controls.Add(this.btnRecord);
this.Controls.Add(this.cboPrice);
this.Controls.Add(this.cboLoot);
this.Controls.Add(this.cboPeople);
this.Controls.Add(this.lblPrice);
this.Controls.Add(this.lblPerson);
this.Controls.Add(this.lblLoot);
this.Controls.Add(this.lblRaidDate);
this.Controls.Add(this.lblDate);
this.Controls.Add(this.lblRaidName);
this.Controls.Add(this.lblRaid);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "RecordLootDialog";
this.Text = "Record loot";
this.ResumeLayout(false);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#endregion
}
}