0)
{
// update
$upd = " update BCItemspecification set ";
$upd .= " Spec01 = '".iconv('utf-8','tis-620',$_POST['txtspec1'])."', ";
$upd .= " Spec02 = '".iconv('utf-8','tis-620',$_POST['txtspec2'])."', ";
$upd .= " Spec03 = '".iconv('utf-8','tis-620',$_POST['txtspec3'])."', ";
$upd .= " Spec04 = '".iconv('utf-8','tis-620',$_POST['txtspec4'])."' ";
$upd .= " where ItemCode = '".$_POST['itemcode']."' ";
$obupd = odbc_exec($dbh2, $upd);
}
else
{
//ดึง โกดัง และ หน่วยนับ
$itm = odbc_fetch_array(obc_exec($dbh2,"select DefStkUnitCode as unitcode, DefBuyWHCode as whcode from BCITEM where Code='".$_POST["itemcode"]."' "));
//insert
$ins = "insert into BCItemspecification ";
$ins .= " (ItemCode, Spec01, Spec02, Spec03, Spec04, WHCode, UnitCode) ";
$ins .= " values ";
$ins .= " ('".$_POST['itemcode']."', '".iconv('utf-8','tis-620',$_POST['txtspec1'])."', '".iconv('utf-8','tis-620',$_POST['txtspec2'])."', '".iconv('utf-8','tis-620',$_POST['txtspec3'])."', '".iconv('utf-8','tis-620',$_POST['txtspec4'])."', '".$itm["whcode"]."', '".$_POST["unitcode"]."' ) ";
$obins = odbc_exec($dbh2,$ins);
}
}
else if($_POST['managevalue'] == 21) // เพิ่มรายการสินค้าทดแทน
{
//ตรวจสอบรหัส ว่า มีการป้อนรายการซ้ำกันหรือไม่
$ch = odbc_num_rows(odbc_exec($dbh2, "select * from BCITEMSUBSTITUTE where ItemCode = '".$_POST['itemcode']."' and SUBSTITUTECode = '".$_POST['itemcode_sub']."' "));
if($ch > 0)
{
echo '1' ;
odbc_close($dbh2);
exit();
}
$ins = "insert into BCITEMSUBSTITUTE ";
$ins .= " ( ItemCode, SUBSTITUTECode ) ";
$ins .= " values ";
$ins .= " ( '".$_POST['itemcode']."', '".$_POST['itemcode_sub']."' ) ";
$obins = odbc_exec($dbh2,$ins);
//ตรวจสอบรหัส ว่า มีการป้อนรายการซ้ำกันหรือไม่ สินค้าที่คู่กัน
$ch = odbc_num_rows(odbc_exec($dbh2, "select * from BCITEMSUBSTITUTE where ItemCode = '".$_POST['itemcode_sub']."' and SUBSTITUTECode = '".$_POST['itemcode']."' "));
if($ch == 0)
{
$ins = "insert into BCITEMSUBSTITUTE ";
$ins .= " ( ItemCode, SUBSTITUTECode ) ";
$ins .= " values ";
$ins .= " ( '".$_POST['itemcode_sub']."', '".$_POST['itemcode']."' ) ";
$obins = odbc_exec($dbh2,$ins);
}
echo '2' ;
}
else if($_POST['managevalue'] == 22) // ลบรายการสินค้าทดแทน
{
$del = "delete from BCITEMSUBSTITUTE where Itemcode = '".$_POST['itemcode']."' and SUBSTITUTECode = '".$_POST['itemcode_sub']."' ";
$obdel = odbc_exec($dbh2,$del);
//ลบรายการคู่ไปด้วย
$del2 = "delete from BCITEMSUBSTITUTE where Itemcode = '".$_POST['itemcode_sub']."' and SUBSTITUTECode = '".$_POST['itemcode']."' ";
$obdel2 = odbc_exec($dbh2,$del2);
}
else if($_POST['managevalue'] == 23 ) // ลบรายการสินค้าทดแทน แบบลบทั้งหมด
{
//ดึงข้อมูลสินค้าทดแทนของรหัสนี้
$slc = odbc_exec($dbh2,"select ItemCode, SUBSTITUTECode from BCITEMSUBSTITUTE where ItemCode='".$_POST['itemcode']."' ");
while($sub=odbc_fetch_array($slc))
{
//ลบสินค้าทดแทนที่เป็นสินค้าที่จับคู่กับสินค้าที่ต้องการลบ
$del = odbc_exec($dbh2,"delete from BCITEMSUBSTITUTE where ItemCode='".$sub['SUBSTITUTECode']."' and SUBSTITUTECode='".$_POST['itemcode']."' ");
}
//ลบสินค้าทั้งหมด
$del2 = odbc_exec($dbh2,"delete from BCITEMSUBSTITUTE where itemcode='".$_POST['itemcode']."' ");
}
else if($_POST['managevalue'] == 31) // เพิ่มรายการสินค้าขายคู่
{
//ตรวจสอบรหัส ว่า มีการป้อนรายการซ้ำกันหรือไม่
$ch = odbc_num_rows(odbc_exec($dbh2, "select * from BCITEMMATCH where MasterCode = '".$_POST['itemcode']."' and MatchCode = '".$_POST['itemcode_match']."' "));
if($ch > 0)
{
echo '1' ;
odbc_close($dbh2);
exit();
}
$ins = "insert into BCITEMMATCH ";
$ins .= " ( MasterCode, Qty, UnitCode, MatchCode ) ";
$ins .= " values ";
$ins .= " ( '".$_POST['itemcode']."', '".$_POST['qty']."','".$_POST['unitcode']."','".$_POST['itemcode_match']."' ) ";
$obins = odbc_exec($dbh2,$ins);
//ซิ้งค์ข้อมูล
$ch = odbc_num_rows(odbc_exec($dbh2, "select * from BCITEMMATCH where MasterCode = '".$_POST['itemcode_match']."' and MatchCode = '".$_POST['itemcode']."' "));
if($ch == 0)
{
$ins = "insert into BCITEMMATCH ";
$ins .= " ( MasterCode, Qty, UnitCode, MatchCode ) ";
$ins .= " values ";
$ins .= " ( '".$_POST['itemcode_match']."', '".$_POST['qty']."','".$_POST['unitcode']."','".$_POST['itemcode']."' ) ";
$obins = odbc_exec($dbh2,$ins);
}
echo '2' ;
}
else if($_POST['managevalue'] == 32) // ลบการสินค้าขายคู่
{
$del = "delete from BCITEMMATCH where MasterCode = '".$_POST['itemcode']."' and MatchCode = '".$_POST['itemcode_match']."' ";
$obdel = odbc_exec($dbh2,$del);
//ลบสินค้าคู่ไปด้วย
$del2 = "delete from BCITEMMATCH where MasterCode = '".$_POST['itemcode_match']."' and MatchCode = '".$_POST['itemcode']."' ";
$obdel2 = odbc_exec($dbh2,$del2);
}
else if($_POST['managevalue'] == 33) // แก้ไขจำนวนสินค้าขายพ่วง
{
$upd = "update BCITEMMATCH set Qty = '".$_POST['qty']."' where ROWORDER = '".$_POST['roworder']."' ";
$obupd = odbc_exec($dbh2, $upd);
}
else if($_POST['managevalue'] == 34) // ลบสินค้าขายพ่วง แบบลบทั้งหมด
{
//ดึงข้อมูลสินค้าขายพ่วงของรหัสนี้
$slc = odbc_exec($dbh2,"select MasterCode, MatchCode from BCITEMMATCH where MasterCode='".$_POST['itemcode']."' ");
while($sub=odbc_fetch_array($slc))
{
//ลบสินค้าทดแทนที่เป็นสินค้าที่จับคู่กับสินค้าที่ต้องการลบ
$del = odbc_exec($dbh2,"delete from BCITEMMATCH where MasterCode='".$sub['MatchCode']."' and MatchCode='".$_POST['itemcode']."' ");
}
//ลบสินค้าทั้งหมด
$del2 = odbc_exec($dbh2,"delete from BCITEMMATCH where MasterCode='".$_POST['itemcode']."' ");
}
else if($_POST['managevalue'] == 41) //อัพโหลดรูปภาพ
{
$txtsearch = $_POST['searchpic_id'] ;
for($i=1;$i<=3;$i++)
{
$file_name = $_FILES["fileUpload$i"]["name"];
//เช็คว่าได้อัพโหลดรูปมาหรือไม่
if($file_name == '')
{
//echo '' ;
}
else
{
$images = $_FILES["fileUpload$i"]["tmp_name"];
$file_error = $_FILES["fileUpload$i"]["error"];
$type= strrchr($file_name,".");
if($type !=".JPG" AND $type !=".png" AND $type !=".PNG" AND $type !=".jpg")
{
echo '' ;
exit();
}
$year = (date("Y"));
$month = (date("m"));
$day = (date("d"));
$datetime = $year.$month.$day ;
$newfilename = $_POST['pic_id'].'-'.$i.$datetime.$type ; //ตั้งชื่อไฟล์ใหม่
echo $newfilename ;
// ลดขนาดภาพ
$width=800; //*** Fix Width & Heigh (Autu caculate) ***//
$size=GetimageSize($images);
$height=round(($width*$size[1]/$size[0])); //1050
$images_orig = ImageCreateFromJPEG($images);
$photoX = ImagesX($images_orig);
$photoY = ImagesY($images_orig);
$images_fin = ImageCreateTrueColor($width, $height);
ImageCopyResampled($images_fin, $images_orig, 0, 0, 0, 0 , $width+1 ,$height+1 , $photoX, $photoY);
$row = imagerotate($images_fin,0,0);
ImageJPEG($row ,"item/".$newfilename);
ImageDestroy($images_orig);
ImageDestroy($images_fin);
//move_uploaded_file($_FILES["fileUpload"]["tmp_name"],"item/".$newfilename);
$fileuploads = "update BCITEM
set picFileName$i = 'item/".$newfilename."'
where Code = '".$_POST['pic_id']."'
";
$obqueryfile = odbc_exec($dbh2,$fileuploads);
}
}
echo ' ';
echo '';
}
odbc_close($dbh2);
?>