Monday 23 July 2018

hr management system part 6 asp net How to Upload and Change Profile Pic...



   public string file_upload(FileUpload fileupload)

        {

            string msg = "-1";



            if (fileupload.HasFile)

            {



                string fileextenion = Path.GetExtension(fileupload.FileName);



                if (fileextenion.ToLower() != ".png" && fileextenion.ToLower() != ".jpg")

                {

                    Response.Write("<script>alert('Only images are allowed to upload , please select jpg or png image.... '); </script> ");

                }

                else

                {

                    int filesize = fileupload.PostedFile.ContentLength;



                    if (filesize > 2097152) //cannot upload > 2 mb image......

                    {

                        Response.Write("<script>alert('Only images are allowed to upload that are size of less than 2 MB  '); </script> ");

                    }

                    else

                    {

                        Random r = new Random();

                        int r1 = r.Next();

                        int r2 = r.Next();

                        msg = "~/Content/Uploads/" + r1 + r2 + fileupload.FileName;

                        fileupload.SaveAs(Server.MapPath(msg));

                    }







                }









            }

            else

            {

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



            }



            return msg;





        }


Thursday 12 July 2018

Select ,Any and All operator in Linq C#





using ConsoleApplication3.Model;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication3

{

    class Program

    {

        static void Main(string[] args)

        {





            List<Employee> li = new List<Employee>()

        {

            new Employee{id=1,name="Ali",salary=50000},

           new Employee{id=2,name="Ahmed",salary=30000},

          new Employee{id=3,name="Ahsan",salary=50000},

          new Employee{id=4,name="Asim",salary=40000},

          new Employee{id=5,name="Asad",salary=10000},





        };



        //  var  list = li.Select(x => new { ID = x.id, Name = x.name });

            //var list = li.ToList();







            //foreach (var item in list)

            //{

            //    Console.WriteLine("ID: " + item.id + "\nName" + item.name);

            //}



            //bool a = li.All(x => x.salary >= 10000);

            bool b = li.Any(x => x.salary > 30000);



            Console.WriteLine(b);







       

        }

    }

}

-----------------------------------------------------------------------------------------------
 class Employee
    {
        public int id { get; set; }
        public string name { get; set; }
        public int salary { get; set; }


    }

Wednesday 11 July 2018

Join Query in Linq C#





using ConsoleApplication2.Model;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication2

{

    class Program

    {

        static void Main(string[] args)

        {

            List<department> deplist = new List<department>

            {

                new department{deptid=1, deptname="HR"},

                new department{deptid=2, deptname="Marketing"},

                new department{deptid=3, deptname="IT"},

                new department{deptid=4, deptname="Accounts"},



            };



            List<Employee> emplist = new List<Employee>

            {

                new Employee{empid=101,name="ali",deptfkid=1},

                new Employee{empid=102,name="ahmed",deptfkid=2},

               new Employee{empid=103,name="ahsan",deptfkid=1},

               new Employee{empid=104,name="bilal",deptfkid=3},

               new Employee{empid=105,name="zahid",deptfkid=1},

                new Employee{empid=106,name="fahad",deptfkid=2},







            };





            var joinlist = emplist.Join(deplist, emp => emp.deptfkid, dep => dep.deptid, (emp, dep) => new

            {

                empid=emp.empid,

                name=emp.name,

                deptname=dep.deptname

           

            });



           



            foreach (var item in joinlist)

            {

                Console.WriteLine("-------------------");



                Console.WriteLine("id: "+item.empid);

                Console.WriteLine("Name: " + item.name);

                Console.WriteLine("Department: " + item.deptname);



                Console.WriteLine("-------------------");



            }



            Console.ReadKey();





        }

    }

}

----------------------------------------------------------------------------------------------------
 class department
    {
        public int deptid { get; set; }
        public string deptname { get; set; }

    }
-----------------------------------------------------------------------------------------------
 class Employee
    {

        public int  empid { get; set; }
        public string name { get; set; }
        public int deptfkid { get; set; }
    }

Monday 9 July 2018

HR Management system part 2









click here to download source code

Group By and ToLookup in Linq C#





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication1

{

    class student

    {

        public int studentID { get; set; }

        public string studentName { get; set; }

        public int Age { get; set; }

    }

    class Program

    {

        static void Main(string[] args)

        {

            List<student> li = new List<student>()

          {



             new student() { studentID = 5, studentName = "Ron" , Age = 21 },

            new student() { studentID = 6, studentName = "Chris",  Age = 18 },

             new student() { studentID = 7, studentName = "Rob",Age = 19  },

            new student() { studentID = 8, studentName = "Rob",Age = 21  },

            new student() { studentID = 1, studentName = "John", Age = 18 },

            new student() { studentID = 2, studentName = "Steve",  Age = 21 },

            new student() { studentID = 3, studentName = "Bill",  Age = 25 },

            new student() { studentID = 4, studentName = "Ram" , Age = 19 },

            new student() { studentID = 9, studentName = "Bill",Age = 19  },



        };



           // var agegroup = li.GroupBy(x => x.Age).ToList();

            var agegroup = li.ToLookup(x => x.Age).ToList();

            foreach (var group in agegroup)

            {

                Console.ForegroundColor = System.ConsoleColor.Green;



                Console.WriteLine("====AGE:"+group.Key+"====");

                Console.ForegroundColor = System.ConsoleColor.Red;



                foreach (var item  in group)

                {

                    Console.WriteLine(item.studentName);

                }

               

            }





     





        }

    }

}


