123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.Wpf;
- using InABox.WPF;
- namespace PRSDesktop;
- public class JobDocumentSetMilestoneTasks : DynamicDataGrid<JobDocumentSetMileStoneKanban>
- {
- public Guid MileStoneID { get; set; }
- public Guid JobID { get; set; }
- public JobDocumentSetSettings Settings { get; set; }
-
- protected override void DoReconfigure(FluentList<DynamicGridOption> options)
- {
- base.DoReconfigure(options);
- options.BeginUpdate()
- .Clear()
- .Add(DynamicGridOption.RecordCount)
- .EndUpdate();
- }
- protected override void Init()
- {
- base.Init();
- HiddenColumns.Add(x => x.Kanban.ID);
- HiddenColumns.Add(x => x.Kanban.Summary);
- HiddenColumns.Add(x => x.Entity.DocumentSet.Code);
- HiddenColumns.Add(x => x.Entity.Type.Code);
- HiddenColumns.Add(x => x.Entity.Revision);
- // HiddenColumns.Add(x => x.Kanban.Completed);
- // ActionColumns.Add(new DynamicImageColumn(StatusImage));
- ActionColumns.Add(new DynamicMenuColumn(TaskMenuOpening));
- AddButton("", PRSDesktop.Resources.add.AsBitmapImage(), AddTask);
- AddButton("", PRSDesktop.Resources.pencil.AsBitmapImage(), EditTask);
- AddButton("", PRSDesktop.Resources.delete.AsBitmapImage(), DeleteTask, DynamicGridButtonPosition.Right);
- }
- private void TaskMenuOpening(DynamicMenuColumn column, CoreRow? row)
- {
- var status = column.AddItem("Set Status", PRSDesktop.Resources.kanban, null);
- column.AddItem("To Do", null, (r) => SetTaskStatus(r, KanbanStatus.Open,false), status);
- column.AddItem("In Progress", null, (r) => SetTaskStatus(r, KanbanStatus.InProgress,false), status);
- column.AddItem("Waiting", null, (r) => SetTaskStatus(r, KanbanStatus.Waiting,false), status);
- column.AddItem("Complete", null, (r) => SetTaskStatus(r, KanbanStatus.Complete,true), status);
- column.AddSeparator();
- column.AddItem("Email Task", PRSDesktop.Resources.email, EmailTask);
- }
-
- private void SetTaskStatus(CoreRow row, KanbanStatus category, bool complete)
- {
- using (new WaitCursor())
- {
- var kanbanID = row.Get<JobDocumentSetMileStoneKanban, Guid>(c => c.Kanban.ID);
- var kanban = new Client<Kanban>().Load(
- new Filter<Kanban>(x => x.ID).IsEqualTo(kanbanID)).FirstOrDefault();
- if (kanban == null)
- {
- MessageWindow.ShowError("Cannot Load Kanban", $"No Kanban with ID {kanbanID}");
- return;
- }
- if (category != kanban.Status)
- {
- kanban.Status = category;
- Client.Save(kanban, "Updated from Job Document Milestone List");
- DoChanged();
- Refresh(false,true);
- }
- }
- }
-
- private void EmailTask(CoreRow? row)
- {
- var files = new Client<Document>().Query(
- new Filter<Document>(x => x.ID).InQuery(new Filter<JobDocumentSetMileStoneFile>(x => x.EntityLink.ID).IsEqualTo(MileStoneID),
- x => x.DocumentLink.ID),
- new Columns<Document>(x=>x.FileName,x=>x.Data)
- ).ToDictionary<Document, String, byte[]>(c => c.FileName, c => c.Data);
-
- StringBuilder subject = new StringBuilder();
- subject.AppendFormat("{0}: ", row.Get<JobDocumentSetMileStoneKanban, int>(x => x.Kanban.Number));
- subject.AppendFormat("{0}", row.Get<JobDocumentSetMileStoneKanban, String>(x => x.Kanban.Title));
- StringBuilder body = new StringBuilder();
- body.AppendLine("Dear ,");
- body.AppendLine();
- body.AppendLine("Some information is required regarding the attached documents:");
- body.AppendLine();
- body.AppendLine(row.Get<JobDocumentSetMileStoneKanban, String>(x => x.Kanban.Summary));
- body.AppendLine();
- body.AppendLine("Regards,");
- body.AppendLine(App.EmployeeName);
-
- EmailUtils.CreateEMLFile(
- files,
- "",
- subject.ToString(),
- body.ToString()
- );
- }
- protected override DynamicGridColumns LoadColumns()
- {
- return new DynamicGridColumns()
- {
- new DynamicGridColumn()
- {
- ColumnName = CoreUtils.GetFullPropertyName<JobDocumentSetMileStoneKanban, int>(x => x.Kanban.Number, "."),
- Caption = "#",
- Width = 50,
- Alignment = Alignment.MiddleCenter
- },
- new DynamicGridColumn()
- {
- ColumnName = CoreUtils.GetFullPropertyName<JobDocumentSetMileStoneKanban, String>(x => x.Kanban.Title, "."),
- Caption = "Title",
- Width = 0
- },
- new DynamicGridColumn()
- {
- ColumnName = CoreUtils.GetFullPropertyName<JobDocumentSetMileStoneKanban, KanbanStatus>(x => x.Kanban.Status, "."),
- Caption = "Status",
- Width = 70,
- Alignment = Alignment.MiddleCenter
- }
- };
- }
- // private readonly BitmapImage _status = PRSDesktop.Resources.tick.AsBitmapImage();
- //
- // private BitmapImage? StatusImage(CoreRow? arg)
- // {
- // return arg == null
- // ? _status
- // : arg.Get<JobDocumentSetMileStoneKanban, DateTime>(c => c.Kanban.Completed).IsEmpty()
- // ? null
- // : _status;
- // }
- private bool AddTask(Button arg1, CoreRow[] arg2)
- {
- if (MileStoneID == Guid.Empty)
- return false;
-
- var kg = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), typeof(Kanban));
- kg.OnAfterSave += (editor, items) =>
- {
- List<JobDocumentSetMileStoneKanban> msks = new List<JobDocumentSetMileStoneKanban>();
- foreach (Kanban item in items.Cast<Kanban>())
- {
- JobDocumentSetMileStoneKanban msk = new JobDocumentSetMileStoneKanban();
- msk.Kanban.ID = item.ID;
- msk.Entity.ID = MileStoneID;
- msks.Add(msk);
- }
- new Client<JobDocumentSetMileStoneKanban>().Save(msks, "");
- };
-
- var kanban = new Kanban();
- kanban.EmployeeLink.ID = App.EmployeeID;
- kanban.ManagerLink.ID = App.EmployeeID;
- kanban.JobLink.ID = JobID;
- kanban.Status = KanbanStatus.Open;
- kanban.Type.ID = Settings?.DocumentMilestoneKanbanType.ID ?? Guid.Empty;
- var milestone = new Client<JobDocumentSetMileStone>().Query(new Filter<JobDocumentSetMileStone>(x => x.ID).IsEqualTo(MileStoneID),
- new Columns<JobDocumentSetMileStone>(x => x.DocumentSet.Code).Add(x => x.Type.Code).Add(x => x.Revision)
- ).ToTuples<JobDocumentSetMileStone, String, String, String>(x => x.DocumentSet.Code, x => x.Type.Code, x => x.Revision).FirstOrDefault();
- if (milestone != null)
- {
- kanban.Title = String.Format(
- "{0}: {1} ({2}{3})",
- Settings?.DocumentMilestoneKanbanType.Code,
- milestone.Item1,
- milestone.Item2,
- !String.IsNullOrWhiteSpace(milestone.Item3) ? $" Rev {milestone.Item3}" : ""
- );
- }
- if (kg.EditItems(new Kanban[] { kanban }) == true)
- {
- DoChanged();
- return true;
- }
- return false;
- }
-
- private bool EditTask(Button arg1, CoreRow[] arg2)
- {
- if (MileStoneID == Guid.Empty)
- return false;
- if (!SelectedRows.Any())
- return false;
- var ids = SelectedRows.ToArray().Select(r=>r.Get<JobDocumentSetMileStoneKanban,Guid>(x=>x.Kanban.ID)).ToArray();
- var kanbans = new Client<Kanban>().Load(new Filter<Kanban>(x => x.ID).InList(ids));
- var kg = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), typeof(Kanban));
- if (kg.EditItems(kanbans) == true)
- {
- DoChanged();
- return true;
- }
- return false;
- }
-
- private bool DeleteTask(Button arg1, CoreRow[] arg2)
- {
- if (MileStoneID == Guid.Empty)
- return false;
- if (!SelectedRows.Any())
- return false;
- if (MessageBox.Show("This will unlink the selected task from this milestone, but leave the task active.\n\nDo You wish to continue?",
- "Unlink Task", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
- return false;
- var ids = SelectedRows.ToArray().Select(r=>r.Get<JobDocumentSetMileStoneKanban,Guid>(x=>x.ID)).ToArray();
- var msks = ids.Select(x => new JobDocumentSetMileStoneKanban() { ID = x }).ToArray();
- new Client<JobDocumentSetMileStoneKanban>().Delete(msks, "Removed from Meeting");
- DoChanged();
- return true;
- }
-
- protected override void Reload(Filters<JobDocumentSetMileStoneKanban> criteria, Columns<JobDocumentSetMileStoneKanban> columns, ref SortOrder<JobDocumentSetMileStoneKanban>? sort, Action<CoreTable?, Exception?> action)
- {
- criteria.Add(MileStoneID == Guid.Empty
- ? new Filter<JobDocumentSetMileStoneKanban>(x=>x.Entity.ID).None()
- : new Filter<JobDocumentSetMileStoneKanban>(x => x.Entity.ID).IsEqualTo(MileStoneID));
- base.Reload(criteria, columns, ref sort, action);
- }
-
- }
|