aboutsummaryrefslogtreecommitdiff
path: root/Histacom2/OS/Win98/Win98Apps/AddressBook
diff options
context:
space:
mode:
authorAlex-TIMEHACK <[email protected]>2017-11-04 17:48:05 +0000
committerAlex-TIMEHACK <[email protected]>2017-11-04 17:48:05 +0000
commitcc07981aa3603c74507c9ea0acb6dd0d8418d58e (patch)
tree3a912bad67da226cc0f27e35f8bbd0f568d2f9fe /Histacom2/OS/Win98/Win98Apps/AddressBook
parent4af08fc6e341a45158e23beb13be10aa1a6a3590 (diff)
downloadhistacom2-cc07981aa3603c74507c9ea0acb6dd0d8418d58e.tar.gz
histacom2-cc07981aa3603c74507c9ea0acb6dd0d8418d58e.tar.bz2
histacom2-cc07981aa3603c74507c9ea0acb6dd0d8418d58e.zip
Address Book can now save data!
Diffstat (limited to 'Histacom2/OS/Win98/Win98Apps/AddressBook')
-rw-r--r--Histacom2/OS/Win98/Win98Apps/AddressBook/FRMWinClassicAddressBookNewContact.cs8
-rw-r--r--Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.Designer.cs2
-rw-r--r--Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs157
3 files changed, 131 insertions, 36 deletions
diff --git a/Histacom2/OS/Win98/Win98Apps/AddressBook/FRMWinClassicAddressBookNewContact.cs b/Histacom2/OS/Win98/Win98Apps/AddressBook/FRMWinClassicAddressBookNewContact.cs
index 9facd7b..45384fa 100644
--- a/Histacom2/OS/Win98/Win98Apps/AddressBook/FRMWinClassicAddressBookNewContact.cs
+++ b/Histacom2/OS/Win98/Win98Apps/AddressBook/FRMWinClassicAddressBookNewContact.cs
@@ -7,12 +7,13 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
-
+using Histacom2.Engine;
namespace Histacom2.OS.Win95.Win95Apps
{
public partial class FRMWinClassicAddressBookNewContact : UserControl
{
+ WindowManager wm = new WindowManager();
public AddressBookContact toSet = new AddressBookContact();
public FRMWinClassicAddressBookNewContact()
{
@@ -37,7 +38,7 @@ namespace Histacom2.OS.Win95.Win95Apps
Program.AddressBookSelectedContact = toSet;
((Form)this.TopLevelControl).Close();
} else {
- MessageBox.Show("Please fill out the First, Middle and Last name.");
+ wm.StartInfobox95("Address Book", "Please fill out the First, Middle and Last name.", Engine.Template.InfoboxType.Info, Engine.Template.InfoboxButtons.OK);
}
}
@@ -62,9 +63,6 @@ namespace Histacom2.OS.Win95.Win95Apps
emails.Items.Add(email);
}
}
- } else
- {
- MessageBox.Show("NULL CONTACT!");
}
}
}
diff --git a/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.Designer.cs b/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.Designer.cs
index 09030fb..5452184 100644
--- a/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.Designer.cs
+++ b/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.Designer.cs
@@ -145,12 +145,14 @@
this.importToolStripMenuItem.Name = "importToolStripMenuItem";
this.importToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.importToolStripMenuItem.Text = "Import...";
+ this.importToolStripMenuItem.Click += new System.EventHandler(this.importToolStripMenuItem_Click);
//
// exportToolStripMenuItem
//
this.exportToolStripMenuItem.Name = "exportToolStripMenuItem";
this.exportToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.exportToolStripMenuItem.Text = "Export...";
+ this.exportToolStripMenuItem.Click += new System.EventHandler(this.exportToolStripMenuItem_Click);
//
// toolStripSeparator3
//
diff --git a/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs b/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs
index e4d6c7b..bf4f648 100644
--- a/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs
+++ b/Histacom2/OS/Win98/Win98Apps/AddressBook/WinClassicAddressBook.cs
@@ -9,6 +9,9 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using Histacom2.Engine;
using Histacom2.Engine.Template;
+using System.IO;
+using static Histacom2.Engine.SaveSystem;
+using static Histacom2.Engine.FileDialogBoxManager;
namespace Histacom2.OS.Win95.Win95Apps
{
@@ -42,14 +45,30 @@ namespace Histacom2.OS.Win95.Win95Apps
{
new AddressBookContactList()
{
- AttachedNode = treeView1.Nodes[0].Text
+ NodePath = treeView1.Nodes[0].Text
}
};
+
+ if (File.Exists(Path.Combine(ProfileWindowsDirectory, "Application Data", "Microsoft", "Address Book", $"{ProfileName}.wab")))
+ LoadData();
+ else
+ SaveData();
+
+
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
- UpdateContactListFromNodeName(treeView1.SelectedNode.Text);
+ previousParent = treeView1.SelectedNode.Parent;
+ UpdateContactListFromNodeName(treeView1.SelectedNode);
+
+ // Remove the focus from contactsView
+
+ if (contactsView.SelectedItems.Count != 0)
+ contactsView.SelectedItems[0].Selected = false;
+
+ if (contactsView.FocusedItem != null)
+ contactsView.FocusedItem.Focused = false;
}
//AddressBookContactList GetAddressBookContactListFromNode(string NodeText)
@@ -71,14 +90,15 @@ namespace Histacom2.OS.Win95.Win95Apps
// return toReturn;
//}
- public void UpdateContactListFromNodeName(string NodeName)
+ public void UpdateContactListFromNodeName(TreeNode Node)
{
+ previousParent = Node.Parent;
contactsView.Items.Clear();
try
{
foreach (AddressBookContactList ContactList in AddressBookObjects)
{
- if (ContactList.AttachedNode == NodeName)
+ if (ContactList.NodePath == FindNodePath(Node))
{
foreach (AddressBookContact contact in ContactList.Contacts)
{
@@ -97,15 +117,29 @@ namespace Histacom2.OS.Win95.Win95Apps
{
if (OldTreeNode != null)
{
- OldTreeNode.Nodes.Add(NewNodeName);
+ TreeNode nde = OldTreeNode.Nodes.Add(NewNodeName);
AddressBookObjects.Add(new AddressBookContactList
{
- AttachedNode = NewNodeName,
+ NodePath = FindNodePath(nde)
});
}
}
+ TreeNode previousParent;
+ public string FindNodePath(TreeNode nde)
+ {
+ if (nde != null)
+ {
+ string ret = nde.Text;
+ previousParent = nde.Parent;
+ while (previousParent != null)
+ ret = $"{FindNodePath(nde.Parent)}\\{ret}";
+ return ret;
+ }
+ else return "";
+ }
+
private void newFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
NewFolder();
@@ -145,7 +179,7 @@ namespace Histacom2.OS.Win95.Win95Apps
{
foreach (AddressBookContactList ContactList in AddressBookObjects)
{
- if (ContactList.AttachedNode == treeView1.SelectedNode.Text)
+ if (ContactList.NodePath == FindNodePath(treeView1.SelectedNode))
{
ContactList.Contacts.Add(Program.AddressBookSelectedContact);
contactsView.Items.Add(Program.AddressBookSelectedContact.FirstName + " " + Program.AddressBookSelectedContact.MiddleName + " " + Program.AddressBookSelectedContact.LastName);
@@ -169,7 +203,7 @@ namespace Histacom2.OS.Win95.Win95Apps
{
foreach (AddressBookContactList ContactList in AddressBookObjects)
{
- if (ContactList.AttachedNode == treeView1.SelectedNode.Text)
+ if (ContactList.NodePath == FindNodePath(treeView1.SelectedNode))
{
foreach (AddressBookContact Contact in ContactList.Contacts)
{
@@ -195,7 +229,7 @@ namespace Histacom2.OS.Win95.Win95Apps
{
foreach (AddressBookContactList ContactList in AddressBookObjects)
{
- if (ContactList.AttachedNode == treeView1.SelectedNode.Text)
+ if (ContactList.NodePath == FindNodePath(treeView1.SelectedNode))
{
foreach (AddressBookContact Contact in ContactList.Contacts)
{
@@ -228,31 +262,31 @@ namespace Histacom2.OS.Win95.Win95Apps
{
try
{
- if (treeView1.SelectedNode != null)
+ foreach (AddressBookContactList ContactList in AddressBookObjects)
{
- foreach (AddressBookContactList ContactList in AddressBookObjects)
+ if (ContactList.NodePath == FindNodePath(treeView1.SelectedNode))
{
- if (ContactList.AttachedNode == treeView1.SelectedNode.Text)
+ foreach (AddressBookContact Contact in ContactList.Contacts)
{
- foreach (AddressBookContact Contact in ContactList.Contacts)
- {
- if (contactsView.FocusedItem == null)
- { // Most likely they are trying to delete a whole folder!
- if (treeView1.SelectedNode.Text != "Shared Contacts")
- if (treeView1.SelectedNode != null)
- {
- AddressBookObjects.Remove(ContactList);
- treeView1.Nodes.Remove(treeView1.SelectedNode);
- UpdateContactListFromNodeName("Shared Contacts");
- }
- }
- else
- {
- if ((Contact.FirstName + " " + Contact.MiddleName + " " + Contact.LastName) == contactsView.FocusedItem.Text)
+ if (contactsView.FocusedItem == null)
+ { // Most likely they are trying to delete a whole folder!
+ if (treeView1.SelectedNode.Text != "Shared Contacts")
+ if (treeView1.SelectedNode != null)
{
- ContactList.Contacts.Remove(Contact);
+ AddressBookObjects.Remove(ContactList);
+ treeView1.Nodes.Remove(treeView1.SelectedNode);
+ previousParent = null;
+ UpdateContactListFromNodeName(treeView1.Nodes[0]);
}
- }
+ }
+ else
+ {
+ if ((Contact.FirstName + " " + Contact.MiddleName + " " + Contact.LastName) == contactsView.FocusedItem.Text)
+ {
+ ContactList.Contacts.Remove(Contact);
+ previousParent = treeView1.SelectedNode.Parent;
+ UpdateContactListFromNodeName(treeView1.SelectedNode);
+ }
}
}
}
@@ -310,14 +344,75 @@ namespace Histacom2.OS.Win95.Win95Apps
public void SaveData()
{
-
+ string toSave = Newtonsoft.Json.JsonConvert.SerializeObject(AddressBookObjects, Newtonsoft.Json.Formatting.Indented);
+ CreateWindowsFile(Path.Combine(ProfileWindowsDirectory, "Application Data", "Microsoft", "Address Book"), $"{ProfileName}.wab", toSave, 21, toSave.Length);
}
public void SaveDataAs()
{
+ try
+ {
+ string toSave = Newtonsoft.Json.JsonConvert.SerializeObject(AddressBookObjects, Newtonsoft.Json.Formatting.Indented);
+
+ ActivateSaveFileDialog(".wab");
+ string selectedPath = Program.OpenFileExplorerAsDialogAndReturnGivenPath();
+ DeactivateFileDialog();
+
+ if (selectedPath != "")
+ CreateWindowsFile(new FileInfo(selectedPath).Directory.FullName, selectedPath.Split('\\').Last(), toSave, 21, toSave.Length);
+ } catch { }
+ }
+
+ public void LoadData()
+ {
+ AddressBookObjects = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AddressBookContactList>>(File.ReadAllText(Path.Combine(ProfileWindowsDirectory, "Application Data", "Microsoft", "Address Book", $"{ProfileName}.wab")));
+
+ foreach (AddressBookContactList lst in AddressBookObjects)
+ UpdateTreeView(lst);
+ }
+
+ public void LoadDataAs()
+ {
+ ActivateOpenFileDialog(".wab");
+ string selectedPath = Program.OpenFileExplorerAsDialogAndReturnGivenPath();
+ DeactivateFileDialog();
+
+ if (selectedPath != "")
+ AddressBookObjects = Newtonsoft.Json.JsonConvert.DeserializeObject<List<AddressBookContactList>>(File.ReadAllText(selectedPath));
+ foreach (AddressBookContactList lst in AddressBookObjects)
+ UpdateTreeView(lst);
}
+ TreeNode UpdatePrevParent;
+ public void UpdateTreeView(AddressBookContactList lst, int count = 0)
+ {
+ try
+ {
+ string[] parts = lst.NodePath.Split('\\');
+ if (count == 0) UpdatePrevParent = treeView1.Nodes[0];
+ if (lst.NodePath != FindNodePath(treeView1.Nodes[0]))
+ {
+ if (UpdatePrevParent.Nodes.ContainsKey(parts[count + 1]))
+ UpdatePrevParent.Nodes.RemoveByKey(parts[count + 1]);
+
+ TreeNode newNde = UpdatePrevParent.Nodes.Add(parts[count + 1], parts[count + 1]);
+ UpdatePrevParent = newNde;
+ if (count != parts.Length - 2) UpdateTreeView(lst, ++count);
+ }
+
+ } catch { }
+ }
+
+ private void importToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ LoadDataAs();
+ }
+
+ private void exportToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ SaveDataAs();
+ }
}
public class AddressBookContact
@@ -330,7 +425,7 @@ namespace Histacom2.OS.Win95.Win95Apps
public class AddressBookContactList
{
- public string AttachedNode;
+ public string NodePath;
public List<AddressBookContact> Contacts = new List<AddressBookContact>();
}
}