C2025-027-AnnotationsTypeSelect #574

Merged
jjenko merged 10 commits from C2025-027-AnnotationsTypeSelect into Development 2025-07-30 08:23:07 -04:00
13 changed files with 2286 additions and 1277 deletions
Showing only changes of commit d3888e3c32 - Show all commits

View File

@@ -93,8 +93,8 @@ namespace VEPROMS
// Save selected list to DB. // Save selected list to DB.
private void btnUpdate_Click(object sender, EventArgs e) private void btnUpdate_Click(object sender, EventArgs e)
{ {
DataTable dt2 = coverToTable(UserID); DataTable dt2 = coverToTable();
VEPROMS.CSLA.Library.AnnotationstypeSelections.Update(dt2); VEPROMS.CSLA.Library.AnnotationstypeSelections.Update(dt2, UserID);
} }
public class AnnotataionItem public class AnnotataionItem
{ {
@@ -145,33 +145,27 @@ namespace VEPROMS
lstSelected.DisplayMember = "NameStr"; lstSelected.DisplayMember = "NameStr";
lstSelected.ValueMember = "TypeID"; lstSelected.ValueMember = "TypeID";
DataTable lstSelectedTbl = VEPROMS.CSLA.Library.AnnotationstypeSelections.Retrieve(UserID); DataTable lstSelectedTbl = VEPROMS.CSLA.Library.AnnotationstypeSelections.Retrieve(UserID);
if (lstSelectedTbl.Rows.Count > 0)
mschill marked this conversation as resolved
Review

I closed this previous comment since it moved down and reposted here - "Shouldn't need this as foreach loop below should loop 0 times if no rows."

This comment moved down thanks to changes since --- this is referring to the if statement now on line 148 - if (lstSelectedTbl.Rows.Count > 0)
since next statement is
foreach (DataRow lstSelectedRow in lstSelectedTbl.Rows)

I closed this previous comment since it moved down and reposted here - "Shouldn't need this as foreach loop below should loop 0 times if no rows." This comment moved down thanks to changes since --- this is referring to the if statement now on line 148 - if (lstSelectedTbl.Rows.Count > 0) since next statement is foreach (DataRow lstSelectedRow in lstSelectedTbl.Rows)
{
foreach (DataRow lstSelectedRow in lstSelectedTbl.Rows) foreach (DataRow lstSelectedRow in lstSelectedTbl.Rows)
{ {
lstSelected.Items.Add(new AnnotataionItem(lstSelectedRow["Name"].ToString(), (int)lstSelectedRow["TypeID"])); lstSelected.Items.Add(new AnnotataionItem(lstSelectedRow["Name"].ToString(), (int)lstSelectedRow["TypeID"]));
} }
} }
}
private void btnCancel_Click_1(object sender, EventArgs e) private void btnCancel_Click_1(object sender, EventArgs e)
{ {
this.Close(); this.Close();
} }
private DataTable coverToTable(string userid) private DataTable coverToTable()
{ {
int RowID = 0;
DataTable dt = new DataTable(); DataTable dt = new DataTable();
dt.Columns.Add("TypeID", typeof(Int32)); 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>()) foreach (AnnotataionItem item in lstSelected.Items.OfType<AnnotataionItem>())
{ {
++RowID; dt.Rows.Add(item.TypeID);
dt.Rows.Add(item.TypeID, item.NameStr, userid, RowID);
} }
return dt; return dt;
} }
mschill marked this conversation as resolved
Review

see comments in SQL --- shouldn't need RowID

see comments in SQL --- shouldn't need RowID

View File

