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

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 ...