วันอังคารที่ 5 มีนาคม พ.ศ. 2556

update1


<?php

require('config.php');
$myConn = mysql_connect($hostname_library, $username_library, $password_library) or die(mysql_error());
mysql_select_db($database_library,$mycon);
$pass=$_POST["txtStreet"];
$name = $_POST["txtname"];
$gender = $_POST["selCity"];

//header('Location: list.php');

echo "<br />"."customer_name :".$name;
echo "<br />"."customer_name :".$pass;
echo "<br />"."customer_name :".$gender;

$update = mysql_query("update user set password = '".$_POST["txtStreet"]."' , gender = '".$_POST["selCity"]."' where username = '".$_POST["txtname"]."' ");

?>

<script type="text/javascript">
window.location = "index.php"
</script>

update


<?
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Update</title>
</head>

<body>

<p>
<?php
require('config.php');
$myConn = mysql_connect($hostname_library, $username_library, $password_library) or die(mysql_error());
mysql_select_db($database_library,$mycon);


$update = mysql_query("update user set password = '$street_conf' where username ='".$_GET['name']." ");
?>
</p>


<form id="form1" name="form1" method="post" action="update1.php">
<?php
$nameup = $_GET['name'] ;
?>
<table width="399" border="0">
<tr>
<td width="97" bgcolor="#FF9900">Username</td>
<td width="286" bgcolor="#FFCC66"><input type="hidden" name= "txtname" value="<?php echo $_GET['name'] ?>"><?php echo $_GET['name'] ?>
        </td>
  </tr>
<tr>
<td bgcolor="#FF9900">Password</td>
<td bgcolor="#FFCC66"><input name="txtStreet" type="text" id="txtStreet" value="<? echo $result['password'];?>" />
        </td>
</tr>
  <tr>
<td bgcolor="#FF9900">Gender</td>
<td bgcolor="#FFCC66">

<select name="selCity">
<?
require('config.php');
$myConn = mysql_connect($hostname_library, $username_library, $password_library) or die(mysql_error());
mysql_select_db($database_library);
if (!$myConn)die('Could not connectooo:' . mysql_error());

$query= "SELECT distinct(gender) FROM user";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
?>
<option value = "<? echo $row['gender'];?>" <? if($row[ 'gender']==$city){ echo "selected"; } ?> > <? echo $row['gender'];?>
    </option>
<?

}

echo $result;
mysql_free_result($result); // เมื่อ process เสร็จแล้วให้ free result set ด้วย
mysql_close($mycon); // ปิด connection กับ MySQL Server
?>
</select>

</form>
<input type="submit" name="submit" id="submit" value="Update" />
</td>
<a href="index.php"><input type="button" name="button" id="button" value="Back" /></a>

</tr>
</form>
</body>
</html>

insert.php


<?
session_start();
?>
<form name="form1" method="post" >
  <table width="258" border="0">
    <tr>
      <td width="101" bgcolor="#FF9900">Username :</td>
      <td width="147" bgcolor="#FFCC66">
      <input name="username" type="text">
      </td>
    </tr>
    <tr>
      <td  bgcolor="#FF9900">Password :</td>
      <td bgcolor="#FFCC66">
      <input type="password" name="password">
      </td>
    </tr>
    <tr>
    <td bgcolor="#FF9900">(ยืนยัน) password :</td>
    <td bgcolor="#FFCC66"><input type="password" name="re_password" /></td>
  </tr>
    <tr>
    <td  bgcolor="#FF9900">เพศ :</td>
    <td bgcolor="#FFCC66"><select name="gender" id="gender">
      <option value="male">ชาย</option>
      <option value="femal">หญิง</option>
    </select></td>
    </tr>
  </table>
  <p>
    <input type="submit" name="submit" id="button" value="Submit">
    <input type="reset" name="button2" id="button2" value="Reset">
  </p>
