PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Argus/frmMain.cs

https://github.com/kordansk/Argus
C# | 676 lines | 666 code | 6 blank | 4 comment | 40 complexity | 67c7208327ac2e75da6f00575191332b MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Xml.Linq;
  11. using System.Threading;
  12. namespace Argus
  13. {
  14. public partial class frmMain : Form
  15. {
  16. #region Globals
  17. public List<ImportedData> CSVList = new List<ImportedData>();
  18. public List<CorpData> CorporationDataList = new List<CorpData>();
  19. public List<SkillSheet> EveSkillList = new List<SkillSheet>();
  20. public SkillSheet EveSkillObject = new SkillSheet();
  21. public List<CharacterSheet> EveCharactersList = new List<CharacterSheet>();
  22. public List<UserData> UserInfoList = new List<UserData>();
  23. public List<ListItem> CorpDropDownList = new List<ListItem>();
  24. public AdvancedList<CharacterView> CharacterDataGrid = new AdvancedList<CharacterView>();
  25. public string CorpFileXML;
  26. public string CharacterDataXML = "datasheet.xml";
  27. public string EveSkillsLocalXML = "skilldata.xml";
  28. public string UserDataLocalXML = "userdata.xml";
  29. public string EVE_API_RemoteXML = "https://api.eveonline.com";
  30. public string ImportFileNameXML;
  31. #endregion
  32. public frmMain()
  33. {
  34. InitializeComponent();
  35. _dgMainView.AutoGenerateColumns = false;
  36. _dgMainView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
  37. DataGridViewTextBoxColumn ownerColumn = new DataGridViewTextBoxColumn();
  38. ownerColumn.DataPropertyName = "forumName";
  39. ownerColumn.HeaderText = "Forum Owner";
  40. DataGridViewTextBoxColumn nameColumn = new DataGridViewTextBoxColumn();
  41. nameColumn.DataPropertyName = "name";
  42. nameColumn.HeaderText = "Character Name";
  43. DataGridViewTextBoxColumn corpnameColumn = new DataGridViewTextBoxColumn();
  44. corpnameColumn.DataPropertyName = "corporationName";
  45. corpnameColumn.HeaderText = "Corporation Name";
  46. DataGridViewTextBoxColumn startdateColumn = new DataGridViewTextBoxColumn();
  47. startdateColumn.DataPropertyName = "startDateTime";
  48. startdateColumn.HeaderText = "Start Date";
  49. DataGridViewTextBoxColumn logoffdateColumn = new DataGridViewTextBoxColumn();
  50. logoffdateColumn.DataPropertyName = "logoffDateTime";
  51. logoffdateColumn.HeaderText = "Last Time Logged In";
  52. DataGridViewTextBoxColumn titlesColumn = new DataGridViewTextBoxColumn();
  53. titlesColumn.DataPropertyName = "titles";
  54. titlesColumn.HeaderText = "Titles";
  55. _dgMainView.Columns.Add(ownerColumn);
  56. _dgMainView.Columns.Add(nameColumn);
  57. _dgMainView.Columns.Add(corpnameColumn);
  58. _dgMainView.Columns.Add(startdateColumn);
  59. _dgMainView.Columns.Add(logoffdateColumn);
  60. _dgMainView.Columns.Add(titlesColumn);
  61. }
  62. private void frmMain_Load(object sender, EventArgs e)
  63. {
  64. cb_LockAddCorporation.Checked = true;
  65. btn_AddCorp.Enabled = false;
  66. tb_CorpKeyID.Enabled = false;
  67. tb_Corp_vCode.Enabled = false;
  68. LoadFormData();
  69. }
  70. private void LoadFormData()
  71. {
  72. List<CharacterSheet> emptyEveCharactersList = new List<CharacterSheet>();
  73. List<CorpData> emptyCorporationDataList = new List<CorpData>();
  74. List<SkillSheet> emptyEveSkillList = new List<SkillSheet>();
  75. List<ImportedData> emptyCSVList = new List<ImportedData>();
  76. List<ListItem> emptyCorpDropDownList = new List<ListItem>();
  77. List<UserData> emptyUserInfoList = new List<UserData>();
  78. AdvancedList<CharacterView> emptyCharacterDataGrid = new AdvancedList<CharacterView>();
  79. EveCharactersList = emptyEveCharactersList;
  80. CorporationDataList = emptyCorporationDataList;
  81. EveSkillList = emptyEveSkillList;
  82. CSVList = emptyCSVList;
  83. CorpDropDownList = emptyCorpDropDownList;
  84. UserInfoList = emptyUserInfoList;
  85. CharacterDataGrid = emptyCharacterDataGrid;
  86. cbRemoveCorp.Items.Clear();
  87. listCharacters.Items.Clear();
  88. if (File.Exists(EveSkillsLocalXML))
  89. {
  90. EveSkillList = EveSkillObject.GetSkills(EveSkillsLocalXML);
  91. listMainView.Items.Add("Loading Skill List.");
  92. }
  93. else
  94. {
  95. listMainView.Items.Add("Updating Skill List.");
  96. UpdateLocalEveSkillsXML();
  97. }
  98. if (File.Exists(UserDataLocalXML))
  99. {
  100. XElement xUserData;
  101. xUserData = XElement.Load(UserDataLocalXML);
  102. foreach (XElement usersettings in xUserData.Elements("settings"))
  103. {
  104. foreach (XElement xe in usersettings.Elements("user"))
  105. {
  106. UserInfoList.Add(new UserData(
  107. xe.Attribute("corp_keyID").Value,
  108. xe.Attribute("corp_vCode").Value,
  109. xe.Attribute("corpdataxml").Value));
  110. }
  111. listMainView.Items.Add("Loading User Data.");
  112. }
  113. if (UserInfoList.Count > 0)
  114. {
  115. foreach (UserData user in UserInfoList)
  116. {
  117. LoadCorpData(user.corp_corpdata_xml);
  118. }
  119. int i = 0;
  120. foreach (CorpData corp in CorporationDataList)
  121. {
  122. CorpDropDownList.Add(new ListItem(corp.corporationName.ToString(), UserInfoList[i].corp_KeyID.ToString()));
  123. listMainView.Items.Add("Loading corporation data for: " + corp.corporationName);
  124. i++;
  125. }
  126. }
  127. foreach (ListItem item in CorpDropDownList)
  128. {
  129. cbRemoveCorp.Items.Add(item);
  130. cbRemoveCorp.SelectedIndex = 0;
  131. }
  132. if (cbRemoveCorp.Items.Count == 0)
  133. {
  134. cbRemoveCorp.Text = "";
  135. }
  136. }
  137. else
  138. {
  139. listMainView.Items.Add("No user data loaded, please add your corp API information.");
  140. }
  141. if (File.Exists(CharacterDataXML))
  142. {
  143. LoadLocalDataSheet();
  144. listMainView.Items.Add("Loading all character data.");
  145. }
  146. else
  147. {
  148. XDocument CreateDatasheetXML = new XDocument();
  149. XElement DatasheetRoot = new XElement("characters");
  150. CreateDatasheetXML.Add(DatasheetRoot);
  151. CreateDatasheetXML.Save(CharacterDataXML);
  152. listMainView.Items.Add("No character data currently available.");
  153. }
  154. foreach (CharacterSheet pilot in EveCharactersList)
  155. {
  156. StringBuilder pilot_titles_build = new StringBuilder();
  157. foreach (CharacterSheet.CharacterTitles title in pilot.titles)
  158. {
  159. pilot_titles_build.Append(title.titleName).Append(", ");
  160. }
  161. string str_pilot_titles = pilot_titles_build.ToString();
  162. CorpData this_pilots_corp = CorporationDataList.Find(delegate(CorpData s) { return s.corporationID == pilot.corporationID; });
  163. if (this_pilots_corp != null)
  164. {
  165. CorpData.Member this_pilots_corp_name = this_pilots_corp.memberList.Find(delegate(CorpData.Member s) { return s.characterID == pilot.characterID; });
  166. CharacterDataGrid.Add(new CharacterView(pilot.name, pilot.corporationName, pilot.forumName, this_pilots_corp_name.startDateTime, this_pilots_corp_name.logoffDateTime, pilot.skills, str_pilot_titles, pilot.titles));
  167. }
  168. else
  169. {
  170. CharacterDataGrid.Add(new CharacterView(pilot.name, pilot.corporationName, pilot.forumName, Convert.ToDateTime("1/1/1000"), Convert.ToDateTime("1/1/1000"), pilot.skills, str_pilot_titles, pilot.titles));
  171. }
  172. }
  173. BindingSource charsource = new BindingSource();
  174. charsource.DataSource = CharacterDataGrid;
  175. _dgMainView.DataSource = charsource;
  176. foreach (CharacterView item in CharacterDataGrid)
  177. {
  178. listCharacters.Items.Add(item.forumName + "\t\t" + item.name);
  179. }
  180. listMainView.Items.Add("Total characters loaded: " + CharacterDataGrid.Count);
  181. }
  182. private void LoadCorpData(string file)
  183. {
  184. XElement xCorpData;
  185. CorpData corp_object = new CorpData();
  186. xCorpData = XElement.Load(file);
  187. List<CorpData.Member> temp_list = new List<CorpData.Member>();
  188. foreach (XElement csettings in xCorpData.Elements("corpinfo"))
  189. {
  190. corp_object.corporationID = Int64.Parse(csettings.Element("corporationID").Value);
  191. corp_object.corporationName = csettings.Element("corporationName").Value;
  192. corp_object.corporationTicker = csettings.Element("corporationTicker").Value;
  193. corp_object.memberCount = int.Parse(csettings.Element("memberCount").Value);
  194. corp_object.memberLimit = int.Parse(csettings.Element("memberLimit").Value);
  195. corp_object.ceoName = csettings.Element("ceoName").Value;
  196. corp_object.cachedUntil = Convert.ToDateTime(csettings.Element("cachedUntil").Value);
  197. }
  198. foreach (XElement members in xCorpData.Elements("members"))
  199. {
  200. foreach (XElement member in members.Elements("member"))
  201. {
  202. temp_list.Add(new CorpData.Member(int.Parse(member.Attribute("characterID").Value),
  203. member.Attribute("name").Value,
  204. Convert.ToDateTime(member.Attribute("startDateTime").Value),
  205. Convert.ToDateTime(member.Attribute("logoffDateTime").Value),
  206. member.Attribute("location").Value,
  207. member.Attribute("shipType").Value));
  208. }
  209. }
  210. corp_object.memberList = temp_list;
  211. CorporationDataList.Add(corp_object);
  212. }
  213. private void LoadLocalDataSheet() //loads local datasheet into memory (this is the file with the actual information to manipulate
  214. {
  215. XElement xDataSheet;
  216. xDataSheet = XElement.Load(CharacterDataXML);
  217. foreach (XElement pilot in xDataSheet.Elements("pilot"))
  218. {
  219. List<CharacterSheet.CharacterSkills> temp_skills = new List<CharacterSheet.CharacterSkills>();
  220. List<CharacterSheet.CharacterTitles> temp_titles = new List<CharacterSheet.CharacterTitles>();
  221. foreach (XElement skills in pilot.Elements("skills"))
  222. {
  223. foreach (XElement skill in skills.Elements("skill"))
  224. {
  225. temp_skills.Add(new CharacterSheet.CharacterSkills(
  226. int.Parse(skill.Attribute("typeID").Value),
  227. int.Parse(skill.Attribute("skillpoints").Value),
  228. int.Parse(skill.Attribute("level").Value),
  229. skill.Attribute("name").Value));
  230. }
  231. }
  232. foreach (XElement titles in pilot.Elements("titles"))
  233. {
  234. foreach (XElement title in titles.Elements("title"))
  235. {
  236. temp_titles.Add(new CharacterSheet.CharacterTitles(
  237. int.Parse(title.Attribute("titleID").Value),
  238. title.Attribute("titleName").Value));
  239. }
  240. }
  241. EveCharactersList.Add(new CharacterSheet(
  242. Convert.ToInt64(pilot.Attribute("characterID").Value),
  243. pilot.Attribute("name").Value,
  244. Convert.ToInt64(pilot.Attribute("corporationID").Value),
  245. pilot.Attribute("corporationName").Value,
  246. pilot.Attribute("forumName").Value,
  247. temp_skills,
  248. temp_titles));
  249. }
  250. }
  251. private void UpdateLocalEveSkillsXML() //grabs remote skill data and saves it locally
  252. {
  253. Application.DoEvents();
  254. XElement xRemoteSkillTree;
  255. string remote_skills_api = EVE_API_RemoteXML + "/eve/SkillTree.xml.aspx";
  256. xRemoteSkillTree = XElement.Load(remote_skills_api);
  257. foreach (XElement result in xRemoteSkillTree.Elements("result"))
  258. {
  259. foreach (XElement rowset_upper in result.Elements("rowset"))
  260. {
  261. foreach (XElement rowgroup in rowset_upper.Elements("row"))
  262. {
  263. foreach (XElement rowset_lower in rowgroup.Elements("rowset"))
  264. {
  265. foreach (XElement row in rowset_lower.Elements("row"))
  266. {
  267. EveSkillList.Add(new SkillSheet(
  268. rowgroup.Attribute("groupName").Value,
  269. int.Parse(row.Attribute("groupID").Value),
  270. row.Attribute("typeName").Value,
  271. int.Parse(row.Attribute("typeID").Value)));
  272. }
  273. }
  274. }
  275. }
  276. }
  277. if (File.Exists(EveSkillsLocalXML))
  278. {
  279. File.Delete(EveSkillsLocalXML);
  280. }
  281. XDocument WriteLocalSkills = new XDocument();
  282. XElement xroot = new XElement("skill_list");
  283. xroot.Add(new XElement("skills"));
  284. WriteLocalSkills.Add(xroot);
  285. WriteLocalSkills.Save(EveSkillsLocalXML);
  286. foreach (SkillSheet skill in EveSkillList)
  287. {
  288. WriteLocalSkills.Root.Element("skills").Add(
  289. new XElement("skill",
  290. new XAttribute("groupName", skill.groupName),
  291. new XAttribute("groupID", skill.groupID),
  292. new XAttribute("typeName", skill.typeName),
  293. new XAttribute("typeID", skill.typeID)));
  294. }
  295. WriteLocalSkills.Save(EveSkillsLocalXML);
  296. EveSkillList = EveSkillObject.GetSkills(EveSkillsLocalXML);
  297. }
  298. private void UpdateLocalCorpXML() //grabs remote api data and saves it locally; updates all CorpXML Files
  299. {
  300. foreach (UserData users in UserInfoList)
  301. {
  302. if (File.Exists(users.corp_corpdata_xml))
  303. {
  304. File.Delete(users.corp_corpdata_xml);
  305. }
  306. string remote_corp_API = EVE_API_RemoteXML + "/corp/CorporationSheet.xml.aspx?keyID=" + users.corp_KeyID + "&vCode=" + users.corp_vCode;
  307. string remote_corp_members = EVE_API_RemoteXML + "/corp/MemberTracking.xml.aspx?keyID=" + users.corp_KeyID + "&vCode=" + users.corp_vCode + "&extended=1";
  308. XElement xRemoteCorpAPI;
  309. XElement xRemoteCorpMembers;
  310. CorpData temp_corp_vals = new CorpData();
  311. xRemoteCorpAPI = XElement.Load(remote_corp_API);
  312. xRemoteCorpMembers = XElement.Load(remote_corp_members);
  313. XDocument WriteCorpData = new XDocument();
  314. XElement corproot = new XElement("corpdata");
  315. corproot.Add(new XElement("corpinfo"));
  316. corproot.Add(new XElement("members"));
  317. WriteCorpData.Add(corproot);
  318. WriteCorpData.Save(users.corp_corpdata_xml);
  319. List<CorpData.Member> temp_members = new List<CorpData.Member>();
  320. foreach (XElement result in xRemoteCorpAPI.Elements("result"))
  321. {
  322. temp_corp_vals.corporationID = Int64.Parse(result.Element("corporationID").Value);
  323. temp_corp_vals.corporationName = result.Element("corporationName").Value;
  324. temp_corp_vals.corporationTicker = result.Element("ticker").Value;
  325. temp_corp_vals.ceoName = result.Element("ceoName").Value;
  326. temp_corp_vals.allianceName = result.Element("allianceName").Value;
  327. temp_corp_vals.memberCount = int.Parse(result.Element("memberCount").Value);
  328. temp_corp_vals.memberLimit = int.Parse(result.Element("memberLimit").Value);
  329. }
  330. temp_corp_vals.cachedUntil = Convert.ToDateTime(xRemoteCorpAPI.Element("cachedUntil").Value);
  331. foreach (XElement result in xRemoteCorpMembers.Elements("result"))
  332. {
  333. foreach (XElement rowset in result.Elements("rowset"))
  334. {
  335. foreach (XElement row in rowset.Elements("row"))
  336. {
  337. temp_members.Add(new CorpData.Member(
  338. Int64.Parse(row.Attribute("characterID").Value),
  339. row.Attribute("name").Value,
  340. Convert.ToDateTime(row.Attribute("startDateTime").Value),
  341. Convert.ToDateTime(row.Attribute("logoffDateTime").Value),
  342. row.Attribute("location").Value,
  343. row.Attribute("shipType").Value));
  344. }
  345. }
  346. }
  347. temp_corp_vals.memberList = temp_members;
  348. WriteCorpData.Root.Element("corpinfo").Add(
  349. new XElement("corporationID", temp_corp_vals.corporationID),
  350. new XElement("corporationName", temp_corp_vals.corporationName),
  351. new XElement("corporationTicker", temp_corp_vals.corporationTicker),
  352. new XElement("memberCount", temp_corp_vals.memberCount),
  353. new XElement("memberLimit", temp_corp_vals.memberLimit),
  354. new XElement("ceoName", temp_corp_vals.ceoName),
  355. new XElement("cachedUntil", temp_corp_vals.cachedUntil)
  356. );
  357. foreach (CorpData.Member members in temp_corp_vals.memberList)
  358. {
  359. WriteCorpData.Root.Element("members").Add(
  360. new XElement("member",
  361. new XAttribute("characterID", members.characterID),
  362. new XAttribute("name", members.name),
  363. new XAttribute("startDateTime", members.startDateTime),
  364. new XAttribute("logoffDateTime", members.logoffDateTime),
  365. new XAttribute("location", members.location),
  366. new XAttribute("shipType", members.shipType)
  367. ));
  368. }
  369. listMainView.Items.Add("Corporation Updated: " + temp_corp_vals.corporationName);
  370. WriteCorpData.Save(users.corp_corpdata_xml);
  371. }
  372. }
  373. private void AddToDatasetXML()
  374. {
  375. List<CharacterSheet.CharacterImport> list_getcharids = new List<CharacterSheet.CharacterImport>();
  376. List<CharacterSheet> list_updatechars = new List<CharacterSheet>();
  377. foreach (ImportedData line in CSVList)
  378. {
  379. string remote_corp_API = EVE_API_RemoteXML + "/account/Characters.xml.aspx?keyID=" + line.KeyID + "&vCode=" + line.vCode;
  380. XElement xRemoteCharacters;
  381. xRemoteCharacters = XElement.Load(remote_corp_API);
  382. foreach (XElement result in xRemoteCharacters.Elements("result"))
  383. {
  384. foreach (XElement rowset in result.Elements("rowset"))
  385. {
  386. foreach (XElement row in rowset.Elements("row"))
  387. {
  388. list_getcharids.Add(new CharacterSheet.CharacterImport(
  389. row.Attribute("name").Value,
  390. Int64.Parse(row.Attribute("characterID").Value),
  391. row.Attribute("corporationName").Value,
  392. Int64.Parse(row.Attribute("corporationID").Value),
  393. line.KeyID,
  394. line.vCode,
  395. line.ForumName));
  396. }
  397. }
  398. }
  399. }
  400. // Retrieving the XML data from EVE API
  401. foreach (CharacterSheet.CharacterImport chars in list_getcharids)
  402. {
  403. List<CharacterSheet.CharacterSkills> temp_skills = new List<CharacterSheet.CharacterSkills>();
  404. List<CharacterSheet.CharacterTitles> temp_titles = new List<CharacterSheet.CharacterTitles>();
  405. string remote_character_sheet_API = EVE_API_RemoteXML + "/char/CharacterSheet.xml.aspx?keyID=" + chars.keyID + "&vCode=" + chars.vCode + "&characterID=" + chars.characterID;
  406. XElement xRemoteCharacterSheet;
  407. xRemoteCharacterSheet = XElement.Load(remote_character_sheet_API);
  408. XDocument xdocCharSheet = XDocument.Load(remote_character_sheet_API);
  409. IEnumerable<XElement> select_titles =
  410. from el in xdocCharSheet.Descendants("rowset")
  411. where el.Attribute("name").Value == "corporationTitles"
  412. select el;
  413. foreach (XElement titles in select_titles.Elements("row"))
  414. {
  415. temp_titles.Add(new CharacterSheet.CharacterTitles(
  416. int.Parse(titles.Attribute("titleID").Value),
  417. titles.Attribute("titleName").Value));
  418. }
  419. IEnumerable<XElement> select_skills =
  420. from el in xdocCharSheet.Descendants("rowset")
  421. where el.Attribute("name").Value == "skills"
  422. select el;
  423. foreach (XElement skills in select_skills.Elements("row"))
  424. {
  425. SkillSheet skill_name = EveSkillList.Find(delegate(SkillSheet s) { return s.typeID == int.Parse(skills.Attribute("typeID").Value); });
  426. temp_skills.Add(new CharacterSheet.CharacterSkills(
  427. int.Parse(skills.Attribute("typeID").Value),
  428. int.Parse(skills.Attribute("skillpoints").Value),
  429. int.Parse(skills.Attribute("level").Value),
  430. skill_name.typeName));
  431. }
  432. foreach (XElement result in xRemoteCharacterSheet.Descendants("result"))
  433. {
  434. CharacterSheet.CharacterImport this_character = list_getcharids.Find(delegate(CharacterSheet.CharacterImport s) { return s.characterID.ToString() == result.Element("characterID").Value.ToString(); });
  435. list_updatechars.Add(new CharacterSheet(
  436. Int64.Parse(result.Element("characterID").Value),
  437. result.Element("name").Value,
  438. Int64.Parse(result.Element("corporationID").Value),
  439. result.Element("corporationName").Value,
  440. this_character.forumName,
  441. temp_skills,
  442. temp_titles
  443. ));
  444. }
  445. }
  446. //Adding to dataset here.
  447. // if updatedatasheet doesn't contain a reference to a characterid in the list_updatechars,
  448. // add it to the sheet; else delete that node and add new data to update list_updatechars and EveCharactersList
  449. XDocument UpdateDataSheet = XDocument.Load(CharacterDataXML);
  450. List<long> characterID_duplicates = new List<long>();
  451. foreach (CharacterSheet import in list_updatechars)
  452. {
  453. foreach (CharacterSheet exists in EveCharactersList)
  454. {
  455. if (import.characterID == exists.characterID)
  456. {
  457. characterID_duplicates.Add(exists.characterID);
  458. }
  459. }
  460. }
  461. foreach (long id in characterID_duplicates)
  462. {
  463. UpdateDataSheet.Descendants("pilot").Where(p => p.Attribute("characterID") != null && (string)p.Attribute("characterID") == id.ToString()).Remove();
  464. }
  465. listMainView.Items.Add("Pilots updated: " + characterID_duplicates.Count);
  466. listMainView.Items.Add("New Pilots added: " + (list_updatechars.Count-characterID_duplicates.Count));
  467. characterID_duplicates.Clear();
  468. UpdateDataSheet.Save(CharacterDataXML);
  469. foreach (CharacterSheet pilot in list_updatechars)
  470. {
  471. UpdateDataSheet.Element("characters").Add(
  472. new XElement("pilot",
  473. new XAttribute("characterID", pilot.characterID),
  474. new XAttribute("name", pilot.name),
  475. new XAttribute("corporationID", pilot.corporationID),
  476. new XAttribute("corporationName", pilot.corporationName),
  477. new XAttribute("forumName", pilot.forumName)
  478. ));
  479. IEnumerable<XElement> children = from el in UpdateDataSheet.Root.Elements("pilot")
  480. where (string)el.Attribute("characterID") == pilot.characterID.ToString()
  481. select el;
  482. foreach (XElement el in children)
  483. {
  484. el.Add(new XElement("skills"));
  485. el.Add(new XElement("titles"));
  486. foreach (CharacterSheet.CharacterSkills skill in pilot.skills)
  487. {
  488. el.Element("skills").Add(
  489. new XElement("skill",
  490. new XAttribute("typeID", skill.typeID),
  491. new XAttribute("skillpoints", skill.skillpoints),
  492. new XAttribute("level", skill.level),
  493. new XAttribute("name", skill.name)));
  494. }
  495. foreach (CharacterSheet.CharacterTitles title in pilot.titles)
  496. {
  497. el.Element("titles").Add(
  498. new XElement("title",
  499. new XAttribute("titleID", title.titleID),
  500. new XAttribute("titleName", title.titleName)));
  501. }
  502. }
  503. }
  504. UpdateDataSheet.Save(CharacterDataXML);
  505. LoadFormData();
  506. } // adds pilots to dataset.xml
  507. private void AddDataFromCSV()
  508. {
  509. char[] seps = { ',' };
  510. if (ImportFileNameXML != null)
  511. {
  512. string[] csvDataFile = File.ReadAllLines(ImportFileNameXML);
  513. foreach (string line in csvDataFile)
  514. {
  515. string[] split_values = line.Split(seps, StringSplitOptions.RemoveEmptyEntries);
  516. CSVList.Add(new ImportedData(split_values[0], split_values[1], split_values[2]));
  517. }
  518. }
  519. AddToDatasetXML();
  520. } //grabs all new user data files and loads them into memory from CSV file
  521. private void AddCorpAPI()
  522. {
  523. string corpdataFileName = "corpdata_" + tb_CorpKeyID.Text + ".xml";
  524. if (!File.Exists(UserDataLocalXML))
  525. {
  526. XDocument WriteUserData = new XDocument();
  527. XElement xroot = new XElement("UserData");
  528. xroot.Add(new XElement("settings"));
  529. WriteUserData.Add(xroot);
  530. WriteUserData.Save(UserDataLocalXML);
  531. WriteUserData.Root.Element("settings").Add(
  532. new XElement("user",
  533. new XAttribute("corp_keyID", tb_CorpKeyID.Text),
  534. new XAttribute("corp_vCode", tb_Corp_vCode.Text),
  535. new XAttribute("corpdataxml", corpdataFileName)));
  536. WriteUserData.Save(UserDataLocalXML);
  537. }
  538. else
  539. {
  540. XDocument UpdateUserData = XDocument.Load(UserDataLocalXML);
  541. UpdateUserData.Root.Element("settings").Add(new XElement("user",
  542. new XAttribute("corp_keyID", tb_CorpKeyID.Text),
  543. new XAttribute("corp_vCode", tb_Corp_vCode.Text),
  544. new XAttribute("corpdataxml", corpdataFileName)));
  545. UpdateUserData.Save(UserDataLocalXML);
  546. }
  547. tb_Corp_vCode.Clear();
  548. tb_CorpKeyID.Clear();
  549. cb_LockAddCorporation.Checked = true;
  550. btn_AddCorp.Enabled = false;
  551. tb_CorpKeyID.Enabled = false;
  552. tb_Corp_vCode.Enabled = false;
  553. XElement xUserData;
  554. xUserData = XElement.Load(UserDataLocalXML);
  555. foreach (XElement usersettings in xUserData.Elements("settings"))
  556. {
  557. foreach (XElement xe in usersettings.Elements("user"))
  558. {
  559. UserInfoList.Add(new UserData(
  560. xe.Attribute("corp_keyID").Value,
  561. xe.Attribute("corp_vCode").Value,
  562. xe.Attribute("corpdataxml").Value));
  563. }
  564. }
  565. } // adds corps to the dataset
  566. private void RemoveCorp()
  567. {
  568. if (CorpDropDownList.Count > 0)
  569. {
  570. ListItem corpKeyID = (ListItem)cbRemoveCorp.SelectedItem;
  571. XDocument RemoveCorp = XDocument.Load(UserDataLocalXML);
  572. RemoveCorp.Descendants("settings").Elements("user").Where(p => p.Attribute("corp_keyID") != null && (string)p.Attribute("corp_keyID") == corpKeyID.value.ToString()).Remove();
  573. RemoveCorp.Save(UserDataLocalXML);
  574. File.Delete("corpdata_" + corpKeyID.value + ".xml");
  575. cbRemoveCorp.Items.RemoveAt(cbRemoveCorp.SelectedIndex);
  576. LoadFormData();
  577. }
  578. } // removes corps form the dataset
  579. private void DeleteCharacter()
  580. {
  581. XDocument RemoveCharacter = XDocument.Load(CharacterDataXML);
  582. int indexofPilot = listCharacters.SelectedIndex;
  583. CharacterSheet pilotToRemove = EveCharactersList[indexofPilot];
  584. RemoveCharacter.Descendants("characters").Elements("pilot").Where(p => p.Attribute("characterID") != null && (string)p.Attribute("characterID").Value == pilotToRemove.characterID.ToString()).Remove();
  585. listCharacters.Items.RemoveAt(indexofPilot);
  586. RemoveCharacter.Save(CharacterDataXML);
  587. LoadFormData();
  588. } // deletes characters from the dataset
  589. private void cb_LockCorpUpdate_CheckedChanged(object sender, EventArgs e)
  590. {
  591. if (cb_LockAddCorporation.Checked == false)
  592. {
  593. btn_AddCorp.Enabled = true;
  594. tb_CorpKeyID.Enabled = true;
  595. tb_Corp_vCode.Enabled = true;
  596. }
  597. else
  598. {
  599. btn_AddCorp.Enabled = false;
  600. tb_CorpKeyID.Enabled = false;
  601. tb_Corp_vCode.Enabled = false;
  602. }
  603. }
  604. private void btn_AddCorp_Click(object sender, EventArgs e) //saves corp data in the boxes into an xml
  605. {
  606. if (tb_CorpKeyID.Text != "" & tb_Corp_vCode.Text != "")
  607. {
  608. AddCorpAPI();
  609. UpdateLocalCorpXML();
  610. LoadFormData();
  611. }
  612. else
  613. {
  614. MessageBox.Show("Please enter a Key ID and a vCode.");
  615. }
  616. }
  617. private void btn_UpdateCorpDataXML_Click(object sender, EventArgs e)
  618. {
  619. UpdateLocalCorpXML();
  620. }
  621. private void btn_UpdateSkillTree_Click(object sender, EventArgs e) //this begins updating the skill data from remotely
  622. {
  623. UpdateLocalEveSkillsXML();
  624. }
  625. private void btn_ImportData_Click(object sender, EventArgs e) //gets the csv file path to import into memory
  626. {
  627. ImportFileNameXML = getFileName();
  628. AddDataFromCSV();
  629. }
  630. private void btn_RefreshList_Click(object sender, EventArgs e)
  631. {
  632. RefreshData();
  633. }
  634. public string getFileName()
  635. {
  636. OpenFileDialog fileBrowserDialog = new OpenFileDialog();
  637. fileBrowserDialog.InitialDirectory = Directory.GetCurrentDirectory();
  638. fileBrowserDialog.Filter = "csv files (*.csv)|*.csv";
  639. fileBrowserDialog.FilterIndex = 1;
  640. if (fileBrowserDialog.ShowDialog() == DialogResult.OK)
  641. {
  642. string _filename = fileBrowserDialog.FileName;
  643. return _filename;
  644. }
  645. else
  646. {
  647. return null;
  648. }
  649. }
  650. private void RefreshData()
  651. {
  652. LoadFormData();
  653. } //reloads all information into memory
  654. private void btnRemoveCorp_Click(object sender, EventArgs e)
  655. {
  656. RemoveCorp();
  657. }
  658. private void btnDeleteCharacter_Click(object sender, EventArgs e)
  659. {
  660. if (listCharacters.Items.Count > 0)
  661. {
  662. DeleteCharacter();
  663. }
  664. }
  665. private void btnClearListmainView_Click(object sender, EventArgs e)
  666. {
  667. listMainView.Items.Clear();
  668. }
  669. }
  670. }