C2025-027-AnnotationsTypeSelect

This commit is contained in:
2025-07-25 23:06:50 -04:00
parent 025fa57e24
commit 99445406fc
5 changed files with 124 additions and 162 deletions

View File

@@ -14,9 +14,6 @@ namespace VEPROMS
// C2025-027 Annotation Type Filtering
public partial class dlgAnnotationsSelect : Form
{
//int AnnotationTypeID;
//string AnnotationNameStr = "";
public dlgAnnotationsSelect()
{
InitializeComponent();
@@ -96,22 +93,8 @@ namespace VEPROMS
// Save selected list to DB.
private void btnUpdate_Click(object sender, EventArgs e)
{
int AnnotationTypeID;
string AnnotationNameStr = "";
// dltFlg flag is used to notify SQL SP to deleted all the entries for the user before entering the annotation type selections.
int dltFlg = 1;
//foreach (AnnotataionItem item in lstSelected.Items.OfType<AnnotataionItem>())
//{
// AnnotationTypeID = item.TypeID;
// AnnotationNameStr = item.NameStr;
DataTable dt2 = coverToTable(UserID);
VEPROMS.CSLA.Library.AnnotationstypeSelections.Update2(dt2);
// dltFlg = 0;
//}
VEPROMS.CSLA.Library.AnnotationstypeSelections.Update(dt2);
}
public class AnnotataionItem
{
@@ -178,14 +161,17 @@ namespace VEPROMS
private DataTable coverToTable(string userid)
{
int RowID = 0;
DataTable dt = new DataTable();
dt.Columns.Add("TypeID", typeof(Int32));
dt.Columns.Add("NameStr", typeof(string));
dt.Columns.Add("UserID", typeof(string));
dt.Columns.Add("RowID", typeof(string));
foreach (AnnotataionItem item in lstSelected.Items.OfType<AnnotataionItem>())
{
dt.Rows.Add(item.TypeID, item.NameStr, userid);
++RowID;
dt.Rows.Add(item.TypeID, item.NameStr, userid, RowID);
}
return dt;
}

View File

@@ -24104,15 +24104,10 @@ CREATE TABLE [dbo].[AnnotationTypeSelections](
[Config] [nvarchar](max) NULL,
[DTS] [datetime] NULL,
[UserID] [nvarchar](100) NULL,
[LastChanged] [timestamp] NULL,
[IsEPAnnotationType] [bit] NULL
[LastChanged] [timestamp] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
--CREATE UNIQUE INDEX idx_AnnotationTypeSelections_Usrid
--ON AnnotationTypeSelections (TypeID, Name, UsrID);
--GO
IF EXISTS (SELECT * FROM sys.indexes WHERE name='idx_AnnotationTypeSelections_UsrID'
AND object_id = OBJECT_ID('[dbo].[AnnotationTypeSelections]'))
begin
@@ -24124,17 +24119,6 @@ CREATE NONCLUSTERED INDEX idx_AnnotationTypeSelections_UsrID
INCLUDE (TypeID, Name)
GO
--CREATE NONCLUSTERED INDEX [idx_AnnotationTypeSelections_Usrid] ON [dbo].[AnnotationTypeSelections]
--(
-- [UsrID] ASC
--)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
--GO
--CREATE NONCLUSTERED INDEX [idx_AnnotationTypeSelections_TypeID] ON [dbo].[AnnotationTypeSelections]
--(
-- [TypeID] ASC
--)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
--GO
-- C2025-027 Annotation Type Filtering
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getAnnotationSelectListTypes]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [getAnnotationSelectListTypes];
@@ -24161,8 +24145,7 @@ AS
(SELECT COUNT(*) FROM [Annotations] WHERE [Annotations].[TypeID]= [TypeID]) [AnnotationCount],
[IsEPAnnotationType]
FROM [AnnotationTypes] --A
WHERE TypeID NOT IN (SELECT TypeID FROM AnnotationTypeSelections WHERE UsrID = @UserID)
WHERE TypeID NOT IN (SELECT TypeID FROM AnnotationTypeSelections WHERE UsrID = @UserID)
GO
-- C2025-027 Annotation Type Filtering
@@ -24187,26 +24170,23 @@ CREATE PROC [dbo].[getAnnotationstypeSelections]
AS
BEGIN
SELECT [ASTypeID]
,[TypeID]
,ATS.[TypeID]
,[UsrID]
,[Name]
,[Config]
,[DTS]
,[UserID]
,[IsEPAnnotationType]
FROM [dbo].[AnnotationTypeSelections]
,AT.[Name]
,AT.[Config]
,ATS.[DTS]
,AT.[UserID]
,AT.[IsEPAnnotationType]
FROM [dbo].[AnnotationTypeSelections] ATS
INNER JOIN AnnotationTypes AT ON AT.TypeID = ATS.TypeID
WHERE UsrID = @UsrID
END
GO
GO
-- C2025-027 Annotation Type Filtering
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getAnnotationstypeFiltered]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [getAnnotationstypeFiltered];
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Paul Larsen
@@ -24223,14 +24203,15 @@ BEGIN
IF((SELECT count(TypeID) FROM AnnotationTypeSelections WHERE UsrID = @UsrID) > 0)
BEGIN
SELECT [ASTypeID]
,[TypeID]
,ATS.[TypeID]
,[UsrID]
,[Name]
,[Config]
,[DTS]
,[UserID]
,[IsEPAnnotationType]
FROM [dbo].[AnnotationTypeSelections]
,AT.[Name]
,AT.[Config]
,ATS.[DTS]
,AT.[UserID]
,AT.[IsEPAnnotationType]
FROM [dbo].[AnnotationTypeSelections] ATS
INNER JOIN AnnotationTypes AT ON AT.TypeID = ATS.TypeID
WHERE UsrID = @UsrID
END
ELSE
@@ -24249,28 +24230,12 @@ BEGIN
END
GO
-- C2025-027 Annotation Type Filtering
--IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[TableValAnnotTypeSelections]') AND OBJECTPROPERTY(id,N'IsType') = 1)
-- Type --
--IF NOT EXISTS (SELECT * FROM sys.types WHERE is_table_type = 1 AND name ='TableValAnnotTypeSelections')
-- DROP PROCEDURE [TableValAnnotTypeSelections];
--GO
--/****** Object: UserDefinedTableType [dbo].[TableValAnnotTypeSelections] Script Date: 7/21/2025 8:06:11 PM ******/
--CREATE TYPE [dbo].[TableValAnnotTypeSelections] AS TABLE(
-- [TypeID] [int] NOT NULL,
-- [NameStr] [varchar](200) NULL,
-- [UserID] [varchar](50) NULL
--)
--GO
-- C2025-027 Annotation Type Filtering
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[UpdateAnnotationstypeSelections2]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [UpdateAnnotationstypeSelections2];
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[UpdateAnnotationstypeSelections]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [UpdateAnnotationstypeSelections];
-- Need to drop UpdateAnnotationstypeSelections2 SP first so script can drop and recreate the TableValAnnotTypeSelections table type
-- Need to drop UpdateAnnotationstypeSelections SP first so script can drop and recreate the TableValAnnotTypeSelections table type
IF EXISTS( SELECT * FROM INFORMATION_SCHEMA.DOMAINS WHERE Domain_Name = 'TableValAnnotTypeSelections' )
DROP TYPE [dbo].[TableValAnnotTypeSelections]
@@ -24278,63 +24243,46 @@ IF EXISTS( SELECT * FROM INFORMATION_SCHEMA.DOMAINS WHERE Domain_Name = 'TableVa
CREATE TYPE [dbo].[TableValAnnotTypeSelections] AS TABLE(
[TypeID] [int] NOT NULL,
[NameStr] [varchar](200) NULL,
[UserID] [varchar](50) NULL
[UserID] [varchar](50) NULL,
[RowID] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[RowID] ASC
)WITH (IGNORE_DUP_KEY = OFF)
)
GO
/****** Object: StoredProcedure [dbo].[UpdateAnnotationstypeSelections2] Script Date: 7/21/2025 8:51:42 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/****** Object: StoredProcedure [dbo].[UpdateAnnotationstypeSelections] Script Date: 7/21/2025 8:51:42 PM ******/
-- =============================================
-- Author: Paul Larsen
-- Create date: 07/21/2025
-- Description: Manage user choice annotation types
-- =============================================
CREATE PROC [dbo].[UpdateAnnotationstypeSelections2]
CREATE PROC [dbo].[UpdateAnnotationstypeSelections]
(
@TempTable AS dbo.TableValAnnotTypeSelections READONLY
)
AS
BEGIN
--INSERT INTO CUSTOMER (CustomerId,CustomerName ,Isdeleted )
--SELECT CustomerId, CustomerName, 0 AS Isdeleted FROM @TempTable
DECLARE @cnt integer = 0
DECLARE @cnt2 integer = 0
SET @cnt = (SELECT count(*) from @TempTable)
DECLARE @UserID VARCHAR(50) = (SELECT TOP 1 UserID FROM @TempTable)
DELETE FROM AnnotationTypeSelections WHERE usrID = @UserID;
MERGE AnnotationTypeSelections AS TARGET
USING @TempTable AS SOURCE
declare @i int
select @i = min(RowID) from @TempTable
declare @max int
select @max = max(RowID) from @TempTable
/* 1. Performing the UPDATE operation */
/* If the P_ID is same,
check for change in P_NAME or P_PRICE */
ON (TARGET.TypeID = SOURCE.TypeID)
WHEN MATCHED
AND TARGET.Name <> SOURCE.NameStr
/* Update the records in TARGET */
THEN UPDATE
SET TARGET.Name = SOURCE.NameStr,
TARGET.UsrID = SOURCE.UserID
/* 2. Performing the INSERT operation */
/* When no records are matched with TARGET table
Then insert the records in the target table */
WHEN NOT MATCHED BY TARGET
THEN INSERT (TypeID, Name, UsrID)
VALUES (SOURCE.TypeID, SOURCE.NameStr,SOURCE.UserID)
/* 3. Performing the DELETE operation */
/* When no records are matched with SOURCE table
Then delete the records from the target table */
WHEN NOT MATCHED BY SOURCE
THEN DELETE;
WHILE @i <= @max
BEGIN
INSERT INTO AnnotationTypeSelections (TypeID, Name, Usrid)
select TypeID, NameStr, UserID from @TempTable where RowID = @i
set @i = @i + 1
END
END
GO

View File

@@ -158,6 +158,11 @@
<Compile Include="dlgAnnotationsSelect.Designer.cs">
<DependentUpon>dlgAnnotationsSelect.cs</DependentUpon>
</Compile>
<Compile Include="dlgAnnotationsSelect.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>dlgAnnotationsSelect.resx</DependentUpon>
</Compile>
<Compile Include="dlgApproveProcedure.cs">
<SubType>Form</SubType>
</Compile>
@@ -346,7 +351,6 @@
<EmbeddedResource Include="dlgAnnotationsSelect.resx">
<DependentUpon>dlgAnnotationsSelect.cs</DependentUpon>
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>dlgAnnotationsSelect2.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="dlgMSWordMessage.resx">
<DependentUpon>dlgMSWordMessage.cs</DependentUpon>

View File

@@ -39,6 +39,8 @@ namespace VEPROMS
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.btnCancel = new System.Windows.Forms.Button();
this.lblMessage = new System.Windows.Forms.Label();
this.lblAvailableTypes = new System.Windows.Forms.Label();
this.lblSelected = new System.Windows.Forms.Label();
this.tableLayoutPanel1.SuspendLayout();
this.SuspendLayout();
//
@@ -47,12 +49,12 @@ namespace VEPROMS
this.lstUnselected.Dock = System.Windows.Forms.DockStyle.Fill;
this.lstUnselected.FormattingEnabled = true;
this.lstUnselected.IntegralHeight = false;
this.lstUnselected.ItemHeight = 20;
this.lstUnselected.ItemHeight = 16;
this.lstUnselected.Location = new System.Drawing.Point(3, 3);
this.lstUnselected.Name = "lstUnselected";
this.tableLayoutPanel1.SetRowSpan(this.lstUnselected, 4);
this.lstUnselected.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.lstUnselected.Size = new System.Drawing.Size(287, 359);
this.lstUnselected.Size = new System.Drawing.Size(287, 347);
this.lstUnselected.TabIndex = 0;
this.lstUnselected.SelectedIndexChanged += new System.EventHandler(this.lst_SelectedIndexChanged);
//
@@ -61,19 +63,19 @@ namespace VEPROMS
this.lstSelected.Dock = System.Windows.Forms.DockStyle.Fill;
this.lstSelected.FormattingEnabled = true;
this.lstSelected.IntegralHeight = false;
this.lstSelected.ItemHeight = 20;
this.lstSelected.ItemHeight = 16;
this.lstSelected.Location = new System.Drawing.Point(334, 3);
this.lstSelected.Name = "lstSelected";
this.tableLayoutPanel1.SetRowSpan(this.lstSelected, 4);
this.lstSelected.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
this.lstSelected.Size = new System.Drawing.Size(288, 359);
this.lstSelected.Size = new System.Drawing.Size(288, 347);
this.lstSelected.TabIndex = 1;
this.lstSelected.SelectedIndexChanged += new System.EventHandler(this.lst_SelectedIndexChanged);
//
// btnSelect
//
this.btnSelect.Anchor = System.Windows.Forms.AnchorStyles.None;
this.btnSelect.Location = new System.Drawing.Point(298, 34);
this.btnSelect.Location = new System.Drawing.Point(298, 32);
this.btnSelect.Name = "btnSelect";
this.btnSelect.Size = new System.Drawing.Size(28, 23);
this.btnSelect.TabIndex = 2;
@@ -84,9 +86,9 @@ namespace VEPROMS
// btnSelectAll
//
this.btnSelectAll.Anchor = System.Windows.Forms.AnchorStyles.None;
this.btnSelectAll.Location = new System.Drawing.Point(298, 125);
this.btnSelectAll.Location = new System.Drawing.Point(296, 120);
this.btnSelectAll.Name = "btnSelectAll";
this.btnSelectAll.Size = new System.Drawing.Size(28, 23);
this.btnSelectAll.Size = new System.Drawing.Size(32, 23);
this.btnSelectAll.TabIndex = 3;
this.btnSelectAll.Text = ">>";
this.btnSelectAll.UseVisualStyleBackColor = true;
@@ -95,9 +97,9 @@ namespace VEPROMS
// btnDeselectAll
//
this.btnDeselectAll.Anchor = System.Windows.Forms.AnchorStyles.None;
this.btnDeselectAll.Location = new System.Drawing.Point(298, 216);
this.btnDeselectAll.Location = new System.Drawing.Point(297, 207);
this.btnDeselectAll.Name = "btnDeselectAll";
this.btnDeselectAll.Size = new System.Drawing.Size(28, 23);
this.btnDeselectAll.Size = new System.Drawing.Size(30, 26);
this.btnDeselectAll.TabIndex = 5;
this.btnDeselectAll.Text = "<<";
this.btnDeselectAll.UseVisualStyleBackColor = true;
@@ -106,7 +108,7 @@ namespace VEPROMS
// btnDeselect
//
this.btnDeselect.Anchor = System.Windows.Forms.AnchorStyles.None;
this.btnDeselect.Location = new System.Drawing.Point(298, 307);
this.btnDeselect.Location = new System.Drawing.Point(298, 297);
this.btnDeselect.Name = "btnDeselect";
this.btnDeselect.Size = new System.Drawing.Size(28, 23);
this.btnDeselect.TabIndex = 4;
@@ -140,14 +142,14 @@ namespace VEPROMS
this.tableLayoutPanel1.Controls.Add(this.btnDeselectAll, 1, 2);
this.tableLayoutPanel1.Controls.Add(this.btnSelect, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.btnSelectAll, 1, 1);
this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 51);
this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 62);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 4;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(625, 365);
this.tableLayoutPanel1.Size = new System.Drawing.Size(625, 353);
this.tableLayoutPanel1.TabIndex = 6;
//
// btnCancel
@@ -163,28 +165,49 @@ namespace VEPROMS
// lblMessage
//
this.lblMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblMessage.Location = new System.Drawing.Point(50, 18);
this.lblMessage.Location = new System.Drawing.Point(43, 12);
this.lblMessage.Name = "lblMessage";
this.lblMessage.Size = new System.Drawing.Size(317, 28);
this.lblMessage.Size = new System.Drawing.Size(317, 16);
this.lblMessage.TabIndex = 10;
this.lblMessage.Text = "Updates will appear when PROMS is restarted.";
//
// DlgAnnotationsSelect
// lblAvailableTypes
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.lblAvailableTypes.AutoSize = true;
this.lblAvailableTypes.Location = new System.Drawing.Point(12, 43);
this.lblAvailableTypes.Name = "lblAvailableTypes";
this.lblAvailableTypes.Size = new System.Drawing.Size(110, 16);
this.lblAvailableTypes.TabIndex = 11;
this.lblAvailableTypes.Text = "Types Available ";
//
// lblSelected
//
this.lblSelected.AutoSize = true;
this.lblSelected.Location = new System.Drawing.Point(343, 43);
this.lblSelected.Name = "lblSelected";
this.lblSelected.Size = new System.Drawing.Size(104, 16);
this.lblSelected.TabIndex = 12;
this.lblSelected.Text = "Types Selected";
//
// dlgAnnotationsSelect
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(653, 466);
this.Controls.Add(this.lblSelected);
this.Controls.Add(this.lblAvailableTypes);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.tableLayoutPanel1);
this.Controls.Add(this.btnUpdate);
this.Controls.Add(this.lblMessage);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "DlgAnnotationsSelect";
this.Name = "dlgAnnotationsSelect";
this.Text = "Select Annotation Types";
this.Load += new System.EventHandler(this.DlgAnnotationsSelect_Load);
this.tableLayoutPanel1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
@@ -200,6 +223,7 @@ namespace VEPROMS
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Label lblMessage;
private System.Windows.Forms.Label lblAvailableTypes;
private System.Windows.Forms.Label lblSelected;
}
}