</form>
<a href="index.php"><input type="button" name="button" id="button" value="Back" /></a>
<?
require('config.php');
echo $_POST['username']."<br />";
echo $_POST['password']."<br />";
echo $_POST['gender']."<br />";
//กด submit
if(isset($_POST['submit'])){
$hve = mysql_query("select* from user where username ='".$_POST['password']."'");
$user_in_DB = mysql_fetch_array($hve);
echo $user_in_DB['username'];
//ถ้าทุกช่องว่าง
if(empty($_POST['username'])|empty($_POST['password'])|empty($_POST['re_password'])|empty($_POST['gender']))
{
?>
        <script>
alert ('ท่่านกรอกข้อมูลไม่ครบ');
window.location ="insert.php";
</script>
<?
}//ถ้าไม่ว่าง
else {
if(empty($user_in_DB))
{//ถ้า password เหมือนกัน
if($_POST['password']==$_POST['re_password'])
{
echo "complete";
mysql_query("insert into user (username,password,gender) values('".$_POST['username']."','".$_POST['password']."','".$_POST['gender']."')");
?>
        <script>
alert ('สมัครเสมาชิครียบร้อยแล้ว');
window.location ="index.php";
</script>
<?
}//ถ้าไม่เหมือน
else{
?>
        <script>
alert ('รหัสผ่านไม่ตรงกัน');
window.location ="insert.php";
</script>
        <?
}
}//ถ้ามีชื่อนี้อยู่แล้ว
else{
?>
        <script>
alert ('username นี้มีผู้ใช้งานแล้ว');
window.location ="insert.php";
</script>
      <?
}}}
?>




index.php


<?
session_start();
?>
<?
include("config.php");
$query = "SELECT * FROM user" ;
$result = mysql_query($query,$mycon);
///order by----------------------------------------------------------------
if($count_click1 =$_GET['count1'])
{
///order by customer_name
if ($count_click1%2 == 0)
{$query = "select * from user  order by username " ;}
else
{$query = "select * from user  order by username  DESC";}
}
else if($count_click2 =$_GET['count2'])
{///order by customer_street
if ($count_click2%2 == 0)
{$query = "select * from user order by password " ;}
else
{$query = "select * from user order by password  DESC";}
}
else if($count_click3 =$_GET['count3'])
{///order by customer_city
if ($count_click3%2 == 0)
{$query = "select * from user order by gender " ;}
else
{$query = "select * from user order by gender  DESC";}
}
///delete row
if(isset($_POST['submit']))
{
foreach($_POST['chk']as $name)
{$query = "DELETE FROM user WHERE username = '".$name."'";
  mysql_query($query,$mycon);
}
}
///search word customer_name
$name = $_POST['Search'];
if(isset($_POST['Search-bt'])){
$query = "SELECT * FROM user WHERE username like '$name%' ";
$result = mysql_query($query,$mycon);
}
else $result = mysql_query($query,$mycon);
//search customer_city by list
$gender = $_POST['gender_list'];
if(isset($_POST['Search-2']))
{
    if($gender == 'All'){
$gender = $_POST['gender_list'];
$query = "SELECT * FROM user" ;
}else {
$gender = $_POST['gender_list'];
$query = "SELECT * FROM user where gender = '$gender' ";
}
$result = mysql_query($query,$mycon);
}
?>
<form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <p>
    <input type="text" name="Search" id="Search" />
    <input type="submit" name="Search-bt" id="Search-bt" value="Search_name" title="ค้นหาชื่อลูกค้า" />
  </p>
  <p>
    <label for="gender_list"></label>
    <select name="gender_list" >
     <option value="All">All</option>
      <option value="femal">หญิง</option>
      <option value="male">ชาย</option>
    </select>
    <input type="submit" name="Search-2" id="Search" value="Select_gender">
  </p>
  <table width="458" border="0">
 <tr>
 <td width="22" bgcolor="#FF9900">&nbsp;</td>
 <td width="26" bgcolor="#FF9900"><strong>Edit</strong></td>
 <td width="115" bgcolor="#FF9900" title="username"><strong><a href=index.php?count1=<?=$count_click1+1?>>Username</a></strong></td>
 <td width="111" bgcolor="#FF9900" title="password"><strong><a href=index.php?count2=<?=$count_click2+1?>>Password</a></strong></td>
 <td width="105" bgcolor="#FF9900" title="gender"><strong><a href=index.php?count3=<?=$count_click3+1?>>Gender</a></strong></td>
 </tr>
 <?
 while($row = mysql_fetch_array($result))
 {
 ?>
 <tr bgcolor="#FFCC66">
 <td><input type="checkbox" name="chk[]" id="chk[]" title="คลิกเลือก"value="<?php echo $row['username'];?>" /></td>
 <td><a href ="update.php?name=<?php echo $row['username'];?>">
   <img src="img/b_edit.png" width="16" height="16" alt="Edit" title="แก้ไข" /></a></td>

 <td><?php echo $row['username'];?></td>
 <td><?php echo $row['password'];?></td>
 <td><?php echo $row['gender'];?></td>
 </tr>
 <?
 }
