Showing posts with label c# Tutorial. Show all posts
Showing posts with label c# Tutorial. Show all posts

Wednesday 8 November 2023

Success Pending order chart

 

Sales Chart

Welcome, This post will help you to make a chart for Success Pending order count datewise. This Sales chart shows the business summary of a month date-wise in just a glimpse. It takes a few seconds the get an idea of the whole month's business, It is a better choice to written  business summary. 


Developer Information


Language        : C#
Framework     : MVC ASP.Net 
Database         : SQL Server
Inline              : HTML,CSS,Java script
Chart               : Google Chart
Application     : Show Success-Pending order datewise for a current month

Database Table



 Let's get Start


At the beginning I thought it was a simple task but when I dived into dept, I found it a complicated task because success and pedning order is detected by the status field from the database. 1 indicates success, 0 indicates pending. The main problem was counting separately success,pending on the same date


Google Chart

I have used google chart for render chart. Chart data is three column format given below. First parameter is date,second , third for show chart lines for show pending or success order .

data.addRows([
 [1, 0, 0],
 [2, 2, 0],
 [3, 0, 3],
 [4, 18, 10]
]);


Requirement

As you see in the above chart data format, it is divided into three parts. The main challenge is to get pending and success counts datewise. I will show you the query step by step because to explanation of the entire query will be difficult to understand. Each sub-query will render output for the next query.

1. Get the pending and success order list of the current month datewise. Pending-Success valie save in status filed. 1 for success and 0 for pending.

