Читайте также:
|
|
import java.awt.Color;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import static java.awt.image.ImageObserver.WIDTH;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class JAuthorization extends javax.swing.JFrame {
/**
* Creates new form JAuthorization
*/
public JAuthorization() {
initComponents();
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
this.getContentPane().setBackground(new Color(205,175,192));
this.setTitle("Авторизація");
// підєднуємося до бази даних
try {
String sIP = "127.0.0.1";
String sDatabase ="doctor_db";
String sRoot = "root";
String sPass ="";
Properties p = new Properties();
p.setProperty("user",sRoot);
p.setProperty("password",sPass);
// налаштовуємо вивід тексту з кодуванням кирилиці
p.setProperty("useUnicode","true");
p.setProperty("characterEncoding","cp1251");
Class.forName("com.mysql.jdbc.Driver");
JMain.con = DriverManager.getConnection("jdbc:mysql://" + sIP + "/" + sDatabase,p);
// SearchData("");
} catch (ClassNotFoundException ex) {
JOptionPane.showMessageDialog(null, "Проблема в підключенні: " + ex);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Проблема в підключенні: " + ex);
Logger.getLogger(JMain.class.getName()).log(Level.SEVERE, null, ex);
}
Змн. |
Арк. |
№ докум. |
Підпис |
Дата |
Арк. |
КП.КДК 12/021.15.000.ПЗ |
Розроб. |
Федарка Ю.І |
Перевір. |
Лукаіська А.В |
Реценз. |
Н. Контр. |
Попович М.Т |
Затверд. |
Щербан І.І |
Довідник меломана Додаток 1. Лістинг |
Літ. |
Аркушів |
ПГК ДВНЗ "УжНУ" КН-31 |
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
txtLogin = new javax.swing.JTextField();
txtPass = new javax.swing.JTextField();
btExit = new javax.swing.JButton();
btEnter = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
jLabel1.setText("Логін");
jLabel2.setText("Пароль");
btExit.setText("Вихід");
btExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btExitActionPerformed(evt);
}
});
btEnter.setText("Увійти");
btEnter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btEnterActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(btEnter)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.
RELATED)
.addComponent(btExit))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtLogin)
.addComponent(txtPass, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE))))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btExit)
.addComponent(btEnter))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btExitActionPerformed(java.awt.event.ActionEvent evt) {
Runtime.getRuntime().halt(0);
}
btEnterActionPerformed(java.awt.event.ActionEvent evt) {
String r1 = null;
String r2 = null;
String sql = "SELECT * FROM tb_authorization WHERE id=1";
try {
Змн. |
Арк. |
№ докум. |
Підпис |
Дата |
Арк. |
КП.КДК12/021.15.000.ПЗ КП.КДК12/002.ПЗ |
try (Statement stmt = JMain.con.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
while (rs.next()) {
r1 = rs.getString("login");
r2 = rs.getString("password");
}
if (txtLogin.getText().equals(r1))
{
if (txtPass.getText().equals(r2))
{
JMain.main(null);
this.dispose();
}
else
{
JOptionPane.showMessageDialog(this, "Введіть правильний пароль", "Помилка", WIDTH, null);
}
}
else
{
JOptionPane.showMessageDialog(this, "Введіть правильний логін", "Помилка", WIDTH, null);
}
}
} catch (SQLException | HeadlessException ex) {
JOptionPane.showMessageDialog(this, ex, ex.getMessage(), WIDTH, null);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info: javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(JAuthorization.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(JAuthorization.class.getName(
)).log(java.util.logging.Level.SEVERE, null, ex);
Змн. |
Арк. |
№ докум. |
Підпис |
Дата |
Арк. |
КП.КДК12/021.15.000.ПЗ КП.КДК12/002.ПЗ |
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(JAuthorization.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(JAuthorization.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new JAuthorization().setVisible(true);
}
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
import static java.awt.image.ImageObserver.WIDTH;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class JMain extends javax.swing.JFrame {
public static Connection con = null;
public static String sTable = "tb_drugs"; //**************************************************************//
// очищує таблицю
//**************************************************************//
private void ClearTable()
{
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
for(int i = model.getRowCount() - 1; i >= 0; i--)
{
model.removeRow(i);
}
} //**************************************************************//
// вивід типу препарату
//****************************************************
**********//
private String GetTypeByName(String sName)
{
String result = null;
String sql = "SELECT * FROM " + sTable + " WHERE drugname like '" + sName + "'";
try {
try (Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
// отримуємо інформацію з колонки
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
// дадаємо препарати з бази даних до нашої таблиці
while (rs.next()) {
result = rs.getString(4);
}
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex, ex.getMessage(), WIDTH, null);
}
return result;
}
//**************************************************************//
// вивід інформації про препарат
//**************************************************************//
private String GetInfoByDrugName(String sName)
{
String result = null;
String sql = "SELECT * FROM " + sTable + " WHERE drugname like '" + sName + "'";
try {
try (Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
// отримуємо інформацію з колонки
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
// дадаємо препарати з бази даних до нашої таблиці
while (rs.next()) {
result = rs.getString(3);
}
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex, ex.getMessage(), WIDTH, null);
}
return result;
}
//**************************************************************//
//
//**************************************************************//
private String GetFormbyDrugName(String sName)
{
String result = null;
String sql = "SELECT * FROM " + sTable + " WHERE drugname like '" + sName + "'";
try {
try (Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
// отримуємо інформацію з колонки
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
// дадаємо препарати з бази даних до нашої таблиці
while (rs.next()) {
result = rs.getString(5);
}
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex, ex.getMessage(), WIDTH, null);
}
return result;
}
//**************************************************************//
//
//**************************************************************//
private String GetEffectbyDrugName(String sName)
{
String result = null;
String sql = "SELECT * FROM " + sTable + " WHERE drugname like '" + sName + "'";
try {
try (Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
// отримуємо інформацію з колонки
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
// дадаємо препарати з бази даних до нашої таблиці
while (rs.next()) {
result = rs.getString(6);
}
Змн. |
Арк. |
№ докум. |
Підпис |
Дата |
Арк. |
КП.КДК12/021.15.000.ПЗ КП.КДК12/002.ПЗ |
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex, ex.getMessage(), WIDTH, null);
}
return result;
}
//**************************************************************//
//
//**************************************************************//
private String GetSaveDrugName(String sName)
{
String result = null;
String sql = "SELECT * FROM " + sTable + " WHERE drugname like '" + sName + "'";
try {
try (Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
// отримуємо інформацію з колонки
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
// дадаємо препарати з бази даних до нашої таблиці
while (rs.next()) {
result = rs.getString(7);
}
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex, ex.getMessage(), WIDTH, null);
}
return result;
}
//**************************************************************//
// вивід інформації про препарат
//**************************************************************//
private int GetID(String sName, String sInfo)
{
int result = 0;
String sql = "SELECT * FROM " + sTable + " WHERE drugname like '" + sName + "' AND druginfo like '" + sInfo + "'";
try {
try (Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
// отримуємо інформацію з колонки
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
// дадаємо препарати з бази даних до нашої таблиці
while (rs.next()) {
result = rs.getInt(1);
}
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex, ex.getMessage(), WIDTH, null);
}
return result;
}
//**************************************************************//
// пошук даних в списку препаратів
//**************************************************************//
public void SearchData(String srchArg, String strArg2)
{
ClearTable();
String sql = "SELECT * FROM " + sTable + " WHERE drugname like '" + srchArg + "%' AND drugtype like '" + strArg2 + "%'";
try {
try (Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
// отримуємо інформацію з колонки
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
DefaultTableModel tm = (DefaultTableModel) jTable1.getModel();
// очищаємо таблицю
ClearTable();
// дадаємо препарати з бази даних до нашої таблиці
while (rs.next()) {
String[] a = new String[columnCount];
for(int i = 1; i < columnCount; i++) {
a[i-1] = rs.getString(i+1);
}
tm.addRow(a);
}
tm.fireTableDataChanged();
// забороняємо зміну полів таблиці в реальному часі
for (int c = 0; c < tm.getColumnCount(); c++)
{
Class<?> col_class = tm.getColumnClass(c);
jTable1.setDefaultEditor(col_class, null);
}
}
} catch (Exception ex) {
Змн. |
Арк. |
№ докум. |
Підпис |
Дата |
Арк. |
КП.КДК12/021.15.000.ПЗ КП.КДК12/002.ПЗ |
JOptionPane.showMessageDialog(this, ex, ex.getMessage(), WIDTH, null);
}
}
//**************************************************************//
// пошук даних в списку препаратів по алфавіту
//**************************************************************//
private void SearchAlphabetic(Character srchArg)
{
SearchData(srchArg.toString(), "");
}
// ***************************************************************************************************** //
public JMain() {
initComponents();
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2);
this.getContentPane().setBackground(new Color(205,175,192));
this.setTitle("Довідник лікаря");
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
txtSearch = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
jLabel13 = new javax.swing.JLabel();
jLabel14 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jLabel16 = new javax.swing.JLabel();
jLabel17 = new javax.swing.JLabel();
jLabel18 = new javax.swing.JLabel();
jLabel19 = new javax.swing.JLabel();
jLabel20 = new javax.swing.JLabel();
jLabel21 = new javax.swing.JLabel();
jLabel22 = new javax.swing.JLabel();
jLabel23 = new javax.swing.JLabel();
jLabel24 = new javax.swing.JLabel();
jLabel25 = new javax.swing.JLabel();
jLabel26 = new javax.swing.JLabel();
jLabel27 = new javax.swing.JLabel();
jLabel28 = new javax.swing.JLabel();
jLabel29 = new javax.swing.JLabel();
jLabel30 = new javax.swing.JLabel();
jLabel31 = new javax.swing.JLabel();
jLabel32 = new javax.swing.JLabel();
jLabel33 = new javax.swing.JLabel();
cbDrugType = new javax.swing.JComboBox();
jLabel34 = new javax.swing.JLabel();
jButton7 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
txtSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtSearchActionPerformed(evt);
}
});
jLabel1.setText("Введіть назву препарату");
jButton1.setText("Пошук");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Список препаратів"
}
));
jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
jTable1MousePressed(evt);
}
});
jScrollPane1.setViewportView(jTable1);
jButton2.setText("Додати препарат");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Змн. |
Арк. |
№ докум. |
Підпис |
Дата |
Арк. |
КП.КДК12/021.15.000.ПЗ КП.КДК12/002.ПЗ |
}
});
jButton3.setText("Видалити препарат");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton5.setText("Про програму");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jButton6.setText("Вивід всього списку препаратів");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel2.setText("Б");
jLabel2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel2MouseClicked(evt);
}
});
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText("В");
jLabel3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel3MouseClicked(evt);
}
});
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel4.setText("А");
jLabel4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel4MouseClicked(evt);
}
});
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel5.setText("Ґ");
jLabel5.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel5MouseClicked(evt);
}
});
jLabel6.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel6.setText("Д");
jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLabel6MouseClicked(evt);
}
});
jLabel7.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
Дата добавления: 2015-09-11; просмотров: 101 | Поможем написать вашу работу | Нарушение авторских прав |