 |
|
ขอสอบถามหน่อยครับ C#
คือว่าผมเขียนโปรแกรม login โดยใช้เครื่องสแกนบาโค๊ดตอนนี้เขียนติดต่อกับ ฮาดแวร์ ได้แล้ว แล้วใช้ labal.text เป็นตัวเก็บข้อมูลของ
แล้วผมจะเช็คค่าอย่างไรหรอครับ ให้ ค่าของ password ใน mysql (ผมให้ mysql นะครับ ไม่ใช่ ms sql ) ตรงกัน...ถ้าใช้ตามเงื่อนไข ก็จะให้เข้าสู่กระบวนการต่อไป แต่ถ้าไม่ใช่ ก็ขึ้น massang แจ้งเตือนอ่ะครับ รบกวนด้วยนะครับ (ผมรับค่า รหัสที่เป็นเลขบาโค็ดอย่างเดียวนะครับ เดียว user ผมจะให้มันแสดงขึ้นเอง )
C# , Sharp Develop .net
อันนี้โค็ดที่ผมเขียนนะครับ
ผิดอย่างไร ก็อภัยด้วยนะคับ
//------------------------------
/*
* Created by SharpDevelop.
* User: Trace
* Date: 5/20/2014
* Time: 11:36 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using INI;
using MySql.Data.MySqlClient;
namespace Login_mysql_Code
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
Form1 F1 = new Form1();
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
IniFile iniconfig ;
MySqlConnection conn;
string InputDataScanner;
//-------------------------------
private bool connection()
{
string IP = iniconfig.IniReadValue("Server","IP");
string User = iniconfig.IniReadValue("Server","User");
string Pass = iniconfig.IniReadValue("Server","Pass");
string DB = iniconfig.IniReadValue("Server","DB_NAME");
conn = new MySqlConnection("Server="+IP+";Database="+DB+";Uid="+User+";Password="+Pass+";");
try
{
conn.Open();
return true;
}
catch
{
return false ;
}
}
//-------------------------------
void MainFormLoad(object sender, EventArgs e)
{
iniconfig = new IniFile(Application.StartupPath+@"\config.ini");
initialPortEFCard();
if (chackuser() == true)
{
F1.Show();
}
else
{
MessageBox.Show("Not Data","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
//----------------------------------
private bool chackuser()
{
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM empleyee WHERE PASS = '" + this.txReceive2.Text+ "'",conn);
// MySqlDataAdapter da = new MySqlDataAdapter("SELECT * from empleyee where PASS = '"+label1.Text+"' ", conn);
try
{
return true;
}
catch
{
return false;
}
}
//----------------------------------
//------------------------ connection to port
private bool initialPortEFCard()
{
RS232Scan.PortName = "COM"+iniconfig.IniReadValue("RS232Scan", "Com");
RS232Scan.BaudRate = Convert.ToInt32(iniconfig.IniReadValue("RS232Scan", "Boudrate"));
try
{
if(RS232Scan.IsOpen == true)
RS232Scan.Close();
RS232Scan.Open();
}
catch
{
MessageBox.Show(RS232Scan.PortName.ToString()+" Open Error !","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
return true;
}
void RS232ScanDataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string Data = RS232Scan.ReadExisting().Replace("\0","");
if(Data != String.Empty)
{
for(int i=0; i<Data.Length; i++)
{
string Key = Data.Substring(i, 1);
if((Key == "\n") || (Key == "\r"))
{
SetText(Trim_R_N_(InputDataScanner));
InputDataScanner = "";
}
else
{
InputDataScanner += Key;
}
}
}
}
private string Trim_R_N_(string text)
{
int length = text.Length;
string output = "", Key = "";
for(int i=0; i<length; i++)
{
Key = text.Substring(i, 1);
if(!((Key == "\r") || (Key == "\n"))) output += Key;
}
return output;
}
delegate void SetTextCallback(string text);
private void SetText(string text)
{
if(txReceive2.Text == "")
{
if(txReceive2.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
Invoke(d, new object[] { text });
}
else
{
txReceive2.Text = text;
}
}
}
void TxReceiveTextChanged(object sender, EventArgs e)
{
if(txReceive2.Text != "")
{
//MessageBox.Show(txReceive2.Text,"Alert");
//SendKeys.Send(txReceive2.Text);
SendKeys.Send(label1.Text = txReceive2.Text);
SendKeys.Send("{Enter}");
}
txReceive2.Text = "";
}
//------------------------
}
}
Tag : VB.NET, C#
|
|
 |
 |
 |
 |
Date :
2014-05-20 16:03:37 |
By :
ต๋องคับ |
View :
1804 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |