Skip to content

Instantly share code, notes, and snippets.

@shihchun
Created May 9, 2018 02:21
Show Gist options
  • Save shihchun/63ecfe4b8613e65ee1c009fec4cedd3f to your computer and use it in GitHub Desktop.
Save shihchun/63ecfe4b8613e65ee1c009fec4cedd3f to your computer and use it in GitHub Desktop.
C# test 1
using System;
using System.Windows;
namespace MySql_Inject
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void login_btn_Click(object sender, RoutedEventArgs e)
{
string user = "rufus";
int pass = 1234;
if (user == this.ID_Txt.Text )
{
MessageBox.Show("Username and password is correct");
this.Hide();
Views.tpl mainTemplates = new Views.tpl(); //namespace concept, preffix(Views.tpl), all in the MySql_Inject
mainTemplates.ShowDialog();
this.Close();
}
else
{
MessageBox.Show("Something is Wrong !");
}
}
}
}
using System;
using System.Windows;
using System.Windows.Controls;
using System.Data;
using MySql.Data.MySqlClient;
using Microsoft.Win32;
using System.Drawing;
namespace MySql_Inject.Views
{
/// <summary>
/// Interaction logic for member.xaml
/// </summary>
public partial class member : UserControl
{
public member()
{
InitializeComponent();
epc_Txt.Text = RfidMe.RfidMeEPC;
epc_Txt.IsEnabled = false;
filename_Txt.IsEnabled = false;
}
// database info
public string dbUser = "root";
public string dbHost = "localhost";
public string dbPass = "";
public string dbName = "members";
public string id = "";
public void MySqlCheck()
{
string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
MySqlConnection conn = new MySqlConnection(connStr);
MySqlCommand command = conn.CreateCommand();
}
public void bind()
{
string sql = "SELECT badge_num, firstname, lastname, fullname, gender, birth_date, department, position, epc, id, regist_date FROM members.empolyees AS regist_date";
string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
MySqlConnection conn = new MySqlConnection(connStr);
MySqlCommand command = conn.CreateCommand();
conn.Open();
MySqlCommand cmdSel = new MySqlCommand(sql, conn);
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);
da.Fill(dt);
dataGrid1.DataContext = dt;
}
// Define the Member content
public string badge_num = "";
public string fullname = "";
public string firstname = "";
public string lastname = "";
public string gender = "";
public string birth_date = "";
public string department = "";
public string position = "";
public string epc = RfidMe.RfidMeEPC;
private void getMbr()
{
badge_num = Badge_Txt.Text;
firstname = fName_Txt.Text;
lastname = lName_Txt.Text;
gender = gender_Txt.Text;
fullname = firstname + " " + lastname;
birth_date = DOB_Txt.Text;
department = department_Txt.Text;
position = title_Txt.Text;
epc = "TestCode!@#$%^&"; //TestCode
}
private void commitMbr() // get the info of this form
{
if ( Badge_Txt.Text != ""
&& fName_Txt.Text != ""
&& lName_Txt.Text != ""
&& DOB_Txt.Text != ""
&& department_Txt.Text != ""
&& epc_Txt.Text != "")
{
getMbr();
string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
MySqlConnection conn = new MySqlConnection(connStr);
MySqlCommand command = conn.CreateCommand();
conn.Open();
MessageBox.Show("One Record Insert !");
command.CommandText = "INSERT INTO `empolyees` ( `badge_num`, `fullname`, `firstname`, `lastname`,`gender`, `birth_date`, `department`, `position`, `epc`) VALUES" +
"( '" + badge_num + "', '" + fullname + "', '" + firstname + "', '" + lastname + "', '" + gender + "', '" + birth_date + "', '" + department + "','" + position + "', '" + epc + "')";
command.ExecuteNonQuery();
conn.Close();
}
else
{
MessageBox.Show("The info is not completed insert");
}
}
private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
DataRowView _DataView = dataGrid1.CurrentCell.Item as DataRowView;
if (_DataView != null)
{
epc_Txt.Text = _DataView.Row[8].ToString();
Badge_Txt.Text = _DataView.Row[0].ToString();
fName_Txt.Text = _DataView.Row[1].ToString();
lName_Txt.Text = _DataView.Row[2].ToString();
gender_Txt.Text = _DataView.Row[4].ToString();
DOB_Txt.Text = _DataView.Row[5].ToString();
department_Txt.Text = _DataView.Row[6].ToString();
title_Txt.Text = _DataView.Row[7].ToString();
id = _DataView.Row[9].ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void Add_Btn_Click(object sender, RoutedEventArgs e)
{
commitMbr();
bind();
}
private void Del_Btn_Click(object sender, RoutedEventArgs e)
{
string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
MySqlConnection conn = new MySqlConnection(connStr);
MySqlCommand command = conn.CreateCommand();
conn.Open();
MessageBox.Show("One Record Delete !");
command.CommandText = "DELETE FROM `empolyees` WHERE '" + id + "' LIMIT 1";
command.ExecuteNonQuery();
conn.Close();
bind();
}
private void Update_Btn_Click(object sender, RoutedEventArgs e)
{
getMbr();
string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
MySqlConnection conn = new MySqlConnection(connStr);
MySqlCommand command = conn.CreateCommand();
conn.Open();
MessageBox.Show("One Record Update !");
command.CommandText = "UPDATE `empolyees` SET " +
"`badge_num`= '" + badge_num + "', `fullname` = '" + fullname + "', `firstname` = '" + firstname + "', " +
"`lastname` = '" + lastname + "',`gender` = '" + gender + "', `birth_date` = '" + birth_date + "', " +
"`department` = '" + department + "', `position` = '" + position + "', `epc` = '" + epc + "' WHERE '" + id + "' limit 1";
command.ExecuteNonQuery();
conn.Close();
bind();
}
private void clear_Btn_Click(object sender, RoutedEventArgs e)
{
Badge_Txt.Text = string.Empty;
fName_Txt.Text = string.Empty;
lName_Txt.Text = string.Empty;
DOB_Txt.Text = string.Empty;
department_Txt.Text = string.Empty;
title_Txt.Text = string.Empty;
epc_Txt.Text = string.Empty;
dataGrid1.DataContext = null;
epc_Txt.Text = RfidMe.RfidMeEPC;
}
private void Display_Btn_Click(object sender, RoutedEventArgs e)
{
//declare at our memory(newDatabase)
//database.member newDatabase = new database.member();
//newDatabase.dbHost = "localhost"; //setting manually
//newDatabase.Insert();
bind();
}
private void browse_Btn_Click(object sender, RoutedEventArgs e)
{
}
}
}
using System.Windows;
using System.Windows.Controls;
namespace MySql_Inject.Views
{
/// <summary>
/// Interaction logic for RfidMe.xaml
/// </summary>
public partial class RfidMe : System.Windows.Controls.UserControl
{
// Declare our DevKit to memory
public RFIDMEDevKit.reader myReader = new RFIDMEDevKit.reader();
// if no EPC display RESET serialNum and Conn() again
string serialNum = "";
string rawtag = "Error";
public static string RfidMeEPC = "No tag read !"; // Send to other form
// If the file getting large, public static waste the memory
//Conect to RfidMe Refer to the SDK DEMO project
private void RfidMeConn()
{
bool myResult = myReader.Activation("Demo");
lbox.Items.Add(myResult.ToString());
if (serialNum == "")
lbox.Items.Add(myReader.Connect("RFIDME"));
else
lbox.Items.Add(myReader.Connect("RFIDME", serialNum)); // throw the serial number to the string create
}
private void RfidMeRead()
{
string myTags = "";
myTags = myReader.ReadEPC(false, ",");
string[] myTagList = myTags.Split(',');
foreach (string tag in myTagList)
{
lbox.Items.Add(tag);
rawtag = tag;
}
}
public RfidMe()
{
InitializeComponent();
}
private void Cnt_btn_Click(object sender, RoutedEventArgs e)
{
RfidMeConn();
}
private void Read_btn_Click(object sender, RoutedEventArgs e)
{
RfidMeRead();
if (rawtag == "-1" || rawtag == "A problem occured while communicating with the reader: RFIDME")
{
RfidMeEPC = "No tag read !";
}
else
{
RfidMeEPC = rawtag;
}
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment