 |
|
ช่วยเขียนโค๊ต C# เมื่อหยอดเหรียญครบแล้ว ให้ สร้าง username password ออกมาให้หน่อยคับ |
|
 |
|
|
 |
 |
|
ใครพอรู้ หรือมีแนวทาง มีวิธีทำแบบไหนช่วยบอกหน่อยนะคับ พอดีผมพึงหัดเขียนอ่ะคับ เลยไม่ค่อยเข้าใจเท่าไหร่
ขอความหรุณาด้วยคับ 
Code (C#)
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.IO.Ports;
namespace TestC_Sharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string iData;
// สำหรับเก็บรูปแบบการทำงาน
private enum WorkTypeID { IsPerday = 0, IsPerWeek = 1, IsPerMonth = 3, IsUnknown = 4 };
private WorkTypeID _cWorkType;
// สำหรับเก็บจำนวนเงินที่หยอด ณ ปัจจุบัน
private int _cMoney;
private void Form1_Load(object sender, EventArgs e)
{
if (!serialPort1.IsOpen)
{
serialPort1.Open();
_cMoney = 0;
_cWorkType = WorkTypeID.IsUnknown;
this.txtMonitor.Text = "กรุณาเลือกรูปแบบ"; // แสดงที่จอให้เลือกรูปแบบ (กดปุ่ม)
}
}
private void Form1_close(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
serialPort1.Close();
}
public static byte[] ConvertStringToByteArray(string stringToConvert)
{
return (new UnicodeEncoding()).GetBytes(stringToConvert);
}
private void ReceiveData(object s, EventArgs e)
{
byte[] myBytes = ConvertStringToByteArray(iData);
string hexString = BitConverter.ToString(myBytes);
// Replace the - seperator for an whitespace
hexString = hexString.Replace("-", " ");
if (hexString == "3F 00 06 00 12 00 01 00 03 00 3F 00")
_cMoney += 1;
else if (hexString == "3F 00 06 00 12 00 06 00 03 00 3F 00")
_cMoney += 1;
else if (hexString == "3F 00 06 00 12 00 02 00 03 00 3F 00")
_cMoney += 2;
else if (hexString == "3F 00 06 00 12 00 05 00 03 00 3F 00")
_cMoney += 2;
else if (hexString == "3F 00 06 00 12 00 03 00 03 00 3F 00")
_cMoney += 5;
else if (hexString == "3F 00 06 00 12 00 04 00 03 00 3F 00")
_cMoney += 10;
switch (_cWorkType)
{
case WorkTypeID.IsPerday:
if (_cMoney >= 15)
{
this.txtMonitor.Text = "พิมพ์";
}
else
{
this.txtMonitor.Text = "หยอดแล้ว " + _cMoney.ToString() + " บาท";
}
break;
case WorkTypeID.IsPerWeek:
if (_cMoney >= 20)
{
this.txtMonitor.Text = "พิมพ์";
}
else
{
this.txtMonitor.Text = "หยอดแล้ว " + _cMoney.ToString() + " บาท";
}
break;
case WorkTypeID.IsPerMonth:
if (_cMoney >= 25)
{
this.txtMonitor.Text = "พิมพ์";
}
else
{
this.txtMonitor.Text = "หยอดแล้ว " + _cMoney.ToString() + " บาท";
}
break;
};
}
private void serRf_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (_cWorkType == WorkTypeID.IsUnknown)
{
MessageBox.Show("กรุณาเลือกรูปแบบการทำงาน", "คำอธิบาย", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// ตรงนี้ที่จริงเครื่องต่องคืนเหรียญด้วย ทำอย่างไร จัดการเอาเองนะครับ
}
else
{
iData = serialPort1.ReadExisting();
this.Invoke(new EventHandler(ReceiveData));
}
}
private void btnPerDay_Click_1(object sender, EventArgs e)
{
// หากมีการเปลี่ยนรูปแบบใหม่ แสดงว่าเงินต้องเป็น 0
_cMoney = 0;
_cWorkType = WorkTypeID.IsPerday;
this.txtMonitor.Text = "กรุณาหยอดเหรียญทั้งสิ้น 15 บาท";
}
private void btnPerWeek_Click_1(object sender, EventArgs e)
{
// หากมีการเปลี่ยนรูปแบบใหม่ แสดงว่าเงินต้องเป็น 0
_cMoney = 0;
_cWorkType = WorkTypeID.IsPerWeek;
this.txtMonitor.Text = "กรุณาหยอดเหรียญทั้งสิ้น 20 บาท";
}
private void btnPerMonth_Click_1(object sender, EventArgs e)
{
// หากมีการเปลี่ยนรูปแบบใหม่ แสดงว่าเงินต้องเป็น 0
_cMoney = 0;
_cWorkType = WorkTypeID.IsPerMonth;
this.txtMonitor.Text = "กรุณาหยอดเหรียญทั้งสิ้น 25 บาท";
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (_cWorkType == WorkTypeID.IsUnknown)
{
MessageBox.Show("กรุณาเลือกรูปแบบการทำงาน", "คำอธิบาย", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// ตรงนี้ที่จริงเครื่องต่องคืนเหรียญด้วย ทำอย่างไร จัดการเอาเองนะครับ
}
else
{
iData = serialPort1.ReadExisting();
this.Invoke(new EventHandler(ReceiveData));
}
}
// ถ้าคุณมีปุ่มพิมพ์ อย่าลืมถ้ากดพิมพ์แล้ว
// _cWorkType = WorkTypeID.IsUnknown;
// _cMoney = 0;
}
}
|
ประวัติการแก้ไข 2013-05-06 02:09:33
 |
 |
 |
 |
