From da6416ab4b394f84a7be8d0b32d4d4fc1544b564 Mon Sep 17 00:00:00 2001 From: Hai Cao Date: Tue, 23 Nov 2021 21:23:36 -0800 Subject: [PATCH 1/3] save --- .../TableDesigner/TableDesignerService.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs index 217b655608..a0737a92fc 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs @@ -108,6 +108,9 @@ private Task HandleProcessTableDesignerEditRequest(ProcessTableDesignerEditReque case DesignerEditType.Remove: this.HandleRemoveItemRequest(requestParams); break; + case DesignerEditType.Update: + this.HandleUpdateItemRequest(requestParams); + break; default: // TODO: Handle 'Update' request break; @@ -185,6 +188,35 @@ private void HandleRemoveItemRequest(ProcessTableDesignerEditRequestParams reque } } + private void HandleUpdateItemRequest(ProcessTableDesignerEditRequestParams requestParams) + { + var table = this.GetTable(requestParams.TableInfo); + var path = requestParams.TableChangeInfo.Path; + + if (path.Length == 3) + { + var propertyName = path[0] as string; + switch (propertyName) + { + case TablePropertyNames.Columns: + var colIndex = (long)path[1]; + var colPropertyName = path[2] as string; + if (colPropertyName == TableColumnPropertyNames.Length) { + table.Columns.Items[Convert.ToInt32(colIndex)].Length = requestParams.TableChangeInfo.Value as string; + } else if (colPropertyName == TableColumnPropertyNames.AllowNulls) { + table.Columns.Items[Convert.ToInt32(colIndex)].IsNullable = (bool)requestParams.TableChangeInfo.Value; + } + break; + default: + break; + } + } + else + { + + } + } + private TableViewModel GetTableViewModel(TableInfo tableInfo) { var table = this.GetTable(tableInfo); From 59105b3b67320c8ce2850c5498d81cfe099347b6 Mon Sep 17 00:00:00 2001 From: Hai Cao Date: Tue, 14 Dec 2021 13:08:36 -0800 Subject: [PATCH 2/3] more handlers for column edits --- .../TableDesigner/TableDesignerService.cs | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs index a0737a92fc..d1012f31cb 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs @@ -199,12 +199,30 @@ private void HandleUpdateItemRequest(ProcessTableDesignerEditRequestParams reque switch (propertyName) { case TablePropertyNames.Columns: - var colIndex = (long)path[1]; + var colIndex = Convert.ToInt32(path[1]); var colPropertyName = path[2] as string; - if (colPropertyName == TableColumnPropertyNames.Length) { - table.Columns.Items[Convert.ToInt32(colIndex)].Length = requestParams.TableChangeInfo.Value as string; - } else if (colPropertyName == TableColumnPropertyNames.AllowNulls) { - table.Columns.Items[Convert.ToInt32(colIndex)].IsNullable = (bool)requestParams.TableChangeInfo.Value; + switch (colPropertyName) + { + case TableColumnPropertyNames.Name: + table.Columns.Items[colIndex].Name = requestParams.TableChangeInfo.Value as string; + break; + case TableColumnPropertyNames.Length: + table.Columns.Items[colIndex].Length = requestParams.TableChangeInfo.Value as string; + break; + case TableColumnPropertyNames.AllowNulls: + table.Columns.Items[colIndex].IsNullable = (bool)requestParams.TableChangeInfo.Value; + break; + case TableColumnPropertyNames.Precision: + table.Columns.Items[colIndex].Precision = Int32.Parse(requestParams.TableChangeInfo.Value as string); + break; + case TableColumnPropertyNames.Scale: + table.Columns.Items[colIndex].Scale = Int32.Parse(requestParams.TableChangeInfo.Value as string); + break; + case TableColumnPropertyNames.Type: + table.Columns.Items[colIndex].DataType = requestParams.TableChangeInfo.Value as string; + break; + default: + break; } break; default: From 3e77230a020fe11ce2dc9dc894fc6848eb1feadc Mon Sep 17 00:00:00 2001 From: Hai Cao Date: Tue, 14 Dec 2021 13:24:07 -0800 Subject: [PATCH 3/3] clean up --- .../TableDesigner/TableDesignerService.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs index d1012f31cb..88ff72188c 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/TableDesigner/TableDesignerService.cs @@ -112,7 +112,6 @@ private Task HandleProcessTableDesignerEditRequest(ProcessTableDesignerEditReque this.HandleUpdateItemRequest(requestParams); break; default: - // TODO: Handle 'Update' request break; } await requestContext.SendResult(new ProcessTableDesignerEditResponse() @@ -229,10 +228,6 @@ private void HandleUpdateItemRequest(ProcessTableDesignerEditRequestParams reque break; } } - else - { - - } } private TableViewModel GetTableViewModel(TableInfo tableInfo)