Wednesday, November 9, 2022

Paging With database in ASP Dot net C sharp

Store Procedure Code :-

CREATE PROCEDURE getDeals
      @StartIndex int,
      @PageSize int,
      @TotalCount int OutPut
as

select @TotalCount=count(1) from mstrDeals;
WITH CTE AS
(
   select top(@startIndex+@PageSize-1) ROW_NUMBER() OVER(ORDER BY creationdate) RowNumber,dealid,dealTitle
   from mstrDeals
)
select * from CTE where RowNumber between @startIndex and (@startIndex+@PageSize-1)

Binding Grid Control Code:-

public void bindGrid(int currentPage)
{
 int pageSize = 10;
 int _TotalRowCount = 0;

 string _ConStr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
 using (SqlConnection con = new SqlConnection(_ConStr))
 {

   SqlCommand cmd = new SqlCommand("getDeals", con);
   cmd.CommandType = CommandType.StoredProcedure;

   int startRowNumber = ((currentPage - 1) * pageSize) + 1;
      
   cmd.Parameters.AddWithValue("@StartIndex", startRowNumber);
   cmd.Parameters.AddWithValue("@PageSize", pageSize);

   SqlParameter parTotalCount = new SqlParameter("@TotalCount"SqlDbType.Int);
   parTotalCount.Direction = ParameterDirection.Output;
   cmd.Parameters.Add(parTotalCount);

   SqlDataAdapter da = new SqlDataAdapter(cmd);
   DataSet ds = new DataSet();
   da.Fill(ds);

   _TotalRowCount = Convert.ToInt32(parTotalCount.Value);

   grdCustomPagging.DataSource = ds;
   grdCustomPagging.DataBind();

   generatePager(_TotalRowCount, pageSize, currentPage);

 }
}


<asp:GridView Width="500" runat="server" ID="grdCustomPagging">
</asp:GridView>


Generate Pager Code :

public void generatePager(int totalRowCount, int pageSize, int currentPage)
{
  int totalLinkInPage = 5;
  int totalPageCount = (int)Math.Ceiling((decimal)totalRowCount / pageSize);

  int startPageLink = Math.Max(currentPage - (int)Math.Floor((decimal)totalLinkInPage / 2), 1);
  int lastPageLink = Math.Min(startPageLink + totalLinkInPage - 1, totalPageCount);

  if ((startPageLink + totalLinkInPage - 1) > totalPageCount)
  {
      lastPageLink = Math.Min(currentPage + (int)Math.Floor((decimal)totalLinkInPage / 2), totalPageCount);
      startPageLink = Math.Max(lastPageLink - totalLinkInPage + 1, 1);
  }

  List<ListItem> pageLinkContainer = new List<ListItem>();

  if (startPageLink != 1)
      pageLinkContainer.Add(new ListItem("First""1", currentPage != 1));
  for (int i = startPageLink; i <= lastPageLink; i++)
  {
      pageLinkContainer.Add(new ListItem(i.ToString(), i.ToString(), currentPage != i));
  }
  if (lastPageLink != totalPageCount)
      pageLinkContainer.Add(new ListItem("Last", totalPageCount.ToString(), currentPage != totalPageCount));

  dlPager.DataSource = pageLinkContainer;
  dlPager.DataBind();
}

protected void dlPager_ItemCommand(object source, DataListCommandEventArgs e)
{
   if (e.CommandName == "PageNo")
   {
       bindGrid(Convert.ToInt32(e.CommandArgument));
   }
}


<asp:DataList CellPadding="5" RepeatDirection="Horizontal" runat="server" ID="dlPager"
    onitemcommand="dlPager_ItemCommand">
    <ItemTemplate>
       <asp:LinkButton Enabled='<%#Eval("Enabled") %>' runat="server" ID="lnkPageNo" Text='<%#Eval("Text") %>' CommandArgument='<%#Eval("Value") %>' CommandName="PageNo"></asp:LinkButton>
    </ItemTemplate>
</asp:DataList>

Sunday, April 28, 2019

Architect Level Discussion

Design Principle vs Design Pattern.

In the software engineering, design principle and design pattern are not the same.

Design Principle

It provides high level guide lines to design better software applications. Design principles do not provide implementation and not bound to any programming language. E.g. SOLID (SRP, OCP, LSP, ISP, DIP) principles.
For example, Single Responsibility Principle (SRP) suggests that a class should have only one and one reason to change. This is high level statement which we can keep in mind while designing or creating classes for our application. SRP does not provide specific implementation steps but it's on you how you implement SRP in your application.

Design Pattern

It provides low level solution (implementation) for the commonly occurring object oriented problem. In another word, design pattern suggest specific implementation for the specific object oriented programming problem. For example, if you want create a class that can only have one object at a time then you can use Singleton design pattern which suggests the best way to create a class that can only have one object.
Design patterns are tested by others and safe to follow. E.g. Gang of Four patterns: Abstract Factory, Factory, Singleton, Command etc.

Thursday, December 22, 2016

New feature in SQL SERVER 2016

Dynamic Data Masking

