//Вырезает запись типа "Работа" и ее "дела" во внутренний клипборд public void CutJobRecords(List <ViewRecord> SelectedViewRecords) { Int32[] number; Int32 index; Record r; clipboard.Clear(); ViewRecord vr = SelectedViewRecords[0]; number = GetNumbers(vr.Number); foreach (Record rec in modelRecords) { if (rec.ProjNumber == number[0] && rec.JobNumber == number[1]) { index = IndexOfNumber(number[0], number[1], number[2]); r = rec.Clone(); Record undoRecord = rec.Clone(); UndoAction undoAction = new UndoAction(ActionType.delRecord, undoRecord); undoActions.Push(undoAction); clipboard.Enqueue(r); } } foreach (Record rc in clipboard) { modelRecords.Remove(rc); } NumerationRepair(); }
public void CreateAct(String selectedRowNumber) { //Поиск строки по номеру Проект/Работа/Дело String[] number = selectedRowNumber.Split(new char[] { '.' }); Int32 proj = Int32.Parse(number[0]); Int32 job = Int32.Parse(number[1]); Int32 maxActNumber = MaxNumber(proj, job); Record r = new Record { ProjNumber = proj, JobNumber = job, ActNumber = maxActNumber + 1, RecordDate = DateTime.Today.ToString("dd.MM.yyyy"), Content = "Новое дело", AlarmTime = "", AlarmRepit = AlarmRepit.no, Note = "", RecordType = RecordType.act, RecordStatus = RecordStatus.active, Fill = 0, Hide = false }; modelRecords.Add(r); LastRowUpdate(r); //Запись номера созданной записи в свойство (для установки выделения) //Запись действия для отката UndoAction undoAction = new UndoAction(ActionType.addRecord, r); undoActions.Push(undoAction); redoActions.Clear(); modelRecords.Sort(); }
/// <summary> /// Добавление новой записи типа Проект /// </summary> public void CreateProject() { Record r = new Record(); r.ProjNumber = MaxNumber() + 1; r.JobNumber = 0; r.ActNumber = 0; r.RecordDate = DateTime.Today.ToString("dd.MM.yyyy"); r.Content = "Новый проект"; r.AlarmTime = ""; r.AlarmRepit = AlarmRepit.no; r.Note = ""; r.RecordType = RecordType.project; r.RecordStatus = RecordStatus.active; r.Fill = 0; r.Hide = false; modelRecords.Add(r); LastRowUpdate(r); //Запись созданной записи в свойство (для установки выделения) //Запись действия для отката UndoAction undoAction = new UndoAction(ActionType.addRecord, r); undoActions.Push(undoAction); redoActions.Clear(); modelRecords.Sort(); }
/// <summary> /// Изменение полей в существующей записи Record /// </summary> /// <param name="viewRecord">ViewRecord передается из ViewModel</param> public void UpdateModelRecord(ViewRecord viewRecord) { Int32 index; Record updatedRecord; //Поиск строки по номеру Проект/Работа/Дело String[] number = viewRecord.Number.Split(new char[] { '.' }); Int32 proj = Int32.Parse(number[0]); Int32 job = Int32.Parse(number[1]); Int32 act = Int32.Parse(number[2]); index = IndexOfNumber(proj, job, act); if (index < 0) { MessageBox.Show("Не найдена строка для обновления в modelRecords"); return; } updatedRecord = modelRecords[index]; Record undoRecord = updatedRecord.Clone(); UndoAction undoAction = new UndoAction(ActionType.editRecord, undoRecord); undoActions.Push(undoAction); redoActions.Clear(); updatedRecord.RecordDate = viewRecord.RecordDate; updatedRecord.Content = viewRecord.Content; updatedRecord.AlarmTime = viewRecord.AlarmTime; updatedRecord.Note = viewRecord.Note; //MessageBox.Show("Model Updated"); }
public void SetNote(String rowNumber, String noteContent) { Int32[] number = GetNumbers(rowNumber); Int32 rowIndex = IndexOfNumber(number[0], number[1], number[2]); Record undoRecord = modelRecords[rowIndex].Clone(); UndoAction undoAction = new UndoAction(ActionType.editRecord, undoRecord); undoActions.Push(undoAction); redoActions.Clear(); modelRecords[rowIndex].Note = noteContent; }
//Вставляет записи из внутреннего клипборда public void PasteRecords(List <ViewRecord> SelectedViewRecords) { if (clipboard.Count == 0) { return; } Int32[] number; Int32 index; Boolean lastRecordFlag = true; ViewRecord vr = SelectedViewRecords[0]; number = GetNumbers(vr.Number); index = IndexOfNumber(number[0], number[1], number[2]); RecordType type = clipboard.Peek().RecordType; if (type == RecordType.act) //Вставляем группу записей Act { foreach (Record r in clipboard) { Record undoRecord = r.Clone(); UndoAction undoAction = new UndoAction(ActionType.addRecord, undoRecord); undoActions.Push(undoAction); modelRecords.Insert(++index, r); } } else //Вставляем Работу и ее Дела { for (Int32 i = ++index; i < modelRecords.Count(); i++) //Ищем следующую запись типа Проект или Работа { if (modelRecords[i].RecordType == RecordType.job || modelRecords[i].RecordType == RecordType.project) { index = i - 1; lastRecordFlag = false; break; } } if (lastRecordFlag) //Если дошли до конца modelRecords { index = modelRecords.Count() - 1; } foreach (Record r in clipboard) { Record undoRecord = r.Clone(); UndoAction undoAction = new UndoAction(ActionType.addRecord, undoRecord); undoActions.Push(undoAction); modelRecords.Insert(++index, r); } } NumerationRepair(); }
//Установить цвет записи (Установка поля Fill) public void SetColor(String selectedRowNumber, Int32 colorIndex) { Int32 index; Int32[] numbers = GetNumbers(selectedRowNumber); index = IndexOfNumber(numbers[0], numbers[1], numbers[2]); Record undoRecord = modelRecords[index].Clone(); UndoAction undoAction = new UndoAction(ActionType.editRecord, undoRecord); undoActions.Push(undoAction); redoActions.Clear(); modelRecords[index].Fill = colorIndex; }
//Снять признак завершения проекта/Дела/Работы public void UnFinalize(String selectedRowNumber) { Int32 index; Int32[] numbers = GetNumbers(selectedRowNumber); index = IndexOfNumber(numbers[0], numbers[1], numbers[2]); Record undoRecord = modelRecords[index].Clone(); UndoAction undoAction = new UndoAction(ActionType.editRecord, undoRecord); undoActions.Push(undoAction); redoActions.Clear(); modelRecords[index].RecordStatus = RecordStatus.active; }
//Завершить проект/Дело/Работу public void Finalize(String selectedRowNumber) { String[] number = selectedRowNumber.Split(new char[] { '.' }); Int32 proj = Int32.Parse(number[0]); Int32 job = Int32.Parse(number[1]); Int32 act = Int32.Parse(number[2]); Int32 index; if (act > 0) //Завершить дело { index = IndexOfNumber(proj, job, act); Record undoRecord = modelRecords[index].Clone(); UndoAction undoAction = new UndoAction(ActionType.editRecord, undoRecord); undoActions.Push(undoAction); modelRecords[index].RecordStatus = RecordStatus.finished; } else if (job > 0) //Завершить работу { List <Int32> indexes = IndexOfNumberList(proj, job); if (indexes.Count > 0) { foreach (Int32 j in indexes) { Record undoRecord = modelRecords[j].Clone(); UndoAction undoAction = new UndoAction(ActionType.editRecord, undoRecord); undoActions.Push(undoAction); modelRecords[j].RecordStatus = RecordStatus.finished; } } } else //Завершить проект { List <Int32> indexes = IndexOfNumberList(proj); if (indexes.Count > 0) { foreach (Int32 j in indexes) { Record undoRecord = modelRecords[j].Clone(); UndoAction undoAction = new UndoAction(ActionType.editRecord, undoRecord); undoActions.Push(undoAction); modelRecords[j].RecordStatus = RecordStatus.finished; } } } redoActions.Clear(); }
public void UnHideRecord(String selectedRowNumber) { Int32 index; List <Int32> indexes = new List <int>(3); Int32[] numbers = GetNumbers(selectedRowNumber); index = IndexOfNumber(numbers[0], numbers[1], numbers[2]); switch (modelRecords[index].RecordType) { case RecordType.project: indexes = IndexOfNumberList(numbers[0]); break; case RecordType.job: indexes = IndexOfNumberList(numbers[0], numbers[1]); break; case RecordType.act: //Взять следующую строку и запустить цикл по номерам от следующего за текущим и до второй строки indexes.Add(index); for (int i = index + 1; i < modelRecords.Count; i++) { if (modelRecords[i].Hide == true && modelRecords[i].RecordType == RecordType.act) { indexes.Add(i); } else { break; } } break; } foreach (Int32 i in indexes) { Record undoRecord = modelRecords[index].Clone(); UndoAction undoAction = new UndoAction(ActionType.editRecord, undoRecord); undoActions.Push(undoAction); redoActions.Clear(); modelRecords[i].Hide = false; } }
public void UnArhivate(String selectedRowNumber) { String[] number = selectedRowNumber.Split(new char[] { '.' }); Int32 proj = Int32.Parse(number[0]); List <Int32> indexes = IndexOfNumberList(proj); if (indexes.Count > 0) { foreach (Int32 j in indexes) { Record undoRecord = modelRecords[j].Clone(); UndoAction undoAction = new UndoAction(ActionType.editRecord, undoRecord); undoActions.Push(undoAction); redoActions.Clear(); modelRecords[j].RecordStatus = RecordStatus.active; } } }
//Отмена предыдущей операции public void Undo() { Int32 i; UndoAction undoAction = undoActions.Pop(); UndoAction redoAction = new UndoAction(); switch (undoAction.UndoActionType) { case ActionType.addRecord: //Отмена добавления записи i = IndexOfNumber(undoAction.RecordData.ProjNumber, undoAction.RecordData.JobNumber, undoAction.RecordData.ActNumber); redoAction.UndoActionType = ActionType.delRecord; redoAction.RecordData = modelRecords[i]; redoActions.Push(redoAction); modelRecords.RemoveAt(i); break; case ActionType.delRecord: //Отмена удаления записи redoAction.UndoActionType = ActionType.addRecord; redoAction.RecordData = undoAction.RecordData; redoActions.Push(redoAction); modelRecords.Add(undoAction.RecordData); modelRecords.Sort(); break; case ActionType.editRecord: //Отмена редактировании записи i = IndexOfNumber(undoAction.RecordData.ProjNumber, undoAction.RecordData.JobNumber, undoAction.RecordData.ActNumber); Debug.Assert(i > 0); // redoAction.UndoActionType = ActionType.editRecord; redoAction.RecordData = modelRecords[i]; redoActions.Push(redoAction); // modelRecords[i] = undoAction.RecordData; break; default: Debug.Assert(false, "Ошибка ActionType в операции Undo"); break; } }
//Удалить запись или группу записей (все записи Дела/Проекта) public void DelRecord(String selectedRowNumber) { List <Int32> indexList = new List <int>(); List <Record> deletedRecords = new List <Record>(); String[] number = selectedRowNumber.Split(new char[] { '.' }); Int32 proj = Int32.Parse(number[0]); Int32 job = Int32.Parse(number[1]); Int32 act = Int32.Parse(number[2]); Int32 index; index = IndexOfNumber(proj, job, act); Record delatedRecord = modelRecords[index]; // switch (delatedRecord.RecordType) { case RecordType.act: indexList.Add(index); break; case RecordType.job: indexList = IndexOfNumberList(proj, job); break; case RecordType.project: indexList = IndexOfNumberList(proj); break; } foreach (Int32 j in indexList) { deletedRecords.Add(modelRecords[j]); } foreach (Record r in deletedRecords) { Record undoRecord = r.Clone(); UndoAction undoAction = new UndoAction(ActionType.delRecord, undoRecord); undoActions.Push(undoAction); redoActions.Clear(); modelRecords.Remove(r); } }
//Вырезает группу записей типа "Дело" во внутренний клипборд public void CutActRecords(List <ViewRecord> SelectedViewRecords) { Int32[] number; Int32 index; Record r; clipboard.Clear(); foreach (ViewRecord vr in SelectedViewRecords) { number = GetNumbers(vr.Number); index = IndexOfNumber(number[0], number[1], number[2]); r = modelRecords[index].Clone(); Record undoRecord = modelRecords[index].Clone(); UndoAction undoAction = new UndoAction(ActionType.delRecord, undoRecord); undoActions.Push(undoAction); clipboard.Enqueue(r); modelRecords.Remove(r); } NumerationRepair(); //TODO: model.CutActRecords криво работает отмена, добавить перенумерацию записей при выполнении Undo }
public void HideRecord(String selectedRowNumber) { Int32 index; List <Int32> indexes = new List <int>(3); Int32[] numbers = GetNumbers(selectedRowNumber); index = IndexOfNumber(numbers[0], numbers[1], numbers[2]); switch (modelRecords[index].RecordType) { case RecordType.project: indexes = IndexOfNumberList(numbers[0]); break; case RecordType.job: indexes = IndexOfNumberList(numbers[0], numbers[1]); break; case RecordType.act: indexes.Add(index); break; } foreach (Int32 i in indexes) { if (modelRecords[index].RecordType == RecordType.project && modelRecords[i].RecordType == RecordType.project) { continue; } else if (modelRecords[index].RecordType == RecordType.job && modelRecords[i].RecordType == RecordType.job) { continue; } Record undoRecord = modelRecords[i].Clone(); UndoAction undoAction = new UndoAction(ActionType.editRecord, undoRecord); undoActions.Push(undoAction); redoActions.Clear(); modelRecords[i].Hide = true; } }