Order by, Order by Descending, then by and then by Descending in linq c#



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            List<student> li = new List<student>()

          {



             new student() { studentID = 5, studentName = "Ron" , Age = 31 },

            new student() { studentID = 6, studentName = "Chris",  Age = 17 },

             new student() { studentID = 7, studentName = "Rob",Age = 19  },

            new student() { studentID = 8, studentName = "Rob",Age = 21  },

            new student() { studentID = 1, studentName = "John", Age = 18 },

            new student() { studentID = 2, studentName = "Steve",  Age = 21 },

            new student() { studentID = 3, studentName = "Bill",  Age = 25 },

            new student() { studentID = 4, studentName = "Ram" , Age = 20 },

         

            new student() { studentID = 9, studentName = "Bill",Age = 19  },



        };



           // var list = li.OrderBy(x => x.studentID).ToList();

          //  var list = li.OrderByDescending(x => x.studentName).ToList();

          //  var list = li.OrderByDescending(x => x.studentName).ThenBy(x=>x.Age).ToList();

            var list = li.OrderByDescending(x => x.studentName).ThenByDescending(x=>x.Age).ToList();

            foreach (var item in list)

            {

                Console.WriteLine("id: "+item.studentID+"---Name: "+item.studentName+"---age:"+item.Age);

            }



     





        }

    }

}

--------------------------------------------------------------------------------------------------------------
 public int studentID { get; set; }
        public string studentName { get; set; }
        public int Age { get; set; }

Sunday 8 July 2018

Introduction to Linq query in C#



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            List<student> li = new List<student>()

          {



            new student() { studentID = 1, studentName = "John", Age = 18 },

            new student() { studentID = 2, studentName = "Steve",  Age = 21 },

            new student() { studentID = 3, studentName = "Bill",  Age = 25 },

            new student() { studentID = 4, studentName = "Ram" , Age = 20 },

            new student() { studentID = 5, studentName = "Ron" , Age = 31 },

            new student() { studentID = 6, studentName = "Chris",  Age = 17 },

            new student() { studentID = 7, studentName = "Rob",Age = 19  },

        };





            List<student> teenagerlist = li.Where(x => x.Age > 12 && x.Age < 20).ToList();

            Console.WriteLine("Teenager students: ");

            foreach (student item in teenagerlist)

            {

                Console.WriteLine("Name: "+item.studentName);

            }





        }

    }

}

----------------------------------------------------------------------------------------------------------------
class student
    {
        public int studentID { get; set; }
        public string studentName { get; set; }
        public int Age { get; set; }
    }

Friday 6 July 2018

HR Management system ASP.NET C# PART-1









click here to download the source code

insert data using Entity Framewrok database 1st Approach in windows from





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 WindowsFormsApplication9.Model;



namespace WindowsFormsApplication9

{

    public partial class Form1 : Form

    {

        db1708c1Entities db = new db1708c1Entities();

        tbl_student s = new tbl_student();

        public Form1()

        {

            InitializeComponent();

        }



        private void button2_Click(object sender, EventArgs e)

        {

           

            s.name = textBox1.Text;

            s.dob = dateTimePicker1.Value;

            s.contatct = textBox2.Text;

            if (s.C_image==null)

            {

                s.C_image = @"C:\images\unknown.png";

            }

            db.tbl_student.Add(s);

            db.SaveChanges();

            MessageBox.Show("Data successfully inserted......");

            dataGridView1.DataSource = db.tbl_student.ToList();

        }



        private void Form1_Load(object sender, EventArgs e)

        {

            dataGridView1.DataSource = db.tbl_student.ToList();

        }



        private void button1_Click(object sender, EventArgs e)

        {

            OpenFileDialog op = new OpenFileDialog();

            op.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";

            if (op.ShowDialog() == DialogResult.OK)

            {

                pictureBox1.Image = new Bitmap(op.FileName);

                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;

                s.C_image = op.FileName;

               

            }

        }

    }

}


How to delete data from sql server using Windwos form c#



Click here to download the source code

Sunday 1 July 2018

How to Make search Filter in Visual C# WINDOWS FORM





click here to download the source code

How to Upload image in PHP







<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>File Upload</title>

</head>



<body>



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

<table> <tr> <td><input type="file" name="image"/> </td> <td> <button name="btn">Upload  </button> </td> </tr> </table>

</form>



<?php

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

{

if(isset($_FILES['image']))

{



//FILENAME ,FILESIZE, FILETYPE,FILEEXTENSION...........



  //-------------------------------------------------------------------------------

 

      $errors;

//  $file_name=$file_size=$file_type="";

      $file_name = $_FILES['image']['name'];

      $file_size =$_FILES['image']['size'];

      $file_tmp =$_FILES['image']['tmp_name'];

      $file_type=$_FILES['image']['type'];

      $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));

  //-------------------------------------------------------------------------------

  $extensions= array("jpeg","jpg","png");

 

   if(in_array($file_ext,$extensions)=== false)  // values are equal so return true

  {

         $errors="extension not allowed, please choose a JPEG or PNG file.";

      }

  else

  {

     if($file_size > 2097152)

     {

       $errors='File size must be excately 2 MB or lesser...';

     }

else

{

$rand=rand();

move_uploaded_file($file_tmp,"uploads/".$rand.$file_name);

}

 

 }





 if(empty($errors))

 {

echo "<p style='color:green'> File Uploaded...</p>";

 }

 else

{

echo "<p style='color:red'> File not Uploaded...</p>";



}







 



}//IF FILE CONTAINS.................



else

{

echo "<p style='color:red'> plz select a FILE.....</p>";

}



}







?>



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