اینجا کامنتهای انگلیسی را به کد شما اضافه کردهام تا تمام بخشها بهتر توضیح داده شوند:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge.Video; // For handling communication between the webcam and the application
using AForge.Video.DirectShow; // For accessing webcam devices from the system
using TrafficLog.TrafficLogDataSetTableAdapters;
using ZXing; // For decoding QR codes
using System.Threading;
using static System.Net.Mime.MediaTypeNames;
namespace TrafficLog
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent(); // Initialize form components
}
// Class members for holding webcam devices and the selected webcam
FilterInfoCollection FilterInfoCollection;
VideoCaptureDevice captureDevice;
private void Form1_Load(object sender, EventArgs e)
{
// Bind employee-related data from the database to the corresponding labels
FName.DataBindings.Add("Text", employeesBindingSource, "FName");
LName.DataBindings.Add("Text", employeesBindingSource, "LName");
BD.DataBindings.Add("Text", employeesBindingSource, "BD");
NationalCode.DataBindings.Add("Text", employeesBindingSource, "NationalCode");
// Get the list of available video devices (webcams) from the system
FilterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo filterInfo in FilterInfoCollection)
{
// Add each webcam's name to the ComboBox
cboDevice.Items.Add(filterInfo.Name);
}
}
private void button1_Click(object sender, EventArgs e)
{
// Initialize the selected webcam using the comboBox index
captureDevice = new VideoCaptureDevice(FilterInfoCollection[cboDevice.SelectedIndex].MonikerString);
// Assign an event handler for capturing new video frames
captureDevice.NewFrame += CaptureDevice_NewFrame;
captureDevice.Start(); // Start capturing video from the webcam
timer1.Start(); // Start the timer to periodically scan the QR code
}
private void CaptureDevice_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
// Display the captured webcam frame inside the PictureBox
pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
}
private void timer1_Tick(object sender, EventArgs e)
{
// This method runs on a timer to continuously check the image for a QR code
if (pictureBox1.Image != null)
{
BarcodeReader barcodeReader = new BarcodeReader(); // Set up a barcode reader
Result result = barcodeReader.Decode((Bitmap)pictureBox1.Image); // Scan for a QR code
if (result != null)
{
Input.Text = result.ToString(); // Display the QR code result in the text box
}
}
}
private void Input_TextChanged(object sender, EventArgs e)
{
// Query the database using the scanned QR code (or text input)
employeesTableAdapter.FillByFName(informationsDataSet.employees, Input.Text);
if (informationsDataSet.employees.Rows.Count >= 1)
{
// If a matching employee is found, show the detailed information
this.BackgroundImage = Properties.Resources.bg2; // Update the background image
LNamelbltxt.Visible = true;
FNamelbltxt.Visible = true;
BDlbltxt.Visible = true;
NationalCodelbltxt.Visible = true;
FName.Visible = true;
LName.Visible = true;
BD.Visible = true;
NationalCode.Visible = true;
PleaseScan.Visible = false;
welcome.Visible = true;
// Log the employee's entry into the database
logTableAdapter.InsertQuery(
NationalCode.Text,
FName.Text,
LName.Text,
BD.Text,
lbDate.Text + " " + lbltime.Text
);
// Refresh the log display
this.logTableAdapter.Fill(this.trafficLogDataSet.log);
welcome.Visible = false;
}
else
{
// If no matching employee is found, you can handle this case here
}
}
private void timer2_Tick(object sender, EventArgs e)
{
// Update the date using the Persian calendar to maintain proper format
System.Globalization.PersianCalendar p = new System.Globalization.PersianCalendar();
lbDate.Text = p.GetYear(DateTime.Now).ToString() + "/"
+ p.GetMonth(DateTime.Now).ToString("0#") + "/"
+ p.GetDayOfMonth(DateTime.Now).ToString("0#");
// Update the time every second (hh:mm:ss format)
lbltime.Text = DateTime.Now.Hour.ToString("0#") + ":"
+ DateTime.Now.Minute.ToString("0#") + ":"
+ DateTime.Now.Second.ToString("0#");
}
}
}
توضیحات به انگلیسی اضافه شد:
بخشهای مختلف کد شامل عملکردهای اصلی (مانند اتصال به وبکم، اسکن کد QR، نمایش اطلاعات کاربران از پایگاه داده، و ثبت لاگ) با کامنتها توضیح داده شد تا خوانایی آن بالاتر رود. اگر تغییر خاصی یا بخش دیگری از توضیحات نیاز داشتید، حتماً اطلاع دهید! 😊