Ejemplo n.º 1
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("ImportsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[Imports] SET     [FileName] = @FileName,    [OrganizationID] = @OrganizationID,    [ImportGUID] = @ImportGUID,    [RefType] = @RefType,    [AuxID] = @AuxID,    [IsDone] = @IsDone,    [IsRunning] = @IsRunning,    [IsDeleted] = @IsDeleted,    [NeedsDeleted] = @NeedsDeleted,    [TotalRows] = @TotalRows,    [CompletedRows] = @CompletedRows,    [DateStarted] = @DateStarted,    [DateEnded] = @DateEnded,    [IsRolledBack] = @IsRolledBack,    [FilePathID] = @FilePathID  WHERE ([ImportID] = @ImportID);";


            tempParameter = updateCommand.Parameters.Add("ImportID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("FileName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ImportGUID", SqlDbType.UniqueIdentifier, 16);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("AuxID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("IsDone", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsRunning", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsDeleted", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("NeedsDeleted", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("TotalRows", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("CompletedRows", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DateStarted", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("DateEnded", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("IsRolledBack", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("FilePathID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[Imports] (    [FileName],    [OrganizationID],    [ImportGUID],    [RefType],    [AuxID],    [IsDone],    [IsRunning],    [IsDeleted],    [NeedsDeleted],    [TotalRows],    [CompletedRows],    [DateStarted],    [DateEnded],    [DateCreated],    [CreatorID],    [IsRolledBack],    [FilePathID]) VALUES ( @FileName, @OrganizationID, @ImportGUID, @RefType, @AuxID, @IsDone, @IsRunning, @IsDeleted, @NeedsDeleted, @TotalRows, @CompletedRows, @DateStarted, @DateEnded, @DateCreated, @CreatorID, @IsRolledBack, @FilePathID); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("FilePathID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("IsRolledBack", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateEnded", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateStarted", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("CompletedRows", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("TotalRows", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("NeedsDeleted", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsDeleted", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsRunning", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsDone", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("AuxID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ImportGUID", SqlDbType.UniqueIdentifier, 16);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("FileName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[Imports] WHERE ([ImportID] = @ImportID);";
            deleteCommand.Parameters.Add("ImportID", SqlDbType.Int);

            try
            {
                foreach (Import import in this)
                {
                    if (import.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(import);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = import.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["ImportID"].AutoIncrement = false;
                        Table.Columns["ImportID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            import.Row["ImportID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(import);
                    }
                    else if (import.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(import);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = import.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(import);
                    }
                    else if (import.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)import.Row["ImportID", DataRowVersion.Original];
                        deleteCommand.Parameters["ImportID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 2
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("PortalLoginHistorySave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[PortalLoginHistory] SET     [UserName] = @UserName,    [OrganizationID] = @OrganizationID,    [OrganizationName] = @OrganizationName,    [Success] = @Success,    [LoginDateTime] = @LoginDateTime,    [IPAddress] = @IPAddress,    [Browser] = @Browser,    [UserID] = @UserID,    [Source] = @Source  WHERE ([PortalLoginID] = @PortalLoginID);";


            tempParameter = updateCommand.Parameters.Add("PortalLoginID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("UserName", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationName", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Success", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("LoginDateTime", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("IPAddress", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Browser", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("UserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Source", SqlDbType.NVarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[PortalLoginHistory] (    [UserName],    [OrganizationID],    [OrganizationName],    [Success],    [LoginDateTime],    [IPAddress],    [Browser],    [UserID],    [Source]) VALUES ( @UserName, @OrganizationID, @OrganizationName, @Success, @LoginDateTime, @IPAddress, @Browser, @UserID, @Source); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("Source", SqlDbType.NVarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("UserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Browser", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IPAddress", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("LoginDateTime", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("Success", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationName", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("UserName", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[PortalLoginHistory] WHERE ([PortalLoginID] = @PortalLoginID);";
            deleteCommand.Parameters.Add("PortalLoginID", SqlDbType.Int);

            try
            {
                foreach (PortalLoginHistoryItem portalLoginHistoryItem in this)
                {
                    if (portalLoginHistoryItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(portalLoginHistoryItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = portalLoginHistoryItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["PortalLoginID"].AutoIncrement = false;
                        Table.Columns["PortalLoginID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            portalLoginHistoryItem.Row["PortalLoginID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(portalLoginHistoryItem);
                    }
                    else if (portalLoginHistoryItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(portalLoginHistoryItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = portalLoginHistoryItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(portalLoginHistoryItem);
                    }
                    else if (portalLoginHistoryItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)portalLoginHistoryItem.Row["PortalLoginID", DataRowVersion.Original];
                        deleteCommand.Parameters["PortalLoginID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("CustomerHubAuthenticationSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[CustomerHubAuthentication] SET     [CustomerHubID] = @CustomerHubID,    [EnableSelfRegister] = @EnableSelfRegister,    [EnableRequestAccess] = @EnableRequestAccess,    [EnableSSO] = @EnableSSO,    [RequestTicketType] = @RequestTicketType,    [RequestGroupType] = @RequestGroupType,    [AnonymousHubAccess] = @AnonymousHubAccess,    [AnonymousWikiAccess] = @AnonymousWikiAccess,    [AnonymousKBAccess] = @AnonymousKBAccess,    [AnonymousProductAccess] = @AnonymousProductAccess,    [AnonymousTicketAccess] = @AnonymousTicketAccess,    [HonorServiceAgreementExpirationDate] = @HonorServiceAgreementExpirationDate,    [HonorSupportExpiration] = @HonorSupportExpiration,    [RequireTermsAndConditions] = @RequireTermsAndConditions,    [DateModified] = @DateModified,    [ModifierID] = @ModifierID,    [AnonymousChatAccess] = @AnonymousChatAccess  WHERE ([CustomerHubAuthenticationID] = @CustomerHubAuthenticationID);";


            tempParameter = updateCommand.Parameters.Add("CustomerHubAuthenticationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("CustomerHubID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("EnableSelfRegister", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("EnableRequestAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("EnableSSO", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("RequestTicketType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RequestGroupType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("AnonymousHubAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("AnonymousWikiAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("AnonymousKBAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("AnonymousProductAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("AnonymousTicketAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("HonorServiceAgreementExpirationDate", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("HonorSupportExpiration", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("RequireTermsAndConditions", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("AnonymousChatAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[CustomerHubAuthentication] (    [CustomerHubID],    [EnableSelfRegister],    [EnableRequestAccess],    [EnableSSO],    [RequestTicketType],    [RequestGroupType],    [AnonymousHubAccess],    [AnonymousWikiAccess],    [AnonymousKBAccess],    [AnonymousProductAccess],    [AnonymousTicketAccess],    [HonorServiceAgreementExpirationDate],    [HonorSupportExpiration],    [RequireTermsAndConditions],    [DateModified],    [ModifierID],    [AnonymousChatAccess]) VALUES ( @CustomerHubID, @EnableSelfRegister, @EnableRequestAccess, @EnableSSO, @RequestTicketType, @RequestGroupType, @AnonymousHubAccess, @AnonymousWikiAccess, @AnonymousKBAccess, @AnonymousProductAccess, @AnonymousTicketAccess, @HonorServiceAgreementExpirationDate, @HonorSupportExpiration, @RequireTermsAndConditions, @DateModified, @ModifierID, @AnonymousChatAccess); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("AnonymousChatAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("RequireTermsAndConditions", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("HonorSupportExpiration", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("HonorServiceAgreementExpirationDate", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("AnonymousTicketAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("AnonymousProductAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("AnonymousKBAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("AnonymousWikiAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("AnonymousHubAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("RequestGroupType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("RequestTicketType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("EnableSSO", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("EnableRequestAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("EnableSelfRegister", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CustomerHubID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[CustomerHubAuthentication] WHERE ([CustomerHubAuthenticationID] = @CustomerHubAuthenticationID);";
            deleteCommand.Parameters.Add("CustomerHubAuthenticationID", SqlDbType.Int);

            try
            {
                foreach (CustomerHubAuthenticationItem customerHubAuthenticationItem in this)
                {
                    if (customerHubAuthenticationItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(customerHubAuthenticationItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = customerHubAuthenticationItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["CustomerHubAuthenticationID"].AutoIncrement = false;
                        Table.Columns["CustomerHubAuthenticationID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            customerHubAuthenticationItem.Row["CustomerHubAuthenticationID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(customerHubAuthenticationItem);
                    }
                    else if (customerHubAuthenticationItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(customerHubAuthenticationItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = customerHubAuthenticationItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(customerHubAuthenticationItem);
                    }
                    else if (customerHubAuthenticationItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)customerHubAuthenticationItem.Row["CustomerHubAuthenticationID", DataRowVersion.Original];
                        deleteCommand.Parameters["CustomerHubAuthenticationID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 4
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("ActionsViewSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[ActionsView] SET     [ActionTypeID] = @ActionTypeID,    [SystemActionTypeID] = @SystemActionTypeID,    [Name] = @Name,    [Description] = @Description,    [TimeSpent] = @TimeSpent,    [DateStarted] = @DateStarted,    [IsVisibleOnPortal] = @IsVisibleOnPortal,    [IsKnowledgeBase] = @IsKnowledgeBase,    [DateModified] = @DateModified,    [ModifierID] = @ModifierID,    [TicketID] = @TicketID,    [ActionSource] = @ActionSource,    [CreatorName] = @CreatorName,    [ModifierName] = @ModifierName,    [ActionType] = @ActionType,    [ProductName] = @ProductName,    [ReportedVersion] = @ReportedVersion,    [SolvedVersion] = @SolvedVersion,    [GroupName] = @GroupName,    [TicketType] = @TicketType,    [UserName] = @UserName,    [Status] = @Status,    [StatusPosition] = @StatusPosition,    [SeverityPosition] = @SeverityPosition,    [IsClosed] = @IsClosed,    [Severity] = @Severity,    [TicketNumber] = @TicketNumber,    [ReportedVersionID] = @ReportedVersionID,    [SolvedVersionID] = @SolvedVersionID,    [ProductID] = @ProductID,    [GroupID] = @GroupID,    [UserID] = @UserID,    [TicketStatusID] = @TicketStatusID,    [TicketTypeID] = @TicketTypeID,    [TicketSeverityID] = @TicketSeverityID,    [OrganizationID] = @OrganizationID,    [TicketName] = @TicketName,    [DateClosed] = @DateClosed,    [CloserID] = @CloserID,    [DaysClosed] = @DaysClosed,    [DaysOpened] = @DaysOpened,    [CloserName] = @CloserName,    [HoursSpent] = @HoursSpent  WHERE ([ActionID] = @ActionID);";


            tempParameter = updateCommand.Parameters.Add("ActionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ActionTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SystemActionTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Name", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Description", SqlDbType.NVarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("TimeSpent", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DateStarted", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("IsVisibleOnPortal", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsKnowledgeBase", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TicketID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ActionSource", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("CreatorName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ActionType", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ProductName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ReportedVersion", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("SolvedVersion", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("GroupName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("TicketType", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("UserName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Status", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("StatusPosition", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SeverityPosition", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("IsClosed", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Severity", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("TicketNumber", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ReportedVersionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SolvedVersionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ProductID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("GroupID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("UserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TicketStatusID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TicketTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TicketSeverityID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TicketName", SqlDbType.NVarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateClosed", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("CloserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DaysClosed", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DaysOpened", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("CloserName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("HoursSpent", SqlDbType.Decimal, 17);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 24;
                tempParameter.Scale     = 24;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[ActionsView] (    [ActionID],    [ActionTypeID],    [SystemActionTypeID],    [Name],    [Description],    [TimeSpent],    [DateStarted],    [IsVisibleOnPortal],    [IsKnowledgeBase],    [DateCreated],    [DateModified],    [CreatorID],    [ModifierID],    [TicketID],    [ActionSource],    [CreatorName],    [ModifierName],    [ActionType],    [ProductName],    [ReportedVersion],    [SolvedVersion],    [GroupName],    [TicketType],    [UserName],    [Status],    [StatusPosition],    [SeverityPosition],    [IsClosed],    [Severity],    [TicketNumber],    [ReportedVersionID],    [SolvedVersionID],    [ProductID],    [GroupID],    [UserID],    [TicketStatusID],    [TicketTypeID],    [TicketSeverityID],    [OrganizationID],    [TicketName],    [DateClosed],    [CloserID],    [DaysClosed],    [DaysOpened],    [CloserName],    [HoursSpent]) VALUES ( @ActionID, @ActionTypeID, @SystemActionTypeID, @Name, @Description, @TimeSpent, @DateStarted, @IsVisibleOnPortal, @IsKnowledgeBase, @DateCreated, @DateModified, @CreatorID, @ModifierID, @TicketID, @ActionSource, @CreatorName, @ModifierName, @ActionType, @ProductName, @ReportedVersion, @SolvedVersion, @GroupName, @TicketType, @UserName, @Status, @StatusPosition, @SeverityPosition, @IsClosed, @Severity, @TicketNumber, @ReportedVersionID, @SolvedVersionID, @ProductID, @GroupID, @UserID, @TicketStatusID, @TicketTypeID, @TicketSeverityID, @OrganizationID, @TicketName, @DateClosed, @CloserID, @DaysClosed, @DaysOpened, @CloserName, @HoursSpent); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("HoursSpent", SqlDbType.Decimal, 17);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 24;
                tempParameter.Scale     = 24;
            }

            tempParameter = insertCommand.Parameters.Add("CloserName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DaysOpened", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DaysClosed", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CloserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateClosed", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("TicketName", SqlDbType.NVarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("TicketSeverityID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("TicketTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("TicketStatusID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("UserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("GroupID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ProductID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("SolvedVersionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ReportedVersionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("TicketNumber", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Severity", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsClosed", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SeverityPosition", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("StatusPosition", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Status", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("UserName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("TicketType", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("GroupName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SolvedVersion", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ReportedVersion", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ProductName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ActionType", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ActionSource", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("TicketID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("IsKnowledgeBase", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsVisibleOnPortal", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DateStarted", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("TimeSpent", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Description", SqlDbType.NVarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Name", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SystemActionTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ActionTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ActionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[ActionsView] WHERE ([ActionID] = @ActionID);";
            deleteCommand.Parameters.Add("ActionID", SqlDbType.Int);

            try
            {
                foreach (ActionsViewItem actionsViewItem in this)
                {
                    if (actionsViewItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(actionsViewItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = actionsViewItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["ActionID"].AutoIncrement = false;
                        Table.Columns["ActionID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            actionsViewItem.Row["ActionID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(actionsViewItem);
                    }
                    else if (actionsViewItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(actionsViewItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = actionsViewItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(actionsViewItem);
                    }
                    else if (actionsViewItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)actionsViewItem.Row["ActionID", DataRowVersion.Original];
                        deleteCommand.Parameters["ActionID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("TicketSlaViewSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[TicketSlaView] SET     [ViolationTimeClosed] = @ViolationTimeClosed,    [WarningTimeClosed] = @WarningTimeClosed,    [ViolationLastAction] = @ViolationLastAction,    [WarningLastAction] = @WarningLastAction,    [ViolationInitialResponse] = @ViolationInitialResponse,    [WarningInitialResponse] = @WarningInitialResponse  WHERE ([TicketID] = @TicketID);";


            tempParameter = updateCommand.Parameters.Add("TicketID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ViolationTimeClosed", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("WarningTimeClosed", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ViolationLastAction", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("WarningLastAction", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ViolationInitialResponse", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("WarningInitialResponse", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[TicketSlaView] (    [TicketID],    [ViolationTimeClosed],    [WarningTimeClosed],    [ViolationLastAction],    [WarningLastAction],    [ViolationInitialResponse],    [WarningInitialResponse]) VALUES ( @TicketID, @ViolationTimeClosed, @WarningTimeClosed, @ViolationLastAction, @WarningLastAction, @ViolationInitialResponse, @WarningInitialResponse); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("WarningInitialResponse", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ViolationInitialResponse", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("WarningLastAction", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ViolationLastAction", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("WarningTimeClosed", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ViolationTimeClosed", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("TicketID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[TicketSlaView] WHERE ([TicketID] = @TicketID);";
            deleteCommand.Parameters.Add("TicketID", SqlDbType.Int);

            try
            {
                foreach (TicketSlaViewItem ticketSlaViewItem in this)
                {
                    if (ticketSlaViewItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(ticketSlaViewItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = ticketSlaViewItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["TicketID"].AutoIncrement = false;
                        Table.Columns["TicketID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            ticketSlaViewItem.Row["TicketID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(ticketSlaViewItem);
                    }
                    else if (ticketSlaViewItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(ticketSlaViewItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = ticketSlaViewItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(ticketSlaViewItem);
                    }
                    else if (ticketSlaViewItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)ticketSlaViewItem.Row["TicketID", DataRowVersion.Original];
                        deleteCommand.Parameters["TicketID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 6
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("UsersViewSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[UsersView] SET     [Email] = @Email,    [FirstName] = @FirstName,    [MiddleName] = @MiddleName,    [LastName] = @LastName,    [Title] = @Title,    [IsActive] = @IsActive,    [MarkDeleted] = @MarkDeleted,    [LastLogin] = @LastLogin,    [LastActivity] = @LastActivity,    [LastPing] = @LastPing,    [IsSystemAdmin] = @IsSystemAdmin,    [IsFinanceAdmin] = @IsFinanceAdmin,    [IsPasswordExpired] = @IsPasswordExpired,    [IsPortalUser] = @IsPortalUser,    [PrimaryGroupID] = @PrimaryGroupID,    [InOffice] = @InOffice,    [InOfficeComment] = @InOfficeComment,    [ActivatedOn] = @ActivatedOn,    [DeactivatedOn] = @DeactivatedOn,    [OrganizationID] = @OrganizationID,    [Organization] = @Organization,    [LastVersion] = @LastVersion,    [DateModified] = @DateModified,    [ModifierID] = @ModifierID,    [IsOnline] = @IsOnline,    [CryptedPassword] = @CryptedPassword,    [IsChatUser] = @IsChatUser,    [PortalLimitOrgTickets] = @PortalLimitOrgTickets  WHERE ([UserID] = @UserID);";


            tempParameter = updateCommand.Parameters.Add("Email", SqlDbType.NVarChar, 1024);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("FirstName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("UserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("MiddleName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("LastName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Title", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsActive", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("MarkDeleted", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("LastLogin", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("LastActivity", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("LastPing", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("IsSystemAdmin", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsFinanceAdmin", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsPasswordExpired", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsPortalUser", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("PrimaryGroupID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("InOffice", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("InOfficeComment", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ActivatedOn", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("DeactivatedOn", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Organization", SqlDbType.NVarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("LastVersion", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("IsOnline", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("CryptedPassword", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsChatUser", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("PortalLimitOrgTickets", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[UsersView] (    [Email],    [FirstName],    [UserID],    [MiddleName],    [LastName],    [Title],    [IsActive],    [MarkDeleted],    [LastLogin],    [LastActivity],    [LastPing],    [IsSystemAdmin],    [IsFinanceAdmin],    [IsPasswordExpired],    [IsPortalUser],    [PrimaryGroupID],    [InOffice],    [InOfficeComment],    [ActivatedOn],    [DeactivatedOn],    [OrganizationID],    [Organization],    [LastVersion],    [DateCreated],    [DateModified],    [CreatorID],    [ModifierID],    [IsOnline],    [CryptedPassword],    [IsChatUser],    [PortalLimitOrgTickets]) VALUES ( @Email, @FirstName, @UserID, @MiddleName, @LastName, @Title, @IsActive, @MarkDeleted, @LastLogin, @LastActivity, @LastPing, @IsSystemAdmin, @IsFinanceAdmin, @IsPasswordExpired, @IsPortalUser, @PrimaryGroupID, @InOffice, @InOfficeComment, @ActivatedOn, @DeactivatedOn, @OrganizationID, @Organization, @LastVersion, @DateCreated, @DateModified, @CreatorID, @ModifierID, @IsOnline, @CryptedPassword, @IsChatUser, @PortalLimitOrgTickets); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("PortalLimitOrgTickets", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsChatUser", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CryptedPassword", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsOnline", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("LastVersion", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Organization", SqlDbType.NVarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DeactivatedOn", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("ActivatedOn", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("InOfficeComment", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("InOffice", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("PrimaryGroupID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("IsPortalUser", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsPasswordExpired", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsFinanceAdmin", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsSystemAdmin", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("LastPing", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("LastActivity", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("LastLogin", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("MarkDeleted", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsActive", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Title", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("LastName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("MiddleName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("UserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("FirstName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Email", SqlDbType.NVarChar, 1024);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[UsersView] WHERE ([UserID] = @UserID);";
            deleteCommand.Parameters.Add("UserID", SqlDbType.Int);

            try
            {
                foreach (UsersViewItem usersViewItem in this)
                {
                    if (usersViewItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(usersViewItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = usersViewItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["UserID"].AutoIncrement = false;
                        Table.Columns["UserID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            usersViewItem.Row["UserID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(usersViewItem);
                    }
                    else if (usersViewItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(usersViewItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = usersViewItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(usersViewItem);
                    }
                    else if (usersViewItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)usersViewItem.Row["UserID", DataRowVersion.Original];
                        deleteCommand.Parameters["UserID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 7
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("KnowledgeBaseCategoriesSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[KnowledgeBaseCategories] SET     [ParentID] = @ParentID,    [CategoryName] = @CategoryName,    [CategoryDesc] = @CategoryDesc,    [OrganizationID] = @OrganizationID,    [Position] = @Position,    [VisibleOnPortal] = @VisibleOnPortal,    [ProductFamilyID] = @ProductFamilyID  WHERE ([CategoryID] = @CategoryID);";


            tempParameter = updateCommand.Parameters.Add("CategoryID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ParentID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("CategoryName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("CategoryDesc", SqlDbType.NVarChar, 250);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Position", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("VisibleOnPortal", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ProductFamilyID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[KnowledgeBaseCategories] (    [ParentID],    [CategoryName],    [CategoryDesc],    [OrganizationID],    [Position],    [VisibleOnPortal],    [ProductFamilyID]) VALUES ( @ParentID, @CategoryName, @CategoryDesc, @OrganizationID, @Position, @VisibleOnPortal, @ProductFamilyID); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("ProductFamilyID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("VisibleOnPortal", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Position", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CategoryDesc", SqlDbType.NVarChar, 250);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CategoryName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ParentID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[KnowledgeBaseCategories] WHERE ([CategoryID] = @CategoryID);";
            deleteCommand.Parameters.Add("CategoryID", SqlDbType.Int);

            try
            {
                foreach (KnowledgeBaseCategory knowledgeBaseCategory in this)
                {
                    if (knowledgeBaseCategory.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(knowledgeBaseCategory);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = knowledgeBaseCategory.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["CategoryID"].AutoIncrement = false;
                        Table.Columns["CategoryID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            knowledgeBaseCategory.Row["CategoryID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(knowledgeBaseCategory);
                    }
                    else if (knowledgeBaseCategory.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(knowledgeBaseCategory);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = knowledgeBaseCategory.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(knowledgeBaseCategory);
                    }
                    else if (knowledgeBaseCategory.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)knowledgeBaseCategory.Row["CategoryID", DataRowVersion.Original];
                        deleteCommand.Parameters["CategoryID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("AssetsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[Assets] SET     [OrganizationID] = @OrganizationID,    [SerialNumber] = @SerialNumber,    [Name] = @Name,    [Location] = @Location,    [Notes] = @Notes,    [ProductID] = @ProductID,    [WarrantyExpiration] = @WarrantyExpiration,    [AssignedTo] = @AssignedTo,    [DateModified] = @DateModified,    [ModifierID] = @ModifierID,    [SubPartOf] = @SubPartOf,    [Status] = @Status,    [ImportID] = @ImportID,    [ProductVersionID] = @ProductVersionID,    [NeedsIndexing] = @NeedsIndexing,    [ImportFileID] = @ImportFileID  WHERE ([AssetID] = @AssetID);";


            tempParameter = updateCommand.Parameters.Add("AssetID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SerialNumber", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Name", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Location", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Notes", SqlDbType.NVarChar, 2000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ProductID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("WarrantyExpiration", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("AssignedTo", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SubPartOf", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Status", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ImportID", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ProductVersionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("NeedsIndexing", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ImportFileID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[Assets] (    [OrganizationID],    [SerialNumber],    [Name],    [Location],    [Notes],    [ProductID],    [WarrantyExpiration],    [AssignedTo],    [DateCreated],    [DateModified],    [CreatorID],    [ModifierID],    [SubPartOf],    [Status],    [ImportID],    [ProductVersionID],    [NeedsIndexing],    [ImportFileID]) VALUES ( @OrganizationID, @SerialNumber, @Name, @Location, @Notes, @ProductID, @WarrantyExpiration, @AssignedTo, @DateCreated, @DateModified, @CreatorID, @ModifierID, @SubPartOf, @Status, @ImportID, @ProductVersionID, @NeedsIndexing, @ImportFileID); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("ImportFileID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("NeedsIndexing", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ProductVersionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ImportID", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Status", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SubPartOf", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("AssignedTo", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("WarrantyExpiration", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("ProductID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Notes", SqlDbType.NVarChar, 2000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Location", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Name", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SerialNumber", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[Assets] WHERE ([AssetID] = @AssetID);";
            deleteCommand.Parameters.Add("AssetID", SqlDbType.Int);

            try
            {
                foreach (Asset asset in this)
                {
                    if (asset.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(asset);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = asset.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["AssetID"].AutoIncrement = false;
                        Table.Columns["AssetID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            asset.Row["AssetID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(asset);
                    }
                    else if (asset.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(asset);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = asset.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(asset);
                    }
                    else if (asset.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)asset.Row["AssetID", DataRowVersion.Original];
                        deleteCommand.Parameters["AssetID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 9
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("EMailAlternateInboundSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[EMailAlternateInbound] SET     [OrganizationID] = @OrganizationID,    [Description] = @Description,    [GroupToAssign] = @GroupToAssign,    [DefaultTicketType] = @DefaultTicketType,    [ProductID] = @ProductID,    [SendingEMailAddress] = @SendingEMailAddress  WHERE ([SystemEMailID] = @SystemEMailID);";


            tempParameter = updateCommand.Parameters.Add("SystemEMailID", SqlDbType.UniqueIdentifier, 16);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Description", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("GroupToAssign", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DefaultTicketType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ProductID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SendingEMailAddress", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[EMailAlternateInbound] (    [SystemEMailID],    [OrganizationID],    [Description],    [GroupToAssign],    [DefaultTicketType],    [ProductID],    [SendingEMailAddress]) VALUES ( @SystemEMailID, @OrganizationID, @Description, @GroupToAssign, @DefaultTicketType, @ProductID, @SendingEMailAddress); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("SendingEMailAddress", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ProductID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DefaultTicketType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("GroupToAssign", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Description", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("SystemEMailID", SqlDbType.UniqueIdentifier, 16);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[EMailAlternateInbound] WHERE ([SystemEMailID] = @SystemEMailID);";
            deleteCommand.Parameters.Add("SystemEMailID", SqlDbType.Int);

            try
            {
                foreach (EMailAlternateInboundItem eMailAlternateInboundItem in this)
                {
                    if (eMailAlternateInboundItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(eMailAlternateInboundItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = eMailAlternateInboundItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["SystemEMailID"].AutoIncrement = false;
                        Table.Columns["SystemEMailID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            eMailAlternateInboundItem.Row["SystemEMailID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(eMailAlternateInboundItem);
                    }
                    else if (eMailAlternateInboundItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(eMailAlternateInboundItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = eMailAlternateInboundItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(eMailAlternateInboundItem);
                    }
                    else if (eMailAlternateInboundItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)eMailAlternateInboundItem.Row["SystemEMailID", DataRowVersion.Original];
                        deleteCommand.Parameters["SystemEMailID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("CRMLinkTableSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[CRMLinkTable] SET     [OrganizationID] = @OrganizationID,    [Active] = @Active,    [CRMType] = @CRMType,    [Username] = @Username,    [Password] = @Password,    [SecurityToken] = @SecurityToken,    [TypeFieldMatch] = @TypeFieldMatch,    [LastLink] = @LastLink,    [SendBackTicketData] = @SendBackTicketData,    [LastProcessed] = @LastProcessed,    [LastTicketID] = @LastTicketID,    [AllowPortalAccess] = @AllowPortalAccess,    [SendWelcomeEmail] = @SendWelcomeEmail,    [DefaultSlaLevelID] = @DefaultSlaLevelID,    [PullCasesAsTickets] = @PullCasesAsTickets,    [PushTicketsAsCases] = @PushTicketsAsCases,    [PullCustomerProducts] = @PullCustomerProducts,    [UpdateStatus] = @UpdateStatus,    [ActionTypeIDToPush] = @ActionTypeIDToPush,    [HostName] = @HostName,    [DefaultProject] = @DefaultProject,    [MatchAccountsByName] = @MatchAccountsByName,    [UseSandBoxServer] = @UseSandBoxServer,    [AlwaysUseDefaultProjectKey] = @AlwaysUseDefaultProjectKey,    [RestrictedToTicketTypes] = @RestrictedToTicketTypes,    [UpdateTicketType] = @UpdateTicketType,    [InstanceName] = @InstanceName,    [ExcludedTicketStatusUpdate] = @ExcludedTicketStatusUpdate,    [IncludeIssueNonRequired] = @IncludeIssueNonRequired,    [UseNetworkCredentials] = @UseNetworkCredentials,    [WebHookTokenId] = @WebHookTokenId  WHERE ([CRMLinkID] = @CRMLinkID);";


            tempParameter = updateCommand.Parameters.Add("CRMLinkID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Active", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("CRMType", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Username", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Password", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("SecurityToken", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("TypeFieldMatch", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("LastLink", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("SendBackTicketData", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("LastProcessed", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("LastTicketID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("AllowPortalAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("SendWelcomeEmail", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DefaultSlaLevelID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("PullCasesAsTickets", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("PushTicketsAsCases", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("PullCustomerProducts", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("UpdateStatus", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ActionTypeIDToPush", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("HostName", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DefaultProject", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("MatchAccountsByName", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("UseSandBoxServer", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("AlwaysUseDefaultProjectKey", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("RestrictedToTicketTypes", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("UpdateTicketType", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("InstanceName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ExcludedTicketStatusUpdate", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IncludeIssueNonRequired", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("UseNetworkCredentials", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("WebHookTokenId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[CRMLinkTable] (    [OrganizationID],    [Active],    [CRMType],    [Username],    [Password],    [SecurityToken],    [TypeFieldMatch],    [LastLink],    [SendBackTicketData],    [LastProcessed],    [LastTicketID],    [AllowPortalAccess],    [SendWelcomeEmail],    [DefaultSlaLevelID],    [PullCasesAsTickets],    [PushTicketsAsCases],    [PullCustomerProducts],    [UpdateStatus],    [ActionTypeIDToPush],    [HostName],    [DefaultProject],    [MatchAccountsByName],    [UseSandBoxServer],    [AlwaysUseDefaultProjectKey],    [RestrictedToTicketTypes],    [UpdateTicketType],    [InstanceName],    [ExcludedTicketStatusUpdate],    [IncludeIssueNonRequired],    [UseNetworkCredentials],    [WebHookTokenId]) VALUES ( @OrganizationID, @Active, @CRMType, @Username, @Password, @SecurityToken, @TypeFieldMatch, @LastLink, @SendBackTicketData, @LastProcessed, @LastTicketID, @AllowPortalAccess, @SendWelcomeEmail, @DefaultSlaLevelID, @PullCasesAsTickets, @PushTicketsAsCases, @PullCustomerProducts, @UpdateStatus, @ActionTypeIDToPush, @HostName, @DefaultProject, @MatchAccountsByName, @UseSandBoxServer, @AlwaysUseDefaultProjectKey, @RestrictedToTicketTypes, @UpdateTicketType, @InstanceName, @ExcludedTicketStatusUpdate, @IncludeIssueNonRequired, @UseNetworkCredentials, @WebHookTokenId); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("WebHookTokenId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("UseNetworkCredentials", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IncludeIssueNonRequired", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ExcludedTicketStatusUpdate", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("InstanceName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("UpdateTicketType", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("RestrictedToTicketTypes", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("AlwaysUseDefaultProjectKey", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("UseSandBoxServer", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("MatchAccountsByName", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DefaultProject", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("HostName", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ActionTypeIDToPush", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("UpdateStatus", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("PullCustomerProducts", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("PushTicketsAsCases", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("PullCasesAsTickets", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DefaultSlaLevelID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("SendWelcomeEmail", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("AllowPortalAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("LastTicketID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("LastProcessed", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("SendBackTicketData", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("LastLink", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("TypeFieldMatch", SqlDbType.VarChar, 500);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SecurityToken", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Password", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Username", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CRMType", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Active", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[CRMLinkTable] WHERE ([CRMLinkID] = @CRMLinkID);";
            deleteCommand.Parameters.Add("CRMLinkID", SqlDbType.Int);

            try
            {
                foreach (CRMLinkTableItem cRMLinkTableItem in this)
                {
                    if (cRMLinkTableItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(cRMLinkTableItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = cRMLinkTableItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["CRMLinkID"].AutoIncrement = false;
                        Table.Columns["CRMLinkID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            cRMLinkTableItem.Row["CRMLinkID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(cRMLinkTableItem);
                    }
                    else if (cRMLinkTableItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(cRMLinkTableItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = cRMLinkTableItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(cRMLinkTableItem);
                    }
                    else if (cRMLinkTableItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)cRMLinkTableItem.Row["CRMLinkID", DataRowVersion.Original];
                        deleteCommand.Parameters["CRMLinkID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("WaterCoolerViewSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[NewWaterCoolerView] SET     [UserID] = @UserID,    [OrganizationID] = @OrganizationID,    [TimeStamp] = @TimeStamp,    [Message] = @Message,    [MessageParent] = @MessageParent,    [IsDeleted] = @IsDeleted,    [LastModified] = @LastModified,    [RefType] = @RefType,    [AttachmentID] = @AttachmentID,    [NeedsIndexing] = @NeedsIndexing,    [UserName] = @UserName  WHERE ([MessageID] = @MessageID);";


            tempParameter = updateCommand.Parameters.Add("MessageID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("UserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TimeStamp", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("Message", SqlDbType.Text, 2147483647);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("MessageParent", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("IsDeleted", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("LastModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("AttachmentID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("NeedsIndexing", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("UserName", SqlDbType.VarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[NewWaterCoolerView] (    [MessageID],    [UserID],    [OrganizationID],    [TimeStamp],    [Message],    [MessageParent],    [IsDeleted],    [LastModified],    [RefType],    [AttachmentID],    [NeedsIndexing],    [UserName]) VALUES ( @MessageID, @UserID, @OrganizationID, @TimeStamp, @Message, @MessageParent, @IsDeleted, @LastModified, @RefType, @AttachmentID, @NeedsIndexing, @UserName); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("UserName", SqlDbType.VarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("NeedsIndexing", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("AttachmentID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("LastModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("IsDeleted", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("MessageParent", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Message", SqlDbType.Text, 2147483647);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("TimeStamp", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("UserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("MessageID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[NewWaterCoolerView] WHERE ([MessageID] = @MessageID);";
            deleteCommand.Parameters.Add("MessageID", SqlDbType.Int);

            try
            {
                foreach (WaterCoolerViewItem waterCoolerViewItem in this)
                {
                    if (waterCoolerViewItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(waterCoolerViewItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = waterCoolerViewItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["MessageID"].AutoIncrement = false;
                        Table.Columns["MessageID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            waterCoolerViewItem.Row["MessageID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(waterCoolerViewItem);
                    }
                    else if (waterCoolerViewItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(waterCoolerViewItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = waterCoolerViewItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(waterCoolerViewItem);
                    }
                    else if (waterCoolerViewItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)waterCoolerViewItem.Row["MessageID", DataRowVersion.Original];
                        deleteCommand.Parameters["MessageID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("CalendarEventsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[CalendarEvents] SET     [OrganizationID] = @OrganizationID,    [StartDate] = @StartDate,    [EndDate] = @EndDate,    [Title] = @Title,    [Description] = @Description,    [Repeat] = @Repeat,    [RepeatFrequency] = @RepeatFrequency,    [LastModified] = @LastModified,    [AllDay] = @AllDay,    [StartDateUTC] = @StartDateUTC,    [EndDateUTC] = @EndDateUTC,    [IsHoliday] = @IsHoliday  WHERE ([CalendarID] = @CalendarID);";


            tempParameter = updateCommand.Parameters.Add("CalendarID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("StartDate", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("EndDate", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("Title", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Description", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Repeat", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("RepeatFrequency", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("LastModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("AllDay", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("StartDateUTC", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("EndDateUTC", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("IsHoliday", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[CalendarEvents] (    [OrganizationID],    [StartDate],    [EndDate],    [Title],    [Description],    [Repeat],    [RepeatFrequency],    [LastModified],    [CreatorID],    [AllDay],    [StartDateUTC],    [EndDateUTC],    [IsHoliday]) VALUES ( @OrganizationID, @StartDate, @EndDate, @Title, @Description, @Repeat, @RepeatFrequency, @LastModified, @CreatorID, @AllDay, @StartDateUTC, @EndDateUTC, @IsHoliday); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("IsHoliday", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("EndDateUTC", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("StartDateUTC", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("AllDay", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("LastModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("RepeatFrequency", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Repeat", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Description", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Title", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("EndDate", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("StartDate", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[CalendarEvents] WHERE ([CalendarID] = @CalendarID);";
            deleteCommand.Parameters.Add("CalendarID", SqlDbType.Int);

            try
            {
                foreach (CalendarEvent calendarEvent in this)
                {
                    if (calendarEvent.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(calendarEvent);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = calendarEvent.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["CalendarID"].AutoIncrement = false;
                        Table.Columns["CalendarID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            calendarEvent.Row["CalendarID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(calendarEvent);
                    }
                    else if (calendarEvent.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(calendarEvent);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = calendarEvent.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(calendarEvent);
                    }
                    else if (calendarEvent.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)calendarEvent.Row["CalendarID", DataRowVersion.Original];
                        deleteCommand.Parameters["CalendarID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 13
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("ExceptionLogViewSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[ExceptionLogView] SET     [URL] = @URL,    [PageInfo] = @PageInfo,    [ExceptionName] = @ExceptionName,    [Message] = @Message,    [StackTrace] = @StackTrace,    [FirstName] = @FirstName,    [LastName] = @LastName,    [Name] = @Name  WHERE ([ExceptionLogID] = @ExceptionLogID);";


            tempParameter = updateCommand.Parameters.Add("ExceptionLogID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("URL", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("PageInfo", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ExceptionName", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Message", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("StackTrace", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("FirstName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("LastName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Name", SqlDbType.NVarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[ExceptionLogView] (    [ExceptionLogID],    [URL],    [PageInfo],    [ExceptionName],    [Message],    [StackTrace],    [CreatorID],    [DateCreated],    [FirstName],    [LastName],    [Name]) VALUES ( @ExceptionLogID, @URL, @PageInfo, @ExceptionName, @Message, @StackTrace, @CreatorID, @DateCreated, @FirstName, @LastName, @Name); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("Name", SqlDbType.NVarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("LastName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("FirstName", SqlDbType.NVarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("StackTrace", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Message", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ExceptionName", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("PageInfo", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("URL", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ExceptionLogID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[ExceptionLogView] WHERE ([ExceptionLogID] = @ExceptionLogID);";
            deleteCommand.Parameters.Add("ExceptionLogID", SqlDbType.Int);

            try
            {
                foreach (ExceptionLogViewItem exceptionLogViewItem in this)
                {
                    if (exceptionLogViewItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(exceptionLogViewItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = exceptionLogViewItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["ExceptionLogID"].AutoIncrement = false;
                        Table.Columns["ExceptionLogID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            exceptionLogViewItem.Row["ExceptionLogID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(exceptionLogViewItem);
                    }
                    else if (exceptionLogViewItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(exceptionLogViewItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = exceptionLogViewItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(exceptionLogViewItem);
                    }
                    else if (exceptionLogViewItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)exceptionLogViewItem.Row["ExceptionLogID", DataRowVersion.Original];
                        deleteCommand.Parameters["ExceptionLogID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 14
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("OrganizationsViewSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[OrganizationsView] SET     [Name] = @Name,    [Description] = @Description,    [Website] = @Website,    [IsActive] = @IsActive,    [InActiveReason] = @InActiveReason,    [PrimaryUserID] = @PrimaryUserID,    [PrimaryContactEmail] = @PrimaryContactEmail,    [PrimaryContact] = @PrimaryContact,    [ParentID] = @ParentID,    [DateModified] = @DateModified,    [ModifierID] = @ModifierID,    [HasPortalAccess] = @HasPortalAccess,    [CreatedBy] = @CreatedBy,    [LastModifiedBy] = @LastModifiedBy,    [SAExpirationDate] = @SAExpirationDate,    [SlaName] = @SlaName,    [CRMLinkID] = @CRMLinkID,    [PortalGuid] = @PortalGuid,    [SlaLevelID] = @SlaLevelID,    [DefaultWikiArticleID] = @DefaultWikiArticleID,    [DefaultSupportGroupID] = @DefaultSupportGroupID,    [DefaultSupportUserID] = @DefaultSupportUserID,    [DefaultSupportUser] = @DefaultSupportUser,    [DefaultSupportGroup] = @DefaultSupportGroup,    [CompanyDomains] = @CompanyDomains,    [SupportHoursMonth] = @SupportHoursMonth,    [SupportHoursUsed] = @SupportHoursUsed,    [SupportHoursRemaining] = @SupportHoursRemaining,    [NeedsIndexing] = @NeedsIndexing,    [CustDisIndex] = @CustDisIndex,    [CustDistIndexTrend] = @CustDistIndexTrend,    [PhoneNumbers] = @PhoneNumbers  WHERE ([OrganizationID] = @OrganizationID);";


            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Name", SqlDbType.NVarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Description", SqlDbType.VarChar, 1024);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Website", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsActive", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("InActiveReason", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("PrimaryUserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("PrimaryContactEmail", SqlDbType.NVarChar, 1024);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("PrimaryContact", SqlDbType.NVarChar, 202);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ParentID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("HasPortalAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("CreatedBy", SqlDbType.NVarChar, 202);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("LastModifiedBy", SqlDbType.NVarChar, 202);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("SAExpirationDate", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("SlaName", SqlDbType.VarChar, 150);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("CRMLinkID", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("PortalGuid", SqlDbType.UniqueIdentifier, 16);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("SlaLevelID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DefaultWikiArticleID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DefaultSupportGroupID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DefaultSupportUserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DefaultSupportUser", SqlDbType.NVarChar, 202);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DefaultSupportGroup", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("CompanyDomains", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("SupportHoursMonth", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SupportHoursUsed", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SupportHoursRemaining", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("NeedsIndexing", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("CustDisIndex", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("CustDistIndexTrend", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("PhoneNumbers", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[OrganizationsView] (    [OrganizationID],    [Name],    [Description],    [Website],    [IsActive],    [InActiveReason],    [PrimaryUserID],    [PrimaryContactEmail],    [PrimaryContact],    [ParentID],    [DateCreated],    [DateModified],    [CreatorID],    [ModifierID],    [HasPortalAccess],    [CreatedBy],    [LastModifiedBy],    [SAExpirationDate],    [SlaName],    [CRMLinkID],    [PortalGuid],    [SlaLevelID],    [DefaultWikiArticleID],    [DefaultSupportGroupID],    [DefaultSupportUserID],    [DefaultSupportUser],    [DefaultSupportGroup],    [CompanyDomains],    [SupportHoursMonth],    [SupportHoursUsed],    [SupportHoursRemaining],    [NeedsIndexing],    [CustDisIndex],    [CustDistIndexTrend],    [PhoneNumbers]) VALUES ( @OrganizationID, @Name, @Description, @Website, @IsActive, @InActiveReason, @PrimaryUserID, @PrimaryContactEmail, @PrimaryContact, @ParentID, @DateCreated, @DateModified, @CreatorID, @ModifierID, @HasPortalAccess, @CreatedBy, @LastModifiedBy, @SAExpirationDate, @SlaName, @CRMLinkID, @PortalGuid, @SlaLevelID, @DefaultWikiArticleID, @DefaultSupportGroupID, @DefaultSupportUserID, @DefaultSupportUser, @DefaultSupportGroup, @CompanyDomains, @SupportHoursMonth, @SupportHoursUsed, @SupportHoursRemaining, @NeedsIndexing, @CustDisIndex, @CustDistIndexTrend, @PhoneNumbers); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("PhoneNumbers", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CustDistIndexTrend", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CustDisIndex", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("NeedsIndexing", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SupportHoursRemaining", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("SupportHoursUsed", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("SupportHoursMonth", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CompanyDomains", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DefaultSupportGroup", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DefaultSupportUser", SqlDbType.NVarChar, 202);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DefaultSupportUserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DefaultSupportGroupID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DefaultWikiArticleID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("SlaLevelID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("PortalGuid", SqlDbType.UniqueIdentifier, 16);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CRMLinkID", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SlaName", SqlDbType.VarChar, 150);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SAExpirationDate", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("LastModifiedBy", SqlDbType.NVarChar, 202);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CreatedBy", SqlDbType.NVarChar, 202);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("HasPortalAccess", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("ParentID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("PrimaryContact", SqlDbType.NVarChar, 202);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("PrimaryContactEmail", SqlDbType.NVarChar, 1024);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("PrimaryUserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("InActiveReason", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsActive", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Website", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Description", SqlDbType.VarChar, 1024);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Name", SqlDbType.NVarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[OrganizationsView] WHERE ([OrganizationID] = @OrganizationID);";
            deleteCommand.Parameters.Add("OrganizationID", SqlDbType.Int);

            try
            {
                foreach (OrganizationsViewItem organizationsViewItem in this)
                {
                    if (organizationsViewItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(organizationsViewItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = organizationsViewItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["OrganizationID"].AutoIncrement = false;
                        Table.Columns["OrganizationID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            organizationsViewItem.Row["OrganizationID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(organizationsViewItem);
                    }
                    else if (organizationsViewItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(organizationsViewItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = organizationsViewItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(organizationsViewItem);
                    }
                    else if (organizationsViewItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)organizationsViewItem.Row["OrganizationID", DataRowVersion.Original];
                        deleteCommand.Parameters["OrganizationID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("CustomFieldsViewSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[CustomFieldsView] SET     [CustomFieldID] = @CustomFieldID,    [OrganizationID] = @OrganizationID,    [Name] = @Name,    [ApiFieldName] = @ApiFieldName,    [RefType] = @RefType,    [FieldType] = @FieldType,    [AuxID] = @AuxID,    [Position] = @Position,    [ListValues] = @ListValues,    [Description] = @Description,    [IsVisibleOnPortal] = @IsVisibleOnPortal,    [IsFirstIndexSelect] = @IsFirstIndexSelect,    [IsRequired] = @IsRequired,    [DateModified] = @DateModified,    [ModifierID] = @ModifierID,    [CustomFieldCategoryID] = @CustomFieldCategoryID,    [IsRequiredToClose] = @IsRequiredToClose,    [Mask] = @Mask,    [ParentCustomFieldID] = @ParentCustomFieldID,    [ParentCustomValue] = @ParentCustomValue,    [ParentProductID] = @ParentProductID,    [ParentFieldName] = @ParentFieldName,    [ParentProductName] = @ParentProductName  WH);";


            tempParameter = updateCommand.Parameters.Add("CustomFieldID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Name", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ApiFieldName", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("FieldType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("AuxID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Position", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ListValues", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Description", SqlDbType.VarChar, 250);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsVisibleOnPortal", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsFirstIndexSelect", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsRequired", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("CustomFieldCategoryID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("IsRequiredToClose", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Mask", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ParentCustomFieldID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ParentCustomValue", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ParentProductID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ParentFieldName", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ParentProductName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[CustomFieldsView] (    [CustomFieldID],    [OrganizationID],    [Name],    [ApiFieldName],    [RefType],    [FieldType],    [AuxID],    [Position],    [ListValues],    [Description],    [IsVisibleOnPortal],    [IsFirstIndexSelect],    [IsRequired],    [DateCreated],    [DateModified],    [CreatorID],    [ModifierID],    [CustomFieldCategoryID],    [IsRequiredToClose],    [Mask],    [ParentCustomFieldID],    [ParentCustomValue],    [ParentProductID],    [ParentFieldName],    [ParentProductName]) VALUES ( @CustomFieldID, @OrganizationID, @Name, @ApiFieldName, @RefType, @FieldType, @AuxID, @Position, @ListValues, @Description, @IsVisibleOnPortal, @IsFirstIndexSelect, @IsRequired, @DateCreated, @DateModified, @CreatorID, @ModifierID, @CustomFieldCategoryID, @IsRequiredToClose, @Mask, @ParentCustomFieldID, @ParentCustomValue, @ParentProductID, @ParentFieldName, @ParentProductName); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("ParentProductName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ParentFieldName", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ParentProductID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ParentCustomValue", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ParentCustomFieldID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Mask", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsRequiredToClose", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CustomFieldCategoryID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("IsRequired", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsFirstIndexSelect", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsVisibleOnPortal", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Description", SqlDbType.VarChar, 250);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ListValues", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Position", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("AuxID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("FieldType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ApiFieldName", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Name", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CustomFieldID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[CustomFieldsView] WH);";
            deleteCommand.Parameters.Add("", SqlDbType.Int);

            try
            {
                foreach (CustomFieldsViewItem customFieldsViewItem in this)
                {
                    if (customFieldsViewItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(customFieldsViewItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = customFieldsViewItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns[""].AutoIncrement = false;
                        Table.Columns[""].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            customFieldsViewItem.Row[""] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(customFieldsViewItem);
                    }
                    else if (customFieldsViewItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(customFieldsViewItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = customFieldsViewItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(customFieldsViewItem);
                    }
                    else if (customFieldsViewItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)customFieldsViewItem.Row["", DataRowVersion.Original];
                        deleteCommand.Parameters[""].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("OrganizationEmailsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[OrganizationEmails] SET     [OrganizationID] = @OrganizationID,    [EmailTemplateID] = @EmailTemplateID,    [Subject] = @Subject,    [Header] = @Header,    [Footer] = @Footer,    [Body] = @Body,    [IsHtml] = @IsHtml,    [UseGlobalTemplate] = @UseGlobalTemplate,    [ProductFamilyID] = @ProductFamilyID  WHERE ([OrganizationEmailID] = @OrganizationEmailID);";


            tempParameter = updateCommand.Parameters.Add("OrganizationEmailID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("EmailTemplateID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Subject", SqlDbType.NVarChar, 4000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Header", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Footer", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Body", SqlDbType.NVarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsHtml", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("UseGlobalTemplate", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ProductFamilyID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[OrganizationEmails] (    [OrganizationID],    [EmailTemplateID],    [Subject],    [Header],    [Footer],    [Body],    [IsHtml],    [UseGlobalTemplate],    [ProductFamilyID]) VALUES ( @OrganizationID, @EmailTemplateID, @Subject, @Header, @Footer, @Body, @IsHtml, @UseGlobalTemplate, @ProductFamilyID); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("ProductFamilyID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("UseGlobalTemplate", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsHtml", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Body", SqlDbType.NVarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Footer", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Header", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Subject", SqlDbType.NVarChar, 4000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("EmailTemplateID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[OrganizationEmails] WHERE ([OrganizationEmailID] = @OrganizationEmailID);";
            deleteCommand.Parameters.Add("OrganizationEmailID", SqlDbType.Int);

            try
            {
                foreach (OrganizationEmail organizationEmail in this)
                {
                    if (organizationEmail.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(organizationEmail);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = organizationEmail.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["OrganizationEmailID"].AutoIncrement = false;
                        Table.Columns["OrganizationEmailID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            organizationEmail.Row["OrganizationEmailID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(organizationEmail);
                    }
                    else if (organizationEmail.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(organizationEmail);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = organizationEmail.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(organizationEmail);
                    }
                    else if (organizationEmail.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)organizationEmail.Row["OrganizationEmailID", DataRowVersion.Original];
                        deleteCommand.Parameters["OrganizationEmailID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 17
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("PhoneNumbersViewSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[PhoneNumbersView] SET     [PhoneTypeID] = @PhoneTypeID,    [RefID] = @RefID,    [RefType] = @RefType,    [PhoneNumber] = @PhoneNumber,    [Extension] = @Extension,    [OtherTypeName] = @OtherTypeName,    [DateModified] = @DateModified,    [ModifierID] = @ModifierID,    [PhoneType] = @PhoneType,    [CreatorName] = @CreatorName,    [ModifierName] = @ModifierName  WHERE ([PhoneID] = @PhoneID);";


            tempParameter = updateCommand.Parameters.Add("PhoneID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("PhoneTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RefID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("PhoneNumber", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Extension", SqlDbType.VarChar, 10);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("OtherTypeName", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("PhoneType", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("CreatorName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[PhoneNumbersView] (    [PhoneID],    [PhoneTypeID],    [RefID],    [RefType],    [PhoneNumber],    [Extension],    [OtherTypeName],    [DateCreated],    [DateModified],    [CreatorID],    [ModifierID],    [PhoneType],    [CreatorName],    [ModifierName]) VALUES ( @PhoneID, @PhoneTypeID, @RefID, @RefType, @PhoneNumber, @Extension, @OtherTypeName, @DateCreated, @DateModified, @CreatorID, @ModifierID, @PhoneType, @CreatorName, @ModifierName); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("ModifierName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorName", SqlDbType.NVarChar, 201);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("PhoneType", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("OtherTypeName", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Extension", SqlDbType.VarChar, 10);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("PhoneNumber", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("RefID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("PhoneTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("PhoneID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[PhoneNumbersView] WHERE ([PhoneID] = @PhoneID);";
            deleteCommand.Parameters.Add("PhoneID", SqlDbType.Int);

            try
            {
                foreach (PhoneNumbersViewItem phoneNumbersViewItem in this)
                {
                    if (phoneNumbersViewItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(phoneNumbersViewItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = phoneNumbersViewItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["PhoneID"].AutoIncrement = false;
                        Table.Columns["PhoneID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            phoneNumbersViewItem.Row["PhoneID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(phoneNumbersViewItem);
                    }
                    else if (phoneNumbersViewItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(phoneNumbersViewItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = phoneNumbersViewItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(phoneNumbersViewItem);
                    }
                    else if (phoneNumbersViewItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)phoneNumbersViewItem.Row["PhoneID", DataRowVersion.Original];
                        deleteCommand.Parameters["PhoneID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("CreditCardsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[CreditCards] SET     [OrganizationID] = @OrganizationID,    [DisplayNumber] = @DisplayNumber,    [CreditCardType] = @CreditCardType,    [CardNumber] = @CardNumber,    [SecurityCode] = @SecurityCode,    [ExpirationDate] = @ExpirationDate,    [NameOnCard] = @NameOnCard,    [DateModfied] = @DateModfied,    [ModifierID] = @ModifierID  WHERE ([CreditCardID] = @CreditCardID);";


            tempParameter = updateCommand.Parameters.Add("CreditCardID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DisplayNumber", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("CreditCardType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("CardNumber", SqlDbType.VarBinary, 2147483647);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("SecurityCode", SqlDbType.VarChar, 250);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ExpirationDate", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("NameOnCard", SqlDbType.VarChar, 250);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModfied", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[CreditCards] (    [OrganizationID],    [DisplayNumber],    [CreditCardType],    [CardNumber],    [SecurityCode],    [ExpirationDate],    [NameOnCard],    [DateCreated],    [DateModfied],    [CreatorID],    [ModifierID]) VALUES ( @OrganizationID, @DisplayNumber, @CreditCardType, @CardNumber, @SecurityCode, @ExpirationDate, @NameOnCard, @DateCreated, @DateModfied, @CreatorID, @ModifierID); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModfied", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("NameOnCard", SqlDbType.VarChar, 250);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ExpirationDate", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("SecurityCode", SqlDbType.VarChar, 250);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CardNumber", SqlDbType.VarBinary, 2147483647);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("CreditCardType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DisplayNumber", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[CreditCards] WHERE ([CreditCardID] = @CreditCardID);";
            deleteCommand.Parameters.Add("CreditCardID", SqlDbType.Int);

            try
            {
                foreach (CreditCard creditCard in this)
                {
                    if (creditCard.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(creditCard);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = creditCard.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["CreditCardID"].AutoIncrement = false;
                        Table.Columns["CreditCardID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            creditCard.Row["CreditCardID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(creditCard);
                    }
                    else if (creditCard.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(creditCard);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = creditCard.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(creditCard);
                    }
                    else if (creditCard.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)creditCard.Row["CreditCardID", DataRowVersion.Original];
                        deleteCommand.Parameters["CreditCardID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("ApiLogsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[ApiLogs] SET     [OrganizationID] = @OrganizationID,    [IPAddress] = @IPAddress,    [Url] = @Url,    [Verb] = @Verb,    [StatusCode] = @StatusCode,    [RequestBody] = @RequestBody  WHERE ([ApiLogID] = @ApiLogID);";


            tempParameter = updateCommand.Parameters.Add("ApiLogID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("IPAddress", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Url", SqlDbType.VarChar, 2100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Verb", SqlDbType.VarChar, 20);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("StatusCode", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RequestBody", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[ApiLogs] (    [OrganizationID],    [IPAddress],    [Url],    [Verb],    [StatusCode],    [RequestBody],    [DateCreated]) VALUES ( @OrganizationID, @IPAddress, @Url, @Verb, @StatusCode, @RequestBody, @DateCreated); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("RequestBody", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("StatusCode", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Verb", SqlDbType.VarChar, 20);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Url", SqlDbType.VarChar, 2100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IPAddress", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[ApiLogs] WHERE ([ApiLogID] = @ApiLogID);";
            deleteCommand.Parameters.Add("ApiLogID", SqlDbType.Int);

            try
            {
                foreach (ApiLog apiLog in this)
                {
                    if (apiLog.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(apiLog);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = apiLog.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["ApiLogID"].AutoIncrement = false;
                        Table.Columns["ApiLogID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            apiLog.Row["ApiLogID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(apiLog);
                    }
                    else if (apiLog.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(apiLog);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = apiLog.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(apiLog);
                    }
                    else if (apiLog.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)apiLog.Row["ApiLogID", DataRowVersion.Original];
                        deleteCommand.Parameters["ApiLogID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("ScheduledReportsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[ScheduledReports] SET     [EmailSubject] = @EmailSubject,    [EmailBody] = @EmailBody,    [EmailRecipients] = @EmailRecipients,    [ReportId] = @ReportId,    [OrganizationId] = @OrganizationId,    [RunCount] = @RunCount,    [IsActive] = @IsActive,    [StartDate] = @StartDate,    [RecurrencyId] = @RecurrencyId,    [Every] = @Every,    [Weekday] = @Weekday,    [Monthday] = @Monthday,    [LastRun] = @LastRun,    [IsSuccessful] = @IsSuccessful,    [NextRun] = @NextRun,    [CreatorId] = @CreatorId,    [ModifierId] = @ModifierId,    [DateModified] = @DateModified,    [LockProcessId] = @LockProcessId,    [FilePathID] = @FilePathID  WHERE ([Id] = @Id);";


            tempParameter = updateCommand.Parameters.Add("Id", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("EmailSubject", SqlDbType.NVarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("EmailBody", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("EmailRecipients", SqlDbType.NVarChar, 2000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ReportId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RunCount", SqlDbType.SmallInt, 2);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 5;
                tempParameter.Scale     = 5;
            }

            tempParameter = updateCommand.Parameters.Add("IsActive", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("StartDate", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("RecurrencyId", SqlDbType.TinyInt, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 3;
                tempParameter.Scale     = 3;
            }

            tempParameter = updateCommand.Parameters.Add("Every", SqlDbType.TinyInt, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 3;
                tempParameter.Scale     = 3;
            }

            tempParameter = updateCommand.Parameters.Add("Weekday", SqlDbType.TinyInt, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 3;
                tempParameter.Scale     = 3;
            }

            tempParameter = updateCommand.Parameters.Add("Monthday", SqlDbType.TinyInt, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 3;
                tempParameter.Scale     = 3;
            }

            tempParameter = updateCommand.Parameters.Add("LastRun", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("IsSuccessful", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("NextRun", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("CreatorId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("LockProcessId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("FilePathID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[ScheduledReports] (    [EmailSubject],    [EmailBody],    [EmailRecipients],    [ReportId],    [OrganizationId],    [RunCount],    [IsActive],    [StartDate],    [RecurrencyId],    [Every],    [Weekday],    [Monthday],    [LastRun],    [IsSuccessful],    [NextRun],    [CreatorId],    [ModifierId],    [DateCreated],    [DateModified],    [LockProcessId],    [FilePathID]) VALUES ( @EmailSubject, @EmailBody, @EmailRecipients, @ReportId, @OrganizationId, @RunCount, @IsActive, @StartDate, @RecurrencyId, @Every, @Weekday, @Monthday, @LastRun, @IsSuccessful, @NextRun, @CreatorId, @ModifierId, @DateCreated, @DateModified, @LockProcessId, @FilePathID); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("FilePathID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("LockProcessId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("NextRun", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("IsSuccessful", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("LastRun", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("Monthday", SqlDbType.TinyInt, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 3;
                tempParameter.Scale     = 3;
            }

            tempParameter = insertCommand.Parameters.Add("Weekday", SqlDbType.TinyInt, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 3;
                tempParameter.Scale     = 3;
            }

            tempParameter = insertCommand.Parameters.Add("Every", SqlDbType.TinyInt, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 3;
                tempParameter.Scale     = 3;
            }

            tempParameter = insertCommand.Parameters.Add("RecurrencyId", SqlDbType.TinyInt, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 3;
                tempParameter.Scale     = 3;
            }

            tempParameter = insertCommand.Parameters.Add("StartDate", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("IsActive", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("RunCount", SqlDbType.SmallInt, 2);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 5;
                tempParameter.Scale     = 5;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ReportId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("EmailRecipients", SqlDbType.NVarChar, 2000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("EmailBody", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("EmailSubject", SqlDbType.NVarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[ScheduledReports] WHERE ([Id] = @Id);";
            deleteCommand.Parameters.Add("Id", SqlDbType.Int);

            try
            {
                foreach (ScheduledReport scheduledReport in this)
                {
                    if (scheduledReport.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(scheduledReport);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = scheduledReport.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["Id"].AutoIncrement = false;
                        Table.Columns["Id"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            scheduledReport.Row["Id"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(scheduledReport);
                    }
                    else if (scheduledReport.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(scheduledReport);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = scheduledReport.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(scheduledReport);
                    }
                    else if (scheduledReport.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)scheduledReport.Row["Id", DataRowVersion.Original];
                        deleteCommand.Parameters["Id"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("AttachmentsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[Attachments] SET     [OrganizationID] = @OrganizationID,    [FileName] = @FileName,    [FileType] = @FileType,    [FileSize] = @FileSize,    [Path] = @Path,    [Description] = @Description,    [DateModified] = @DateModified,    [ModifierID] = @ModifierID,    [RefType] = @RefType,    [RefID] = @RefID,    [SentToJira] = @SentToJira,    [AttachmentGUID] = @AttachmentGUID,    [ProductFamilyID] = @ProductFamilyID,    [SentToTFS] = @SentToTFS,    [SentToSnow] = @SentToSnow,    [FilePathID] = @FilePathID  WHERE ([AttachmentID] = @AttachmentID);";


            tempParameter = updateCommand.Parameters.Add("AttachmentID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("FileName", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("FileType", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("FileSize", SqlDbType.BigInt, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 19;
                tempParameter.Scale     = 19;
            }

            tempParameter = updateCommand.Parameters.Add("Path", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Description", SqlDbType.VarChar, 2000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RefID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SentToJira", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("AttachmentGUID", SqlDbType.UniqueIdentifier, 16);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ProductFamilyID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SentToTFS", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("SentToSnow", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("FilePathID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[Attachments] (    [OrganizationID],    [FileName],    [FileType],    [FileSize],    [Path],    [Description],    [DateCreated],    [DateModified],    [CreatorID],    [ModifierID],    [RefType],    [RefID],    [SentToJira],    [AttachmentGUID],    [ProductFamilyID],    [SentToTFS],    [SentToSnow],    [FilePathID]) VALUES ( @OrganizationID, @FileName, @FileType, @FileSize, @Path, @Description, @DateCreated, @DateModified, @CreatorID, @ModifierID, @RefType, @RefID, @SentToJira, @AttachmentGUID, @ProductFamilyID, @SentToTFS, @SentToSnow, @FilePathID); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("FilePathID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("SentToSnow", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SentToTFS", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ProductFamilyID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("AttachmentGUID", SqlDbType.UniqueIdentifier, 16);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SentToJira", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("RefID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("Description", SqlDbType.VarChar, 2000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Path", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("FileSize", SqlDbType.BigInt, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 19;
                tempParameter.Scale     = 19;
            }

            tempParameter = insertCommand.Parameters.Add("FileType", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("FileName", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[Attachments] WHERE ([AttachmentID] = @AttachmentID);";
            deleteCommand.Parameters.Add("AttachmentID", SqlDbType.Int);

            try
            {
                foreach (Attachment attachment in this)
                {
                    if (attachment.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(attachment);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = attachment.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["AttachmentID"].AutoIncrement = false;
                        Table.Columns["AttachmentID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            attachment.Row["AttachmentID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(attachment);
                    }
                    else if (attachment.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(attachment);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = attachment.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(attachment);
                    }
                    else if (attachment.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)attachment.Row["AttachmentID", DataRowVersion.Original];
                        deleteCommand.Parameters["AttachmentID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 22
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("ImportFieldsViewSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[ImportFieldsView] SET     [ImportFieldID] = @ImportFieldID,    [TableName] = @TableName,    [FieldName] = @FieldName,    [Alias] = @Alias,    [DataType] = @DataType,    [Size] = @Size,    [IsVisible] = @IsVisible,    [IsRequired] = @IsRequired,    [Description] = @Description,    [RefType] = @RefType,    [Position] = @Position,    [ImportMapID] = @ImportMapID,    [ImportID] = @ImportID,    [SourceName] = @SourceName,    [IsCustom] = @IsCustom,    [FileName] = @FileName,    [OrganizationID] = @OrganizationID  WH);";


            tempParameter = updateCommand.Parameters.Add("ImportFieldID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TableName", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("FieldName", SqlDbType.VarChar, 561);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Alias", SqlDbType.VarChar, 250);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DataType", SqlDbType.VarChar, 150);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Size", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("IsVisible", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsRequired", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Description", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Position", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ImportMapID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ImportID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SourceName", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsCustom", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("FileName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[ImportFieldsView] (    [ImportFieldID],    [TableName],    [FieldName],    [Alias],    [DataType],    [Size],    [IsVisible],    [IsRequired],    [Description],    [RefType],    [Position],    [ImportMapID],    [ImportID],    [SourceName],    [IsCustom],    [FileName],    [OrganizationID]) VALUES ( @ImportFieldID, @TableName, @FieldName, @Alias, @DataType, @Size, @IsVisible, @IsRequired, @Description, @RefType, @Position, @ImportMapID, @ImportID, @SourceName, @IsCustom, @FileName, @OrganizationID); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("FileName", SqlDbType.VarChar, 255);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsCustom", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SourceName", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ImportID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ImportMapID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Position", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Description", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsRequired", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsVisible", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Size", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DataType", SqlDbType.VarChar, 150);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Alias", SqlDbType.VarChar, 250);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("FieldName", SqlDbType.VarChar, 561);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("TableName", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ImportFieldID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[ImportFieldsView] WH);";
            deleteCommand.Parameters.Add("", SqlDbType.Int);

            try
            {
                foreach (ImportFieldsViewItem importFieldsViewItem in this)
                {
                    if (importFieldsViewItem.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(importFieldsViewItem);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = importFieldsViewItem.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns[""].AutoIncrement = false;
                        Table.Columns[""].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            importFieldsViewItem.Row[""] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(importFieldsViewItem);
                    }
                    else if (importFieldsViewItem.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(importFieldsViewItem);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = importFieldsViewItem.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(importFieldsViewItem);
                    }
                    else if (importFieldsViewItem.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)importFieldsViewItem.Row["", DataRowVersion.Original];
                        deleteCommand.Parameters[""].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("JiraInstanceProductsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[JiraInstanceProducts] SET     [CrmLinkId] = @CrmLinkId,    [ProductId] = @ProductId  WHERE ([JiraInstanceProductsId] = @JiraInstanceProductsId);";


            tempParameter = updateCommand.Parameters.Add("JiraInstanceProductsId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("CrmLinkId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ProductId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[JiraInstanceProducts] (    [CrmLinkId],    [ProductId]) VALUES ( @CrmLinkId, @ProductId); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("ProductId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CrmLinkId", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[JiraInstanceProducts] WHERE ([JiraInstanceProductsId] = @JiraInstanceProductsId);";
            deleteCommand.Parameters.Add("JiraInstanceProductsId", SqlDbType.Int);

            try
            {
                foreach (JiraInstanceProduct jiraInstanceProduct in this)
                {
                    if (jiraInstanceProduct.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(jiraInstanceProduct);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = jiraInstanceProduct.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["JiraInstanceProductsId"].AutoIncrement = false;
                        Table.Columns["JiraInstanceProductsId"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            jiraInstanceProduct.Row["JiraInstanceProductsId"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(jiraInstanceProduct);
                    }
                    else if (jiraInstanceProduct.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(jiraInstanceProduct);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = jiraInstanceProduct.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(jiraInstanceProduct);
                    }
                    else if (jiraInstanceProduct.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)jiraInstanceProduct.Row["JiraInstanceProductsId", DataRowVersion.Original];
                        deleteCommand.Parameters["JiraInstanceProductsId"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 24
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("NotesSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[Notes] SET     [RefType] = @RefType,    [RefID] = @RefID,    [Title] = @Title,    [Description] = @Description,    [ModifierID] = @ModifierID,    [DateModified] = @DateModified,    [NeedsIndexing] = @NeedsIndexing,    [IsAlert] = @IsAlert,    [ImportFileID] = @ImportFileID,    [ProductFamilyID] = @ProductFamilyID, [ActivityType] = @ActivityType, [DateOccurred] = @DateOccurred   WHERE ([NoteID] = @NoteID);";


            tempParameter = updateCommand.Parameters.Add("DateOccurred", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ActivityType", SqlDbType.NVarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("NoteID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RefID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Title", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Description", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("NeedsIndexing", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsAlert", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ImportFileID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ProductFamilyID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[Notes] (    [RefType],    [RefID],    [Title],    [Description],    [CreatorID],    [ModifierID],    [DateCreated],    [DateModified],    [NeedsIndexing],    [IsAlert],    [ImportFileID],    [ProductFamilyID], [ActivityType], [DateOccurred]) VALUES ( @RefType, @RefID, @Title, @Description, @CreatorID, @ModifierID, @DateCreated, @DateModified, @NeedsIndexing, @IsAlert, @ImportFileID, @ProductFamilyID, @ActivityType, @DateOccurred); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("DateOccurred", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("ActivityType", SqlDbType.NVarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ProductFamilyID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ImportFileID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("IsAlert", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("NeedsIndexing", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Description", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Title", SqlDbType.VarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("RefID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("RefType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[Notes] WHERE ([NoteID] = @NoteID);";
            deleteCommand.Parameters.Add("NoteID", SqlDbType.Int);

            try
            {
                foreach (Note note in this)
                {
                    if (note.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(note);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = note.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["NoteID"].AutoIncrement = false;
                        Table.Columns["NoteID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            note.Row["NoteID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(note);
                    }
                    else if (note.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(note);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = note.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(note);
                    }
                    else if (note.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)note.Row["NoteID", DataRowVersion.Original];
                        deleteCommand.Parameters["NoteID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 25
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("OrganizationProductsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[OrganizationProducts] SET     [OrganizationID] = @OrganizationID,    [ProductID] = @ProductID,    [ProductVersionID] = @ProductVersionID,    [IsVisibleOnPortal] = @IsVisibleOnPortal,    [SupportExpiration] = @SupportExpiration,    [ImportID] = @ImportID,    [DateModified] = @DateModified,    [ModifierID] = @ModifierID,    [ImportFileID] = @ImportFileID,    [SlaLevelID] = @SlaLevelID  WHERE ([OrganizationProductID] = @OrganizationProductID);";


            tempParameter = updateCommand.Parameters.Add("OrganizationProductID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ProductID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ProductVersionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("IsVisibleOnPortal", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("SupportExpiration", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ImportID", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ImportFileID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SlaLevelID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[OrganizationProducts] (    [OrganizationID],    [ProductID],    [ProductVersionID],    [IsVisibleOnPortal],    [SupportExpiration],    [ImportID],    [DateCreated],    [DateModified],    [CreatorID],    [ModifierID],    [ImportFileID],    [SlaLevelID]) VALUES ( @OrganizationID, @ProductID, @ProductVersionID, @IsVisibleOnPortal, @SupportExpiration, @ImportID, @DateCreated, @DateModified, @CreatorID, @ModifierID, @ImportFileID, @SlaLevelID); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("SlaLevelID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ImportFileID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("ImportID", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SupportExpiration", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("IsVisibleOnPortal", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ProductVersionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ProductID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[OrganizationProducts] WHERE ([OrganizationProductID] = @OrganizationProductID);";
            deleteCommand.Parameters.Add("OrganizationProductID", SqlDbType.Int);

            try
            {
                foreach (OrganizationProduct organizationProduct in this)
                {
                    if (organizationProduct.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(organizationProduct);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = organizationProduct.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["OrganizationProductID"].AutoIncrement = false;
                        Table.Columns["OrganizationProductID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            organizationProduct.Row["OrganizationProductID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(organizationProduct);
                    }
                    else if (organizationProduct.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(organizationProduct);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = organizationProduct.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(organizationProduct);
                    }
                    else if (organizationProduct.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)organizationProduct.Row["OrganizationProductID", DataRowVersion.Original];
                        deleteCommand.Parameters["OrganizationProductID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("TicketAutomationPossibleActionsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[TicketAutomationPossibleActions] SET     [DisplayName] = @DisplayName,    [ActionName] = @ActionName,    [RequireValue] = @RequireValue,    [ValueList] = @ValueList,    [ValueList2] = @ValueList2,    [Active] = @Active  WHERE ([ActionID] = @ActionID);";


            tempParameter = updateCommand.Parameters.Add("ActionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DisplayName", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ActionName", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("RequireValue", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ValueList", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ValueList2", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Active", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[TicketAutomationPossibleActions] (    [DisplayName],    [ActionName],    [RequireValue],    [ValueList],    [ValueList2],    [Active]) VALUES ( @DisplayName, @ActionName, @RequireValue, @ValueList, @ValueList2, @Active); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("Active", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ValueList2", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ValueList", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("RequireValue", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ActionName", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DisplayName", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[TicketAutomationPossibleActions] WHERE ([ActionID] = @ActionID);";
            deleteCommand.Parameters.Add("ActionID", SqlDbType.Int);

            try
            {
                foreach (TicketAutomationPossibleAction ticketAutomationPossibleAction in this)
                {
                    if (ticketAutomationPossibleAction.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(ticketAutomationPossibleAction);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = ticketAutomationPossibleAction.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["ActionID"].AutoIncrement = false;
                        Table.Columns["ActionID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            ticketAutomationPossibleAction.Row["ActionID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(ticketAutomationPossibleAction);
                    }
                    else if (ticketAutomationPossibleAction.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(ticketAutomationPossibleAction);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = ticketAutomationPossibleAction.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(ticketAutomationPossibleAction);
                    }
                    else if (ticketAutomationPossibleAction.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)ticketAutomationPossibleAction.Row["ActionID", DataRowVersion.Original];
                        deleteCommand.Parameters["ActionID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 27
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("ChatRequestsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[ChatRequests] SET     [OrganizationID] = @OrganizationID,    [ChatID] = @ChatID,    [RequestorID] = @RequestorID,    [RequestorType] = @RequestorType,    [TargetUserID] = @TargetUserID,    [Message] = @Message,    [GroupID] = @GroupID,    [RequestType] = @RequestType,    [IsAccepted] = @IsAccepted  WHERE ([ChatRequestID] = @ChatRequestID);";


            tempParameter = updateCommand.Parameters.Add("ChatRequestID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ChatID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RequestorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RequestorType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TargetUserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Message", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("GroupID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("RequestType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("IsAccepted", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[ChatRequests] (    [OrganizationID],    [ChatID],    [RequestorID],    [RequestorType],    [TargetUserID],    [Message],    [GroupID],    [RequestType],    [IsAccepted],    [DateCreated]) VALUES ( @OrganizationID, @ChatID, @RequestorID, @RequestorType, @TargetUserID, @Message, @GroupID, @RequestType, @IsAccepted, @DateCreated); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("IsAccepted", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("RequestType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("GroupID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Message", SqlDbType.VarChar, 8000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("TargetUserID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("RequestorType", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("RequestorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ChatID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[ChatRequests] WHERE ([ChatRequestID] = @ChatRequestID);";
            deleteCommand.Parameters.Add("ChatRequestID", SqlDbType.Int);

            try
            {
                foreach (ChatRequest chatRequest in this)
                {
                    if (chatRequest.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(chatRequest);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = chatRequest.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["ChatRequestID"].AutoIncrement = false;
                        Table.Columns["ChatRequestID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            chatRequest.Row["ChatRequestID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(chatRequest);
                    }
                    else if (chatRequest.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(chatRequest);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = chatRequest.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(chatRequest);
                    }
                    else if (chatRequest.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)chatRequest.Row["ChatRequestID", DataRowVersion.Original];
                        deleteCommand.Parameters["ChatRequestID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("ActionsSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[Actions] SET     [ActionTypeID] = @ActionTypeID,    [SystemActionTypeID] = @SystemActionTypeID,    [Name] = @Name,    [TimeSpent] = @TimeSpent,    [DateStarted] = @DateStarted,    [IsVisibleOnPortal] = @IsVisibleOnPortal,    [IsKnowledgeBase] = @IsKnowledgeBase,    [ImportID] = @ImportID,    [DateModified] = @DateModified,    [ModifierID] = @ModifierID,    [TicketID] = @TicketID,    [ActionSource] = @ActionSource,    [DateModifiedBySalesForceSync] = @DateModifiedBySalesForceSync,    [SalesForceID] = @SalesForceID,    [DateModifiedByJiraSync] = @DateModifiedByJiraSync,    [JiraID] = @JiraID,    [Pinned] = @Pinned,    [Description] = @Description,    [IsClean] = @IsClean,    [ImportFileID] = @ImportFileID  WHERE ([ActionID] = @ActionID);";


            tempParameter = updateCommand.Parameters.Add("ActionID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ActionTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SystemActionTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Name", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("TimeSpent", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DateStarted", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("IsVisibleOnPortal", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsKnowledgeBase", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ImportID", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TicketID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("ActionSource", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModifiedBySalesForceSync", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("SalesForceID", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModifiedByJiraSync", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("JiraID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Pinned", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Description", SqlDbType.NVarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("IsClean", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("ImportFileID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[Actions] (    [ActionTypeID],    [SystemActionTypeID],    [Name],    [TimeSpent],    [DateStarted],    [IsVisibleOnPortal],    [IsKnowledgeBase],    [ImportID],    [DateCreated],    [DateModified],    [CreatorID],    [ModifierID],    [TicketID],    [ActionSource],    [DateModifiedBySalesForceSync],    [SalesForceID],    [DateModifiedByJiraSync],    [JiraID],    [Pinned],    [Description],    [IsClean],    [ImportFileID]) VALUES ( @ActionTypeID, @SystemActionTypeID, @Name, @TimeSpent, @DateStarted, @IsVisibleOnPortal, @IsKnowledgeBase, @ImportID, @DateCreated, @DateModified, @CreatorID, @ModifierID, @TicketID, @ActionSource, @DateModifiedBySalesForceSync, @SalesForceID, @DateModifiedByJiraSync, @JiraID, @Pinned, @Description, @IsClean, @ImportFileID); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("ImportFileID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("IsClean", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Description", SqlDbType.NVarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Pinned", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("JiraID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModifiedByJiraSync", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("SalesForceID", SqlDbType.VarChar, 100);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DateModifiedBySalesForceSync", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("ActionSource", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("TicketID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("ImportID", SqlDbType.VarChar, 50);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsKnowledgeBase", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("IsVisibleOnPortal", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DateStarted", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("TimeSpent", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Name", SqlDbType.NVarChar, 1000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("SystemActionTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("ActionTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[Actions] WHERE ([ActionID] = @ActionID);";
            deleteCommand.Parameters.Add("ActionID", SqlDbType.Int);

            try
            {
                foreach (Action action in this)
                {
                    switch (action.Row.RowState)
                    {
                    case DataRowState.Added:
                    {
                        BeforeRowInsert(action);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = action.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["ActionID"].AutoIncrement = false;
                        Table.Columns["ActionID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            action.Row["ActionID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }

                        TeamSupport.Data.BusinessObjects.ActionToAnalyze.QueueForWatsonToneAnalysis(action, connection, LoginUser);
                        AfterRowInsert(action);
                    }
                    break;

                    case DataRowState.Modified:
                    {
                        BeforeRowEdit(action);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = action.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(action);
                    }
                    break;

                    case DataRowState.Deleted:
                    {
                        int id = (int)action.Row["ActionID", DataRowVersion.Original];
                        deleteCommand.Parameters["ActionID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                    break;
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 29
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("TicketAutomationTriggersSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[TicketAutomationTriggers] SET     [Name] = @Name,    [Active] = @Active,    [Position] = @Position,    [OrganizationID] = @OrganizationID,    [UseCustomSQL] = @UseCustomSQL,    [CustomSQL] = @CustomSQL,    [DateModified] = @DateModified,    [ModifierID] = @ModifierID,    [LastSQLExecuted] = @LastSQLExecuted  WHERE ([TriggerID] = @TriggerID);";


            tempParameter = updateCommand.Parameters.Add("TriggerID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("Name", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Active", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Position", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("UseCustomSQL", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("CustomSQL", SqlDbType.VarChar, 5000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("LastSQLExecuted", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[TicketAutomationTriggers] (    [Name],    [Active],    [Position],    [OrganizationID],    [UseCustomSQL],    [CustomSQL],    [DateCreated],    [DateModified],    [CreatorID],    [ModifierID],    [LastSQLExecuted]) VALUES ( @Name, @Active, @Position, @OrganizationID, @UseCustomSQL, @CustomSQL, @DateCreated, @DateModified, @CreatorID, @ModifierID, @LastSQLExecuted); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("LastSQLExecuted", SqlDbType.VarChar, -1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("ModifierID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("CreatorID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("DateModified", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DateCreated", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("CustomSQL", SqlDbType.VarChar, 5000);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("UseCustomSQL", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("OrganizationID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Position", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("Active", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("Name", SqlDbType.VarChar, 200);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[TicketAutomationTriggers] WHERE ([TriggerID] = @TriggerID);";
            deleteCommand.Parameters.Add("TriggerID", SqlDbType.Int);

            try
            {
                foreach (TicketAutomationTrigger ticketAutomationTrigger in this)
                {
                    if (ticketAutomationTrigger.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(ticketAutomationTrigger);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = ticketAutomationTrigger.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["TriggerID"].AutoIncrement = false;
                        Table.Columns["TriggerID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            ticketAutomationTrigger.Row["TriggerID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(ticketAutomationTrigger);
                    }
                    else if (ticketAutomationTrigger.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(ticketAutomationTrigger);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = ticketAutomationTrigger.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(ticketAutomationTrigger);
                    }
                    else if (ticketAutomationTrigger.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)ticketAutomationTrigger.Row["TriggerID", DataRowVersion.Original];
                        deleteCommand.Parameters["TriggerID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }
Ejemplo n.º 30
0
        public override void Save(SqlConnection connection)
        {
            //SqlTransaction transaction = connection.BeginTransaction("SlaTriggersSave");
            SqlParameter tempParameter;
            SqlCommand   updateCommand = connection.CreateCommand();

            updateCommand.Connection = connection;
            //updateCommand.Transaction = transaction;
            updateCommand.CommandType = CommandType.Text;
            updateCommand.CommandText = "SET NOCOUNT OFF; UPDATE [dbo].[SlaTriggers] SET     [SlaLevelID] = @SlaLevelID,    [TicketTypeID] = @TicketTypeID,    [TicketSeverityID] = @TicketSeverityID,    [TimeInitialResponse] = @TimeInitialResponse,    [TimeLastAction] = @TimeLastAction,    [TimeToClose] = @TimeToClose,    [NotifyUserOnWarning] = @NotifyUserOnWarning,    [NotifyGroupOnWarning] = @NotifyGroupOnWarning,    [NotifyUserOnViolation] = @NotifyUserOnViolation,    [NotifyGroupOnViolation] = @NotifyGroupOnViolation,    [WarningTime] = @WarningTime,    [UseBusinessHours] = @UseBusinessHours,    [PauseOnHoliday] = @PauseOnHoliday,    [Weekdays] = @Weekdays,    [DayStart] = @DayStart,    [DayEnd] = @DayEnd,    [TimeZone] = @TimeZone,    [NoBusinessHours] = @NoBusinessHours  WHERE ([SlaTriggerID] = @SlaTriggerID);";


            tempParameter = updateCommand.Parameters.Add("SlaTriggerID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("SlaLevelID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TicketTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TicketSeverityID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TimeInitialResponse", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TimeLastAction", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("TimeToClose", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("NotifyUserOnWarning", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("NotifyGroupOnWarning", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("NotifyUserOnViolation", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("NotifyGroupOnViolation", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("WarningTime", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("UseBusinessHours", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("PauseOnHoliday", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("Weekdays", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = updateCommand.Parameters.Add("DayStart", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("DayEnd", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = updateCommand.Parameters.Add("TimeZone", SqlDbType.VarChar, 300);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = updateCommand.Parameters.Add("NoBusinessHours", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }


            SqlCommand insertCommand = connection.CreateCommand();

            insertCommand.Connection = connection;
            //insertCommand.Transaction = transaction;
            insertCommand.CommandType = CommandType.Text;
            insertCommand.CommandText = "SET NOCOUNT OFF; INSERT INTO [dbo].[SlaTriggers] (    [SlaLevelID],    [TicketTypeID],    [TicketSeverityID],    [TimeInitialResponse],    [TimeLastAction],    [TimeToClose],    [NotifyUserOnWarning],    [NotifyGroupOnWarning],    [NotifyUserOnViolation],    [NotifyGroupOnViolation],    [WarningTime],    [UseBusinessHours],    [PauseOnHoliday],    [Weekdays],    [DayStart],    [DayEnd],    [TimeZone],    [NoBusinessHours]) VALUES ( @SlaLevelID, @TicketTypeID, @TicketSeverityID, @TimeInitialResponse, @TimeLastAction, @TimeToClose, @NotifyUserOnWarning, @NotifyGroupOnWarning, @NotifyUserOnViolation, @NotifyGroupOnViolation, @WarningTime, @UseBusinessHours, @PauseOnHoliday, @Weekdays, @DayStart, @DayEnd, @TimeZone, @NoBusinessHours); SET @Identity = SCOPE_IDENTITY();";


            tempParameter = insertCommand.Parameters.Add("NoBusinessHours", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("TimeZone", SqlDbType.VarChar, 300);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("DayEnd", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("DayStart", SqlDbType.DateTime, 8);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 23;
                tempParameter.Scale     = 23;
            }

            tempParameter = insertCommand.Parameters.Add("Weekdays", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("PauseOnHoliday", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("UseBusinessHours", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("WarningTime", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("NotifyGroupOnViolation", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("NotifyUserOnViolation", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("NotifyGroupOnWarning", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("NotifyUserOnWarning", SqlDbType.Bit, 1);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 255;
                tempParameter.Scale     = 255;
            }

            tempParameter = insertCommand.Parameters.Add("TimeToClose", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("TimeLastAction", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("TimeInitialResponse", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("TicketSeverityID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("TicketTypeID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }

            tempParameter = insertCommand.Parameters.Add("SlaLevelID", SqlDbType.Int, 4);
            if (tempParameter.SqlDbType == SqlDbType.Float)
            {
                tempParameter.Precision = 10;
                tempParameter.Scale     = 10;
            }


            insertCommand.Parameters.Add("Identity", SqlDbType.Int).Direction = ParameterDirection.Output;
            SqlCommand deleteCommand = connection.CreateCommand();

            deleteCommand.Connection = connection;
            //deleteCommand.Transaction = transaction;
            deleteCommand.CommandType = CommandType.Text;
            deleteCommand.CommandText = "SET NOCOUNT OFF;  DELETE FROM [dbo].[SlaTriggers] WHERE ([SlaTriggerID] = @SlaTriggerID);";
            deleteCommand.Parameters.Add("SlaTriggerID", SqlDbType.Int);

            try
            {
                foreach (SlaTrigger slaTrigger in this)
                {
                    if (slaTrigger.Row.RowState == DataRowState.Added)
                    {
                        BeforeRowInsert(slaTrigger);
                        for (int i = 0; i < insertCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = insertCommand.Parameters[i];
                            if (parameter.Direction != ParameterDirection.Output)
                            {
                                parameter.Value = slaTrigger.Row[parameter.ParameterName];
                            }
                        }

                        if (insertCommand.Parameters.Contains("ModifierID"))
                        {
                            insertCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (insertCommand.Parameters.Contains("CreatorID") && (int)insertCommand.Parameters["CreatorID"].Value == 0)
                        {
                            insertCommand.Parameters["CreatorID"].Value = LoginUser.UserID;
                        }

                        insertCommand.ExecuteNonQuery();
                        Table.Columns["SlaTriggerID"].AutoIncrement = false;
                        Table.Columns["SlaTriggerID"].ReadOnly      = false;
                        if (insertCommand.Parameters["Identity"].Value != DBNull.Value)
                        {
                            slaTrigger.Row["SlaTriggerID"] = (int)insertCommand.Parameters["Identity"].Value;
                        }
                        AfterRowInsert(slaTrigger);
                    }
                    else if (slaTrigger.Row.RowState == DataRowState.Modified)
                    {
                        BeforeRowEdit(slaTrigger);
                        for (int i = 0; i < updateCommand.Parameters.Count; i++)
                        {
                            SqlParameter parameter = updateCommand.Parameters[i];
                            parameter.Value = slaTrigger.Row[parameter.ParameterName];
                        }
                        if (updateCommand.Parameters.Contains("ModifierID"))
                        {
                            updateCommand.Parameters["ModifierID"].Value = LoginUser.UserID;
                        }
                        if (updateCommand.Parameters.Contains("DateModified"))
                        {
                            updateCommand.Parameters["DateModified"].Value = DateTime.UtcNow;
                        }

                        updateCommand.ExecuteNonQuery();
                        AfterRowEdit(slaTrigger);
                    }
                    else if (slaTrigger.Row.RowState == DataRowState.Deleted)
                    {
                        int id = (int)slaTrigger.Row["SlaTriggerID", DataRowVersion.Original];
                        deleteCommand.Parameters["SlaTriggerID"].Value = id;
                        BeforeRowDelete(id);
                        deleteCommand.ExecuteNonQuery();
                        AfterRowDelete(id);
                    }
                }
                //transaction.Commit();
            }
            catch (Exception)
            {
                //transaction.Rollback();
                throw;
            }
            Table.AcceptChanges();
            if (DataCache != null)
            {
                DataCache.InvalidateItem(TableName, LoginUser.OrganizationID);
            }
        }