Monday, December 1, 2014

ASPxGridView - Enable Disable commandbuttons with conditions in AspxGridView

protected void grid1_CommandButtonInitialize(object sender, ASPxGridViewCommandButtonEventArgs e)
        {

            if (e.VisibleIndex == -1)
                return;
            if (e.ButtonType == ColumnCommandButtonType.Edit)
            {
                e.Enabled = EditButtonVisibleCriteria((ASPxGridView)sender, e.VisibleIndex);
            }


        }
        private bool EditButtonVisibleCriteria(ASPxGridView grid, int visibleIndex)
        {
            object row = grid.GetRow(visibleIndex);
            return ((DataRowView)row)["Status"].ToString().Contains("Entered");

        }

Wednesday, October 22, 2014

Sys.WebForms.PageRequestManagerParserErrorException: DevExpress

What's a PageRequestManagerParserErrorException?
The UpdatePanel control uses asynchronous postbacks to control which parts of the page get rendered. It does this using a whole bunch of JavaScript on the client and a whole bunch of C# on the server. Asynchronous postbacks are exactly the same as regular postbacks except for one important thing: the rendering. Asynchronous postbacks go through the same life cycles events as regular pages (this is a question I get asked often). Only at the render phase do things get different. We capture the rendering of only the UpdatePanels that we care about and send it down to the client using a special format. In addition, we send out some other pieces of information, such as the page title, hidden form values, the form action URL, and lists of scripts.
As I mentioned, this is rendered out using a special format that the JavaScript on the client can understand. If you mess with the format by rendering things outside of the render phase of the page, the format will be messed up. Perhaps the most common way to do this is to call Response.Write() during Page's Load event, which is something that page developers often do for debugging purposes.
The client ends up receiving a blob of data that it can't parse, so it gives up and shows you a PageRequestManagerParserErrorException. Here's an example of what the message contains:

How do I avoid getting a PageRequestManagerParserErrorException?
       protected void Page_Init(object sender, EventArgs e)
        {          

                RegisterPostBackControl();
           
        }

        private void RegisterPostBackControl()
        {
            ScriptManager.RegisterPostBackControl(pageControl);
        }

Saturday, September 13, 2014

Find and Replace Values in All Tables and All Text Columns using SQL Server

DECLARE @stringToFind VARCHAR(100)
DECLARE @stringToReplace VARCHAR(100)
DECLARE @schema sysname
DECLARE @table sysname
DECLARE @count INT
DECLARE @sqlCommand VARCHAR(8000)
DECLARE @where VARCHAR(8000)
DECLARE @columnName sysname
DECLARE @object_id INT
                    
SET @stringToFind = 'Smith'
SET @stringToReplace = 'Jones'
                       
DECLARE TAB_CURSOR CURSOR  FOR
SELECT   B.NAME      AS SCHEMANAME,
         A.NAME      AS TABLENAME,
         A.OBJECT_ID
FROM     sys.objects A
         INNER JOIN sys.schemas B
           ON A.SCHEMA_ID = B.SCHEMA_ID
WHERE    TYPE = 'U'
ORDER BY 1
         
OPEN TAB_CURSOR

FETCH NEXT FROM TAB_CURSOR
INTO @schema,
     @table,
     @object_id
     
WHILE @@FETCH_STATUS = 0
  BEGIN
    DECLARE COL_CURSOR CURSOR FOR
    SELECT A.NAME
    FROM   sys.columns A
           INNER JOIN sys.types B
             ON A.SYSTEM_TYPE_ID = B.SYSTEM_TYPE_ID
    WHERE  OBJECT_ID = @object_id
           AND IS_COMPUTED = 0
           AND B.NAME IN ('char','nchar','nvarchar','varchar','text','ntext')

    OPEN COL_CURSOR
    
    FETCH NEXT FROM COL_CURSOR
    INTO @columnName
    
    WHILE @@FETCH_STATUS = 0
      BEGIN
        SET @sqlCommand = 'UPDATE ' + @schema + '.' + @table + ' SET [' + @columnName
                           + '] = REPLACE(convert(nvarchar(max),[' + @columnName + ']),'''
                           + @stringToFind + ''',''' + @stringToReplace + ''')'
        
        SET @where = ' WHERE [' + @columnName + '] LIKE ''%' + @stringToFind + '%'''
        
        EXEC( @sqlCommand + @where)
        
        SET @count = @@ROWCOUNT
        
        IF @count > 0
          BEGIN
            PRINT @sqlCommand + @where
            PRINT 'Updated: ' + CONVERT(VARCHAR(10),@count)
            PRINT '----------------------------------------------------'
          END
        
        FETCH NEXT FROM COL_CURSOR
        INTO @columnName
      END
    
    CLOSE COL_CURSOR
    DEALLOCATE COL_CURSOR
    
    FETCH NEXT FROM TAB_CURSOR
    INTO @schema,
         @table,
         @object_id
  END
  