@@ -24074,10 +24074,6 @@ ELSE
GO GO
-- C2025-027 Annotation Type Filtering -- C2025-027 Annotation Type Filtering
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AnnotationTypeSelections]') AND type in (N'U')) IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AnnotationTypeSelections]') AND type in (N'U'))
DROP TABLE [dbo].[AnnotationTypeSelections] DROP TABLE [dbo].[AnnotationTypeSelections]
@@ -24095,28 +24091,36 @@ GO
-- Create date: 07/10/2025 -- Create date: 07/10/2025
-- Description: Store user Annotation selections for annotation filter. -- Description: Store user Annotation selections for annotation filter.
-- ============================================= -- =============================================
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AnnotationTypeSelections]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[AnnotationTypeSelections]( CREATE TABLE [dbo].[AnnotationTypeSelections](
[ASTypeID] [int] IDENTITY(1,1) NOT NULL, [ASTypeID] [int] IDENTITY(1,1) NOT NULL,
[TypeID] [int] NULL, [TypeID] [int] NULL,
[UsrID] [varchar](50) NULL, [UserID] [varchar](50) NULL,
[Name] [nvarchar](100) NULL, [LastChanged] [datetime] NULL,
[Config] [nvarchar](max) NULL, CONSTRAINT [PK_AnnotationTypeSelections] PRIMARY KEY CLUSTERED
[DTS] [datetime] NULL, ([ASTypeID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
[UserID] [nvarchar](100) NULL, ) ON [PRIMARY]
[LastChanged] [timestamp] NULL END
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
mschill marked this conversation as resolved
Review

Would suggest not having columns named both UserID and UserID in the same table as it is confusing which is the function of each,
Would suggest renaming UserID as something like CreatedBy.

Would suggest not having columns named both UserID and UserID in the same table as it is confusing which is the function of each, Would suggest renaming UserID as something like CreatedBy.
IF OBJECT_ID('DF_AnnotationTypeSelections_LastChanged', 'D') IS NULL
ALTER TABLE AnnotationTypeSelections ADD CONSTRAINT [DF_AnnotationTypeSelections_LastChanged] DEFAULT (getdate()) for [LastChanged];
GO GO
IF EXISTS (SELECT * FROM sys.indexes WHERE name='idx_AnnotationTypeSelections_UsrID' IF EXISTS (SELECT * FROM sys.indexes WHERE name='idx_AnnotationTypeSelections_UserIDTypeID'
AND object_id = OBJECT_ID('[dbo].[AnnotationTypeSelections]')) AND object_id = OBJECT_ID('[dbo].[AnnotationTypeSelections]'))
begin begin
DROP INDEX [idx_AnnotationTypeSelections_UsrID] ON [dbo].[AnnotationTypeSelections]; DROP INDEX [idx_AnnotationTypeSelections_UserIDTypeID] ON [dbo].[AnnotationTypeSelections];
end end
CREATE NONCLUSTERED INDEX idx_AnnotationTypeSelections_UsrID CREATE UNIQUE INDEX [idx_AnnotationTypeSelections_UserIDTypeID] ON [dbo].[AnnotationTypeSelections]
ON [dbo].[AnnotationTypeSelections] (UsrID) (
INCLUDE (TypeID, Name) [UserID] ASC,
[TypeID] ASC
)
INCLUDE (ASTypeID)
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 GO
-- C2025-027 Annotation Type Filtering -- C2025-027 Annotation Type Filtering
@@ -24145,7 +24149,7 @@ AS
(SELECT COUNT(*) FROM [Annotations] WHERE [Annotations].[TypeID]= [TypeID]) [AnnotationCount], (SELECT COUNT(*) FROM [Annotations] WHERE [Annotations].[TypeID]= [TypeID]) [AnnotationCount],
[IsEPAnnotationType] [IsEPAnnotationType]
FROM [AnnotationTypes] --A FROM [AnnotationTypes] --A
WHERE TypeID NOT IN (SELECT TypeID FROM AnnotationTypeSelections WHERE UsrID = @UserID) WHERE TypeID NOT IN (SELECT TypeID FROM AnnotationTypeSelections ATS WHERE ATS.UserID = @UserID)
GO GO
-- C2025-027 Annotation Type Filtering -- C2025-027 Annotation Type Filtering
@@ -24171,18 +24175,19 @@ AS
BEGIN BEGIN
SELECT [ASTypeID] SELECT [ASTypeID]
,ATS.[TypeID] ,ATS.[TypeID]
,[UsrID] ,ATS.[UserID]
,AT.[Name] ,AT.[Name]
,AT.[Config] ,AT.[Config]
,ATS.[DTS] ,ATS.[LastChanged]
,AT.[UserID] ,AT.[UserID]
,AT.[IsEPAnnotationType] ,AT.[IsEPAnnotationType]
FROM [dbo].[AnnotationTypeSelections] ATS FROM [dbo].[AnnotationTypeSelections] ATS
INNER JOIN AnnotationTypes AT ON AT.TypeID = ATS.TypeID INNER JOIN AnnotationTypes AT ON AT.TypeID = ATS.TypeID
WHERE UsrID = @UsrID WHERE ATS.UserID = @UsrID
END END
GO GO
-- C2025-027 Annotation Type Filtering -- C2025-027 Annotation Type Filtering
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getAnnotationstypeFiltered]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1) IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[getAnnotationstypeFiltered]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [getAnnotationstypeFiltered]; DROP PROCEDURE [getAnnotationstypeFiltered];
@@ -24200,19 +24205,19 @@ CREATE PROC [dbo].[getAnnotationstypeFiltered]
) )
AS AS
BEGIN BEGIN
IF((SELECT count(TypeID) FROM AnnotationTypeSelections WHERE UsrID = @UsrID) > 0) IF((SELECT count(TypeID) FROM AnnotationTypeSelections WHERE UserID = @UsrID) > 0)
BEGIN BEGIN
SELECT [ASTypeID] SELECT [ASTypeID]
,ATS.[TypeID] ,ATS.[TypeID]
,[UsrID] ,ATS.[UserID]
,AT.[Name] ,AT.[Name]
,AT.[Config] ,AT.[Config]
,ATS.[DTS] ,ATS.[LastChanged]
,AT.[UserID] ,AT.[UserID]
,AT.[IsEPAnnotationType] ,AT.[IsEPAnnotationType]
FROM [dbo].[AnnotationTypeSelections] ATS FROM [dbo].[AnnotationTypeSelections] ATS
INNER JOIN AnnotationTypes AT ON AT.TypeID = ATS.TypeID INNER JOIN AnnotationTypes AT ON AT.TypeID = ATS.TypeID
WHERE UsrID = @UsrID WHERE ATS.UserID = @UsrID
END END
ELSE ELSE
BEGIN BEGIN
@@ -24241,14 +24246,8 @@ IF EXISTS( SELECT * FROM INFORMATION_SCHEMA.DOMAINS WHERE Domain_Name = 'TableVa
DROP TYPE [dbo].[TableValAnnotTypeSelections] DROP TYPE [dbo].[TableValAnnotTypeSelections]
CREATE TYPE [dbo].[TableValAnnotTypeSelections] AS TABLE( CREATE TYPE [dbo].[TableValAnnotTypeSelections] AS TABLE(
[TypeID] [int] NOT NULL, [TypeID] [int] NOT NULL
[NameStr] [varchar](200) NULL,
[UserID] [varchar](50) NULL,
[RowID] [int] NOT NULL,
PRIMARY KEY CLUSTERED
(
[RowID] ASC
)WITH (IGNORE_DUP_KEY = OFF)
) )
GO GO
@@ -24261,28 +24260,30 @@ GO
-- ============================================= -- =============================================
CREATE PROC [dbo].[UpdateAnnotationstypeSelections] CREATE PROC [dbo].[UpdateAnnotationstypeSelections]
( (
@TempTable AS dbo.TableValAnnotTypeSelections READONLY @TempTable AS dbo.TableValAnnotTypeSelections READONLY,
@UserID [varchar](50) NULL
) )
AS AS
BEGIN BEGIN
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;
declare @i int
select @i = min(RowID) from @TempTable
declare @max int
select @max = max(RowID) from @TempTable
WHILE @i <= @max DELETE FROM AnnotationTypeSelections where UserID = @UserID
BEGIN AND
INSERT INTO AnnotationTypeSelections (TypeID, Name, Usrid) TypeID not in
select TypeID, NameStr, UserID from @TempTable where RowID = @i (Select TypeID From @TempTable tmp)
set @i = @i + 1
END --this would insert all the ones that are in the uploaded table and not already in AnnotationTypeSelections
Insert INTO AnnotationTypeSelections (TypeID, UserID)
Select tmp.TypeID, @UserID
FROM
@TempTable tmp
LEFT OUTER JOIN
AnnotationTypeSelections ATS on ATS.TypeID = tmp.TypeID
AND ATS.UserID = @UserID
where
ATS.ASTypeID IS NULL
END END
GO GO

View File

@@ -41,8 +41,6 @@ namespace VEPROMS.CSLA.Library
// if the user has not created a annotation sub-set list saved to AnnotationTypeSelections table. // if the user has not created a annotation sub-set list saved to AnnotationTypeSelections table.
if (dt.Rows.Count < 1) if (dt.Rows.Count < 1)
{ {
//dt.Rows.Add(DataPortal.Fetch<AnnotationTypeInfoList>());
//DataPortal.Fetch<AnnotationTypeInfoList>();
DataRow row; DataRow row;
mschill marked this conversation as resolved
Review

commented out code should be removed or reason given for why it is commented out / should be in the code long term.

commented out code should be removed or reason given for why it is commented out / should be in the code long term.
Review

Comment removed.

Comment removed.
Review

still appears to be:

//dt.Rows.Add(DataPortal.Fetch());
//DataPortal.Fetch();

still appears to be: //dt.Rows.Add(DataPortal.Fetch<AnnotationTypeInfoList>()); //DataPortal.Fetch<AnnotationTypeInfoList>();
int rowflg = 0; int rowflg = 0;
foreach (AnnotationTypeInfo annosel in DataPortal.Fetch<AnnotationTypeInfoList>()) foreach (AnnotationTypeInfo annosel in DataPortal.Fetch<AnnotationTypeInfoList>())
@@ -145,39 +143,12 @@ namespace VEPROMS.CSLA.Library
} }
} }
} }
//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(); public static void Update(DataTable dt, string UserID)
// }
// catch (Exception ex)
// {
// }
// }
// }
//}
public static void Update(DataTable dt)
{ {
using (SqlConnection cn = Database.VEPROMS_SqlConnection) using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{ {
using (SqlCommand cm = cn.CreateCommand()) using (SqlCommand cm = cn.CreateCommand())
{
try
{ {
cm.CommandType = CommandType.StoredProcedure; cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "UpdateAnnotationstypeSelections"; cm.CommandText = "UpdateAnnotationstypeSelections";
@@ -186,13 +157,9 @@ namespace VEPROMS.CSLA.Library
//Pass table Valued parameter to Store Procedure //Pass table Valued parameter to Store Procedure
SqlParameter sqlParam = cm.Parameters.AddWithValue("@TempTable", dt); SqlParameter sqlParam = cm.Parameters.AddWithValue("@TempTable", dt);
sqlParam.SqlDbType = SqlDbType.Structured; sqlParam.SqlDbType = SqlDbType.Structured;
cm.Parameters.AddWithValue("@UserID", UserID);
cm.ExecuteNonQuery(); cm.ExecuteNonQuery();
} }
catch (Exception ex)
{
}
}
} }
} }