1. 程式人生 > >組織機構代碼生成器

組織機構代碼生成器

window += 辦公 else if orm urn exce rgs str

/** * 全國組織機構代碼校驗碼生成程序 * 00251805 7 中共溫州市委辦公室 * 00251807 3 中共溫州市委組織部 * 00251808 1 中共溫州市委老幹部局 沈偉 2002-04-09 2008-05-05 0.0000 詳細 * 00251809 X **/ public class G_Code { public static char[] a = new char[8]; public String jy(char[] a) { int[] ww = { 3, 7, 9, 10, 5, 8, 4, 2 }; int[] cc = new int[8]; int DD = 0; int C9 = 0; for (int i = 0; i < 8; i++) { cc[i] = a[i]; if (47 < cc[i] && cc[i] < 58) cc[i] = cc[i] - 48; else cc[i] = cc[i] - 65; } for (int i = 0; i < 8; i++) { DD += cc[i] * ww[i]; } C9 = 11 - DD % 11; if (C9 == 10) { for (int i = 0; i < 8; i++) System.out.print(G_Code.a[i]); System.out.println("-X"); return new String(a) + "-X"; } else if (C9 == 11) { for (int i = 0; i < 8; i++) System.out.print(G_Code.a[i]); System.out.println("-" + (char) (48)); return new String(a) + "-" + (char) (48); } else { for (int i = 0; i < 8; i++) System.out.print(G_Code.a[i]); System.out.println("-" + (char) (C9 + 48)); return new String(a) + "-" + (char) (C9 + 48); } } /* * public static void main(String[] args){ try{ * * System.out.println("請輸入長8位的本體代碼!"); for(int i=0;i<8;i++){ * * * G_Code.a[i] =(char)System.in.read(); } }catch (IOException e) { } G_Code * G=new G_Code(); G.jy(a); * * } */ } import java.awt.Color; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; @SuppressWarnings("serial") public class UI extends JFrame implements ActionListener{ JPanel panel; JLabel oneLabel; JButton genButton; JTextField oneTextField; JTextField threeTextField; public UI() { super("組織機構代碼生成器"); panel = new JPanel(); panel.setBackground(new Color(192, 192, 192)); panel.setLayout(new FlowLayout()); this.add(panel); oneLabel = new JLabel("請輸入長8位的本體代碼!"); oneTextField = new JTextField(15); threeTextField = new JTextField(15); genButton = new JButton("生成校驗碼"); oneTextField.addActionListener(this); genButton.addActionListener(this); panel.add(oneLabel); panel.add(oneTextField); panel.add(genButton); panel.add(threeTextField); this.setBounds(200, 100, 200, 240); this.setResizable(true); this.setVisible(true); this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { super.windowClosing(e); System.exit(0); } }); } public static void main(String[] args) { new UI(); } @Override public void actionPerformed(ActionEvent e) { String one = oneTextField.getText().trim(); char[] a = new char[8]; for (int i = 0; i<8 ; i++) a[i] = one.charAt(i); String all = new G_Code().jy(a); threeTextField.setText(String.valueOf(all)); } }

組織機構代碼生成器