If you are interested in securing your confidential data so some people can see it, while other people get an obscured version of confidential data then you might be interested in dynamic data masking. With dynamic data masking you can obscure confidential columns of data in a table to SQL Server for users that are not authorized to see the all the data. With dynamic data masking you can identify how the data will be obscured. For instance say you accept credit card numbers and store them in a table, but you want to make sure your help desk staff is only able to see the last four digits of the credit card number. By setting up dynamic data masking you can define a masking rules so unauthorized logins can only read the last four digits of a credit card number, whereas authorized logins can see all of the credit card information.
JSON Support

JSON stands for Java Script Object Notation. With SQL Server 2016 you can now interchange JSON data between applications and the SQL Server database engine. By adding this support Microsoft has provided SQL Server the ability to parse JSON formatted data so it can be stored in a relation format. Additionally, with JSON support you can take relational data, and turn it into JSON formatted data. Microsoft has also added some new functions to provided support for querying JSON data stored in SQL Server. Having these additional JSON features built into SQL Server should make it easier for applications to exchange JSON data with SQL Server.

Always Encrypted

With the Always Encrypted feature enabled your SQL Server data will always be encrypted within SQL Server. Access to encrypted data will only be available to the applications calling SQL Server. Always Encrypted enables client application owners to control who gets access to see their applications confidential data. It does this by allowing the client application to be the one that has the encryption key. That encryption key is never passed to SQL Server. By doing this you can keep those nosey Database or Windows Administrators from poking around sensitive client application data In-Flight or At-Rest. This feature will now allow you to sleep at night knowing your confidential data stored in a cloud managed database is always encrypted and out of the eyes of your cloud provider.


Multiple TempDB Database Files

It has been a best practice for a while to have more than one tempdb data file if you are running on a multi-core machine. In the past, up through SQL Server 2014, you always had to manually add the additional tempdb data files after you installed SQL Server. With SQL Server 2016 you can now configure the number of tempdb files you need while you are installing SQL Server. Having this new feature means you will no longer need to manually add additional tempdb files after installing SQL Server.

PolyBase

PolyBase allows you to query distributed data sets. With the introduction of PolyBase you will be able to use Transact SQL statements to query Hadoop, or SQL Azure blob storage. By using PolyBase you can now write adhoc queries to join relational data from SQL Server with semi-structured data stored in Hadoop, or SQL Azure blob storage. This allows you to get data from Hadoop without knowing the internals of Hadoop. Additionally you can leverage SQL Server’s on the fly column store indexing to optimize your queries against semi-structured data. As organizations spread data across many distributed locations, PolyBase will be a solution for them to leverage SQL Server technology to access their
Query Store

If you are into examining execution plans than you will like the new Query Store feature. Currently in versions of SQL Server prior to 2016 you can see existing execution plans by using dynamic management views (DMVs). But, the DMVs only allow you to see the plans that are actively in the plan cache. You can’t see any history for plans once they are rolled out of the plan cache. With the Query Store feature, SQL Server now saves historical execution plans. Not only that but it also saves the query statistics that go along with those historical plans. This is a great addition and will allow you to now track execution plans performance for your queries over time.
Row Level Security

With Row Level Security the SQL database engine will be able to restrict access to row data, based on a SQL Server login. Restricting rows will be done by filter predicates defined in inline table value function. Security policies will ensure the filter predicates get executed for every SELECT or DELETE operation. Implementing row level security at the database layer means application developers will no longer need to maintain code to restrict data from some logins, while allowing other logins to access all the data. With this new feature, when someone queries a tables that contains row level security they will not even know whether or not any rows of data were filtered out.

Stretch Database

The Stretch Database feature provides you a method to stretch the storage of your On-Premise database to Azure SQL Database. But having the stretch database feature allows you to have your most frequently accessed data stored On-Premise, while your less accessed data is off-site in an Azure SQL databases. When you enable a database to “stretch” the older data starts moving over to the Azure SQL database behind the scenes. When you need to run a query that might access active and historical information in a “stretched” database the database engine seamlessly queries both the On-Premise database as well as Azure SQL database and returns the results to you as if they had come from a single source. This feature will make it easy for DBA’s to archive information to a cheaper storage media without having to change any actual application code. By doing this you should be able to maximize performance on those active On-Premise queries.

Temporal Table

A temporal table is table that holds old versions of rows within a base table.  By having temporal tables SQL Server can automatically manage moving old row versions to the temporal table every time a row in the base table is updated.  The temporal table is physically a different table then the base table, but is linked to the base table.  If you’ve been building or plan to build your own method to managing row versioning then you might want to check out the new temporal tables support in SQL server 2016 before you go forth and build your own row versioning solution.

Tuesday, March 25, 2014

