Warning: Table './tossfest/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./tossfest/cache_filter&amp;#039; is marked as crashed and should be repaired\nquery: SELECT data, created, headers, expire FROM cache_filter WHERE cid = &amp;#039;3:860722733d1d38a687cfee96736c169f&amp;#039;</em> in <em>/var/www/tossfest/includes/database.mysql.inc</em> on line <em>172</em>.', 2, '', 'http://tossfest.opentle.org/node/64', '', '38.103.63.57', 1231560312) in /var/www/tossfest/includes/database.mysql.inc on line 172

Warning: Table './tossfest/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./tossfest/cache_filter&amp;#039; is marked as crashed and should be repaired\nquery: LOCK TABLES cache_filter WRITE</em> in <em>/var/www/tossfest/includes/database.mysql.inc</em> on line <em>172</em>.', 2, '', 'http://tossfest.opentle.org/node/64', '', '38.103.63.57', 1231560312) in /var/www/tossfest/includes/database.mysql.inc on line 172

Warning: Table './tossfest/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./tossfest/cache_filter&amp;#039; is marked as crashed and should be repaired\nquery: UPDATE cache_filter SET data = &amp;#039;&amp;lt;p&amp;gt;แนวคิดการสร้างโปรแกรม&amp;lt;br /&amp;gt; ในชีวิตปกติของคนจะมีการใช้เงินหลัก ๆ อยู่ 5 รูปแบบได้แก่&amp;lt;br /&amp;gt;1.เงินสด เป็นเงินที่ติดกับตัวเอง&amp;lt;br /&amp;gt;2.เงินหมุนเวียนประจำ ได้แก่บัญชีธนาคารต่าง ๆ&amp;lt;br /&amp;gt;3.เงินออม ของธนาคารต่าง in /var/www/tossfest/includes/database.mysql.inc on line 172

Warning: Table './tossfest/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./tossfest/comments&amp;#039; is marked as crashed and should be repaired\nquery: SELECT COUNT(*) FROM comments WHERE nid = 64 AND status = 0</em> in <em>/var/www/tossfest/includes/database.mysql.inc</em> on line <em>172</em>.', 2, '', 'http://tossfest.opentle.org/node/64', '', '38.103.63.57', 1231560312) in /var/www/tossfest/includes/database.mysql.inc on line 172

Warning: Table './tossfest/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./tossfest/comments&amp;#039; is marked as crashed and should be repaired\nquery: SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread, c.status FROM comments c INNER JOIN users u ON c.uid = u.uid WHERE c.nid = 64 AND c.status = 0 ORDER BY c.thread DESC LIMIT 0, 50</em> in <em>/var/www/tossfest/includes/database.mysql.inc</em> on line <em>172</em>.', 2, '', 'http://tossfest.opentle.org/node/64', '', '38.103.63.57', 1231560312) in /var/www/tossfest/includes/database.mysql.inc on line 172
เริ่มต้นการพัฒนาโปรแกรม BunShee ด้วยไพธอน | Thailand Open Source Software Festival