Date :
2013-05-06 02:01:54 |
By :
goingmary |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
gen username password คืออะไรครับ? อ่านแล้ว งง
อันนี้ไม่งง ผมอ่านแล้วพอเข้าใจ (แบบงูงูปลาปลา)
Code (C#)
byte[] myBytes = ConvertStringToByteArray(iData);
==
Code (VB.NET)
Public Shared Function String2Hex(input As String) As String ' "-", " ", etc
Return String.Join(" ", (From c In input.ToCharArray() Select Convert.ToString(AscW(CChar(c)), 16)).ToArray).ToUpper()
End Function
|
 |
 |
 |
 |
Date :
2013-05-06 07:25:30 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
C# ดูอิ่มอุ่นกว่า VB
Code (C#)
public string String2Hex(string input) // " ", "-", etc
{
return String.Join(" ", (from c in input.ToCharArray()
select Convert.ToString(c, 16))).ToUpper();
}
|
 |
 |
 |
 |
Date :
2013-05-06 07:29:25 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือ ให้มันสร้าง username password มาอะคับ
|
 |
 |
 |
 |
Date :
2013-05-06 14:45:16 |
By :
goingmary |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งั้นคุณต้องบอกก่อนครับว่าที่บอกให้สร้าง username กับ password เนี่ย
เอาหลักการหรือข้อมูลมาจากไหน
มีอยู่ใน database แล้ว หรือว่าให้สร้างขึ้นมาใหม่เอง
ถ้าให้สร้างขึ้นมาใหม่เองเนี่ยมีหลักการอะไร เช่น username คือวันปัจจุบัน password คือ เวลาปัจจุบัน อะไรประมาณนี้ครับ
ถ้าใช้แบบที่ว่า ก็จะได้ออกมาประมาณนี้
1. ตรวจสอบเงื่อนไข
2. ถ้าตรงตามเงื่อนไข ก็ให้เอาวันที่เครื่อง กับเวลาเครื่องในตอนนั้น
Code (C#)
string user = datetime.now.ToString("dd/MM/yyyy");
string pwd = datetiime.now.ToString("HH:mm:ss);
Code (VB.NET)
Dim user as string = datetime.now.ToString("dd/MM/yyyy")
Dim pwd as string = datetiime.now.ToString("HH:mm:ss)
|
ประวัติการแก้ไข 2013-05-06 16:34:12
 |
 |
 |
 |
Date :
2013-05-06 16:31:07 |
By :
Nameless |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมสร้าง username กับ password ขึ้นมาเองเลยคับ
แต่ผมจะเอามารวมกับโค๊ดหยอดเหรียญ เมื่อเหรียญครบแล้วให้กดปุ่มสุ่ม แด่ถ้าเหรียญยังไม่ครบปุ่มก็จะไม่ทำงาน
ช่วยดูให้หน่อยนะคับ
ผมใช้โค๊ดสุ่ม ตัวนี้ครับ

Code (C#)
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 Random_String_Generator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public String generateRandomString(int length)
{
//Initiate objects & vars Random random = new Random();
String randomString = "";
int randNumber = 10;
Random rd = new Random();
//Loop ‘length’ times to generate a random number or character
for (int i = 0; i < length; i++)
{
if (rd.Next(1, 3) == 1)
randNumber = rd.Next(97, 123);
//char {a-z}
else
randNumber = rd.Next(48, 58);
//int {0-9}
//append random char or digit to random string
randomString = randomString + (char)randNumber;
}
//return the random string
return randomString;
}
public String generateRandomNumber(int length)
{
//Initiate objects & vars Random random = new Random();
String randomString = "";
int randNumber = 0;
Random rd = new Random();
//Loop ‘length’ times to generate a random number or character
for (int i = 0; i < length; i++)
{
// if (rd.Next(1, 3) == 1)
//randNumber = rd.Next(97, 123);
//char {a-z}
// else
randNumber = rd.Next(48, 58);
//int {0-9}
//append random char or digit to random string
randomString = randomString + (char)randNumber;
}
//return the random string
return randomString;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = "CET" + generateRandomString(int.Parse(textBox2.Text));
textBox3.Text = generateRandomNumber(int.Parse(textBox4.Text));
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
}
}
}
|
ประวัติการแก้ไข 2013-05-07 22:42:02
 |
 |
 |
 |
Date :
2013-05-07 22:30:35 |
By :
goingmary |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นอกจากจะสร้าง username กับ password แล้ว
จะต้องคิดวิธีอ่านสองตัวนี้ด้วยหรือเปล่าครับ ถ้าไม่อย่างสร้างมาก็ไม่ได้นำไปใช้ประโยชน์นะครับ
อย่างที่คุณ nott บอกผมว่าก็น่าจะใช้ได้นะครับ
ถ้าไม่อย่างงั้นจะต้องไปสร้างใหม่และเก็บเข้า database เวลาจะเช็คก็ไปอ่านจาก database แล้วเชคอะครับ
พยายามเข้า ทาเคชิ
|
 |
 |
 |
 |
Date :
2013-05-07 22:53:14 |
By :
batiboy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมจะนำเอา username กับ password ที่ได้ในนั้นไปปริ้นคับ
|
ประวัติการแก้ไข 2013-05-07 23:40:35
 |
 |
 |
 |
Date :
2013-05-07 23:14:48 |
By :
goingmary |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สงสัยผมต้องหาเวลาว่างไปหัดอ่านเขียน ก ข ค ง (วัยของผมมันกลับมาเป็นเด็ก)
ระยะหลังมานี้ผม ฟัง/คุย กับใครฯ ไม่ค่อยจะรู้เรื่อง? สงสัย แก่เกินแกง
|
 |
 |
 |
 |
Date :
2013-05-08 07:05:59 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|