Wednesday, 24 October 2018

Upload and Save Image in database , asp net mvc 5



public string uploadimage(HttpPostedFileBase file)

        {

            Random r = new Random();

            string path = "-1";

            int random = r.Next();

            if (file != null && file.ContentLength > 0)

            {

                string extension = Path.GetExtension(file.FileName);

                if (extension.ToLower().Equals(".jpg") || extension.ToLower().Equals(".jpeg") || extension.ToLower().Equals(".png"))

                {

                    try

                    {



                        path = Path.Combine(Server.MapPath("~/Content/upload"), random + Path.GetFileName(file.FileName));

                        file.SaveAs(path);

                        path = "~/Content/upload/" + random + Path.GetFileName(file.FileName);



                        //    ViewBag.Message = "File uploaded successfully";

                    }

                    catch (Exception ex)

                    {

                        path = "-1";

                    }

                }

                else

                {

                    Response.Write("<script>alert('Only jpg ,jpeg or png formats are acceptable....'); </script>");

                }

            }



            else

            {

                Response.Write("<script>alert('Please select a file'); </script>");

                path = "-1";

            }







            return path;

        }


Friday, 19 October 2018

Pagination in asp net mvc





Action code:



public ActionResult Index(int? page)

        {

            int pagesize = 6, pageindex = 1;

            pageindex = page.HasValue ? Convert.ToInt32(page) : 1;

            var list = db.tbl_services.OrderByDescending(x => x.s_id).ToList();

            IPagedList<tbl_services> stu = list.ToPagedList(pageindex, pagesize);



            return View(stu);

        }

View code:

@using PagedList.Mvc

@model  PagedList.IPagedList<WebApplication1.Models.tbl_services>







@{

    ViewBag.Title = "Home Page";

}



<div class="row">



    @foreach (var item in Model)

    {

        <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">

            <img  src="@Url.Content(item.s_img)" style="width:200px; height:200px;"/>

            <h1 style="text-align:center"> @item.s_name</h1>



        </div>



    }

   





</div>

   

    <div>



        <div class="pagination" style="margin-left: 400px">

            Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)

            of @Model.PageCount   @Html.PagedListPager(Model, page => Url.Action("Index", new { page }))

        </div>







    </div>


Wednesday, 17 October 2018

Crystal Report in C# Winforms





create database dbcrytalreport

use dbcrytalreport



create table tbl_employee

(

emp_id int identity primary key,

emp_name nvarchar(20) not null,

emp_salary int not null,

emp_contact nvarchar(20)

)



insert into tbl_employee

values('ali',50000,'03432145678')

insert into tbl_employee

values('ahmed',40000,'03421145678')

insert into tbl_employee

values('bilal',30000,'03412145678')

insert into tbl_employee

values('basit',50000,'03442145678')





select * from tbl_employee

---------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {//Data Source=.;Initial Catalog=dbcrytalreport;User ID=sa;Password=***********
        ReportDocument rd = new ReportDocument(); 
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=dbcrytalreport;User ID=sa;Password=aptech");
            SqlDataAdapter da = new SqlDataAdapter("select * from tbl_employee", conn);
            conn.Open();
            DataSet ds = new DataSet();
            da.Fill(ds,"employee");
            rd.Load(@"C:\Users\salman\documents\visual studio 2013\Projects\WindowsFormsApplication1\WindowsFormsApplication1\CrystalReport1.rpt");
            rd.SetDataSource(ds);
            crystalReportViewer1.ReportSource = rd;


        }
    }
}

--------------------------------------------------------------------------------------------------

Monday, 1 October 2018

CRUD OPERATION IN ASP NET WEB FORM PART 2



create proc sp_getdata
as
begin
select d_name as 'Name',d_contact as 'Contact',d_email as 'Email' from tbl_doctor

end

Click here to download the source code

Friday, 28 September 2018

CRUD OPERATION IN ASP.NET WEB FORM PART 1





use clinicalmanagementsystem

create table tbl_doctor

(

d_id int primary key identity,

d_name nvarchar(50) not null,

d_contact nvarchar(50) not null unique,

d_email nvarchar(50) unique,

d_dateofbirth date



)



create proc sp_insert_doctor

(

@d_name nvarchar(50) ,

@d_contact nvarchar(50) ,

@d_email nvarchar(50) ,

@d_dateofbirth date

)

AS

BEGIN

INSERT INTO tbl_doctor VALUES(

@d_name ,

@d_contact ,

@d_email ,

@d_dateofbirth



)

END





select * from tbl_doctor


CRUD OPERATION IN PHP WITH MYSQLI PART 3









<!doctype html>

<html>

<head>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">



<style type="text/css">



table,th

{

text-align: center;



}

td

{

padding: 10px;

}



</style>



</head>



<body>



<div class="col-lg-12 col-md-12 col-sm-12"  style="height: 200px;">



<form method="post">



<table>



<tr>

<td> Book Name</td>

<td> <input type="text" name="book" class="form-control" placeholder="Book Name"></td>



</tr>





<tr>

<td> Book Price</td>

<td> <input type="text" name="price" class="form-control" placeholder="Book Price"></td>



</tr>





<tr>

<td> <input type="submit" name="btnAdd" class="btn btn-info"> </td>



</tr>





</table>





</form>



</div>











<?php

include 'includes/connection.php';



if (isset($_POST['btnAdd']))

{

$book=$_POST['book'];

$price= $_POST['price'];



$sql      ="INSERT INTO `tbl_book`( `BOOK_NAME`, `BOOK_pirce`) VALUES (?,?)";



$stmt=$conn->prepare($sql);



if (!$stmt)

{

echo "<script>alert('failed to insert data.....'); </script>";

}

else

{

$stmt->bind_param('ss',$book,$price);



$stmt->execute();

$stmt->close();







}





} // button event ends here.........................................................















$sqlquery="SELECT * FROM `tbl_book` ";



if($result=mysqli_query($conn,$sqlquery))

{

echo '<table class="table table-bordered table-responsive table-striped">';

echo "<thead>

<tr>

<th>ID </th>

<th>NAME </th>

<th>PRICE </th>







 </tr>

 </thead> ";



while ($row= mysqli_fetch_assoc($result))

{



echo "<tr> <td>". $row["BOOK_ID"]." </td>  <td>". $row["BOOK_NAME"]."  </td> <td>".$row["BOOK_pirce"]." </td> </tr>";



}

echo "</table>";





 mysqli_free_result($result);





}

else 

{

# code...





}



mysqli_close($conn);



 ?>









</body>





</html>


Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...