เริ่มต้นการพัฒนาโปรแกรม BunShee ด้วยไพธอน

  • user warning: Table './tossfest/cache_filter' is marked as crashed and should be repaired query: SELECT data, created, headers, expire FROM cache_filter WHERE cid = '3:860722733d1d38a687cfee96736c169f' in /var/www/tossfest/includes/database.mysql.inc on line 172.
  • user warning: Table './tossfest/cache_filter' is marked as crashed and should be repaired query: LOCK TABLES cache_filter WRITE in /var/www/tossfest/includes/database.mysql.inc on line 172.
  • user warning: Table './tossfest/cache_filter' is marked as crashed and should be repaired query: UPDATE cache_filter SET data = '<p>แนวคิดการสร้างโปรแกรม<br /> ในชีวิตปกติของคนจะมีการใช้เงินหลัก ๆ อยู่ 5 รูปแบบได้แก่<br />1.เงินสด เป็นเงินที่ติดกับตัวเอง<br />2.เงินหมุนเวียนประจำ ได้แก่บัญชีธนาคารต่าง ๆ<br />3.เงินออม ของธนาคารต่าง ๆ เช่นเดียวกัน รวมถึงทรัพย์สินที่มีค่าต่าง ๆ <br />4.ประกันภัย <br />5.บัตรเครดิต</p>\n<p>การกระทำหลัก กับบัญชีเหล่านี้ได้แก่ การใช้จ่ายในชีวิตประจำวัน รายได้เงินเดือนหรือรับจ้าง การถอนเงินจาก ATM การใช้บัตรเครดิต</p>\n<p>ในการเขียนโปรแกรมเราต้องแบ่งฐานข้อมูลออกเป้นตารางย่อย ๆ สำหรับบุคคลหนึ่ง ได้แก่<br />1.ตารางจัดเก็บรายชื่อบัญชีต่าง ๆ ทั้ง 5 ข้อทั้งนี้ในแต่ละข้ออาจจะมากกว่า 1 บัญชี<br />2.ตารางเก็บรายการค่าใช้จ่าย<br />3.ตารางเก็บรายการรายได้<br />4.ตารางเก็บรายการโอนย้ายเงิน ทั้งผ่านสมุดธนาคารหรือ ATM<br />5.ตารางเวลาการกำหนดรายการล่วงหน้า</p>\n<p>การเขียนโปรแกรมออกแบบการทำงานดังนี้ <br />1.โปรแกรมหลัก มีการแสดงหน้าการจัดการ รายจ่าย รายได้ การโอนย้าย กำหนดการล่วงหน้า และจัดการบัญชี ทั้งหมด 5 หน้า<br />2.ปุ่มกดควบคุมต่าง ๆ ได้แก่ปุ่มบันทึก และปุ่มจัดการชนิดของรายได้และรายจ่าย</p>\n<p>นำข้อมูลมาออกแบบโปรแกรมได้คลาส 5 คลาสได้แก่ <br />1.Incomes() สำหรับจัดการรายได้<br />2.Expenses() สำหรับจัดการรายจ่าย<br />3.Account() สำหรับจัดการบัญชี<br />4.Transfer() สำหรับจัดการรายการดอนย้ายเงิน<br />5.Schduel() สำหรับจัดการกำหนดการล่วงหน้า</p>\n<p>ในที่นี้จะแสดงการใช้งาน 3 คลาสคือ Incomes() Expenses() และ Account() การทำงานโดยรวมสามารถแสดง ดังรูปด้านล่าง</p>\n<p><img src=\"/files/u1/BunShee_Structure.jpg\" width=\"636\" height=\"360\" /> </p>\n<p align=\"center\">รูปที่ 1 แสดงโครงสร้างการทำงานของโปรแกรม<br /> tb_account ถูกจัดการโดยคลาส Account()<br />tb_incomes และ tb_expenses ถูกจัดการโดยคลาส Base()<br />การบันทึกและเพิ่มลดรายการในบัญชีรายได้และรายจ่ายจัดการโดยคลาส MainApp()</p>\n<p align=\"left\">ลำดับขั้นตอนการทำงาน </p>\n<ol>\n<li>Initialization โปรแกรมดังนี้<br />- สร้างไฟล์ฐานข้อมูลชื่อ default <font color=\"#ff6600\"> connection = sqlite.connect(&#39;default&#39;) # ติดต่อฐานข้อมูลชื่อ default</font><br />- สร้างตาราง tb_incomes <font color=\"#999999\"><font color=\"#ff6600\"><font color=\"#333333\">เพื่อเก็บรายการรายได้</font></font></font><br />- สร้างตาราง tb_expenses <font color=\"#999999\"><font color=\"#ff6600\"><font color=\"#333333\">เพื่อเก็บรายการรายจ่าย</font></font></font><br />- สร้างตาราง tb_excategories <font color=\"#333333\">เพื่อเก็บข้อมูลชนิดของรายจ่าย</font><br />- สร้างตาราง tb_incategories <font color=\"#333333\">เพื่อเก็บข้อมูลชนิดของรายได้</font><br />- สร้างตาราง tb_account <font color=\"#000000\">เพื่อเก็บรายการบัญชีตาง ๆ</font><br />ยกตัวอย่างการสร้างตาราง tb_accout <br /><font color=\"#999999\"><font color=\"#ff6600\">cursor.execute(&#39;CREATE TABLE tb_account (id INTEGER PRIMARY KEY,name STR, type STR)&#39;) </font></font></li>\n<li><font color=\"#999999\">รายการบัญชี tb_account ข้อมูลที่ต้องเก็บคือ ชื่อบัญชี ชนิดของบัญชื และเงินเริ่มต้น ชนิดของบัญชีได้แก่<br /></font>\n<ul>\n<li><font color=\"#000000\">Cash เงินสด<br /></font></li>\n<li><font color=\"#000000\">Current Account เงินหมุนเวียน<br /></font></li>\n<li><font color=\"#000000\">Saving Account เงินออม<br /></font></li>\n<li><font color=\"#000000\">Liabilities ประกันภัย<br /></font></li>\n<li><font color=\"#ff6600\"><font color=\"#000000\">Credit Card </font><br /></font></li>\n</ul>\n<p>ทั้งหมดนี้อยู่ในตัวแปรชื่อ <font color=\"#ff6600\">account_array<br /></font> <font color=\"#999999\"><font color=\"#ff6600\"><br /></font></font></li>\n<li><font color=\"#333333\">รายการในชีวิตประจำวันของเราจะมี รายจ่าย รายได้ การโอนเงิน เป็นหลัก ทั้งสามรายการนี้อยู่ในตัวแปรชื่อ </font><br /><font color=\"#ff6600\">itemtype_array = [&quot;Income&quot;,&quot;Expense&quot;,&quot;Transfer&quot;]</font></li>\n<li><font color=\"#333333\">เสร็จการ Intialize ตัวโปรแกรม ต่อมาสร้าง Instance ของ main โปรแกรม โดย main โปรแกรมถูกจัดการด้วย class ชื่อ MainApp() โครงสร้างอธิบายการทำงานของมันจะแสดงไว้ในตอนต่อไป<br /><font color=\"#ff6600\">hwg = MainApp() # สร้าง Instance <br />gtk.main() # เข้าสู่โปรแกรมหลักคอยจัดการกับ Message ต่าง ๆ\n<p>หลังจากสร้าง Instance แล้วจะได้หน้าตา Main โปรแกรมดังภาพ</p>\n<p></font></font><img src=\"/files/u1/BunShee.png\" width=\"500\" height=\"373\" /></li>\n</ol>\n', created = 1231560312, expire = 1231646712, headers = '' WHERE cid = '3:860722733d1d38a687cfee96736c169f' in /var/www/tossfest/includes/database.mysql.inc on line 172.
  • user warning: Table './tossfest/comments' is marked as crashed and should be repaired query: SELECT COUNT(*) FROM comments WHERE nid = 64 AND status = 0 in /var/www/tossfest/includes/database.mysql.inc on line 172.
  • user warning: Table './tossfest/comments' is marked as crashed and should be repaired query: SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.picture, u.data, c.score, c.users, c.thread, c.status FROM comments c INNER JOIN users u ON c.uid = u.uid WHERE c.nid = 64 AND c.status = 0 ORDER BY c.thread DESC LIMIT 0, 50 in /var/www/tossfest/includes/database.mysql.inc on line 172.

