เขียนโปรแกรมเช็คเลขบัตรประชาชน VB.NET,C#.NET,C++/CLI,Java NetBeans,Java Eclipse,IntelliJ IDEA

ในห้อง 'คอมพิวเตอร์ & อินเตอร์เน็ต' ตั้งกระทู้โดย ledphong, 7 กันยายน 2014.

  1. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    ตัวอย่าง
     

    ไฟล์ที่แนบมา:

    • CPP9.png
      CPP9.png
      ขนาดไฟล์:
      191.4 KB
      เปิดดู:
      2,938
    แก้ไขครั้งล่าสุดโดยผู้ดูแล: 6 พฤศจิกายน 2015
  2. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    VB.NET
    ==============================
    Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    If VerifyPeopleID(TextBox1.Text) Then
    MessageBox.Show("รหัสบัตรประชาชนถูกต้อง", "รายงานสถานะ")
    Else
    MessageBox.Show("รหัสบัตรประชาชนไม่ถูกต้อง", "รายงานสถานะ")
    End If
    End Sub

    Private Function VerifyPeopleID(PID As [String]) As [Boolean]
    'ตรวจสอบว่าทุก ๆ ตัวอักษรเป็นตัวเลข
    If PID.ToCharArray().All(Function(c) Char.IsNumber(c)) = False Then
    Return False
    End If
    'ตรวจสอบว่าข้อมูลมีทั้งหมด 13 ตัวอักษร
    If PID.Trim().Length <> 13 Then
    Return False
    End If

    Dim sumValue As Integer = 0
    For i As Integer = 0 To PID.Length - 2
    sumValue += Integer.Parse(PID(i).ToString()) * (13 - i)
    Next
    Dim v As Integer = 11 - (sumValue Mod 11)
    Return PID(12).ToString() = v.ToString()
    End Function

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    TextBox1.Text = ""
    End Sub
    End Class
     
  3. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    C#.NET
    ===========================
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsFormsApplication1
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void btnCheckPeopleID_Click(object sender, EventArgs e)
    {
    if (VerifyPeopleID(txtIDCard.Text))
    {
    MessageBox.Show("รหัสบัตรประชาชนถูกต้อง");
    }
    else
    {
    MessageBox.Show("รหัสบัตรประชาชนไม่ถูกต้อง");
    }
    }

    private Boolean VerifyPeopleID(String PID)
    {
    //ตรวจสอบว่าทุก ๆ ตัวอักษรเป็นตัวเลข
    if (PID.ToCharArray().All(c => char.IsNumber(c)) == false)
    return false;
    //ตรวจสอบว่าข้อมูลมีทั้งหมด 13 ตัวอักษร
    if (PID.Trim().Length != 13)
    return false;

    int sumValue = 0;
    for (int i = 0; i < PID.Length - 1; i++)
    sumValue += int.Parse(PID.ToString()) * (13 - i);
    int v = 11 - (sumValue % 11);
    return PID[12].ToString() == v.ToString();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    txtIDCard.Text = "";
    }
    }
    }
     
  4. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    C++/CLI
    =================================
    เขบ็ดจาก C#.NET ไปเป็น C++/CLI หวังว่าคงทำได้นะครับ
    =================================
    private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
    textBox1->Text = "";
    }
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    if(VerifyPeopleID(textBox1->Text)){
    MessageBox::Show("รหัสบัตรประชาชนถูกต้อง");
    }
    else{
    MessageBox::Show("รหัสบัตรประชาชนไม่ถูกต้อง");
    }
    }
    private:
    System::Boolean VerifyPeopleID(String ^PID){
    //ตรวจสอบว่าทุก ๆ ตัวอักษรเป็นตัวเลข
    if( !Microsoft::VisualBasic::Information::IsNumeric(this->textBox1->Text) )
    return false;
    //ตรวจสอบว่าข้อมูลมีทั้งหมด 13 ตัวอักษร
    if(PID->Trim()->Length != 13)
    return false;
    int sumValue = 0;
    for(int i = 0;i< PID->Length-1;i++)
    sumValue += int::parse(PID.ToString()) * (13-i);
    int v =11 - (sumValue % 11);
    return PID[12].ToString()==v.ToString();//อาศัย C#.NET เหมือนเดิมอยู่ครับ
    }
     
    แก้ไขครั้งล่าสุดโดยผู้ดูแล: 7 กันยายน 2014
  5. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    รอปรับปรุงโค้ดใหม่อีกรอบนะครับ
     
  6. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    หากตัวอย่างเป็นดังภาพ
     

    ไฟล์ที่แนบมา:

    • 1.png
      1.png
      ขนาดไฟล์:
      154.2 KB
      เปิดดู:
      552
  7. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    Code C#.NET
    =======================
    #region "Using Title"
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Text.RegularExpressions;//ใช้กับค้นหา ID Card
    #endregion

    //ปีงบประมาณ 2557
    if (cmbBudget.Text == "2557")
    {

    string conStr = @"Data Source=.\SQLEXPRESS;
    AttachDbFilename=|DataDirectory|\dbOlder.mdf;
    Integrated Security=True;User Instance=True;";

    string sql = "Select CodeID,SexFK,TitleFK,tblOlder.FirstName + ' ' + tblOlder.LastName As FullName, " +
    "IDCard, " +
    "convert(varchar,dateadd(year,543,Birthdate),103) As BirthDay , " +
    "(CAST(DATEDIFF(DD,Birthdate,'2013-09-30')/365.25 As INT )) As [Age] ," +
    "BanID,Moo,TypeNameFK,MethodMoneyFK,Box1 ," +
    "case when (CAST(DATEDIFF(DD,Birthdate,'2013-09-30')/365.25 As INT )) >= 90 then '1000.00' " +
    "when (CAST(DATEDIFF(DD,Birthdate,'2013-09-30')/365.25 As INT )) >= 80 then '800.00' " +
    "when (CAST(DATEDIFF(DD,Birthdate,'2013-09-30')/365.25 As INT )) >= 70 then '700.00' " +
    "when (CAST(DATEDIFF(DD,Birthdate,'2013-09-30')/365.25 As INT )) >= 60 then '600.00' " +
    "else '0.00' END AS [Money]" +
    "from tblOlder " +
    "WHERE " +
    "(Birthdate <= '1953-09-30') " +
    "And ((CAST(DATEDIFF(DD,Birthdate,'2013-09-30')/365.25 As INT )) Between @LevelStart And @LevelEnd) " +
    "And [TypeNameFK] LIKE '%ผู้%' " +
    "And [MethodMoneyFK] LIKE '%สด%' " +
    "And ([Box1] <= '2557') " +
    "And ([Moo] Like '%" + txtSearchMoo.Text + "%') " +
    "And ([IDCard] Like '%" + txtBarcodeIDCard.Text + "%')" +
    "ORDER BY [Moo],[BanID] ASC";

    SqlConnection con = new SqlConnection(conStr);
    con.Open();
    SqlCommand comm = new SqlCommand(sql, con);
     
  8. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    Java NetBeans
    ==============================
    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {
    txtIDCard.setText("");
    }

    private void btnCheckActionPerformed(java.awt.event.ActionEvent evt) {
    if(VerifyPeopleID(txtIDCard.getText())){
    JOptionPane.showMessageDialog(null,"รหัสบัตรประชาชนถูกต้อง");
    }else{
    JOptionPane.showMessageDialog(null,"รหัสบัตรประชาชนไม่ถูกต้อง");
    }
    }

    private Boolean VerifyPeopleID(String PID)
    {
    //ตรวจสอบว่าข้อมูลมีทั้งหมด 13 ตัวอักษร
    if (PID.trim().length() != 13)
    return false;
    int sumValue = 0;
    for(int i = 0;i< PID.length()-1;i++)//หรือ for (int i = 0; i < 12; i++)
    sumValue += Integer.parseInt(String.valueOf(PID.charAt(ไอ))) * (13 - i);//หรือ i
    int v =11 - (sumValue % 11);
    return PID.charAt(12) - '0' == (v % 10);
    }
     

    ไฟล์ที่แนบมา:

    แก้ไขครั้งล่าสุดโดยผู้ดูแล: 24 พฤษภาคม 2015
  9. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    Java Eclipse (Text เพียว ๆ)
    ================================
     

    ไฟล์ที่แนบมา:

    • IDCard.png
      IDCard.png
      ขนาดไฟล์:
      37.4 KB
      เปิดดู:
      467
    • IDCard2.png
      IDCard2.png
      ขนาดไฟล์:
      153.9 KB
      เปิดดู:
      396
    แก้ไขครั้งล่าสุดโดยผู้ดูแล: 15 กันยายน 2015
  10. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    IDCard.java
    ================================================
    <pre style="background:#404040;color:#dedede">package com.java.idcard;

    <span style="color:#ffffa0">import</span> javax.swing.JDesktopPane;
    <span style="color:#ffffa0">import</span> javax.swing.JMenu;
    <span style="color:#ffffa0">import</span> javax.swing.JMenuItem;
    <span style="color:#ffffa0">import</span> javax.swing.JMenuBar;
    <span style="color:#ffffa0">import</span> javax.swing.JFrame;
    <span style="color:#ffffa0">import</span> javax.swing.KeyStroke;
    <span style="color:#ffffa0">import</span> java.awt.event.<span style="color:#ffffa0">*</span>;
    <span style="color:#ffffa0">import</span> java.awt.<span style="color:#ffffa0">*</span>;

    @SuppressWarnings(<span style="color:#ff2020">"serial"</span>)
    <span style="color:#ffffa0">public</span> <span style="color:#6080ff">class</span> <span style="color:#f09040">IDCard</span> extends JFrame <span style="color:#ffffa0">implements</span> ActionListener{
    JDesktopPane desktop;

    <span style="color:#ffffa0">public</span> IDCard() {
    <span style="color:#ffffa0">super</span>(<span style="color:#ff2020">"โปรแกรมเช็คหมายเลขบัตรประชาชน Program Check IDCard V.2016 Release 1.0 ( Java Eclipse Helios 3.6.2x86 )"</span>);
    this.setExtendedState(IDCard.MAXIMIZED_BOTH);<span style="color:#709070;font-style:italic">//Maximized</span>

    <span style="color:#709070;font-style:italic">//Make the big window be indented 50 pixels from each edge</span>
    <span style="color:#709070;font-style:italic">//of the screen.</span>
    int inset <span style="color:#ffffa0">=</span> <span style="color:#22c0ff">50</span>;
    Dimension screenSize <span style="color:#ffffa0">=</span> Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset,screenSize.width <span style="color:#ffffa0">-</span> inset<span style="color:#ffffa0">*</span><span style="color:#22c0ff">2</span>,screenSize.height <span style="color:#ffffa0">-</span> inset<span style="color:#ffffa0">*</span><span style="color:#22c0ff">2</span>);

    <span style="color:#709070;font-style:italic">//Set up the GUI.</span>
    desktop <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> JDesktopPane(); <span style="color:#709070;font-style:italic">//a specialized layered pane</span>
    <span style="color:#709070;font-style:italic">//createFrame(); //create first "window"</span>
    setContentPane(desktop);
    setJMenuBar(createMenuBar());

    <span style="color:#709070;font-style:italic">//Make dragging a little faster but perhaps uglier.</span>
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    getContentPane().setBackground(<span style="color:#ffffa0">new</span> Color(<span style="color:#22c0ff">0xE8F2FE</span>));
    }

    protected JMenuBar createMenuBar() {
    JMenuBar menuBar <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> JMenuBar();

    <span style="color:#709070;font-style:italic">//============Menu File=============================</span>
    <span style="color:#709070;font-style:italic">//Set up the lone menu.</span>
    JMenu menu <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> JMenu(<span style="color:#ff2020">"แฟ้ม"</span>);
    menu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(menu);

    JMenu menu2 <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> JMenu(<span style="color:#ff2020">"เพิ่มรายการ"</span>);

    <span style="color:#709070;font-style:italic">//Set up the first menu item.</span>
    <span style="color:#709070;font-style:italic">//==============FormAdd=============================</span>
    JMenuItem FormAdd <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> JMenuItem(<span style="color:#ff2020">"รายการหลัก"</span>);
    FormAdd.setMnemonic(KeyEvent.VK_N);
    FormAdd.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_N, ActionEvent.ALT_MASK));
    FormAdd.setActionCommand(<span style="color:#ff2020">"newFormAdd"</span>);
    FormAdd.addActionListener(this);
    menu2.add(FormAdd);
    menu.add(menu2);
    <span style="color:#709070;font-style:italic">//===================================================</span>

    <span style="color:#709070;font-style:italic">//Set up the second menu item.</span>
    FormAdd <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> JMenuItem(<span style="color:#ff2020">"Quit"</span>);
    FormAdd.setMnemonic(KeyEvent.VK_Q);
    FormAdd.setAccelerator(KeyStroke.getKeyStroke(
    KeyEvent.VK_Q, ActionEvent.ALT_MASK));
    FormAdd.setActionCommand(<span style="color:#ff2020">"quit"</span>);
    FormAdd.addActionListener(this);
    menu.add(FormAdd);

    <span style="color:#ffffa0">return</span> menuBar;
    }

    <span style="color:#709070;font-style:italic">//React to menu selections.</span>
    <span style="color:#ffffa0">public</span> void actionPerformed(ActionEvent e) {
    <span style="color:#ffffa0">if</span> (<span style="color:#ff2020">"newFormAdd"</span>.equals(e.getActionCommand())) { <span style="color:#709070;font-style:italic">//FormAdd</span>
    createFormAdd();
    } <span style="color:#ffffa0">else</span> { <span style="color:#709070;font-style:italic">//quit</span>
    quit();
    }
    }

    <span style="color:#709070;font-style:italic">//Create a new internal frame.</span>
    protected void createFormAdd() {<span style="color:#709070;font-style:italic">//FormAdd</span>
    FormAdd frame <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> FormAdd();
    frame.setVisible(true); <span style="color:#709070;font-style:italic">//necessary as of 1.3</span>
    desktop.add(frame);
    }


    <span style="color:#709070;font-style:italic">//Quit the application.</span>
    protected void quit() {
    System.exit(<span style="color:#22c0ff">0</span>);
    }

    <span style="color:#ffffa0">private</span> <span style="color:#ffffa0">static</span> void createAndShowGUI() {
    <span style="color:#709070;font-style:italic">//Make sure we have nice window decorations.</span>
    JFrame.setDefaultLookAndFeelDecorated(true);

    <span style="color:#709070;font-style:italic">//Create and set up the window.</span>
    IDCard frame <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> IDCard();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    <span style="color:#709070;font-style:italic">//Display the window.</span>
    frame.setVisible(true);
    }

    <span style="color:#ffffa0">public</span> <span style="color:#ffffa0">static</span> void main(<span style="color:#6080ff">String</span>[] args) {
    javax.swing.SwingUtilities.invokeLater(<span style="color:#ffffa0">new</span> Runnable() {
    <span style="color:#ffffa0">public</span> void run() {
    createAndShowGUI();
    }
    });
    }
    }

    </pre>
     
  11. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    FormAdd.java
    ========================================
    <pre style="background:#404040;color:#dedede">package com.java.idcard;

    <span style="color:#ffffa0">import</span> java.awt.Dimension;
    <span style="color:#ffffa0">import</span> java.awt.Toolkit;
    <span style="color:#ffffa0">import</span> java.awt.event.ActionEvent;
    <span style="color:#ffffa0">import</span> java.awt.event.ActionListener;
    <span style="color:#ffffa0">import</span> java.awt.event.KeyAdapter;
    <span style="color:#ffffa0">import</span> java.awt.event.KeyEvent;

    <span style="color:#ffffa0">import</span> javax.swing.ImageIcon;
    <span style="color:#ffffa0">import</span> javax.swing.JButton;
    <span style="color:#ffffa0">import</span> javax.swing.JInternalFrame;
    <span style="color:#ffffa0">import</span> javax.swing.JLabel;
    <span style="color:#ffffa0">import</span> javax.swing.JOptionPane;
    <span style="color:#ffffa0">import</span> javax.swing.JTextField;

    @SuppressWarnings(<span style="color:#ff2020">"serial"</span>)
    <span style="color:#ffffa0">public</span> <span style="color:#6080ff">class</span> <span style="color:#f09040">FormAdd</span> extends JInternalFrame{

    <span style="color:#ffffa0">static</span> int openFrameCount <span style="color:#ffffa0">=</span> <span style="color:#22c0ff">0</span>;
    final JTextField txtIDCard;
    final JButton btnOK,btnRefresh;

    <span style="color:#ffffa0">public</span> FormAdd() {
    <span style="color:#ffffa0">super</span>(<span style="color:#ff2020">"ตรวจสอบหมายเลขบัตรประชาชน # "</span> <span style="color:#ffffa0">+</span> (<span style="color:#ffffa0">+</span><span style="color:#ffffa0">+</span>openFrameCount),
    true, <span style="color:#709070;font-style:italic">//resizable</span>
    true, <span style="color:#709070;font-style:italic">//closable</span>
    true, <span style="color:#709070;font-style:italic">//maximizable</span>
    true);<span style="color:#709070;font-style:italic">//iconifiable</span>

    <span style="color:#709070;font-style:italic">//Display the window.</span>

    pack();
    setVisible(true);
    <span style="color:#709070;font-style:italic">//setBounds(350, 10, 690, 630);</span>

    setSize(<span style="color:#22c0ff">585</span>,<span style="color:#22c0ff">180</span>);
    setResizable(false);<span style="color:#709070;font-style:italic">//ไม่ให้ Resize </span>
    final Toolkit toolkit <span style="color:#ffffa0">=</span> Toolkit.getDefaultToolkit();
    final Dimension screenSize <span style="color:#ffffa0">=</span> toolkit.getScreenSize();
    final int x <span style="color:#ffffa0">=</span> (screenSize.width <span style="color:#ffffa0">-</span> getWidth()) <span style="color:#ffffa0">/</span> <span style="color:#22c0ff">2</span>;
    final int y <span style="color:#ffffa0">=</span> (screenSize.height <span style="color:#ffffa0">-</span> getHeight()) <span style="color:#ffffa0">/</span> <span style="color:#22c0ff">12</span>;
    setLocation(x, y);

    getContentPane().setLayout(null);<span style="color:#709070;font-style:italic">//new</span>

    <span style="color:#709070;font-style:italic">//==========JLabel=========================</span>
    JLabel lblIDCard <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> JLabel(<span style="color:#ff2020">"เลขบัตรประชาชน : "</span>);
    lblIDCard.setBounds(<span style="color:#22c0ff">10</span>, <span style="color:#22c0ff">10</span>, <span style="color:#22c0ff">140</span>, <span style="color:#22c0ff">14</span>);
    getContentPane().add(lblIDCard);

    <span style="color:#709070;font-style:italic">//==========JTextField=====================</span>

    txtIDCard <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> JTextField(<span style="color:#ff2020">"txtIDCard"</span>, <span style="color:#22c0ff">15</span>);
    txtIDCard.setBounds(<span style="color:#22c0ff">180</span>, <span style="color:#22c0ff">10</span>, <span style="color:#22c0ff">120</span>, <span style="color:#22c0ff">25</span>);
    getContentPane().add(txtIDCard);

    <span style="color:#709070;font-style:italic">//==========JButton=========================</span>
    ImageIcon iconok <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> ImageIcon(<span style="color:#ff2020">"res/iconok.png"</span>);
    ImageIcon iconrefresh <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> ImageIcon(<span style="color:#ff2020">"res/refresh.png"</span>);

    btnOK <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> JButton(<span style="color:#ff2020">"ตกลง"</span>,iconok);
    btnOK.setPreferredSize(<span style="color:#ffffa0">new</span> Dimension(<span style="color:#22c0ff">115</span>, <span style="color:#22c0ff">45</span>));
    btnOK.setBounds(<span style="color:#22c0ff">305</span>, <span style="color:#22c0ff">10</span>, <span style="color:#22c0ff">115</span>, <span style="color:#22c0ff">45</span>);
    getContentPane().add(btnOK);

    btnRefresh <span style="color:#ffffa0">=</span> <span style="color:#ffffa0">new</span> JButton(<span style="color:#ff2020">"รีเฟรซข้อมูล"</span>,iconrefresh);
    btnRefresh.setPreferredSize(<span style="color:#ffffa0">new</span> Dimension(<span style="color:#22c0ff">145</span>, <span style="color:#22c0ff">45</span>));
    btnRefresh.setBounds(<span style="color:#22c0ff">425</span>, <span style="color:#22c0ff">10</span>, <span style="color:#22c0ff">145</span>, <span style="color:#22c0ff">45</span>);
    getContentPane().add(btnRefresh);

    <span style="color:#709070;font-style:italic">//=======Command Button==================================================</span>
    btnOK.addActionListener(<span style="color:#ffffa0">new</span> ButtonListener());
    btnRefresh.addActionListener(<span style="color:#ffffa0">new</span> ButtonListener());
    txtIDCard.addActionListener(<span style="color:#ffffa0">new</span> TextListener());
    <span style="color:#709070;font-style:italic">//==================Clear All Data Form Load=============================</span>
    txtIDCard.setText(<span style="color:#ff2020">""</span>);

    <span style="color:#709070;font-style:italic">//=====================txtIDCard Only Number===========================</span>
    txtIDCard.addKeyListener(<span style="color:#ffffa0">new</span> KeyAdapter(){
    @Override
    <span style="color:#ffffa0">public</span> void keyReleased(KeyEvent e) {
    JTextField txtIDCard <span style="color:#ffffa0">=</span> (JTextField) e.getSource();
    <span style="color:#6080ff">String</span> str <span style="color:#ffffa0">=</span> txtIDCard.getText();
    txtIDCard.setText(str.replaceAll(<span style="color:#ff2020">"[^0-9]"</span>, <span style="color:#ff2020">""</span>));
    }
    });
    }
    <span style="color:#709070;font-style:italic">//==============txtIDCard KeyPress=========================================</span>
    <span style="color:#ffffa0">private</span> <span style="color:#6080ff">class</span> <span style="color:#f09040">TextListener</span> <span style="color:#ffffa0">implements</span> ActionListener
    {
    @Override
    <span style="color:#ffffa0">public</span> void actionPerformed(ActionEvent ae) {
    Object source <span style="color:#ffffa0">=</span> ae.getSource();
    <span style="color:#709070;font-style:italic">//===========txtIDCard====================</span>
    <span style="color:#ffffa0">if</span>(source <span style="color:#ffffa0">=</span><span style="color:#ffffa0">=</span> txtIDCard){
    <span style="color:#ffffa0">if</span>(txtIDCard.getText().equals(<span style="color:#ff2020">""</span>)){
    JOptionPane.showMessageDialog(null,<span style="color:#ff2020">"กรุณาใส่เลขบัตรประชาชนก่อนและกดปุ่มตกลง"</span>,<span style="color:#ff2020">"รายงานสถานะ"</span>,JOptionPane.QUESTION_MESSAGE,null);
    txtIDCard.requestFocus();
    <span style="color:#709070;font-style:italic">//return; </span>
    }<span style="color:#ffffa0">else</span> {
    btnOK.doClick();<span style="color:#709070;font-style:italic">//แทนการ Click btnOK</span>
    }
    }
    }
    }
    <span style="color:#709070;font-style:italic">//===================End txtIDCard KeyPress============================</span>

    <span style="color:#ffffa0">private</span> <span style="color:#6080ff">Boolean</span> VerifyPeopleID(<span style="color:#6080ff">String</span> PID){
    <span style="color:#709070;font-style:italic">//ตรวจสอบว่าข้อมูลมีทั้งหมด 13 ตัวอักษร</span>
    <span style="color:#ffffa0">if</span> (PID.trim().length() <span style="color:#ffffa0">!</span><span style="color:#ffffa0">=</span> <span style="color:#22c0ff">13</span>)
    <span style="color:#ffffa0">return</span> false;
    int sumValue <span style="color:#ffffa0">=</span> <span style="color:#22c0ff">0</span>;
    <span style="color:#ffffa0">for</span>(int i <span style="color:#ffffa0">=</span> <span style="color:#22c0ff">0</span>;i&lt; PID.length()<span style="color:#ffffa0">-</span><span style="color:#22c0ff">1</span>;i<span style="color:#ffffa0">+</span><span style="color:#ffffa0">+</span>)<span style="color:#709070;font-style:italic">//หรือ for (int i = 0; i &lt; 12; i++)</span>
    sumValue <span style="color:#ffffa0">+</span><span style="color:#ffffa0">=</span> Integer.parseInt(<span style="color:#6080ff">String</span>.valueOf(PID.charAt(i))) <span style="color:#ffffa0">*</span> (<span style="color:#22c0ff">13</span> <span style="color:#ffffa0">-</span> i);<span style="color:#709070;font-style:italic">//หรือ i</span>
    int v <span style="color:#ffffa0">=</span><span style="color:#22c0ff">11</span> <span style="color:#ffffa0">-</span> (sumValue <span style="color:#ffffa0">%</span> <span style="color:#22c0ff">11</span>);
    <span style="color:#ffffa0">return</span> PID.charAt(<span style="color:#22c0ff">12</span>) <span style="color:#ffffa0">-</span> <span style="color:#ff2020">'0'</span> <span style="color:#ffffa0">=</span><span style="color:#ffffa0">=</span> (v <span style="color:#ffffa0">%</span> <span style="color:#22c0ff">10</span>);
    }
    <span style="color:#709070;font-style:italic">//==============Button Command=========================================</span>
    <span style="color:#ffffa0">private</span> <span style="color:#6080ff">class</span> <span style="color:#f09040">ButtonListener</span> <span style="color:#ffffa0">implements</span> ActionListener{
    @Override
    <span style="color:#ffffa0">public</span> void actionPerformed(ActionEvent ae) {
    Object source <span style="color:#ffffa0">=</span> ae.getSource();
    <span style="color:#709070;font-style:italic">//===========btnRefresh====================</span>
    <span style="color:#ffffa0">if</span>(source <span style="color:#ffffa0">=</span><span style="color:#ffffa0">=</span> btnRefresh){
    txtIDCard.setText(<span style="color:#ff2020">""</span>);
    }
    <span style="color:#ffffa0">if</span>(source <span style="color:#ffffa0">=</span><span style="color:#ffffa0">=</span> btnOK){
    <span style="color:#ffffa0">if</span>(VerifyPeopleID(txtIDCard.getText())){
    JOptionPane.showMessageDialog(null,<span style="color:#ff2020">"รหัสบัตรประชาชนถูกต้อง"</span>);
    }<span style="color:#ffffa0">else</span>{
    JOptionPane.showMessageDialog(null,<span style="color:#ff2020">"รหัสบัตรประชาชนไม่ถูกต้อง"</span>);
    }
    }
    }
    }
    }
    </pre>
     
  12. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    คอยพบกับ IntelliJ IDEA 15.0 กับการเช็คหมายเลขบัตรประชาชน ครับ
     
  13. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    ส่วนมากผมจะเขียน Java ไม่ว่าจะเป็น NetBeans,Eclipse,IntelliJ IDEA จะเขียนแบบเพียว ๆ ไม่ยึดถือ Plugin GUI ที่ทำสำเร็จ (WindowBuilders) ที่มากับ Java แต่ละเวอร์ชั่น เพราะว่าหากเรามัวแต่หา Plugin มาเขียนแบบสบายเราจะเข้าวิธีการเขียนจาวา แบบสุดยอดลึกซึ้งได้อย่างไร ทางกลับกันหากเราเขียน Text Mode ได้แล้วเราก็สามารถปรับประยุกต์ได้ทุกอย่างตามที่เราปรารถนา ไม่ว่าจะทำอะไรก็สบาย
     

    ไฟล์ที่แนบมา:

    • 1.png
      1.png
      ขนาดไฟล์:
      34.7 KB
      เปิดดู:
      288
    • 2.png
      2.png
      ขนาดไฟล์:
      125.3 KB
      เปิดดู:
      268
    แก้ไขครั้งล่าสุดโดยผู้ดูแล: 16 พฤศจิกายน 2015
  14. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    Main.java
    ===================================
    <pre style="background:#000;color:#f8f8f8">package com.java.idcard;

    <span style="color:#e28964">import</span> java.awt.<span style="color:#9b859d">Color</span>;
    <span style="color:#e28964">import</span> java.awt.Dimension;
    <span style="color:#e28964">import</span> java.awt.Toolkit;
    <span style="color:#e28964">import</span> java.awt.<span style="color:#dad085">event</span>.ActionEvent;
    <span style="color:#e28964">import</span> java.awt.<span style="color:#dad085">event</span>.ActionListener;
    <span style="color:#e28964">import</span> javax.swing.JDesktopPane;
    <span style="color:#e28964">import</span> javax.swing.JFrame;
    <span style="color:#e28964">import</span> javax.swing.JMenu;
    <span style="color:#e28964">import</span> javax.swing.JMenuBar;
    <span style="color:#e28964">import</span> javax.swing.JMenuItem;
    <span style="color:#e28964">import</span> javax.swing.KeyStroke;
    <span style="color:#e28964">import</span> javax.swing.SwingUtilities;

    <span style="color:#e28964">public</span> <span style="color:#99cf50">class</span> <span style="text-decoration:underline">Main</span> <span style="color:#99cf50">extends</span> <span style="color:#9b5c2e;font-style:italic">JFrame</span> <span style="color:#e28964">implements</span> ActionListener {
    JDesktopPane desktop;

    <span style="color:#e28964">public</span> Main() {
    <span style="color:#e28964">super</span>(<span style="color:#65b042">"โปรแกรมเช็คหมายเลขบัตรประชาชน Program Check IDCard V.2016 Release 1.0 ( Java IntelliJ IDEA 15.0x86 )"</span>);
    <span style="color:#dad085">this</span>.setExtendedState(<span style="color:#3387cc">6</span>);
    byte inset <span style="color:#e28964">=</span> <span style="color:#3387cc">50</span>;
    Dimension screenSize <span style="color:#e28964">=</span> Toolkit.getDefaultToolkit().getScreenSize();
    <span style="color:#dad085">this</span>.setBounds(inset, inset, screenSize.<span style="color:#dad085">width</span> <span style="color:#e28964">-</span> inset <span style="color:#e28964">*</span> <span style="color:#3387cc">2</span>, screenSize.<span style="color:#dad085">height</span> <span style="color:#e28964">-</span> inset <span style="color:#e28964">*</span> <span style="color:#3387cc">2</span>);
    <span style="color:#dad085">this</span>.desktop <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> JDesktopPane();
    <span style="color:#dad085">this</span>.setContentPane(<span style="color:#dad085">this</span>.desktop);
    <span style="color:#dad085">this</span>.setJMenuBar(<span style="color:#dad085">this</span>.createMenuBar());
    <span style="color:#dad085">this</span>.desktop.setDragMode(<span style="color:#3387cc">1</span>);
    <span style="color:#dad085">this</span>.getContentPane().<span style="color:#dad085">setBackground</span>(<span style="color:#e28964">new</span> <span style="color:#9b859d">Color</span>(<span style="color:#3387cc">15266558</span>));
    }

    protected JMenuBar createMenuBar() {
    JMenuBar menuBar <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> JMenuBar();
    JMenu <span style="color:#dad085">menu</span> <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> JMenu(<span style="color:#65b042">"แฟ้ม"</span>);
    <span style="color:#dad085">menu</span>.setMnemonic(<span style="color:#3387cc">70</span>);
    menuBar.<span style="color:#dad085">add</span>(<span style="color:#dad085">menu</span>);
    JMenu menu2 <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> JMenu(<span style="color:#65b042">"เพิ่มรายการ"</span>);
    JMenuItem FormAdd <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> JMenuItem(<span style="color:#65b042">"รายการหลัก"</span>);
    FormAdd.setMnemonic(<span style="color:#3387cc">78</span>);
    FormAdd.setAccelerator(KeyStroke.getKeyStroke(<span style="color:#3387cc">78</span>, <span style="color:#3387cc">8</span>));
    FormAdd.setActionCommand(<span style="color:#65b042">"newFormAdd"</span>);
    FormAdd.addActionListener(<span style="color:#dad085">this</span>);
    menu2.<span style="color:#dad085">add</span>(FormAdd);
    <span style="color:#dad085">menu</span>.<span style="color:#dad085">add</span>(menu2);
    FormAdd <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> JMenuItem(<span style="color:#65b042">"Quit"</span>);
    FormAdd.setMnemonic(<span style="color:#3387cc">81</span>);
    FormAdd.setAccelerator(KeyStroke.getKeyStroke(<span style="color:#3387cc">81</span>, <span style="color:#3387cc">8</span>));
    FormAdd.setActionCommand(<span style="color:#65b042">"quit"</span>);
    FormAdd.addActionListener(<span style="color:#dad085">this</span>);
    <span style="color:#dad085">menu</span>.<span style="color:#dad085">add</span>(FormAdd);
    <span style="color:#e28964">return</span> menuBar;
    }

    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> actionPerformed(ActionEvent e) {
    <span style="color:#e28964">if</span>(<span style="color:#65b042">"newFormAdd"</span>.equals(e.getActionCommand())) {
    <span style="color:#dad085">this</span>.createFormAdd();
    } <span style="color:#e28964">else</span> {
    <span style="color:#dad085">this</span>.quit();
    }

    }

    protected <span style="color:#dad085">void</span> createFormAdd() {
    FormAdd frame <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> FormAdd();
    frame.setVisible(<span style="color:#3387cc">true</span>);
    <span style="color:#dad085">this</span>.desktop.<span style="color:#dad085">add</span>(frame);
    }

    protected <span style="color:#dad085">void</span> quit() {
    <span style="color:#9b859d">System</span>.exit(<span style="color:#3387cc">0</span>);
    }

    <span style="color:#e28964">private</span> <span style="color:#e28964">static</span> <span style="color:#dad085">void</span> createAndShowGUI() {
    JFrame.setDefaultLookAndFeelDecorated(<span style="color:#3387cc">true</span>);
    Main frame <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> Main();
    frame.setDefaultCloseOperation(<span style="color:#3387cc">3</span>);
    frame.setVisible(<span style="color:#3387cc">true</span>);
    }

    <span style="color:#e28964">public</span> <span style="color:#e28964">static</span> <span style="color:#dad085">void</span> main(<span style="color:#99cf50">String</span>[] args) {
    SwingUtilities.invokeLater(<span style="color:#e28964">new</span> Runnable() {
    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> run() {
    Main.createAndShowGUI();
    }
    });
    }
    }
    </pre>
     
  15. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    FormAdd.java
    ==================================
    <pre style="background:#000;color:#f8f8f8">package com.java.idcard;

    <span style="color:#e28964">import</span> java.awt.Component;
    <span style="color:#e28964">import</span> java.awt.Dimension;
    <span style="color:#e28964">import</span> java.awt.LayoutManager;
    <span style="color:#e28964">import</span> java.awt.Toolkit;
    <span style="color:#e28964">import</span> java.awt.<span style="color:#dad085">event</span>.ActionEvent;
    <span style="color:#e28964">import</span> java.awt.<span style="color:#dad085">event</span>.ActionListener;
    <span style="color:#e28964">import</span> java.awt.<span style="color:#dad085">event</span>.KeyAdapter;
    <span style="color:#e28964">import</span> java.awt.<span style="color:#dad085">event</span>.KeyEvent;
    <span style="color:#e28964">import</span> javax.swing.Icon;
    <span style="color:#e28964">import</span> javax.swing.ImageIcon;
    <span style="color:#e28964">import</span> javax.swing.JButton;
    <span style="color:#e28964">import</span> javax.swing.JInternalFrame;
    <span style="color:#e28964">import</span> javax.swing.JLabel;
    <span style="color:#e28964">import</span> javax.swing.JOptionPane;
    <span style="color:#e28964">import</span> javax.swing.JTextField;

    <span style="color:#e28964">public</span> <span style="color:#99cf50">class</span> <span style="text-decoration:underline">FormAdd</span> <span style="color:#99cf50">extends</span> <span style="color:#9b5c2e;font-style:italic">JInternalFrame</span> {
    <span style="color:#e28964">static</span> <span style="color:#dad085">int</span> openFrameCount <span style="color:#e28964">=</span> <span style="color:#3387cc">0</span>;
    final JTextField txtIDCard;
    final JButton btnOK;
    final JButton btnRefresh;

    <span style="color:#e28964">public</span> FormAdd() {
    <span style="color:#e28964">super</span>(<span style="color:#65b042">"ตรวจสอบหมายเลขบัตรประชาชน # "</span> <span style="color:#e28964">+</span> <span style="color:#e28964">+</span><span style="color:#e28964">+</span>openFrameCount, <span style="color:#3387cc">true</span>, <span style="color:#3387cc">true</span>, <span style="color:#3387cc">true</span>, <span style="color:#3387cc">true</span>);
    <span style="color:#dad085">this</span>.pack();
    <span style="color:#dad085">this</span>.setVisible(<span style="color:#3387cc">true</span>);
    <span style="color:#dad085">this</span>.<span style="color:#dad085">setSize</span>(<span style="color:#3387cc">585</span>, <span style="color:#3387cc">180</span>);
    <span style="color:#dad085">this</span>.<span style="color:#dad085">setResizable</span>(<span style="color:#3387cc">false</span>);
    Toolkit toolkit <span style="color:#e28964">=</span> Toolkit.getDefaultToolkit();
    Dimension screenSize <span style="color:#e28964">=</span> toolkit.getScreenSize();
    <span style="color:#dad085">int</span> <span style="color:#dad085">x</span> <span style="color:#e28964">=</span> (screenSize.<span style="color:#dad085">width</span> <span style="color:#e28964">-</span> <span style="color:#dad085">this</span>.<span style="color:#dad085">getWidth</span>()) <span style="color:#e28964">/</span> <span style="color:#3387cc">2</span>;
    <span style="color:#dad085">int</span> y <span style="color:#e28964">=</span> (screenSize.<span style="color:#dad085">height</span> <span style="color:#e28964">-</span> <span style="color:#dad085">this</span>.<span style="color:#dad085">getHeight</span>()) <span style="color:#e28964">/</span> <span style="color:#3387cc">12</span>;
    <span style="color:#dad085">this</span>.setLocation(<span style="color:#dad085">x</span>, y);
    <span style="color:#dad085">this</span>.getContentPane().setLayout((LayoutManager)<span style="color:#3387cc">null</span>);
    JLabel lblIDCard <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> JLabel(<span style="color:#65b042">"เลขบัตรประชาชน : "</span>);
    lblIDCard.setBounds(<span style="color:#3387cc">10</span>, <span style="color:#3387cc">10</span>, <span style="color:#3387cc">140</span>, <span style="color:#3387cc">14</span>);
    <span style="color:#dad085">this</span>.getContentPane().<span style="color:#dad085">add</span>(lblIDCard);
    <span style="color:#dad085">this</span>.txtIDCard <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> JTextField(<span style="color:#65b042">"txtIDCard"</span>, <span style="color:#3387cc">15</span>);
    <span style="color:#dad085">this</span>.txtIDCard.setBounds(<span style="color:#3387cc">180</span>, <span style="color:#3387cc">10</span>, <span style="color:#3387cc">120</span>, <span style="color:#3387cc">25</span>);
    <span style="color:#dad085">this</span>.getContentPane().<span style="color:#dad085">add</span>(<span style="color:#dad085">this</span>.txtIDCard);
    ImageIcon iconok <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> ImageIcon(<span style="color:#65b042">"res/iconok.png"</span>);
    ImageIcon iconrefresh <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> ImageIcon(<span style="color:#65b042">"res/refresh.png"</span>);
    <span style="color:#dad085">this</span>.btnOK <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> JButton(<span style="color:#65b042">"ตกลง"</span>, iconok);
    <span style="color:#dad085">this</span>.btnOK.setPreferredSize(<span style="color:#e28964">new</span> Dimension(<span style="color:#3387cc">115</span>, <span style="color:#3387cc">45</span>));
    <span style="color:#dad085">this</span>.btnOK.setBounds(<span style="color:#3387cc">305</span>, <span style="color:#3387cc">10</span>, <span style="color:#3387cc">115</span>, <span style="color:#3387cc">45</span>);
    <span style="color:#dad085">this</span>.getContentPane().<span style="color:#dad085">add</span>(<span style="color:#dad085">this</span>.btnOK);
    <span style="color:#dad085">this</span>.btnRefresh <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> JButton(<span style="color:#65b042">"รีเฟรซข้อมูล"</span>, iconrefresh);
    <span style="color:#dad085">this</span>.btnRefresh.setPreferredSize(<span style="color:#e28964">new</span> Dimension(<span style="color:#3387cc">145</span>, <span style="color:#3387cc">45</span>));
    <span style="color:#dad085">this</span>.btnRefresh.setBounds(<span style="color:#3387cc">425</span>, <span style="color:#3387cc">10</span>, <span style="color:#3387cc">145</span>, <span style="color:#3387cc">45</span>);
    <span style="color:#dad085">this</span>.getContentPane().<span style="color:#dad085">add</span>(<span style="color:#dad085">this</span>.btnRefresh);
    <span style="color:#dad085">this</span>.btnOK.addActionListener(<span style="color:#e28964">new</span> FormAdd.ButtonListener());
    <span style="color:#dad085">this</span>.btnRefresh.addActionListener(<span style="color:#e28964">new</span> FormAdd.ButtonListener());
    <span style="color:#dad085">this</span>.txtIDCard.addActionListener(<span style="color:#e28964">new</span> FormAdd.TextListener());
    <span style="color:#dad085">this</span>.txtIDCard.setText(<span style="color:#65b042">""</span>);

    <span style="color:#dad085">this</span>.txtIDCard.addKeyListener(<span style="color:#e28964">new</span> KeyAdapter() {
    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> keyReleased(KeyEvent e) {
    JTextField txtIDCard <span style="color:#e28964">=</span> (JTextField)e.<span style="color:#dad085">getSource</span>();
    <span style="color:#99cf50">String</span> str <span style="color:#e28964">=</span> txtIDCard.<span style="color:#dad085">getText</span>();
    txtIDCard.setText(str.replaceAll(<span style="color:#65b042">"[^0-9]"</span>, <span style="color:#65b042">""</span>));
    }
    });
    }

    <span style="color:#e28964">private</span> <span style="color:#99cf50">Boolean</span> VerifyPeopleID(<span style="color:#99cf50">String</span> PID) {
    <span style="color:#e28964">if</span>(PID.trim().<span style="color:#dad085">length</span>() <span style="color:#e28964">!</span><span style="color:#e28964">=</span> <span style="color:#3387cc">13</span>) {
    <span style="color:#e28964">return</span> <span style="color:#99cf50">Boolean</span>.<span style="color:#dad085">valueOf</span>(<span style="color:#3387cc">false</span>);
    } <span style="color:#e28964">else</span> {
    <span style="color:#dad085">int</span> sumValue <span style="color:#e28964">=</span> <span style="color:#3387cc">0</span>;

    <span style="color:#dad085">int</span> v;
    <span style="color:#e28964">for</span>(v <span style="color:#e28964">=</span> <span style="color:#3387cc">0</span>; v &lt; PID.<span style="color:#dad085">length</span>() <span style="color:#e28964">-</span> <span style="color:#3387cc">1</span>; <span style="color:#e28964">+</span><span style="color:#e28964">+</span>v) {
    sumValue <span style="color:#e28964">+</span><span style="color:#e28964">=</span> Integer.<span style="color:#dad085">parseInt</span>(<span style="color:#99cf50">String</span>.<span style="color:#dad085">valueOf</span>(PID.<span style="color:#dad085">charAt</span>(v))) <span style="color:#e28964">*</span> (<span style="color:#3387cc">13</span> <span style="color:#e28964">-</span> v);
    }

    v <span style="color:#e28964">=</span> <span style="color:#3387cc">11</span> <span style="color:#e28964">-</span> sumValue <span style="color:#e28964">%</span> <span style="color:#3387cc">11</span>;
    <span style="color:#e28964">return</span> PID.<span style="color:#dad085">charAt</span>(<span style="color:#3387cc">12</span>) <span style="color:#e28964">-</span> <span style="color:#3387cc">48</span> <span style="color:#e28964">=</span><span style="color:#e28964">=</span> v <span style="color:#e28964">%</span> <span style="color:#3387cc">10</span><span style="color:#e28964">?</span><span style="color:#99cf50">Boolean</span>.<span style="color:#dad085">valueOf</span>(<span style="color:#3387cc">true</span>)<span style="color:#e28964">:</span><span style="color:#99cf50">Boolean</span>.<span style="color:#dad085">valueOf</span>(<span style="color:#3387cc">false</span>);
    }
    }

    <span style="color:#e28964">private</span> <span style="color:#99cf50">class</span> <span style="text-decoration:underline">ButtonListener</span> <span style="color:#e28964">implements</span> ActionListener {
    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> actionPerformed(ActionEvent ae) {
    <span style="color:#9b859d">Object</span> <span style="color:#dad085">source</span> <span style="color:#e28964">=</span> ae.<span style="color:#dad085">getSource</span>();
    <span style="color:#e28964">if</span>(<span style="color:#dad085">source</span> <span style="color:#e28964">=</span><span style="color:#e28964">=</span> FormAdd.<span style="color:#dad085">this</span>.btnRefresh) {
    FormAdd.<span style="color:#dad085">this</span>.txtIDCard.setText(<span style="color:#65b042">""</span>);
    FormAdd.<span style="color:#dad085">this</span>.txtIDCard.requestFocus();
    }

    <span style="color:#e28964">if</span>(<span style="color:#dad085">source</span> <span style="color:#e28964">=</span><span style="color:#e28964">=</span> FormAdd.<span style="color:#dad085">this</span>.btnOK) {
    <span style="color:#e28964">if</span>(FormAdd.<span style="color:#dad085">this</span>.VerifyPeopleID(FormAdd.<span style="color:#dad085">this</span>.txtIDCard.<span style="color:#dad085">getText</span>()).booleanValue()) {
    JOptionPane.showMessageDialog((Component)<span style="color:#3387cc">null</span>, <span style="color:#65b042">"รหัสบัตรประชาชนถูกต้อง"</span>);
    } <span style="color:#e28964">else</span> {
    JOptionPane.showMessageDialog((Component)<span style="color:#3387cc">null</span>, <span style="color:#65b042">"รหัสบัตรประชาชนไม่ถูกต้อง"</span>);
    }
    }
    }
    }

    <span style="color:#e28964">private</span> <span style="color:#99cf50">class</span> <span style="text-decoration:underline">TextListener</span> <span style="color:#e28964">implements</span> ActionListener {
    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> actionPerformed(ActionEvent ae) {
    <span style="color:#9b859d">Object</span> <span style="color:#dad085">source</span> <span style="color:#e28964">=</span> ae.<span style="color:#dad085">getSource</span>();
    <span style="color:#e28964">if</span>(<span style="color:#dad085">source</span> <span style="color:#e28964">=</span><span style="color:#e28964">=</span> FormAdd.<span style="color:#dad085">this</span>.txtIDCard) {
    <span style="color:#e28964">if</span>(FormAdd.<span style="color:#dad085">this</span>.txtIDCard.<span style="color:#dad085">getText</span>().equals(<span style="color:#65b042">""</span>)) {
    JOptionPane.showMessageDialog((Component)<span style="color:#3387cc">null</span>, <span style="color:#65b042">"กรุณาใส่เลขบัตรประชาชนก่อนและกดปุ่มตกลง"</span>, <span style="color:#65b042">"รายงานสถานะ"</span>, <span style="color:#3387cc">3</span>, (Icon)<span style="color:#3387cc">null</span>);
    FormAdd.<span style="color:#dad085">this</span>.txtIDCard.requestFocus();
    } <span style="color:#e28964">else</span> {
    FormAdd.<span style="color:#dad085">this</span>.btnOK.doClick();
    }
    }
    }
    }
    }

    </pre>
     
  16. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    ตัวใหม่ Java IntelliJ 15.0.2

    ดีกว่าเดิมและเสถียรกว่าเดิม
     

    ไฟล์ที่แนบมา:

    • IntelliJ_1.png
      IntelliJ_1.png
      ขนาดไฟล์:
      665.1 KB
      เปิดดู:
      186
    • IntelliJ_2.png
      IntelliJ_2.png
      ขนาดไฟล์:
      130 KB
      เปิดดู:
      259
  17. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    วิธีเช็คเลขบัตรประชาชน ผ่านโปรแกรม MS Excel
    (ตรวจสอบหมายเลขบัตรประชาชน จากเว็ป welfare ของกรมส่งเสริมการปกครองท้องถิ่น)
    ============================================
    ใช้คำสั่ง
    ==========
    =IF(VALUE(RIGHT(E9,1))=MOD(11-MOD(SUMPRODUCT(MID(E9,ROW($E$1:$E$12),1)*{13;12;11;10;9;8;7;6;5;4;3;2}),11),10),"ถูก","ผิด")
     

    ไฟล์ที่แนบมา:

    • CHK.png
      ขนาดไฟล์:
      0 bytes
      เปิดดู:
      126
    • CHK2.png
      ขนาดไฟล์:
      0 bytes
      เปิดดู:
      124
    • pic.png
      pic.png
      ขนาดไฟล์:
      256.8 KB
      เปิดดู:
      209
    แก้ไขครั้งล่าสุดโดยผู้ดูแล: 15 พฤษภาคม 2016
  18. ledphong

    ledphong เป็นที่รู้จักกันดี

    วันที่สมัครสมาชิก:
    28 มีนาคม 2009
    โพสต์:
    1,425
    ค่าพลัง:
    +165
    Code Java IntelliJ IDEA 15.0.4 (Android Mobile)
    =============================
    <pre style="background:#000;color:#f8f8f8">package com.nongsungtai.myapplication1.pla2017;

    <span style="color:#e28964">import</span> android.app.AlertDialog;
    <span style="color:#e28964">import</span> android.app.Fragment;
    <span style="color:#e28964">import</span> android.<span style="color:#dad085">os</span>.Bundle;
    <span style="color:#e28964">import</span> android.view.LayoutInflater;
    <span style="color:#e28964">import</span> android.view.View;
    <span style="color:#e28964">import</span> android.view.ViewGroup;
    <span style="color:#e28964">import</span> android.widget.<span style="color:#9b859d">Button</span>;
    <span style="color:#e28964">import</span> android.widget.Spinner;
    <span style="color:#e28964">import</span> android.widget.AdapterView;
    <span style="color:#e28964">import</span> android.widget.AdapterView.OnItemSelectedListener;
    <span style="color:#e28964">import</span> android.widget.TextView;
    <span style="color:#e28964">import</span> android.<span style="color:#dad085">content</span>.DialogInterface;
    <span style="color:#e28964">import</span> android.view.KeyEvent;
    <span style="color:#e28964">import</span> android.widget.<span style="color:#e28964">*</span>;
    <span style="color:#e28964">import</span> android.widget.Toast;

    <span style="color:#e28964">public</span> <span style="color:#99cf50">class</span> <span style="text-decoration:underline">menu1_FragmentCHK</span> <span style="color:#99cf50">extends</span> <span style="color:#9b5c2e;font-style:italic">Fragment</span> <span style="color:#e28964">implements</span> OnItemSelectedListener{
    View v;
    TextView ViewShow;
    <span style="color:#9b859d">Button</span> Calculate,Refresh,btnExit;
    EditText TextNumber;
    Spinner spinner;
    <span style="color:#99cf50">String</span>[] <span style="color:#dad085">items</span> <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> <span style="color:#99cf50">String</span>[] {<span style="color:#65b042">"เลขบัตร : เช็คเลขบัตร ปช."</span>,
    <span style="color:#65b042">"ประชากร : ความคลาดเคลื่อน 1%(Doctor)"</span>,
    <span style="color:#65b042">"ประชากร : ความคลาดเคลื่อน 5%(Social)"</span>};

    <span style="color:#e28964">public</span> boolean <span style="color:#dad085">onKeyDown</span>(<span style="color:#dad085">int</span> keyCode, KeyEvent <span style="color:#dad085">event</span>) { <span style="color:#aeaeae;font-style:italic">// this is override method</span>
    <span style="color:#e28964">if</span>(keyCode <span style="color:#e28964">=</span><span style="color:#e28964">=</span> KeyEvent.KEYCODE_BACK){
    onBackPressed(); <span style="color:#aeaeae;font-style:italic">// call the function below</span>
    <span style="color:#aeaeae;font-style:italic">//return true;</span>
    }
    <span style="color:#e28964">return</span> <span style="color:#3387cc">false</span>;
    }

    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> onBackPressed() {
    AlertDialog.Builder dialog <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> AlertDialog.Builder(v.getContext());<span style="color:#aeaeae;font-style:italic">//เดิม new AlertDialog.Builder(getView().getContext());</span>
    dialog.<span style="color:#dad085">setTitle</span>(<span style="color:#65b042">"Exit?"</span>); <span style="color:#aeaeae;font-style:italic">// set title</span>
    dialog.<span style="color:#dad085">setMessage</span>(<span style="color:#65b042">"คุณต้องการออกหรือไม่?"</span>); <span style="color:#aeaeae;font-style:italic">// set message</span>
    dialog.setPositiveButton(<span style="color:#65b042">"ตกลง"</span>,
    <span style="color:#e28964">new</span> DialogInterface.OnClickListener() {
    @Override
    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> onClick(DialogInterface dialog, <span style="color:#dad085">int</span> which) {
    <span style="color:#aeaeae;font-style:italic">//FragmentTab1.this.onBackPressed(); // when click OK button, finish current activity!</span>
    getActivity().finish();
    }
    });
    dialog.setNegativeButton(<span style="color:#65b042">"ยกเลิก"</span>,
    <span style="color:#e28964">new</span> DialogInterface.OnClickListener() {
    @Override
    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> onClick(DialogInterface dialog, <span style="color:#dad085">int</span> which) {
    Toast.makeText(getActivity(), <span style="color:#65b042">"Cancelled"</span>, Toast.LENGTH_SHORT).<span style="color:#dad085">show</span>(); <span style="color:#aeaeae;font-style:italic">// just show a Toast, do nothing else</span>
    }
    });
    dialog.create().<span style="color:#dad085">show</span>();
    }

    <span style="color:#e28964">private</span> boolean <span style="color:#dad085">isEmpty</span>(EditText TextNumber) {
    <span style="color:#e28964">return</span> TextNumber.<span style="color:#dad085">getText</span>().<span style="color:#dad085">toString</span>().trim().<span style="color:#dad085">length</span>() <span style="color:#e28964">=</span><span style="color:#e28964">=</span> <span style="color:#3387cc">0</span>;
    }

    <span style="color:#e28964">private</span> <span style="color:#99cf50">Boolean</span> VerifyPeopleID(<span style="color:#99cf50">String</span> PID) {
    <span style="color:#e28964">if</span>(PID.trim().<span style="color:#dad085">length</span>() <span style="color:#e28964">!</span><span style="color:#e28964">=</span> <span style="color:#3387cc">13</span>) {
    <span style="color:#e28964">return</span> <span style="color:#dad085">isEmpty</span>(TextNumber);<span style="color:#aeaeae;font-style:italic">//false</span>
    } <span style="color:#e28964">else</span> {
    <span style="color:#dad085">int</span> sumValue <span style="color:#e28964">=</span> <span style="color:#3387cc">0</span>;

    <span style="color:#dad085">int</span> v;
    <span style="color:#e28964">for</span>(v <span style="color:#e28964">=</span> <span style="color:#3387cc">0</span>; v &lt; PID.<span style="color:#dad085">length</span>() <span style="color:#e28964">-</span> <span style="color:#3387cc">1</span>; <span style="color:#e28964">+</span><span style="color:#e28964">+</span>v) {
    sumValue <span style="color:#e28964">+</span><span style="color:#e28964">=</span> Integer.<span style="color:#dad085">parseInt</span>(<span style="color:#99cf50">String</span>.<span style="color:#dad085">valueOf</span>(PID.<span style="color:#dad085">charAt</span>(v))) <span style="color:#e28964">*</span> (<span style="color:#3387cc">13</span> <span style="color:#e28964">-</span> v);
    }

    v <span style="color:#e28964">=</span> <span style="color:#3387cc">11</span> <span style="color:#e28964">-</span> sumValue <span style="color:#e28964">%</span> <span style="color:#3387cc">11</span>;
    <span style="color:#e28964">return</span> PID.<span style="color:#dad085">charAt</span>(<span style="color:#3387cc">12</span>) <span style="color:#e28964">-</span> <span style="color:#3387cc">48</span> <span style="color:#e28964">=</span><span style="color:#e28964">=</span> v <span style="color:#e28964">%</span> <span style="color:#3387cc">10</span><span style="color:#e28964">?</span><span style="color:#99cf50">Boolean</span>.<span style="color:#dad085">valueOf</span>(<span style="color:#3387cc">true</span>)<span style="color:#e28964">:</span><span style="color:#99cf50">Boolean</span>.<span style="color:#dad085">valueOf</span>(<span style="color:#3387cc">false</span>);
    }
    }

    @Override
    <span style="color:#e28964">public</span> View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle saveInstanceStates){
    v <span style="color:#e28964">=</span> inflater.inflate(R.layout.menu1_layoutchk,container,<span style="color:#3387cc">false</span>);
    <span style="color:#aeaeae;font-style:italic">//==========Coding============================================</span>
    <span style="color:#aeaeae;font-style:italic">//=======SpinnerAlpha=========================================</span>
    spinner <span style="color:#e28964">=</span> (Spinner) v.findViewById(R.id.mySpinner);

    ArrayAdapter&lt;<span style="color:#99cf50">String</span>> dataAdapter <span style="color:#e28964">=</span> <span style="color:#e28964">new</span> ArrayAdapter&lt;<span style="color:#99cf50">String</span>>(<span style="color:#dad085">this</span>.getActivity(),android.R.layout.simple_spinner_item, <span style="color:#dad085">items</span>);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(dataAdapter);
    <span style="color:#aeaeae;font-style:italic">//=============Button=========================================</span>
    TextNumber <span style="color:#e28964">=</span> (EditText) v.findViewById(R.id.editTextNumber);
    Calculate <span style="color:#e28964">=</span> (<span style="color:#9b859d">Button</span>) v.findViewById(R.id.btnCalculate);
    Refresh <span style="color:#e28964">=</span> (<span style="color:#9b859d">Button</span>) v.findViewById(R.id.btnRefresh);
    btnExit <span style="color:#e28964">=</span> (<span style="color:#9b859d">Button</span>) v.findViewById(R.id.btnExit);
    ViewShow <span style="color:#e28964">=</span> (TextView) v.findViewById(R.id.txtViewShow);

    Calculate.setOnClickListener(<span style="color:#e28964">new</span> <span style="color:#9b859d">Button</span>.OnClickListener(){
    @Override
    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> onClick(View v) {
    <span style="color:#e28964">if</span>(TextNumber.<span style="color:#dad085">getText</span>().<span style="color:#dad085">toString</span>().trim().<span style="color:#dad085">length</span>() <span style="color:#e28964">=</span><span style="color:#e28964">=</span> <span style="color:#3387cc">0</span>){
    ViewShow.setText(<span style="color:#65b042">"***กรุณาใส่ตัวเลขด้วยครับ***"</span>);
    Toast.makeText(getActivity(), <span style="color:#65b042">"กรุณาใส่ตัวเลขด้วยครับ"</span>,Toast.LENGTH_SHORT).<span style="color:#dad085">show</span>();
    <span style="color:#aeaeae;font-style:italic">//TextNumber.getText().toString().trim().equals("")</span>
    <span style="color:#e28964">return</span>;
    }
    double tax95,tax99 <span style="color:#e28964">=</span> <span style="color:#3387cc">0</span>;
    double txtNumber <span style="color:#e28964">=</span> <span style="color:#3387cc">0</span>;
    <span style="color:#dad085">try</span>{
    <span style="color:#99cf50">String</span> converter <span style="color:#e28964">=</span> TextNumber.<span style="color:#dad085">getText</span>().<span style="color:#dad085">toString</span>().trim();
    txtNumber <span style="color:#e28964">=</span> Double.parseDouble(converter);
    <span style="color:#dad085">int</span> idx <span style="color:#e28964">=</span> spinner.getSelectedItemPosition();
    <span style="color:#aeaeae;font-style:italic">//int hardCover = Integer.parseInt(converter.substring(1, 2).trim());</span>
    <span style="color:#99cf50">String</span> str <span style="color:#e28964">=</span> converter.<span style="color:#dad085">substring</span>(<span style="color:#3387cc">1</span>,<span style="color:#3387cc">2</span>).trim();
    <span style="color:#aeaeae;font-style:italic">//==========Random Sampling====================</span>
    tax95 <span style="color:#e28964">=</span> (txtNumber)<span style="color:#e28964">/</span>(<span style="color:#3387cc">1</span><span style="color:#e28964">+</span>(txtNumber<span style="color:#e28964">*</span><span style="color:#3387cc">0.05</span><span style="color:#e28964">*</span><span style="color:#3387cc">0.05</span>));
    tax99 <span style="color:#e28964">=</span> (txtNumber)<span style="color:#e28964">/</span>(<span style="color:#3387cc">1</span><span style="color:#e28964">+</span>(txtNumber<span style="color:#e28964">*</span><span style="color:#3387cc">0.01</span><span style="color:#e28964">*</span><span style="color:#3387cc">0.01</span>));
    <span style="color:#aeaeae;font-style:italic">//==========IDCard Check=======================</span>

    <span style="color:#aeaeae;font-style:italic">//=============================================</span>
    <span style="color:#e28964">switch</span> (idx){
    <span style="color:#e28964">case</span> <span style="color:#3387cc">0</span><span style="color:#e28964">:</span> <span style="color:#aeaeae;font-style:italic">//เช็คเลขบัตร ปช.</span>
    <span style="color:#e28964">if</span> ((TextNumber.<span style="color:#dad085">getText</span>().<span style="color:#dad085">toString</span>().<span style="color:#dad085">length</span>() <span style="color:#e28964">=</span><span style="color:#e28964">=</span> <span style="color:#3387cc">13</span>)) {<span style="color:#aeaeae;font-style:italic">//</span>
    <span style="color:#e28964">if</span>(VerifyPeopleID(TextNumber.<span style="color:#dad085">getText</span>().<span style="color:#dad085">toString</span>().trim()))
    ViewShow.setText(<span style="color:#65b042">"***รหัสบัตรประชาชนถูกต้อง"</span>);
    <span style="color:#e28964">else</span> {
    ViewShow.setText(<span style="color:#65b042">"***รหัสบัตรประชาชนไม่ถูกต้อง***"</span>);
    }
    } <span style="color:#e28964">else</span> <span style="color:#e28964">if</span>((TextNumber.<span style="color:#dad085">getText</span>().<span style="color:#dad085">toString</span>().<span style="color:#dad085">length</span>() > <span style="color:#3387cc">13</span>)){
    ViewShow.setText(<span style="color:#65b042">"***ใส่รหัสบัตรประชาชนมากกว่า 13 ตัว***"</span>);
    TextNumber.requestFocus();
    <span style="color:#e28964">return</span> ;
    } <span style="color:#e28964">else</span> {
    ViewShow.setText(<span style="color:#65b042">"***ใส่รหัสบัตรประชาชนไม่ครบ 13 ตัว***"</span>);
    TextNumber.requestFocus();
    <span style="color:#e28964">return</span> ;
    }

    <span style="color:#e28964">break</span>;
    <span style="color:#e28964">case</span> <span style="color:#3387cc">1</span><span style="color:#e28964">:</span><span style="color:#aeaeae;font-style:italic">//Random Sampling 99% (Doctor)</span>
    ViewShow.setText(<span style="color:#65b042">"***ต้องถ่ายเอกสาร = "</span> <span style="color:#e28964">+</span> <span style="color:#99cf50">String</span>.<span style="color:#dad085">valueOf</span>(<span style="color:#9b859d">Math</span>.<span style="color:#dad085">round</span>(tax99))<span style="color:#e28964">+</span> <span style="color:#65b042">" ชุด"</span>);
    <span style="color:#e28964">break</span>;
    <span style="color:#e28964">case</span> <span style="color:#3387cc">2</span><span style="color:#e28964">:</span> <span style="color:#aeaeae;font-style:italic">//Random Sampling 95% (Social)</span>
    ViewShow.setText(<span style="color:#65b042">"***ต้องถ่ายเอกสาร = "</span> <span style="color:#e28964">+</span> <span style="color:#99cf50">String</span>.<span style="color:#dad085">valueOf</span>(<span style="color:#9b859d">Math</span>.<span style="color:#dad085">round</span>(tax95))<span style="color:#e28964">+</span> <span style="color:#65b042">" ชุด"</span>);
    <span style="color:#e28964">break</span>;
    }
    }<span style="color:#dad085">catch</span>(Exception e){
    Toast.makeText(getActivity(), <span style="color:#65b042">"Error,"</span><span style="color:#e28964">+</span>e.<span style="color:#dad085">getMessage</span>(),Toast.LENGTH_SHORT).<span style="color:#dad085">show</span>();
    }
    }
    });

    Refresh.setOnClickListener(<span style="color:#e28964">new</span> <span style="color:#9b859d">Button</span>.OnClickListener(){
    @Override
    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> onClick(View v) {
    TextNumber.setText(<span style="color:#65b042">""</span>);
    ViewShow.setText(<span style="color:#65b042">""</span>);
    TextNumber.requestFocus();
    }
    });

    btnExit.setOnClickListener(<span style="color:#e28964">new</span> <span style="color:#9b859d">Button</span>.OnClickListener(){
    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> onClick(View v) {
    onBackPressed();
    }
    });
    <span style="color:#aeaeae;font-style:italic">//============================================================</span>
    <span style="color:#e28964">return</span> v;
    }

    @Override
    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> onItemSelected(AdapterView&lt;<span style="color:#e28964">?</span>> parent, View view, <span style="color:#dad085">int</span> <span style="color:#dad085">position</span>, long id) {
    <span style="color:#aeaeae;font-style:italic">// TODO Auto-generated method stub</span>
    <span style="color:#aeaeae;font-style:italic">//spinner.setText("Your Selected : " + arr[position]);</span>
    }


    @Override
    <span style="color:#e28964">public</span> <span style="color:#dad085">void</span> onNothingSelected(AdapterView&lt;<span style="color:#e28964">?</span>> parent) {
    <span style="color:#aeaeae;font-style:italic">// TODO Auto-generated method stub</span>

    }
    }
    </pre>
     

แชร์หน้านี้

Loading...