public ShowAll(LabLog labLog, bool AddUserOrCategory = false, bool UsePassWord = true) { this.labLog = labLog; this.AddUserOrCategory = AddUserOrCategory; this.UsePassWord = UsePassWord; this.ModifiedDataBase = false; InitializeComponent(); dTP1.CustomFormat = "HH:mm:ss dd.MM.yyyy"; dTP2.CustomFormat = "HH:mm:ss dd.MM.yyyy"; this.listBoxUsers.DrawMode = DrawMode.OwnerDrawFixed; this.listBoxUsers.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox_DrawItem); fillUsers(); this.listBoxCategories.DrawMode = DrawMode.OwnerDrawFixed; this.listBoxCategories.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox_DrawItem); fillCategories(); buttonAddUser.Visible = AddUserOrCategory; buttonUsersDelete.Visible = AddUserOrCategory; buttonUsersUp.Visible = AddUserOrCategory; buttonUsersDown.Visible = AddUserOrCategory; buttonAddCategorie.Visible = AddUserOrCategory; buttonCatergoriesDelete.Visible = AddUserOrCategory; buttonCategoriesUp.Visible = AddUserOrCategory; buttonCategoriesDown.Visible = AddUserOrCategory; treeEntries = fillTree(labLog, TreeEntries.SortOrder.Descending); selectAllUsers(true); selectAllCategories(true); }
public static void serialisieren(LabLog _records, string _dbPath) { // set users System.Collections.Generic.List <UsersClass> users = new System.Collections.Generic.List <UsersClass>(_records.metaInformation.AllUsers); _records.metaInformation.Users = null; System.Collections.Generic.List <string> userstrings = new System.Collections.Generic.List <string>(); for (int i = 0; i < users.Count; i++) { if (users[i].Active) { userstrings.Add(users[i].Name); } } _records.metaInformation.Users = userstrings.ToArray(); // set categories System.Collections.Generic.List <CategoryClass> categories = new System.Collections.Generic.List <CategoryClass>(_records.metaInformation.Categories); _records.metaInformation.Categories = null; System.Collections.Generic.List <CategoryClass> categorieslist = new System.Collections.Generic.List <CategoryClass>(); for (int i = 0; i < categories.Count; i++) { if (categories[i].Active) { categorieslist.Add(categories[i]); } } _records.metaInformation.Categories = categorieslist.ToArray(); // serialize XmlSerializer s = new XmlSerializer(typeof(LabLog)); TextWriter w = new StreamWriter(_dbPath); s.Serialize(w, _records); w.Close(); }
public static void insertEntry(ref LabLog labLog, ref Entry _entry, bool edit, out int entryNumber) { entryNumber = -1; if (labLog.InfoEntryItems.Length > 1) { labLog.InfoEntryItems[0].edit = edit; DateTime _actual = DateTime.Parse(_entry.StartTime); DateTime _start = DateTime.Parse(labLog.InfoEntryItems[0].StartTime); DateTime _end = DateTime.Parse(labLog.InfoEntryItems[labLog.InfoEntryItems.Length - 1].StartTime); if (_actual < _start) // entry is the youngest one, insert at the begining of the array { entryNumber = 0; labLog.AddColoumnEntryAt(0, _entry); } else if (_actual >= _start && _actual < _end) // entry is somewhere in betwenn to insert { for (int i = 1; i < labLog.InfoEntryItems.Length; i++) { DateTime dt0 = DateTime.Parse(labLog.InfoEntryItems[i - 1].StartTime); DateTime dt1 = DateTime.Parse(labLog.InfoEntryItems[i].StartTime); if (dt0 <= _actual && _actual < dt1) { entryNumber = i; labLog.AddColoumnEntryAt(i, _entry); break; } } } else if (_actual >= _end) // entry is the oldest one, insert at the end of the array { labLog.AddColoumnEntry(_entry); entryNumber = labLog.InfoEntryItems.Length - 1; } } else { labLog.AddColoumnEntry(_entry); entryNumber = labLog.InfoEntryItems.Length - 1; } }
private TreeEntries fillTree(LabLog lablog, TreeEntries.SortOrder SortOrder) { List <LaborLog.UsersClass> users = new List <LaborLog.UsersClass>(); for (int i = 0; i < listBoxUsers.Items.Count; i++) { if (listBoxUsers.GetSelected(i)) { users.Add(lablog.metaInformation.AllUsers[i]); } } List <LaborLog.CategoryClass> categories = new List <LaborLog.CategoryClass>(); for (int i = 0; i < listBoxCategories.Items.Count; i++) { if (listBoxCategories.GetSelected(i)) { categories.Add(lablog.metaInformation.Categories[i]); } } TreeEntries treeEntries = new TreeEntries(SortOrder); int numberOfEntries = 0; if (SortOrder == TreeEntries.SortOrder.Ascending) { for (int i = 0; i < lablog.InfoEntryItems.Length; i++) { Entry entry = lablog.InfoEntryItems[i]; addEntry(ref treeEntries, ref entry, ref users, ref categories, ref numberOfEntries); } } if (SortOrder == TreeEntries.SortOrder.Descending) { for (int i = lablog.InfoEntryItems.Length - 1; i >= 0; i--) { Entry entry = lablog.InfoEntryItems[i]; addEntry(ref treeEntries, ref entry, ref users, ref categories, ref numberOfEntries); } } textBoxNumberOfEntries.Text = numberOfEntries.ToString(); treeView1.Nodes.Clear(); if (treeEntries.treeList.Count > 0) { treeView1.BeginUpdate(); // Add a root TreeNode for each Customer object in the ArrayList. foreach (TreeEntries.Year year in treeEntries.treeList) { treeView1.Nodes.Add(new TreeNode(year.year.ToString())); // Add a child treenode for each Order object in the current Customer object. foreach (TreeEntries.Month month in year.Month) { List <TreeNode> tList = new List <TreeNode>(); bool c = false; foreach (Entry entry in month.Entries) { DateTime start = DateTime.Parse(entry.StartTime); TimeSpan duration = TimeSpan.Parse(entry.Duration); duration = new TimeSpan(duration.Days, duration.Hours, duration.Minutes, duration.Seconds); TreeNode t = new TreeNode(start.ToString("HH:mm:ss dd.MM.yyyy") + " - " + duration.ToString()); if (c) { t.BackColor = SystemColors.ControlLightLight; } else { t.BackColor = SystemColors.ControlLight; } c = !c; tList.Add(t); } TreeNode treeNode = new TreeNode( System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month.month), tList.ToArray()); treeView1.Nodes[treeEntries.treeList.IndexOf(year)].Nodes.Add(treeNode); } } for (int i = 0; i < treeView1.Nodes.Count; i++) { treeView1.Nodes[i].Expand(); } treeView1.EndUpdate(); if (treeEntries.sortOrder == TreeEntries.SortOrder.Ascending) { buttonAscending.Enabled = false; buttonDescending.Enabled = true; treeView1.Nodes[treeView1.Nodes.Count - 1].Expand(); treeView1.Nodes[treeView1.Nodes.Count - 1].Nodes[treeView1.Nodes[treeView1.Nodes.Count - 1].Nodes.Count - 1].Expand(); int i = treeView1.Nodes.Count - 1; int j = treeView1.Nodes[i].Nodes.Count - 1; int k = treeView1.Nodes[i].Nodes[j].Nodes.Count - 1; treeView1.SelectedNode = treeView1.Nodes[i].Nodes[j].Nodes[k]; treeView1.Nodes[i].Nodes[j].Nodes[k].EnsureVisible(); } if (treeEntries.sortOrder == TreeEntries.SortOrder.Descending) { buttonAscending.Enabled = true; buttonDescending.Enabled = false; treeView1.Nodes[0].Expand(); treeView1.Nodes[0].Nodes[0].Expand(); treeView1.SelectedNode = treeView1.Nodes[0].Nodes[0].Nodes[0]; treeView1.Nodes[0].EnsureVisible(); } } if (treeEntries.treeList.Count == 0) { buttonDeleteEntry.Enabled = false; buttonEditNewEntry1.Enabled = false; panelUsers.Controls.Clear(); } else { buttonDeleteEntry.Enabled = true; buttonEditNewEntry1.Enabled = true; } return(treeEntries); }
private void buttonAddNewEntry_Click(object sender, EventArgs e) { if (operationMode == OperationMode.None) { panelTimeTable.Enabled = false; panelSelection.Enabled = false; buttonClose.Enabled = false; panelEditNew.Enabled = true; // edit entry if (((Button)sender).Name == buttonEditNewEntry1.Name) { if (UsePassWord) { if (labLog.metaInformation.UsePassword) { PasswordEntry pw = new PasswordEntry(labLog.metaInformation.Password); if (pw.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } } } labelOperation.Text = ButtonText.labelOperationEdit; operationMode = OperationMode.EditEntry; buttonEditNewEntry1.Text = ButtonText.buttonEditNewEntry1_Dialog; buttonEditNewEntry2.Text = ButtonText.buttonEditNewEntry2_Dialog; } // new entry if (((Button)sender).Name == buttonEditNewEntry2.Name) { labelOperation.Text = ButtonText.labelOperationNew; operationMode = OperationMode.NewEntry; buttonEditNewEntry1.Text = ButtonText.buttonEditNewEntry1_Dialog; buttonEditNewEntry2.Text = ButtonText.buttonEditNewEntry2_Dialog; setUserbuttons(false); setCategories(); dTP1.Value = DateTime.Now; dTP2.Value = dTP1.Value.AddHours(1); textBoxInfo.Text = ""; } } else if (operationMode == OperationMode.EditEntry || operationMode == OperationMode.NewEntry) { panelUsers.Controls.Clear(); panelTimeTable.Enabled = true; panelSelection.Enabled = true; buttonEditNewEntry1.Enabled = true; buttonClose.Enabled = true; panelEditNew.Enabled = false; labelOperation.Text = ""; buttonEditNewEntry1.Text = ButtonText.buttonEditNewEntry1; buttonEditNewEntry2.Text = ButtonText.buttonEditNewEntry2; if (((Button)sender).Name == buttonEditNewEntry1.Name) { Entry newEntry = getEntry(); if (operationMode == OperationMode.EditEntry) { labLog.RemoveColoumnEntryAt(activeEntry); } else if (operationMode == OperationMode.NewEntry) { // Nothing to do } int entryNumber = -1; LabLog.insertEntry(ref labLog, ref newEntry, false, out entryNumber); ModifiedDataBase = true; treeEntries = fillTree(labLog, treeEntries.sortOrder); } else { if (treeEntries.treeList.Count == 0) { buttonDeleteEntry.Enabled = false; buttonEditNewEntry1.Enabled = false; panelUsers.Controls.Clear(); } else { buttonDeleteEntry.Enabled = true; buttonEditNewEntry1.Enabled = true; } } operationMode = OperationMode.None; } }
public static void insertEntry(ref LabLog labLog, ref Entry _entry, bool edit) { int tmp = 0; insertEntry(ref labLog, ref _entry, edit, out tmp); }