Browse Source

Änderungen vom 12.10. teilweise umgesetzt!

Arne Diekmann 8 years ago
parent
commit
03da4c2d53

+ 72 - 1
GreenTree.Nachtragsmanagement.Web/Controllers/DeviationController.cs

@@ -9,6 +9,7 @@ using GreenTree.Nachtragsmanagement.Services.Logging;
 using GreenTree.Nachtragsmanagement.Services.Site;
 using GreenTree.Nachtragsmanagement.Web.Extensions;
 using GreenTree.Nachtragsmanagement.Web.Framework.Authorization;
+using GreenTree.Nachtragsmanagement.Web.Models.Appendix;
 using GreenTree.Nachtragsmanagement.Web.Models.Deviation;
 using GreenTree.Nachtragsmanagement.Web.Models.Global;
 using Newtonsoft.Json;
@@ -187,10 +188,10 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
             foreach (var column in e.ColumnsInfo)
             {
                 if (column.FieldName == "CustomNumber") { column.ColumnWidth = 30; }
+                if (column.FieldName == "Description") { column.IsVisible = false; column.IsDetail = true; }
                 if (column.FieldName == "SiteDescription") { column.ColumnWidth = 60; }
                 if (column.FieldName == "AppendixDescription") { column.ColumnWidth = 50; }
                 if (column.FieldName == "StatusDescription") { column.ColumnWidth = 60; }
-                if (column.FieldName == "Comment") { column.IsVisible = false; column.IsDetail = true; }
             }
         }
 
@@ -322,6 +323,76 @@ namespace GreenTree.Nachtragsmanagement.Web.Controllers
             return PartialView("~/Views/Deviations/_DeviationEditPartial.cshtml", deviationModel);
         }
 
+        /// <summary>
+        /// Partial Edit result for assigning a deviation to a new appendix
+        /// </summary>
+        /// <param name="id">Id of deviation.</param>
+        public ActionResult AssignDeviationToAppendix(int id)
+        {
+            var deviation = _deviationService.GetDeviationById(id);
+            var availableAppendices = new List<Appendix>();
+
+            if (deviation.Site != null)
+                availableAppendices.AddRange(
+                    deviation.Site.Appendices);
+            else if (deviation.Appendix != null && deviation.Appendix.Site != null)
+            {
+                availableAppendices.AddRange(
+                    deviation.Appendix.Site.Appendices
+                        .Where(a => a.Id != deviation.AppendixId));
+            }
+
+            var appendixModels = availableAppendices
+                .Select(a => AppendixDataModel.FromAppendix(a, false))
+                .ToList();
+
+            if (deviation.Appendix != null && deviation.Appendix.Site != null)
+                appendixModels.Insert(0, new AppendixDataModel { Id = -1, Description = "Keinem (Als \"Offen\" markieren)" });
+
+            ViewData["DeviationId"] = id;
+
+            return PartialView("~/Views/Deviations/_DeviationAssignPartial.cshtml", appendixModels);
+        }
+
+        /// <summary>
+        /// Assigns a deviation to the specified appendix 
+        /// </summary>
+        /// <param name="id">Id of deviation.</param>
+        [HttpPost]
+        public ActionResult AssignDeviation(int id, int appendixId)
+        {
+            try
+            {
+                var deviation = _deviationService.GetDeviationById(id);
+
+                if (appendixId == -1 && deviation.Appendix != null && deviation.Appendix.Site != null)
+                {
+                    deviation.SiteId = deviation.Appendix.SiteId;
+                    deviation.Appendix = null;
+                    deviation.AppendixId = null;
+                }
+                else
+                {
+                    deviation.AppendixId = appendixId;
+                    deviation.Site = null;
+                    deviation.SiteId = null;
+                }
+
+                _deviationService.UpdateDeviation(deviation);
+
+                return new JsonResult
+                {
+                    Data = "success"
+                };
+            }
+            catch (Exception ex)
+            {
+                _logger.Error("Fehler bei Zuweisung einer Vertragsabweichung zu einem Nachtrag.", ex, _userHelper.FromCookies());
+
+                return PartialView("~/Views/Shared/_PopupError.cshtml", ex);
+            }
+        }
+
         /// <summary>
         /// Partial edit result if ModelState is valid, otherwise simple JSON result for success
         /// </summary>

+ 14 - 0
GreenTree.Nachtragsmanagement.Web/Extensions/GridViewSettingsHelper.cs