CRUD Command in entity framework

         //select command        
         int idToupdate = Convert.ToInt32(Request.QueryString["id"].ToString());
            db_testCon db = new db_testCon();
            tblCustomer tb = db.tblCustomers.Single(p => p.CustomerID == idToupdate);
            TextBox1.Text = tb.City;          
           
            and            
        db_testModel.db_testcon db = new db_testcon();
        Repeater1.DataSource = db.tblCustomer;
        Repeater1.DataBind();
           
            //update  commnd
           
             int idToupdate = Convert.ToInt32(Request.QueryString["id"].ToString());
        db_testCon db = new db_testCon();
        tblCustomer tb = db.tblCustomers.SingleOrDefault(a=>a.CustomerID==idToupdate);
        tb.City = TextBox1.Text;
        db.SaveChanges();
       
       
        //Add Command
       
        db_testcon db = new db_testcon();
        tblCustomer tb = new tblCustomer();
        tb.CompanyName = TextBox1.Text;
        tb.ContactName = TextBox2.Text;
        tb.City = TextBox3.Text;
        db.tblCustomer.AddObject(tb);
        if (db.SaveChanges() == 1) { Response.Redirect("et.aspx"); }
       
       
        //delete command
        int idToupdate = Convert.ToInt32(Request.QueryString["id"].ToString());
        db_testcon db1 = new db_testcon();
        tblCustomer tb = db1.tblCustomer.SingleOrDefault(a => a.CustomerID == idToupdate);
        db1.tblCustomer.DeleteObject(tb);
        db1.SaveChanges();

Friday, April 19, 2013

how can i pass value from master page to content page and vice versa ?


/on master pag
Label
lbl =(Label) Page.Master.FindControl("ContentPlaceHolder1").FindControl("lblm");
lbl.Text =
"hgfgc";//lbm  label on aspx pages within ContentPlaceHolder1 id



//how can i pass value from content page  to  master page  ?
//on aspx pages
Label lbl = (Label)this.Master.FindControl("lblm");lbl.Text =
"hgfgc";
//lbm lable on master pages

Monday, September 10, 2012

What is Ecommerce - an overview


In its simplest form ecommerce is the buying and selling of products and services by businesses and consumers over the Internet. People use the term "ecommerce" to describe encrypted payments on the Internet.

Sometimes these transactions include the real-time transfer of funds from buyer to seller and sometimes this is handled manually through an eft-pos terminal once a secure order is received by the merchant.

Internet sales are increasing rapidly as consumers take advantage of lower prices offer by wholesalers retailing their products. This trend is set to strengthen as web sites address consumer security and privacy concerns.

Benefits of E-Commerce


E-commerce can provide the following benefits over non-electronic commerce:

  • Reduced costs by reducing labour, reduced paper work, reduced errors in keying in data, reduce post costs
  • Reduced time. Shorter lead times for payment and return on investment in advertising, faster delivery of product
  • Flexibility with efficiency. The ability to handle complex situations, product ranges and customer profiles without the situation becoming unmanageable.
  • Improve relationships with trading partners. Improved communication between trading partners leads to enhanced long-term relationships.
  • Lock in Customers. The closer you are to your customer and the more you work with them to change from normal business practices to best practice e-commerce the harder it is for a competitor to upset your customer relationship.
  • New Markets. The Internet has the potential to expand your business into wider geographical locations.


B2C - business to consumer


In the Australian context B2C (business to consumer) trading activity has been slow to take off as at first consumers had doubts about the security of credit card transactions.

Initial B2C trading focused on music CDs, software and books - items which were compact and easily shipped and where prices could be slashed once the retailer's cut was taken out of the margin. The Amazon book store would be a good example of this. These products pushed the perimeters of the market out for goods bought on-line.

Books and CDs are relatively generic products. A CD bought in the US will have the same music and quality as one bought locally (the exception is the cover art) and so there is no doubt in the consumers mind exactly what the product is. This is not the case with clothing, where sizes can confuse the purchase decision... and where tactile senses figure strongly in the purchasing decision.

Ebay has really transform purchasing behaviour on the web. Many people have made their first ecommerce transaction on Ebay. Many people sell on Ebay too, given raise to the work-from-home/drop shipping model of ecommerce.

Interestingly though B2C transactions of previously localised or hard to find products can be extremely strong. If you have a unique product that is highly relevant to a niche audience, you are likely to do very well on the web.

Although sales are increasing rapidly on the Internet, the volume of turnover figures continue to fail short of industry estimates. But as retail web sites become more navigable and privacy policies are displayed, more people will be drawn to Net-based purchasing by lower prices and convenience.


B2B - business to business


On the Internet, B2B (business to business) is the exchange of products or services between businesses rather than between businesses and consumers.

Although early interest centered on the growth of retailing on the Internet, forecasts are that B2B revenue will far exceed B2C revenue in the near future.

According to studies published in early 2000, the money volume of B2B exceeds that of B2C by 10 to 1. Over the next five years, B2B is expected to have a compound annual growth of 41%.

Payment Gateways


Both PayPal and Paymate offer credit card to bank account payments. Using one of these services you can invoice a customer, they can pay on Paymate and the funds will be deposited in your bank account ... less a transaction fee.

Unlike a credit card merchant facility you will not have ongoing, minimum monthly fees... and the transaction fee is better than what most card companies offer small merchants. Additional these service are being backed into other ecommerce sites and shopping carts. Ebay for example uses Paypal to process some payments.



For More Details  cal at +91 9911425805 (Sahil singh (SSE ) India))