using Mesnac.Compressor.Data;
using Mesnac.Compressor.Station;
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;
namespace BusinessTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DbHandler db = new DbHandler();
//string LastWorkInfo = LastWorkProductionInfo("E26A00MBB24041215513", "T_RP_StationPara_B140", "ScanBarcode");
//TEST();
//bool bflag = UpdateTraceReStartStation("1", "9", "10", "E26T00MBB24041109028", "AA2404110144");
int codelength = 0;
string code = "A240411014";
//if (code.Length != 0)
//{
// codelength = code.Length + 1;
//}
//code = code.PadRight(20);
object[] bytes = new object[code.Length];
object[] newbytes = new object[20] {0x00, 0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
byte[] buffer = new byte[bytes.Length];
buffer = System.Text.ASCIIEncoding.Default.GetBytes(code);
byte[] addrby = new byte[2] {0x41,0x32 };
uint aaa = Convert.ToUInt32(addrby);
string ssss = "";
for (int i = 0; i < buffer.Length; i++)
{
string s = ",";
if (i == buffer.Length-2)
{
s = "";
}
ssss += buffer[i].ToString("X") + buffer[i + 1].ToString("X") + s;
i = i + 1;
}
string[] sss2 = ssss.Trim().Split(',');
for (int i = 0; i < sss2.Length; i++)
{
bytes[i] = Convert.ToInt32(sss2[i],16);
}
Array.Copy(bytes,0, newbytes,0, bytes.Length);
string sss = buffer[0].ToString("X") + buffer[1].ToString("X");
bytes[0] = sss;
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = buffer[i] + buffer[i + 1];
}
string ss = getSemiBarcodeAByDongPanCode("E26A00MBB2");
string ISDis = db.getChongTouStateByBarCode("2403150139");
string dateCode = DateTime.Now.ToString("yyMMdd");
//string year = dateCode.Substring(0, 2);
//string mouth = dateCode.Substring(2, 2);
//string day = dateCode.Substring(4, 2);
//string test = day + mouth + year;
bool isNG = db.GetStationNGBySemiBarCode("A2303220080");
}
private void TEST()
{
string inputString = "A221205018";
inputString.PadRight(20, '0');
byte[] asciiBytes = Encoding.ASCII.GetBytes(inputString); // 将字符串转换为 ASCII 码数组
StringBuilder hexBuilder = new StringBuilder();
foreach (byte b in asciiBytes)
{
hexBuilder.Append(b.ToString("X2")); // 将每个 ASCII 码转换为 2 位的 16 进制表示
}
string hexString = hexBuilder.ToString();
Console.WriteLine(hexString); // 输出 ASCII 码转换为 16 进制后的字符串
// 如果需要将 16 进制字符串转换回 ASCII 码,可以使用以下方法:
byte[] convertedBytes = new byte[hexString.Length / 2];
for (int i = 0; i < hexString.Length; i += 2)
{
convertedBytes[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16);
}
string convertedString = Encoding.ASCII.GetString(convertedBytes);
Console.WriteLine(convertedString); // 输出将 16 进制字符串转换回 ASCII 码后的字符串
}
public string LastWorkProductionInfo(string barcode, string TableName, string Param)
{
string iflag = "";
try
{
StringBuilder sb = new StringBuilder();
sb.Append(" SELECT TOP(1) State FROM " + TableName + " WHERE ").Append(Param + "='").Append(barcode).Append("' order by InsertTime desc ");
DbHandler db = new DbHandler();
db.dbHelper.ClearParameter();
db.dbHelper.CommandType = CommandType.Text;
db.dbHelper.CommandText = "";
db.dbHelper.CommandText = sb.ToString();
var obj = db.dbHelper.ToScalar();
if (obj != null)
{
return obj.ToString();
}
else
{
return "";
}
}
catch (Exception ex)
{
return iflag;
}
}
public bool UpdateTraceReStartStation(string ISDis, string CurrentStationID, string RestartStation, string ProductBarcode, string SemiBarcode_A)
{
StringBuilder sb = new StringBuilder();
try
{
if (string.IsNullOrEmpty(ProductBarcode))
{
sb.Append(" UPDATE dbo.T_SY_TraceState SET ISDis = '").Append(ISDis);
sb.Append("' , RestartStation='").Append(RestartStation).Append("' ,CurrentStationID='").Append(CurrentStationID).Append("'").Append(" WHERE SemiBarcode_A='").Append(SemiBarcode_A).Append("' ");
}
else
{
sb.Append(" UPDATE dbo.T_SY_TraceState SET ProductBarcode = '").Append(ProductBarcode).Append(" ',ISDis = '").Append(ISDis);
sb.Append("' , RestartStation='").Append(RestartStation).Append("' ,CurrentStationID='").Append(CurrentStationID).Append("'").Append(" WHERE SemiBarcode_A='").Append(SemiBarcode_A).Append("' ");
}
DbHandler db = new DbHandler();
db.dbHelper.ClearParameter();
db.dbHelper.CommandType = CommandType.Text;
db.dbHelper.CommandText = sb.ToString();
db.dbHelper.ExecuteNonQuery();
return true;
}
catch (Exception ex)
{
return false;
}
}
///
/// 16进制转换成字符串
///
///
///
///
public string HexStringToString(string hs, Encoding encode)
{
StringBuilder strTemp = new StringBuilder();
byte[] b = new byte[hs.Length / 2];
for (int i = 0; i < hs.Length / 2; i++)
{
strTemp.Clear();
strTemp.Append(hs.Substring(i * 2, 2));
b[i] = Convert.ToByte(strTemp.ToString(), 16);
}
return encode.GetString(b);
}
private byte[] ReverseBytesByWord(byte[] buffer, int index, int length)
{
if (buffer == null) return null;
// copy data
byte[] tmp = new byte[length];
for (int i = 0; i < length; i++)
{
tmp[i] = buffer[index + i];
}
// change
for (int i = 0; i < length / 2; i++)
{
byte b = tmp[i * 2 + 0];
tmp[i * 2 + 0] = tmp[i * 2 + 1];
tmp[i * 2 + 1] = b;
}
return tmp;
}
public string getSemiBarcodeAByDongPanCode(string productbarcode)
{
StringBuilder sb = new StringBuilder();
try
{
if (productbarcode != "")
{
sb.Append(" SELECT TOP(1) SemiBarcode FROM T_RP_BarcodeRelationShip WHERE ProductBarcode='").Append(productbarcode).Append("' order by InsertTime desc");
}
DbHandler db = new DbHandler();
db.dbHelper.ClearParameter();
db.dbHelper.CommandType = CommandType.Text;
db.dbHelper.CommandText = "";
db.dbHelper.CommandText = sb.ToString();
var obj = db.dbHelper.ToScalar();
if (obj != null)
{
return obj.ToString();
}
else
{
return "";
}
}
catch (Exception e)
{
return "";
}
}
}
}