@@ -342,6 +342,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Extensions
                 column.FieldName = "CustomNumber";
                 column.MinWidth = 50;
                 column.Width = new Unit(60, UnitType.Pixel);
+                column.Settings.SortMode = DevExpress.XtraGrid.ColumnSortMode.Custom;
             });
             s.Columns.Add(column =>
             {
@@ -568,6 +569,19 @@ namespace GreenTree.Nachtragsmanagement.Web.Extensions
                 System.Web.HttpContext.Current.Session["DeviationGridViewState"] = new MVCxGridViewState(gridView);
             };
 
+            s.CustomColumnSort = (sender, e) =>
+            {
+                if (e.Column.Name.Equals("CustomNumber", StringComparison.InvariantCultureIgnoreCase))
+                {
+                    int.TryParse(e.GetRow1Value("CustomNumber").ToString(), out int rowVal1);
+                    int.TryParse(e.GetRow2Value("CustomNumber").ToString(), out int rowVal2);
+
+                    e.Result = (rowVal1).CompareTo(rowVal2);
+
+                    e.Handled = true;
+                }
+            };
+
             s.ClientSideEvents.BeginCallback = "function (s, e) { e.customArgs['scrollHeight'] = [ gridScrollHeight ]; }";
             s.ClientSideEvents.ToolbarItemClick = "function (s, e) { onToolbarItemClick(s, e); }";
 

+ 1 - 0
GreenTree.Nachtragsmanagement.Web/GreenTree.Nachtragsmanagement.Web.csproj

@@ -333,6 +333,7 @@
     <Content Include="Views\Shared\_PrintPopupPartial.cshtml" />
     <Content Include="Views\Shared\_PrintDocumentViewerPartial.cshtml" />
     <Content Include="Views\Shared\SaveDocumentViewer.cshtml" />
+    <Content Include="Views\Deviations\_DeviationAssignPartial.cshtml" />
     <None Include="Web.Debug.config">
       <DependentUpon>Web.config</DependentUpon>
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

+ 9 - 2
GreenTree.Nachtragsmanagement.Web/Models/Site/SiteTreeDataModel.cs

@@ -14,6 +14,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Models.Site
         public string Description { get; set; }
         public DateTime? ReceiptDate { get; set; }
         public decimal? Value { get; set; }
+        public string KindDescription { get; set; }
         public int? StatusId { get; set; }
         public string StatusDescription { get; set; }
         public string StatusColor { get; set; }
@@ -80,6 +81,9 @@ namespace GreenTree.Nachtragsmanagement.Web.Models.Site
                                 ? String.Empty
                                 : r.Disturbance.Description)
                             .ToList(),
+                    KindDescription = openDeviation.Kind == null
+                        ? String.Empty
+                        : openDeviation.Kind.Description,
                     StatusId = openDeviation.StatusId,
                     StatusDescription = openDeviation.Status == null
                         ? String.Empty
@@ -142,10 +146,13 @@ namespace GreenTree.Nachtragsmanagement.Web.Models.Site
                                     ? String.Empty
                                     : r.Disturbance.Description)
                                 .ToList(),
+                        KindDescription = deviation.Kind == null
+                            ? String.Empty
+                            : deviation.Kind.Description,
                         StatusId = deviation.StatusId,
                         StatusDescription = deviation.Status == null
-                        ? String.Empty
-                        : deviation.Status.Description,
+                            ? String.Empty
+                            : deviation.Status.Description,
                         Value = deviation.Value.Value * deviation.Percentage.Value,
                         Comment = deviation.Comment
                     };

+ 80 - 0
GreenTree.Nachtragsmanagement.Web/Views/Deviations/_DeviationAssignPartial.cshtml