with str1 as
(

select day(orderdate) as day,case when status=then  sum(status) end as success,case when status=0 then count(status) end as pending   from [Order]

group  by (OrderDate),status having  month(OrderDate)=month(getdate())

 select * from str1

I have saved query in   CTE to output in str1 variable, which will be used output for next query.





Now we have the list of success and pending order list datewise. We have to combine this in a single row for datewise.


2. Now it is time to sum the pending and success order datewise by combining the above query output to other CTE variable str2


 with str1 as

(

select day(orderdate) as day,case when status=then  sum(status) end as success,case when status=0 then count(status) end as pending   from [Order]
group  by (OrderDate),status
having  month(OrderDate)=month(getdate())
 ),
 str2 as
 (

   select day,sum(success) as success,count(pending) as pending from str1 group by day,success,pending
) select * from str2

 


3. We got a list of success-pending order sum in above list. Now, it's time to remove NULL column and merge row into a single row by the query given below.

with str1 as
(
select day(orderdate) as day,case when status=then  sum(status) end as success,case when status=0 then count(status) end as pending   from [Order]

group  by (OrderDate),status
 having  month(OrderDate)=month(getdate())
 ),
 str2 as
 (
   select day,sum(success) as success,count(pending) as pending from str1 group by day,success,pending

  )
 select day,max(success) s,max(pending) as p from (
  select day,isnull(success,'') as success,isnull(pending,'') as pending from str2 group by day,success,pending) tbl
  group by day



Next Topic

Friday 22 September 2023

Cart Management | C# ASP.Net MVC

 




Cart Management | C# ASP.Net MVC

cart management is the most important part of the E-commerce website design. There are many ways to achieve it but Session is one of the simplest method. This post help you to learn, How to implement a shopping cart using  Session  in C# ASP.Net MVC Pattern from scratch. 





Monday 21 August 2023

CaptchaMvc Mvc5 | C# ASP.Net

 CaptchaMvc Mvc5 Using C# ASP.Net Visual Studio 2019



CAPTCHA stands for "Completely Automated Public Turing test to tell Computers and Humans Apart". It is a test used to distinguish between humans and computers. CAPTCHAs are often used to prevent automated spam and abuse.

Thursday 15 December 2022

FormsAuthentication C# ASP.NET MVC

 


FormsAuthentication

FormsAuthentication class from System.Web.Security is used to authenticate a user whether login or not. FormsAuthentication class has many functions to check the user login and it's very easy to implement. Follow the code given below

Views

<h2>Login</h2>

<form method="post">

    <input type="text" name="UserName" placeholder="User Name"  required /><br /><br />

    <input type="password" name="Password" placeholder="Password" required /><br /><br />

    <input type="submit" value="Login" />

    @if (Request.QueryString["msg"] != null)

    {

        <br /><br />

        <span style="color:red">@Request.QueryString["msg"]</span>

    }

</form>

Thursday 10 November 2022

Make PDF from hyperlink | ASP.NET C#


 This post will help you to create a PDF file from a URL in ASP.Net C#. Follow the steps given below. We will save a PDF file on the server then after viewing the PDF file, the file will be deleted. 

Step 1 : 

Download Select.HtmlToPdf.NetCore package from NuGet. 

Goto Tools Menu>Nuget Package Manager > Manage Nuget Package for Solution

Step 2 : 

 
 Create a Button and call the javascript function, which will create a PDF file from the given URL. The passing argument is URL of the page. Which will be converted into PDF file on the server at the given path. Then you can download the file.

<input type="button" value="Get PDF" onclick="createPDF('https://girfa.co.in/')" />

Step 3 


Javascript Code

function createPDF(pageurl)
 {

         $.ajax({

                url: '/Common/htmltopdf/',
                async: true,
                dataType: "json",
                type: "GET",
                contentType: 'application/json; charset=utf-8',       

                data: { url: pageurl},

                success: function (data) {              

                    DelPDF('/upload/print/' + $.trim(invid) + '.pdf');                   

                    window.location.href = '/upload/print/' + $.trim(invid) + '.pdf';                          

                }

            });          

        }

 

function DelPDF(path) 
{          

            $.ajax({

                url: '/Common/DeleteCommonFile?path=' + path,

                type: "POST",

                contentType: false, // Not to set any content header

                processData: false, // Not to process data           

                 success: function (result) {

                    //Update Extension
                    if (result.sMessage == "1")
                    {
   

                    }
                    else
                        alert(result.sMessage);

                },
                error: function (abc) {
                    alert(abc.statusText); 

                }

            });

}

Step 4

Controller C# code

public JsonResult htmltopdf(string url,string inv)

        {

            // instantiate a html to pdf converter object

            HtmlToPdf converter = new HtmlToPdf(); 

            // create a new pdf document converting an url
            PdfDocument doc = converter.ConvertUrl(url); 

            // save pdf document

            doc.Save(Server.MapPath("~/upload/print/" + inv + ".pdf")); 

            // close pdf document

            doc.Close();

            return Json(new { sMessage = "11"}, JsonRequestBehavior.AllowGet); 

        }

 

[HttpPost]

        public JsonResult DeleteCommonFile(string path)
        {

            try
            {

                string filename = Server.MapPath(path);
                if (System.IO.File.Exists(filename))
                {

                    System.IO.File.Delete(filename);

                } 

                return Json(new { sMessage = "1", JsonRequestBehavior.AllowGet });

            }

            catch (Exception ex)
            {

                return Json(new { sMessage = ex.Message, JsonRequestBehavior.AllowGet });

            }

        }


Monday 12 September 2022

Aggregate Function Entity Framework C#

 Sum 

Get Sum of amount by a select filter using C# MVC Entity Framework


First Method

 dbConnection db = new dbConnection();
 int InvoiceAmount = db.Bill.Where(x => x.CID == 123).Select(i => i.Amount).Sum();


Second Method


data.Where(x => x.msg == "paid").Sum(y => Convert.ToInt32(y.Amount));


Next Topic

Monday 11 July 2022

Google Recaptcha Integration | PHP , ASP.NET C# , Codeiginater 4

 




Monday 23 May 2022

Multiple Condition Entity framework toList Method | ASP.Net C# MVC

Hi, This post will show you, How to apply multiple or complicated condition with Entity framwork dbContext toList method using the where clause. If you are coming first time to this post, please read my post for Entity Framework Introduction. Example of this post-based Entity Framework Introduction. 

Friday 20 May 2022

Introduction Entity Framework for Begina record display | ASP.NET MVC C#

Entity Framework (EF)

Entity Framework (EF) is developed by Microsoft which automates the database insert,Update,select and delete (CRUD) operations without manually coding. ER increase the development time because database-related task is done without long code. 

This post will help you understand ER operation. This post is designed for beginners as well as experts both. Step by step instruction is given to display records from SQL Server. 

Saturday 26 February 2022

Force to Refresh Javascript and CSS files on page load

 To force Javascript and CSS files on every time while page load is good practice when working on live operation because when you made any change in CSS and Javascript files then updated content reflects when cntl + f5 pressed otherwise system get file from cash to save to reload time. Given code below help you to force reload file on every page load in C# ASP.Net MVC.


@{
    Random ob = new Random();
    int ran = ob.Next();
}

<script src="~/AppJs/product.js?v=@ran"></script>
<link href="~/AppCss/gcss.css?v=@ran" rel="stylesheet" type="text/css">

Thursday 13 January 2022

Multiple file upload by form post ASP.NET C# MVC


Multiple file upload by form post ASP.NET C# MVC


This post will let you upload multiple image files through a single form post using the C# ASP.Net MVC platform.

Key Point

  • Upload multiple image files with a new name
  • Save a associate record and file name will be newly created record identity field value
  • No need to save the image name in the database because the file name will start with a record ID and end with a text. 
  • Best for putting student, employee documents without any hassle. 

HTML Code : 

<form method="post" enctype="multipart/form-data">

     @Html.AntiForgeryToken()

    <p class="m-0">

        Photo

        <input type="file" name="Photo" id="Photo" accept="image/x-png,image/jpeg" />

        <br />

        Adhaar

        <input type="file" name="Adhaar" id="Adhaar" accept="image/x-png,image/jpeg" />

        <br />

        Pan

        <input type="file" name="Pan" id="Pan" accept="image/x-png,image/jpeg" />

        <br />

        <input type="checkbox" id="chkconfirm" /> I provide my consent. I will follow the Tangentweb term condition and policy.

        <br /> <br />

        <input type="submit" value="Save" class="button button-primary button-wide-mobile" onclick="return filecheck()" />

    </p> 

</form>