110,567
社区成员
发帖
与我相关
我的任务
分享
private void UploadBtn_Click(object sender, EventArgs e) {
if (string.IsNullOrWhiteSpace(ScanTbx.Text)) return;
string text = ScanTbx.Text.Trim();
using (var connection = SqlCon.TestDbConnection()) {
/***********************************************************************/
if (!next) {
if (LuhnAlgorithm.IsValidNumber(text)) {
string imei = $"select * from Binding where IMEI='{text}'";
var imeiQuery = connection.Query<Binding>(imei).ToList();
if ((imeiQuery.Count == 0) || cbxEdit865Code.Checked) {
lblIMEI.Text = text;
next = !next;
label1.Text = "请扫描小条码";
}
else {
MessageBox.Show("IMEI已扫描", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
}
else {
MessageBox.Show("IMEI错误", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
}
/***********************************************************************/
else {
if (cbxEditCode.Checked) {
string editSN = $"update Binding set SN='{text}' where IMEI='{lblIMEI.Text}'";
var sqlUpdateSN = connection.Execute(editSN);
if (sqlUpdateSN > 0) {
next = !next;
label1.Text = "请扫描大I条码";
lblIMEI.Text = "";
cbxEdit865Code.Checked = false;
/*********************************/
string query = "select * from Binding order by BindingDate desc";
var sqlQuery = connection.Query<Binding>(query).ToList();
dataGridView1.DataSource = sqlQuery;
}
else {
MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
}
else {
string sn = $"select * from Binding where SN='{text}'";
var snQuery = connection.Query<Binding>(sn).ToList();
if (snQuery.Count == 0) {
string insert = $"insert into Binding (IMEI,SN) values(" +
$"'{lblIMEI.Text}','{text}')";
var sqlInsert = connection.Execute(insert);
if (sqlInsert > 0) {
next = !next;
label1.Text = "请扫描大条码";
lblIMEI.Text = "";
/*********************************/
string query = "select * from Binding order by BindingDate desc";
var sqlQuery = connection.Query<Binding>(query).ToList();
dataGridView1.DataSource = sqlQuery;
}
else {
MessageBox.Show("绑定失败", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
}
else {
MessageBox.Show("小条码已扫描", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
}
}
}
ScanTbx.Clear();
ScanTbx.Focus();
return;
}
private void UpdateDataGridView1(??? connection)
{
string query = "select * from Binding order by BindingDate desc";
var sqlQuery = connection.Query<Binding>(query).ToList();
dataGridView1.DataSource = sqlQuery;
}
private bool HasBinding(??? connection, string where)
{
string sn = $"select * from Binding where {where}";
var snQuery = connection.Query<Binding>(sn).ToList();
return (snQuery.Count > 0)
}
public static void SnCheck()
{
//如何进行验证?
string sn = Console.ReadLine();
Request request = new Request()
{
Sn = sn
};
//调用 bll进行逻辑验证
string msg = bll.CheckSn(request);
if (string.IsNullOrEmpty(msg))
{
SuccessMSG("成功请刷别的材料");
}
else
{
ErrorMSG(msg);
}
}
public interface IValidate
{
string Validate(Request t, object help);
}
public static class ListExtend
{
/// <summary>
/// 通用验证 输入参数要求request
/// </summary>
/// <param name="list"></param>
/// <param name="t"></param>
/// <param name="t2"></param>
/// <returns></returns>
public static string ValidateCheck(this List<IValidate> list, Request t, object t2)
{
string msg = "";
foreach (var item in list)
{
msg = item.Validate(t, null);
//不等于null 或空,表示验证失败,验证失败返回结果
if (!string.IsNullOrEmpty(msg)) return msg;
}
return msg;
}
public class SnCheckValidateMain
{
public static string Main(Request requst, object t)
{
List<IValidate> list = new List<IValidate>();
list.Add(new SnCheckLength());///检查sn长度是否合法
list.Add(new SnCheckGroup());///检查sn的当前站别是否存在
list.Add(new SNcheckCustomer());///检查sn的客户别是否正确
return list.ValidateCheck(requst, null);
}
}
大致验证逻辑如下,希望能对你有所帮助private void UploadBtn_Click(object sender, EventArgs e) {
if (string.IsNullOrWhiteSpace(ScanTbx.Text)) return;
string text = ScanTbx.Text.Trim();
using (var connection = SqlCon.TestDbConnection()) {
/***********************************************************************/
if (!next) {
if (!LuhnAlgorithm.IsValidNumber(text)) {
MessageBox.Show("IMEI错误", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
string imei = $"select * from Binding where IMEI='{text}'";
var imeiQuery = connection.Query<Binding>(imei).ToList();
if (!((imeiQuery.Count == 0) || cbxEdit865Code.Checked)) {
MessageBox.Show("IMEI已扫描", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
lblIMEI.Text = text;
next = !next;
label1.Text = "请扫描小条码";
}
/***********************************************************************/
else {
if (cbxEditCode.Checked) {
string editSN = $"update Binding set SN='{text}' where IMEI='{lblIMEI.Text}'";
var sqlUpdateSN = connection.Execute(editSN);
if (sqlUpdateSN <= 0) {
MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
next = !next;
label1.Text = "请扫描大I条码";
lblIMEI.Text = "";
cbxEdit865Code.Checked = false;
/*********************************/
string query = "select * from Binding order by BindingDate desc";
var sqlQuery = connection.Query<Binding>(query).ToList();
dataGridView1.DataSource = sqlQuery;
}
else {
string sn = $"select * from Binding where SN='{text}'";
var snQuery = connection.Query<Binding>(sn).ToList();
if (snQuery.Count != 0) {
MessageBox.Show("小条码已扫描", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
string insert = $"insert into Binding (IMEI,SN) values(" +
$"'{lblIMEI.Text}','{text}')";
var sqlInsert = connection.Execute(insert);
if (sqlInsert <= 0) {
MessageBox.Show("绑定失败", "提示", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
next = !next;
label1.Text = "请扫描大条码";
lblIMEI.Text = "";
/*********************************/
string query = "select * from Binding order by BindingDate desc";
var sqlQuery = connection.Query<Binding>(query).ToList();
dataGridView1.DataSource = sqlQuery;
}
}
}
ScanTbx.Clear();
ScanTbx.Focus();
return;
}