@@ -0,0 +1,80 @@
+@using GreenTree.Nachtragsmanagement.Web.Extensions
+
+@model IEnumerable<GreenTree.Nachtragsmanagement.Web.Models.Appendix.AppendixDataModel>
+
+<div class="deviationAssignContainer">
+
+	<script>
+		function assignDeviation() {
+			var id = $("#DeviationId").val();
+			var appendixId = devListBoxAssignDeviation.GetValue();
+			if (!id || !appendixId) return;
+			$.ajax({
+				type: "POST",
+				url: '@Url.Action("AssignDeviation", "Deviation")',
+				data: { Id: id, AppendixId: appendixId },
+				success: function (response) {
+					if (response == "success") {
+						devPopupControlAssignDeviation.Hide();
+						devTreeListSiteDeviationAppendices.PerformCallback();
+					} else {
+						$("body").append(response);
+					}
+				},
+				error: function () {
+					 alert("error occured");
+				}
+			});
+		}
+	</script>
+
+	@Html.DevExpress().PopupControl(s =>
+{
+	s.Name = "devPopupControlAssignDeviation";
+	s.Modal = false;
+	s.Width = new Unit(350, UnitType.Pixel);
+	s.CloseAction = CloseAction.OuterMouseClick;
+	s.PopupHorizontalAlign = PopupHorizontalAlign.OutsideRight;
+	s.PopupVerticalAlign = PopupVerticalAlign.TopSides;
+	s.AllowDragging = false;
+	s.AllowResize = false;
+	s.ShowFooter = false;
+	s.ShowHeader = false;
+	s.ShowOnPageLoad = false;
+	s.SetContent(() =>
+	{
+		ViewContext.Writer.Write("<input type=\"hidden\" value=\"" + ViewData["DeviationId"] + "\" id=\"DeviationId\" name=\"DeviationId\" />");
+
+		Html.DevExpress().ListBox(t =>
+		{
+			t.Name = "devListBoxAssignDeviation";
+			t.Width = new Unit(100, UnitType.Percentage);
+			t.Height = new Unit(150, UnitType.Pixel);
+			t.Properties.ValueField = "Id";
+			t.Properties.ValueType = typeof(int);
+			t.SetItemTemplateContent(c =>
+			{
+				var id = Convert.ToInt32(DataBinder.Eval(c.DataItem, "Id"));
+				var description = DataBinder.Eval(c.DataItem, "Description").ToString();
+
+				if (id == -1)
+					ViewContext.Writer.Write(description);
+				else
+					ViewContext.Writer.Write("NT - {0} - {1}", id, description);
+			});
+			t.ControlStyle.Border.BorderStyle = BorderStyle.None;
+		}).BindList(Model).Render();
+
+		Html.RenderPartial(
+			"~/Views/Shared/_PopupButtonPanel.cshtml",
+			new GreenTree.Nachtragsmanagement.Web.Models.Global.PopupModel
+			{
+				PopupName = "devPopupControlAssignDeviation",
+				AcceptFunction = "function (s, e) { assignDeviation(); }"
+			}
+		);
+	});
+	s.Styles.Content.Paddings.Padding = new Unit(0);
+	s.Styles.ModalBackground.Opacity = 0;
+}).GetHtml()
+</div>

+ 17 - 0
GreenTree.Nachtragsmanagement.Web/Views/Sites/_SiteEditPartial.cshtml

@@ -190,6 +190,23 @@
 			});
 		}
 
+		function assignDeviationToAppendix(id, elem) {
+			if (!id || !elem) return;
+			$.ajax({
+				type: "GET",
+				url: '@Url.Action("AssignDeviationToAppendix", "Deviation")',
+				data: { Id: id },
+				success: function (response) {
+					$(".deviationAssignContainer").remove();
+					$("body").append(response);
+					devPopupControlAssignDeviation.ShowAtElement(elem);
+				},
+				error: function () {
+					 alert("error occured");
+				}
+			});
+		}
+
 		function editAppendix(id) {
 			if (!id) return;
 			$.ajax({

+ 4 - 1
GreenTree.Nachtragsmanagement.Web/Views/Sites/_SiteEditTreePartial.cshtml

@@ -39,7 +39,9 @@
 				ViewContext.Writer.Write(
 					"<a href=\"#\" onclick=\"editDeviation(" + DataBinder.Eval(c.DataItem, "Id") + ")\">Bearbeiten</a><br />");
 				ViewContext.Writer.Write(
-					"<a href=\"#\" onclick=\"confirmDeleteDeviation(" + DataBinder.Eval(c.DataItem, "Id") + ")\">Löschen</a>");
+					"<a href=\"#\" onclick=\"confirmDeleteDeviation(" + DataBinder.Eval(c.DataItem, "Id") + ")\">Löschen</a><br />");
+				ViewContext.Writer.Write(
+					"<a href=\"#\" onclick=\"assignDeviationToAppendix(" + DataBinder.Eval(c.DataItem, "Id") + ",this)\">NT zuordnen</a>");
 			}
 			else if (treeKey.StartsWith("a"))
 			{
@@ -89,6 +91,7 @@
 		column.FieldName = "Value";
 		column.PropertiesEdit.DisplayFormatString = "c2";
 	});
+	t.Columns.Add("KindDescription", "VA-Art");
 	t.Columns.Add("StatusDescription", "Status");
 	t.Columns.Add(column =>
 	{