mysql_close($mycon);
 ?>
 </table>
  <p>
    <input type="submit" name="submit" id="submit" value="Delete" title="ลบ"/>
    <input type="reset" name="reset" id="reset" value="Reset" title="ยกเลิก" />
  </p>
 
</form>
<p><a href="insert.php">ลงทะเบียน</a></p>
<form enctype="multipart/form-data"  id="form1" name="form1" method="post" action="upload.php" >
<input type="file" name="imagefile" />
<input type="submit" name="submit" value="submit" />
</form>

config.php

วันอาทิตย์ที่ 11 มีนาคม พ.ศ. 2555

mypg


package mypg;

import java.util.*;

public class Geometric {
private String color = "white";
private Date dateCreated;
public Geometric()
{
dateCreated = new Date();

}
public Geometric (String color)
{
this.color = color;
}
public void setColor(String color)
{
this.color = color;
}
public String getColor()
{
return this.color;
}
public Date getDate()
{
return dateCreated;
}
}
+++++++++++++++++++++++++++++++
package mypg;

public class Circle extends Geometric{
private double radius;

public Circle (double radius)
{
this.radius = radius;

}
public Circle(double radius,String color)
{
this.radius = radius;
setColor(color);
}
public double getArea()
{
return radius * radius * Math.PI;
}
}
+++++++++++++++++++++++++++++++++
package mypg;

public class Test {

public static void main(String[] args) {
Geometric geo1 = new Geometric();
System.out.println(geo1.getColor()+" ; "+geo1.getDate());
Circle cir1 = new Circle(4);
cir1.setColor("red");
System.out.println(cir1.getColor()+ " ; " +cir1.getDate() + " ; " +cir1.getArea());

}

}


Polymorphism


