bool Form::slotOpenRed() { open_red=true; return open_red; } bool Form::slotCloseRed() { open_red=false; return open_red; }
时间: 2023-06-27 10:02:31 浏览: 49
这是一个 C++ 中的成员函数,属于一个类的成员函数。这个类叫做 Form。这个类中有一个布尔类型的成员变量 open_red,它的值可以通过这两个函数进行设置和获取。当调用 slotOpenRed 函数时,会将 open_red 变量的值设置为 true,并返回设置后的值。而调用 slotCloseRed 函数时,会将 open_red 变量的值设置为 false,并返回设置后的值。
相关问题
c#窗体应用程序实现当软件开启,就在数据库扫描是否有设置的良品和不良品条码的当天ICT测试记录(ICT_test表中Barcode,Date,Result),良品和不良品条码在本地文件夹txt文件中获取。如果数据库中有良品和不良品测试记录存在,lable状态栏变绿并提示“已点检,请进行ICT测试”,然后进行别的条码的ICT测试。就将扫到的条码通过模拟键盘发送到ICT测试软件进行测试。如果没有,别的条码发送时会被拦截,label状态栏变红,并提示“请进行测试前点检”,然后就先进行设置条码的ICT测试,判断扫描到txt_Barcode中条码是否为获取到设置的良品或不良品条码,如输入的条码不符合,label状态栏变红,并提示“条码错误”,如输入的条码正确并为设置的良品条码,label状态栏变绿,并提示“请进行良品点检”,就将良品条码发送到ICT测试软件进行ICT测试,当发现某一文件夹中有良品测试报告生成,表示良品测试完成,测试完成后就提示“良品点检完成”。如扫描的是设置的不良品条码,则label状态栏变绿,并提示“请进行不良品点检”,进行ICT测试。当发现某一文件夹中有不良品测试报告生成,表示不良品测试完成。(所有条码先扫描到c#窗体软件txt_barcode中,在通过模拟键盘定位发送到ICT测试软件条码框中,然后进行ICT测试)代码实现
以下是一个简单的代码实现,仅供参考:
```csharp
using System;
using System.IO;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace ICTTest
{
public partial class Form1 : Form
{
private string connectionString = "Data Source=.;Initial Catalog=ICT;Integrated Security=True";
private string goodBarcodesFile = "good_barcodes.txt";
private string badBarcodesFile = "bad_barcodes.txt";
private string testFolder = "test_reports";
private string goodTestFile = "good_test.txt";
private string badTestFile = "bad_test.txt";
private bool isGoodTestComplete = false;
private bool isBadTestComplete = false;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
SqlCommand command = new SqlCommand("SELECT * FROM ICT_test WHERE Date=@date AND Barcode IN (SELECT Barcode FROM good_barcodes UNION SELECT Barcode FROM bad_barcodes)", connection);
command.Parameters.AddWithValue("@date", DateTime.Today.ToShortDateString());
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
lblStatus.ForeColor = System.Drawing.Color.Green;
lblStatus.Text = "已点检,请进行ICT测试";
}
else
{
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "请进行测试前点检";
txtBarcode.Focus();
}
connection.Close();
}
private void txtBarcode_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
e.Handled = true;
string barcode = txtBarcode.Text.Trim();
if (lblStatus.Text == "请进行测试前点检")
{
if (CheckBarcode(barcode))
{
if (IsGoodBarcode(barcode))
{
lblStatus.ForeColor = System.Drawing.Color.Green;
lblStatus.Text = "请进行良品点检";
SendBarcodeToICT(barcode);
}
else if (IsBadBarcode(barcode))
{
lblStatus.ForeColor = System.Drawing.Color.Green;
lblStatus.Text = "请进行不良品点检";
SendBarcodeToICT(barcode);
}
else
{
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "条码错误";
}
}
}
else if (lblStatus.Text == "请进行良品点检")
{
if (CheckBarcode(barcode) && IsGoodBarcode(barcode))
{
SendBarcodeToICT(barcode);
if (IsGoodTestComplete())
{
lblStatus.ForeColor = System.Drawing.Color.Green;
lblStatus.Text = "良品点检完成";
}
}
}
else if (lblStatus.Text == "请进行不良品点检")
{
if (CheckBarcode(barcode) && IsBadBarcode(barcode))
{
SendBarcodeToICT(barcode);
if (IsBadTestComplete())
{
lblStatus.ForeColor = System.Drawing.Color.Green;
lblStatus.Text = "不良品点检完成";
}
}
}
txtBarcode.Text = "";
txtBarcode.Focus();
}
}
private bool CheckBarcode(string barcode)
{
// 检查条码是否符合要求,比如长度、字符集等
return true;
}
private bool IsGoodBarcode(string barcode)
{
string[] goodBarcodes = File.ReadAllLines(goodBarcodesFile);
foreach (string goodBarcode in goodBarcodes)
{
if (barcode == goodBarcode)
{
return true;
}
}
return false;
}
private bool IsBadBarcode(string barcode)
{
string[] badBarcodes = File.ReadAllLines(badBarcodesFile);
foreach (string badBarcode in badBarcodes)
{
if (barcode == badBarcode)
{
return true;
}
}
return false;
}
private void SendBarcodeToICT(string barcode)
{
// 使用模拟键盘发送条码到ICT测试软件
}
private bool IsGoodTestComplete()
{
if (isGoodTestComplete)
{
return true;
}
string[] testFiles = Directory.GetFiles(testFolder);
foreach (string testFile in testFiles)
{
if (testFile.EndsWith(goodTestFile))
{
isGoodTestComplete = true;
return true;
}
}
return false;
}
private bool IsBadTestComplete()
{
if (isBadTestComplete)
{
return true;
}
string[] testFiles = Directory.GetFiles(testFolder);
foreach (string testFile in testFiles)
{
if (testFile.EndsWith(badTestFile))
{
isBadTestComplete = true;
return true;
}
}
return false;
}
}
}
```
需要注意的是,代码中涉及到的文件路径、数据库连接字符串等需要根据实际情况进行修改。另外,模拟键盘发送条码需要使用第三方库或API,需要进行额外的研究和开发。
c#窗体应用程序实现软件开机自启,并可以通过路径控制ICT测试软件的打开和关闭。良品条码和不良品条码可以在本地文件夹中的txt文件中获取。当软件开启,定时器就在数据库扫描是否有设置的良品和不良品条码的当天测试记录(数据库ICT_test表中Barcode和Date项的记录),如果存在,lable状态栏变绿并提示“已点检,请进行ICT测试”。就可以通过c#软件开启按钮打开ICT测试软件,进行其他条码的ICT测试。如果数据库中没有设置的良品和不良品条码的测试记录,点击开启ICT测试按钮时,label状态栏变红,并提示“请进行测试前点检”,然后就先进行设置条码的ICT测试,判断扫描到txt_barcode的条码是否为txt文件中设置的良品或不良品条码,如输入的条码不符合,label状态栏变红,并提示“条码错误”,如输入的条码正确并为设置的良品条码,label状态栏变绿,并提示“请进行良品点检”,这时就能打开ICT测试软件,然后将扫到txt_barcode的良品条码通过模拟键盘复制黏贴到ICT条码栏,进行ICT测试,当发现有良品条码的点检报告生成,表示良品点检完成。测试完成后label状态栏提示“良品点检完成”,并将测试记录上传到数据库。c#代码实现
以下是一个示例代码,仅供参考:
首先,需要在窗体的Load事件中添加开机自启代码:
```
private void Form1_Load(object sender, EventArgs e)
{
// 设置开机自启
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rk.SetValue("MyApp", Application.ExecutablePath);
}
```
然后,在“开启ICT测试”按钮的Click事件中,扫描数据库是否存在设置的良品或不良品条码的当天测试记录:
```
private void btnStart_Click(object sender, EventArgs e)
{
// 扫描数据库是否有当天的测试记录
string today = DateTime.Now.ToString("yyyy-MM-dd");
bool hasRecord = CheckDatabase(today);
if (hasRecord)
{
// 如果有记录,则提示已点检
lblStatus.Text = "已点检,请进行ICT测试";
lblStatus.ForeColor = Color.Green;
}
else
{
// 如果没有记录,则提示请进行测试前点检
lblStatus.Text = "请进行测试前点检";
lblStatus.ForeColor = Color.Red;
}
}
```
CheckDatabase方法用于扫描数据库,判断是否存在设置的良品或不良品条码的当天测试记录:
```
private bool CheckDatabase(string date)
{
bool hasRecord = false;
string connStr = "数据库连接字符串";
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
string sql = "SELECT COUNT(*) FROM ICT_test WHERE Date=@date AND Barcode IN (SELECT Barcode FROM GoodBarcodes UNION SELECT Barcode FROM BadBarcodes)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@date", date);
int count = (int)cmd.ExecuteScalar();
if (count > 0)
{
hasRecord = true;
}
}
return hasRecord;
}
```
接着,在“打开ICT测试”按钮的Click事件中,判断输入的条码是否为设置的良品或不良品条码:
```
private void btnOpenICT_Click(object sender, EventArgs e)
{
// 判断输入的条码是否为设置的良品或不良品条码
string barcode = txtBarcode.Text.Trim();
bool isGood = CheckGoodBarcode(barcode);
bool isBad = CheckBadBarcode(barcode);
if (!isGood && !isBad)
{
// 如果不是设置的良品或不良品条码,则提示条码错误
lblStatus.Text = "条码错误";
lblStatus.ForeColor = Color.Red;
return;
}
if (isGood)
{
// 如果是设置的良品条码,则提示请进行良品点检
lblStatus.Text = "请进行良品点检";
lblStatus.ForeColor = Color.Green;
}
else if (isBad)
{
// 如果是设置的不良品条码,则提示请进行不良品点检
lblStatus.Text = "请进行不良品点检";
lblStatus.ForeColor = Color.Green;
}
// 打开ICT测试软件
OpenICTSoftware();
}
```
CheckGoodBarcode和CheckBadBarcode方法用于判断输入的条码是否为设置的良品或不良品条码:
```
private bool CheckGoodBarcode(string barcode)
{
bool isGood = false;
string filePath = "良品条码文件路径";
string[] goodBarcodes = File.ReadAllLines(filePath);
foreach (string goodBarcode in goodBarcodes)
{
if (goodBarcode.Trim() == barcode)
{
isGood = true;
break;
}
}
return isGood;
}
private bool CheckBadBarcode(string barcode)
{
bool isBad = false;
string filePath = "不良品条码文件路径";
string[] badBarcodes = File.ReadAllLines(filePath);
foreach (string badBarcode in badBarcodes)
{
if (badBarcode.Trim() == barcode)
{
isBad = true;
break;
}
}
return isBad;
}
```
最后,在ICT测试完成后,需要将测试记录上传到数据库:
```
private void UploadRecord(string barcode, string date, string result)
{
string connStr = "数据库连接字符串";
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
string sql = "INSERT INTO ICT_test (Barcode, Date, Result) VALUES (@barcode, @date, @result)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@barcode", barcode);
cmd.Parameters.AddWithValue("@date", date);
cmd.Parameters.AddWithValue("@result", result);
cmd.ExecuteNonQuery();
}
}
```
完整的代码:
```
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// 设置开机自启
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rk.SetValue("MyApp", Application.ExecutablePath);
}
private void btnStart_Click(object sender, EventArgs e)
{
// 扫描数据库是否有当天的测试记录
string today = DateTime.Now.ToString("yyyy-MM-dd");
bool hasRecord = CheckDatabase(today);
if (hasRecord)
{
// 如果有记录,则提示已点检
lblStatus.Text = "已点检,请进行ICT测试";
lblStatus.ForeColor = Color.Green;
}
else
{
// 如果没有记录,则提示请进行测试前点检
lblStatus.Text = "请进行测试前点检";
lblStatus.ForeColor = Color.Red;
}
}
private bool CheckDatabase(string date)
{
bool hasRecord = false;
string connStr = "数据库连接字符串";
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
string sql = "SELECT COUNT(*) FROM ICT_test WHERE Date=@date AND Barcode IN (SELECT Barcode FROM GoodBarcodes UNION SELECT Barcode FROM BadBarcodes)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@date", date);
int count = (int)cmd.ExecuteScalar();
if (count > 0)
{
hasRecord = true;
}
}
return hasRecord;
}
private void btnOpenICT_Click(object sender, EventArgs e)
{
// 判断输入的条码是否为设置的良品或不良品条码
string barcode = txtBarcode.Text.Trim();
bool isGood = CheckGoodBarcode(barcode);
bool isBad = CheckBadBarcode(barcode);
if (!isGood && !isBad)
{
// 如果不是设置的良品或不良品条码,则提示条码错误
lblStatus.Text = "条码错误";
lblStatus.ForeColor = Color.Red;
return;
}
if (isGood)
{
// 如果是设置的良品条码,则提示请进行良品点检
lblStatus.Text = "请进行良品点检";
lblStatus.ForeColor = Color.Green;
}
else if (isBad)
{
// 如果是设置的不良品条码,则提示请进行不良品点检
lblStatus.Text = "请进行不良品点检";
lblStatus.ForeColor = Color.Green;
}
// 打开ICT测试软件
OpenICTSoftware();
}
private bool CheckGoodBarcode(string barcode)
{
bool isGood = false;
string filePath = "良品条码文件路径";
string[] goodBarcodes = File.ReadAllLines(filePath);
foreach (string goodBarcode in goodBarcodes)
{
if (goodBarcode.Trim() == barcode)
{
isGood = true;
break;
}
}
return isGood;
}
private bool CheckBadBarcode(string barcode)
{
bool isBad = false;
string filePath = "不良品条码文件路径";
string[] badBarcodes = File.ReadAllLines(filePath);
foreach (string badBarcode in badBarcodes)
{
if (badBarcode.Trim() == barcode)
{
isBad = true;
break;
}
}
return isBad;
}
private void OpenICTSoftware()
{
// 打开ICT测试软件
string softwarePath = "ICT测试软件路径";
Process.Start(softwarePath);
}
private void btnPass_Click(object sender, EventArgs e)
{
// 良品点检完成,上传测试记录
string barcode = txtBarcode.Text.Trim();
string date = DateTime.Now.ToString("yyyy-MM-dd");
string result = "Pass";
UploadRecord(barcode, date, result);
// 提示良品点检完成
lblStatus.Text = "良品点检完成";
lblStatus.ForeColor = Color.Green;
}
private void btnFail_Click(object sender, EventArgs e)
{
// 不良品点检完成,上传测试记录
string barcode = txtBarcode.Text.Trim();
string date = DateTime.Now.ToString("yyyy-MM-dd");
string result = "Fail";
UploadRecord(barcode, date, result);
// 提示不良品点检完成
lblStatus.Text = "不良品点检完成";
lblStatus.ForeColor = Color.Green;
}
private void UploadRecord(string barcode, string date, string result)
{
string connStr = "数据库连接字符串";
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
string sql = "INSERT INTO ICT_test (Barcode, Date, Result) VALUES (@barcode, @date, @result)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@barcode", barcode);
cmd.Parameters.AddWithValue("@date", date);
cmd.Parameters.AddWithValue("@result", result);
cmd.ExecuteNonQuery();
}
}
}
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)