แนวคิดการสร้างโปรแกรม
ในชีวิตปกติของคนจะมีการใช้เงินหลัก ๆ อยู่ 5 รูปแบบได้แก่
1.เงินสด เป็นเงินที่ติดกับตัวเอง
2.เงินหมุนเวียนประจำ ได้แก่บัญชีธนาคารต่าง ๆ
3.เงินออม ของธนาคารต่าง ๆ เช่นเดียวกัน รวมถึงทรัพย์สินที่มีค่าต่าง ๆ
4.ประกันภัย
5.บัตรเครดิต

การกระทำหลัก กับบัญชีเหล่านี้ได้แก่ การใช้จ่ายในชีวิตประจำวัน รายได้เงินเดือนหรือรับจ้าง การถอนเงินจาก ATM การใช้บัตรเครดิต

ในการเขียนโปรแกรมเราต้องแบ่งฐานข้อมูลออกเป้นตารางย่อย ๆ สำหรับบุคคลหนึ่ง ได้แก่
1.ตารางจัดเก็บรายชื่อบัญชีต่าง ๆ ทั้ง 5 ข้อทั้งนี้ในแต่ละข้ออาจจะมากกว่า 1 บัญชี
2.ตารางเก็บรายการค่าใช้จ่าย
3.ตารางเก็บรายการรายได้
4.ตารางเก็บรายการโอนย้ายเงิน ทั้งผ่านสมุดธนาคารหรือ ATM
5.ตารางเวลาการกำหนดรายการล่วงหน้า

การเขียนโปรแกรมออกแบบการทำงานดังนี้
1.โปรแกรมหลัก มีการแสดงหน้าการจัดการ รายจ่าย รายได้ การโอนย้าย กำหนดการล่วงหน้า และจัดการบัญชี ทั้งหมด 5 หน้า
2.ปุ่มกดควบคุมต่าง ๆ ได้แก่ปุ่มบันทึก และปุ่มจัดการชนิดของรายได้และรายจ่าย

นำข้อมูลมาออกแบบโปรแกรมได้คลาส 5 คลาสได้แก่
1.Incomes() สำหรับจัดการรายได้
2.Expenses() สำหรับจัดการรายจ่าย
3.Account() สำหรับจัดการบัญชี
4.Transfer() สำหรับจัดการรายการดอนย้ายเงิน
5.Schduel() สำหรับจัดการกำหนดการล่วงหน้า

ในที่นี้จะแสดงการใช้งาน 3 คลาสคือ Incomes() Expenses() และ Account() การทำงานโดยรวมสามารถแสดง ดังรูปด้านล่าง

รูปที่ 1 แสดงโครงสร้างการทำงานของโปรแกรม
tb_account ถูกจัดการโดยคลาส Account()
tb_incomes และ tb_expenses ถูกจัดการโดยคลาส Base()
การบันทึกและเพิ่มลดรายการในบัญชีรายได้และรายจ่ายจัดการโดยคลาส MainApp()