CLOSE TAB_CURSOR
DEALLOCATE TAB_CURSOR


Find Stored Procedure Containing by Table Name


SELECT DISTINCT t.name [TableName], p.name [ProcedureName]
FROM sys.objects t
LEFT JOIN sys.sql_dependencies d ON
    d.referenced_major_id = t.object_id
LEFT JOIN sys.objects p ON
    p.object_id = d.object_id  
WHERE t.type = 'u'
and t.name like '%tbl_Order%'


Find Tables in a Database Who Have a Filed With Same Name


SELECT SCHEMA_NAME(schema_id) + '.' + t.name AS 'Table Name'
FROM sys.tables t
     INNER JOIN sys.columns c
        ON c.object_id = t.object_id
WHERE c.name like '%OrderID%'
ORDER BY 'Table Name'


Find and Delete Duplicate Rows From a Table in SQL Server


WITH CTE AS(
   SELECT *,     
   RN = ROW_NUMBER()OVER(PARTITION BY OrderID ORDER BY OrderID)
   FROM tbl_Order  
)

SELECT * FROM CTE WHERE RN >1

DELETE   FROM CTE WHERE RN >1

Wednesday, February 12, 2014

Reward Points in eCommerce

Installing, Managing and Implementing Reward Points in AspxCommerce. 

Installing Reward Points Module From Back End:

Login with superuser  in aspxcommerce 2.0

1. Install Reward Points Module zip named AspxRewardPoints by clicking on Dashboard > Module > Install Module. Module will be Installed as AspxRewardPoints.  



   2.  Create New Portal Page as Reward Points by clicking on Dashboard >Pages> New Page.


  3.  Add Module AspxRewardPoints in Reward Points Page by clicking on Dashboard >Page Modules. Select Page Named Reward Points from drop down list and drag AspxRewardPoints Module  insideToppane Container.


Now you can see that module is installed by going Dashboard >AspxCommerce>Customers


Manage Setting and Reward Rules  From Back End:

Login with superuser in aspxcommerce 2.0
Go to Dashboard >AspxCommerce>Customers>Reward Points, A window will be opened as bellow


To manage settings of reward points click on Edit button. Manage setting window will be opened.

Manage Settings:


Exchange Rate: As above setting if customer earns 10 Reward Points then it will be converted to 1 USD.
Awarded Order Status: Reward Points will be added only if order status of ordered items  will be as selected in regarding drop down list.
Cancelled Order Status: Reward Points will be cancelled if order status of ordered items  will be as selected in regarding drop down list.
Reward Points Expires in (Days): Reward Points will be expire in days as per defined in regarding text box. If its 0 then Reward Points will never be expire.
Minimum balance(Reward Points) in order to redeem: Reward Points will be used for discount (Redeem) only if total earned Reward Points will be more or equal to points given in its regarding text box value.
Capped balance(Reward Points): Reward Points will be added to customers account only if his earned Reward Points for the order will be more or equal to Capped Balance.

Add/Edit Reward Rules:


Add: To add new reward rule click on Add New Reward Rule Button.
Edit: To edit reward rule click on rounded button bellow Action column and then click on Edit.
A Window will be appear like this..




Reward Points View:



To see reward points history click on View Button.



To see details of particular Customer click on View .

Reward Points on Front End:

Now we can see Reward ponits for the order are calculated as under If Customer eraned Reward Points for his previous purchase then he can use his reward points by selecting on Slide and clicking on GO. 


 Customer can see his reward point.s earned history by clicking on My Account > My Reward Points.