ตอนนี้ทาง SSC มีแผนที่จะจัดเทรนนิ่ง PB V.12 โดยจะเชิญผู้สอนจากทาง Sybase (สิงค์โปร) วันที่ 29 -30 กรกฎาคม 53 (กำหนดการอาจจะมีการเปลี่ยนแปลงจะแจ้งให้ทราบล่วงหน้า) |
| เขียนscript การคิดส่วนลด |
|
|
|
|
วันจันทร์ที่ 08 มีนาคม 2010 เวลา 17:23 น.
|
|
สวัสดีครับ จากตัวอย่างที่คุณ มนตรีส่งมาให้เรื่องการคิดส่วนลดนั้นผมได้เข้าไปทำการปรับปรุงสคริปต์นิดหน่อยนะครับเพราะพบว่าถ้าผู้ใช้เกิดมือบอนป้อน ส่วนลดมากกว่า 100% มันก็จะคำนวณผลลัพธ์ออกมาเป็นลบ ซึ่งมันไม่ควรที่จะเป็นเช่นนั้น ซึ่งเราสามารถที่จะเตือนผู้ใช้ได้ 2 ทาง คือ เตือนในฟังก์ชั่นดังเช่นตัวอย่างที่ผมลงให้ดูนี้ โดยในสีม่วงจะเป็นส่วนที่ได้แก้ไขพิ่มเติมแล้ว Integer li_pos,li_len,li_pos2 Dec lde_price if dec(as_percent) > 100 then gu_user_func.uf_thaimsg("ข้อผิดพลาด ","คุณกำหนดส่วนลดมากกว่า 100% ทำให้เมื่อลดแล้วค่าที่ได้ติดลบ กรุณากำหนดใหม่",0) return 0 else If Not IsNull(as_percent) and as_percent "0" and as_percent "" then li_len = len(as_percent) li_pos = Pos(as_percent,"%") If li_pos > 0 then lde_price = ade_price - (ade_price * dec(Mid(as_percent,1,li_pos - 1)) / 100) If li_len > li_pos then li_pos2 = Pos(as_percent,"%",li_pos + 1) If li_pos2 > 0 then lde_price = lde_price - (lde_price * dec(Mid(as_percent,li_pos + 1,li_pos2 - li_pos - 1)) / 100) If li_len > li_pos2 then lde_price = lde_price - dec(right(as_percent,li_len - li_pos2)) End if Else lde_price = lde_price - dec(right(as_percent,li_len - li_pos)) End if End if Else lde_price = ade_price - dec(as_percent) End if //ราคาที่ลดแล้ว return lde_price Else //ราคาเดิม return ade_price End if end if หรือ อีกวิธีหนึ่งก็คือเขียนสคริปต์ดักใว้ที่ sle_2 ก่อนที่จะมีการเรียกใช้ฟังก์ชั่นส่วนลดตามสคริปต์ด้านล่าง if dec(this.text) > 100 then gu_user_func.uf_thaimsg("ข้อผิดพลาด ","คุณกำหนดส่วนลดมากกว่า 100% ทำให้เมื่อลดแล้วค่าที่ได้ติดลบ กรุณากำหนดใหม่",0) else sle_3.text = String(gu_user_func.uf_discount(Dec(sle_1.text),this.text)) |