ลำดับขั้นตอนการทำงาน

  1. Initialization โปรแกรมดังนี้
    - สร้างไฟล์ฐานข้อมูลชื่อ default connection = sqlite.connect('default') # ติดต่อฐานข้อมูลชื่อ default
    - สร้างตาราง tb_incomes เพื่อเก็บรายการรายได้
    - สร้างตาราง tb_expenses เพื่อเก็บรายการรายจ่าย
    - สร้างตาราง tb_excategories เพื่อเก็บข้อมูลชนิดของรายจ่าย
    - สร้างตาราง tb_incategories เพื่อเก็บข้อมูลชนิดของรายได้
    - สร้างตาราง tb_account เพื่อเก็บรายการบัญชีตาง ๆ
    ยกตัวอย่างการสร้างตาราง tb_accout
    cursor.execute('CREATE TABLE tb_account (id INTEGER PRIMARY KEY,name STR, type STR)')
  2. รายการบัญชี tb_account ข้อมูลที่ต้องเก็บคือ ชื่อบัญชี ชนิดของบัญชื และเงินเริ่มต้น ชนิดของบัญชีได้แก่
    • Cash เงินสด
    • Current Account เงินหมุนเวียน
    • Saving Account เงินออม
    • Liabilities ประกันภัย
    • Credit Card

    ทั้งหมดนี้อยู่ในตัวแปรชื่อ account_array

  3. รายการในชีวิตประจำวันของเราจะมี รายจ่าย รายได้ การโอนเงิน เป็นหลัก ทั้งสามรายการนี้อยู่ในตัวแปรชื่อ
    itemtype_array = ["Income","Expense","Transfer"]
  4. เสร็จการ Intialize ตัวโปรแกรม ต่อมาสร้าง Instance ของ main โปรแกรม โดย main โปรแกรมถูกจัดการด้วย class ชื่อ MainApp() โครงสร้างอธิบายการทำงานของมันจะแสดงไว้ในตอนต่อไป
    hwg = MainApp() # สร้าง Instance
    gtk.main() # เข้าสู่โปรแกรมหลักคอยจัดการกับ Message ต่าง ๆ

    หลังจากสร้าง Instance แล้วจะได้หน้าตา Main โปรแกรมดังภาพ


Warning: Table './tossfest/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./tossfest/accesslog&amp;#039; is marked as crashed and should be repaired\nquery: INSERT INTO accesslog (title, path, url, hostname, uid, sid, timer, timestamp) values(&amp;#039;เริ่มต้นการพัฒนาโปรแกรม BunShee ด้วยไพธอน&amp;#039;, &amp;#039;node/64&amp;#039;, &amp;#039;&amp;#039;, &amp;#039;38.103.63.57&amp;#039;, 0, &amp;#039;3230ed76d7643cfaec647365b0b0bc81&amp;#039;, 358, 1231560312)</em> in <em>/var/www/tossfest/includes/database.mysql.inc</em> on line <em>172</em>.', 2, '', 'http://tossfest.opentle.org/node/64', '', '38.103.63.57', 1231560312) in /var/www/tossfest/includes/database.mysql.inc on line 172

Warning: Table './tossfest/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./tossfest/sessions&amp;#039; is marked as crashed and should be repaired\nquery: SELECT sid FROM sessions WHERE sid = &amp;#039;3230ed76d7643cfaec647365b0b0bc81&amp;#039;</em> in <em>/var/www/tossfest/includes/database.mysql.inc</em> on line <em>172</em>.', 2, '', 'http://tossfest.opentle.org/node/64', '', '38.103.63.57', 1231560312) in /var/www/tossfest/includes/database.mysql.inc on line 172

Warning: Table './tossfest/watchdog' is marked as crashed and should be repaired query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Table &amp;#039;./tossfest/sessions&amp;#039; is marked as crashed and should be repaired\nquery: INSERT INTO sessions (sid, uid, cache, hostname, session, timestamp) VALUES (&amp;#039;3230ed76d7643cfaec647365b0b0bc81&amp;#039;, 0, 0, &amp;#039;38.103.63.57&amp;#039;, &amp;#039;messages|a:1:{s:5:\\&amp;quot;error\\&amp;quot;;a:1:{i:0;s:497:\\&amp;quot;user warning: Table &amp;amp;#039;./tossfest/accesslog&amp;amp;#039; is marked as crashed and should be repaired\\nquery: INSERT INTO accesslog (title, path, url, hostname, uid, sid, timer, timestamp) values(&amp;amp;#039;เริ่มต้นการพัฒนาโปรแกรม BunShee ด้วยไพธอน&amp;amp;#039;, &amp;amp;#039;node/64&amp;amp;#0 in /var/www/tossfest/includes/database.mysql.inc on line 172