View File

@@ -145,7 +145,33 @@ namespace VEPROMS.CSLA.Library
}
}
}
public static void Update(string UserID, int TypeID, int dltFlg, string Name = "")
//public static void Update(string UserID, int TypeID, int dltFlg, string Name = "")
//{
// using (SqlConnection cn = Database.VEPROMS_SqlConnection)
// {
// using (SqlCommand cm = cn.CreateCommand())
// {
// try
// {
// cm.CommandType = CommandType.StoredProcedure;
// cm.CommandText = "UpdateAnnotationstypeSelections";
// cm.CommandTimeout = Database.DefaultTimeout;
// cm.Parameters.AddWithValue("@UserID", UserID);
// cm.Parameters.AddWithValue("@TypeID", TypeID);
// cm.Parameters.AddWithValue("@dltFlg", dltFlg);
// cm.Parameters.AddWithValue("@Name", Name);
// cm.ExecuteNonQuery();
// }
// catch (Exception ex)
// {
// }
// }
// }
//}
public static void Update(DataTable dt)
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
@@ -156,32 +182,6 @@ namespace VEPROMS.CSLA.Library
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "UpdateAnnotationstypeSelections";
cm.CommandTimeout = Database.DefaultTimeout;
cm.Parameters.AddWithValue("@UserID", UserID);
cm.Parameters.AddWithValue("@TypeID", TypeID);
cm.Parameters.AddWithValue("@dltFlg", dltFlg);
cm.Parameters.AddWithValue("@Name", Name);
cm.ExecuteNonQuery();
}
catch (Exception ex)
{
}
}
}
}
public static void Update2(DataTable dt)
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
using (SqlCommand cm = cn.CreateCommand())
{
try
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "UpdateAnnotationstypeSelections2";
cm.CommandTimeout = Database.DefaultTimeout;
//Pass table Valued parameter to Store Procedure
SqlParameter sqlParam = cm.Parameters.AddWithValue("@TempTable", dt);