nแปลว่า หลายรูปทรง แปลงสภาพได้
Example
class CustomerData{
   protected void CustomerPhone(){
        System.out.println(“02 123 456”);
   {
   protect void ClearAll(){
        System.out.println(“Delete All Data”);
   }
}
+++++++++++++++++++++++++++++++++++++++++ๅๅๅๅ
เวลาเรียกใช้
class CustomerData2 extends CustomerData {
   protected void CustomerPhone(){
         super.CustomerPhone();
         System.out.println(“02 123 456 7”);
   {
   protect void ClearAll(){
   }
}


Inheritance


nแปลว่า การสืบสันดาน หรือ การสืบมรดก
nต่อยอดงานใหม่ จากงานเก่าไม่ต้องเริ่มจากศูนย์
nภาษา OOP สนับสนุน Inheritance เสมอ
Example
class Foo{
   public void WriteFoo(){
      System.out.println(“Foo”);
   }
}

class Bar extends Foo{
   public void WriteBar(){
      System.out.println(“Bar”);
   }
}

+++++++++++++++++++++++++++++++++++++++++ๅ
เวลาเรียกใช้
class Program{
   public static void main (String[] args){
      Bar myBar = new Bar();
      myBar.WriteFoo();
      myBar.WriteBar();
   }



Overloaded Constructor


nเป็นคอนสตรัคเตอร์กำหนดเอง
nคอนสตรัคเตอร์ทุกตัวชื่อเหมือนกับคลาส
nทำการรับพารามิเตอร์ไม่เหมือนกัน

class Calculator{
  Calculator(int x){
  return x + x;}
   Calculator(int x, int y){
  return x + y;}  
   Calculator(int x, int y, int z){
  return x + y + z;}
}

เวลาเรียกใช้คอนสตรัคเตอร์
class TestCalculator{
  public static void main(String[] args) {
  Calculator a = new Calculator();
  System.out.println(a.Calculator(1));
 
  Calculator b = new Calculator();  
  System.out.println(b.Calculator(1, 2));
  Calculator c = new Calculator();
  System.out.println(c.Calculator(1, 2, 3));
  }
}


โอเวอร์โหลดเมธอด


public class TestOver1 {
  public static int add() {
  return 0;       }
  public static int add(int x) {
  return x;      }
  public static int add(int x, int y)   {
  return x+y;               }
  public static int add(int x, int y, int z) {
  return x+y+z;                      }


เวลาเรียกใช้เมธอด
  public static void main(String[] args)                   
{
  System.out.println("Sum = "+add());
  System.out.println("Sum = "+add(3));
  System.out.println("Sum = "+add(1,2));
  System.out.println("Sum = "+add(1,2,3)); }
}
Test_java2

วันจันทร์ที่ 6 กุมภาพันธ์ พ.ศ. 2555

TV

package
java_1;


public
class TV {

private int chanel = 1;//1-10

private int volume = 1;//0-5

private boolean status = false;// By default TV is off

private String brand = "";

public static int count = 0;


TV(){

count++;

brand = "Sony";

}

TV(String newBrand){

count++;

brand = newBrand;

}

TV(String newBrand,
int newchanel){

count++;

brand = newBrand;

chanel = newchanel;

}

public String getBrand(){

return brand;

}

public void turnOn(){

//Mutator of status variable

status = true;

}

public void turnOff(){

//Mutator of status variable

status = false;

}

public boolean getStatus(){

//Accessor of status variable

return status;

}

public void chanelUp(){

chanel++;

if(chanel > 10){

chanel = 1;


}

}

public void chanelDown(){

chanel--;

if(chanel < 1){

chanel = 10;

}

}

public int getChanel(){

if(status == false)

{

System.
out.println("Please TurnOn TV");

return 0;

}

else

return chanel;

}

public void volumeUp(){

if(volume < 5)

volume++;

else

System.
out.println("Maximum");

}

public void volumeDown(){

if(volume > 0)

volume--;

else

System.
out.println("Minimum");


}

public int getVolume(){

return volume;

}

public boolean equalsTV(TV o){

if(o.getChanel() != this.getChanel())

return false;

if(o.getStatus() != this.getStatus())

return false;

if(o.getVolume() != this.getVolume())

return false;

return true;

}


}

Test TV

package
java_1;
import
java.util.ArrayList;
public
class Test {
public static void main(String[] args) {
TV tv1 =
new TV();
System.
out.println("******TV 1*******");
tv1.turnOn();
//turnOn TV
System.
out.println(tv1.getBrand());
System.
out.println(tv1.getChanel());
tv1.chanelDown();
System.
out.println(tv1.getChanel());
tv1.volumeDown();
tv1.volumeDown();
System.
out.println(tv1.getVolume());
tv1.volumeUp();
tv1.volumeUp();
tv1.volumeUp();
tv1.volumeUp();
tv1.volumeUp();
tv1.volumeUp();
System.
out.println(tv1.getVolume());
TV tv2 =
new TV("Sumsung",10);
System.
out.println("******TV 2*******");
tv2.turnOn();
//turnOn TV
System.
out.println(tv2.getBrand());
System.
out.println(tv2.getChanel());
tv2.chanelUp();
System.
out.println(tv2.getChanel());
////// ArrayList ////
ArrayList<TV> listTV =
new ArrayList<TV>();
listTV.add(
new TV());
listTV.add(
new TV("PHILIPS"));
listTV.add(
new TV("SAMSUNG"));
listTV.add(
new TV("PANASONIC"));
System.
out.println("ArraySize:"+listTV.size());
System.
out.println(listTV.get(0).getBrand());
System.
out.println(listTV.get(1).getBrand());
System.
out.println(listTV.get(2).getBrand());
System.
out.println(listTV.get(3).getBrand());
////// Array /////
/*
TV[] arrayTV = new TV[5];
for(int i = 0; i < 5; i++)
{
arrayTV[i] = new TV();
}
System.out.println("Count TV:"+TV.count);
System.out.println(arrayTV[0].getBrand());
System.out.println("Brand:"+arrayTV[0].getBrand());
*/
///// check equals /////
/*tv1.turnOn();
tv1.turnOn();
if(tv1.equalsTV(tv2)==true){
System.out.println("Equal");
}else{
System.out.println("Not equal");
}
tv2.chanelDown();
if(tv1.equalsTV(tv2)==true){
System.out.println("Equal");
}else{
System.out.println("Not equal");
}*/
}
}