void UpdateHistorytable(DocHistoryChange change) { DocTable doc; if (change.restoreID == null) { doc = new DocTable { name = change.newDocument.Substring(change.newDocument.LastIndexOf("\\") + 1), date = change.newTime, username = System.Environment.UserName, id = -1 }; } else { doc = new DocTable { name = change.restoreID.name, date = change.newTime, username = System.Environment.UserName, id = -1 }; } history.Insert(0, doc); DocumentHistory.Items.Refresh(); }
private void RestoreButton_Click(object sender, RoutedEventArgs e) { if (DocumentHistory.SelectedIndex > 0) { if (history[DocumentHistory.SelectedIndex].id != -1) { docHistoryChanges.Add(new DocHistoryChange(history[DocumentHistory.SelectedIndex])); UpdateHistorytable(docHistoryChanges[docHistoryChanges.Count - 1]); } else { DocTable tempTable = history[DocumentHistory.SelectedIndex]; DocHistoryChange tempChange = docHistoryChanges[docHistoryChanges.Count - DocumentHistory.SelectedIndex - 1]; docHistoryChanges.Remove(tempChange); docHistoryChanges.Add(tempChange); history.RemoveAt(DocumentHistory.SelectedIndex); history.Insert(0, tempTable); DocumentHistory.Items.Refresh(); } //DatabaseHandler.RestoreDocumentHistory(history[DocumentHistory.SelectedIndex].id); SaveHistoryChange.IsEnabled = true; CancelChange.IsEnabled = true; } }
private void EditWindow_Closing(object sender, DataGrid originalTable, int selectedIndex, int originalType) { DocumentEditWindow editWindow = (DocumentEditWindow)sender; DocTable item = sources[originalTable][selectedIndex]; int newType = (int)editWindow.DocTypeCombo.SelectedValue; if (newType != originalType) { sources[originalTable].RemoveAt(selectedIndex); sources[originalTable].AddIndexes(); originalTable.Items.Refresh(); if (typeToTable.ContainsKey(newType)) { sources[typeToTable[newType]].Add(item); sources[typeToTable[newType]].AddIndexes(); typeToTable[newType].Items.Refresh(); } else { //if there's no table generated then there is no need to add somewhere return; } } item.name = editWindow.DocumentName.Text; item.date = DatabaseHandler.GetDocumentDate(item.id); //TODO UPDATE POINTS }
public static DocTable GetLatestDocument(int docType, int id) { int latestDocId = databaseContext.DocumentHistories.OrderByDescending(a => a.Date).Select(a => a.DocumentID).First(); var query = from d in databaseContext.Documents.Where(dd => dd.id == latestDocId) let p = databaseContext.DocumentHistories.Where(pp => pp.DocumentID == d.id).OrderBy(a => a.Date).FirstOrDefault() select new DocTable { id = latestDocId, name = d.Name, date = p.Date, username = p.UserName }; DocTable doc = query.First(); if (id != -1) { doc.isConnected = databaseContext.PointDocConnections.Where(a => a.DocumentID == latestDocId && a.PointID == id).Any(); } return(doc); }
private void Table_MouseDoubleClick(int docType, DocTable item) { if (item == null) { return; } DocumentEditWindow editWindow = new DocumentEditWindow(item.id); editWindow.Owner = Window.GetWindow(this); editWindow.ShowInTaskbar = false; editWindow.Closing += (sender, e) => { if (!e.Cancel) { UpdateCategories(); } }; editWindow.ShowDialog(); }
public DocHistoryChange(DocTable restoreDocID) { restoreID = restoreDocID; newTime = DateTime.Now; }