Friday, February 9, 2024

Rnd store procedure and table printing code

 private int currentPage = 1;

private int rowsPerPage = 10;

private int startIndex = 0;

private int lineSpacing = 5; // Adjust as needed


private void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)

{

    // Your existing code


    Rectangle rect7 = new Rectangle(rect1.Left, rect6.Bottom, 750, rect7Height);

    e.Graphics.DrawRectangle(Pens.Black, rect7);


    // Determine the range of rows to print on the current page

    int endIndex = Math.Min(startIndex + rowsPerPage, numberOfRows);


    for (int i = startIndex; i < endIndex; i++)

    {

        DataRow row = data.Rows[i];


        // Adjust x-coordinates based on your layout

        int currentYPosition = rect6.Bottom + 5 + (i - startIndex) * (rowHeight + lineSpacing);


        e.Graphics.DrawString($"{i + 1}", headerFont, Brushes.Black, rect6.X, currentYPosition);

        e.Graphics.DrawString($"{row["Description"]}", headerFont, Brushes.Black, rect6.X + 100 + 15, currentYPosition);

        e.Graphics.DrawString($"{row["HSNCODE"]}", headerFont, Brushes.Black, (rect6.X + 350 + 5), currentYPosition);

        e.Graphics.DrawString($"{row["Charges"]}", headerFont, Brushes.Black, (rect6.X + 450 + 5), currentYPosition);

        e.Graphics.DrawString($"{row["Charges"]}", headerFont, Brushes.Black, (rect6.Width - 35), currentYPosition);


        // Update currentY if needed

        currentY += rowHeight + lineSpacing;

    }


    // Check if there are more rows to print

    if (endIndex < numberOfRows)

    {

        // There are more rows, set HasMorePages to true for the next page

        e.HasMorePages = true;

        currentPage++;

        startIndex = endIndex; // Update the start index for the next page

    }

    else

    {

        // No more rows, set HasMorePages to false

        e.HasMorePages = false;

        currentPage = 1; // Reset the current page for future print jobs

        startIndex = 0; // Reset the start index for future print jobs

    }

}

CREATE PROCEDURE Update_GST_SAC_Code
    @SACCodeID bigint,
    @Heading bigint,
    @GroupCode bigint,
    @SACCode bigint,
    @Description nvarchar(MAX),
    @SGSTRate nvarchar(MAX),
    @CGSTRate nvarchar(MAX),
    @IGSTRate nvarchar(MAX),
    @FirmID nvarchar(MAX),
    @UserID nvarchar(MAX),
    @EffectiveDate nvarchar(MAX),
    @SuccessMessage nvarchar(MAX) OUTPUT,
    @output bigint OUTPUT

AS
BEGIN

 BEGIN TRY

             IF EXISTS ( SELECT 1 FROM [GST-SAC-CODE] WHERE SACCode = @SACCode and IGSTRate =  @IGSTRate )
 BEGIN

                 SET @output = @@ROWCOUNT;
                 SET @SuccessMessage = 'Data which u want to update is already present in Sac Codes ';

                 return;

           
 END
 ELSE
 BEGIN

   
                IF EXISTS ( SELECT 1 FROM  [GST-SAC-CODES-RATES] WHERE EffectDate = @EffectiveDate and Rate =  @IGSTRate and SACCodeID = @SACCodeID   )
                      BEGIN

                                       SET @output = @@ROWCOUNT;
                                       SET @SuccessMessage = 'Data which u want to update is already present in sac codes rates';

                               return;

            
                      END
                ELSE
                     BEGIN
            
                               UPDATE [GST-SAC-CODE] SET Heading = @Heading, GroupCode = @GroupCode, SACCode = @SACCode, Description = @Description, SGSTRate = @SGSTRate, CGSTRate = @CGSTRate, IGSTRate = @IGSTRate,FirmID = @FirmID,UserID = @UserID,SyncDateTime = GETDATE()  WHERE SACCodeID = @SACCodeID;

                                       SET @output = @@ROWCOUNT;
                                        IF (@output > 0)
                                               BEGIN
    SET @output = Null;
      UPDATE [GST-SAC-CODES-RATES]
                                                            SET
                                                                     EffectDate = @EffectiveDate, -- Update the EffectDate as needed
                                                                      Rate = @SGSTRate,            -- Update the Rate column as needed
                                                                      FirmID = @FirmID,            -- Update FirmID if needed
                                                                      UserID = @UserID,            -- Update UserID if needed
                                                                      SyncDateTime = GETDATE()
                                                                      WHERE SACCodeID = @SACCodeID;
     SET @output = @@ROWCOUNT;
                                                                        IF (@output > 0)
                                                                            BEGIN

                                                                               SET @SuccessMessage = 'Data updated Successfully';
   return;
                                                                                    END
                                                                        ELSE
                                                                            BEGIN

                                                                                SET @SuccessMessage = 'Data Updation Failed';
return;
                                                                                    END 

                                                        
                                                       END
                                        ELSE
                                               BEGIN

                                                         SET @SuccessMessage = 'Data Updation Failed';
return;
                                                       END














                                      


                                    


END








     

END


END TRY

BEGIN CATCH

            SET @output = NULL;
            SET @SuccessMessage = ERROR_MESSAGE();

        -- You can log the error, perform additional error handling, or take other actions as needed

END CATCH;



END

No comments:

Post a Comment

Rnd store procedure and table printing code

 private int currentPage = 1; private int rowsPerPage = 10; private int startIndex = 0; private int lineSpacing = 5; // Adjust as needed pri...