初始化上传

This commit is contained in:
2025-08-26 08:37:44 +08:00
commit 31d81b91b6
448 changed files with 80981 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
using CCS.Utility.Security;
using MES.Utility.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ursa.Controls;
using .Base;
namespace .ViewModel._05其他
{
public class MD5DESViewModel : ViewModelBase
{
public string DESKey { get; set; } = "";
public string DESSource { get; set; } = "";
public string DESDest { get; set; } = "";
public string MD5Source { get; set; } = "";
public string MD5Dest { get; set; } = "";
public DelegateCommand CalcMD5Cmd { get; set; }
public DelegateCommand DESEncryptCmd { get; set; }
public DelegateCommand DESDecryptCmd { get; set; }
public MD5DESViewModel()
{
CalcMD5Cmd = new DelegateCommand(CalcMD5CmdFunc);
DESEncryptCmd = new DelegateCommand(DESEncryptCmdFunc);
DESDecryptCmd = new DelegateCommand(DESDecryptCmdFunc);
}
/// <summary>
/// 解密
/// </summary>
/// <param name="obj"></param>
private void DESDecryptCmdFunc(object obj)
{
try
{
if (DESKey.IsNullOrEmpty())
{
DESDest = DESHelper.DESDecrypt(DESSource);
}
else
{
DESDest = DESHelper.DESDecrypt(DESSource, DESKey);
}
}
catch (Exception ex)
{
DESDest = ex.Message;
}
}
private void DESEncryptCmdFunc(object obj)
{
try
{
if (DESKey.IsNullOrEmpty())
{
DESDest = DESHelper.DESEncrypt(DESSource);
}
else
{
DESDest = DESHelper.DESEncrypt(DESSource, DESKey);
}
}
catch (Exception ex)
{
DESDest = ex.Message;
}
}
private void CalcMD5CmdFunc(object obj)
{
if (MD5Source.IsNullOrEmpty())
{
MessageBox.ShowAsync("请输入内容");
return;
}
MD5Dest = MD5Source.MD5Encrypt();
}
}
}

View File

@@ -0,0 +1,606 @@
using MES.Utility.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using .Base;
using NHibernate.AdoNet.Util;
using System.Xml;
using System.IO;
namespace .ViewModel._05其他
{
public class SQLStringBuilder封装ViewModel : ViewModelBase
{
public string Button1Text { get; set; } = "生成";
public string TextBox1 { get; set; } = "";
public string TextBox2 { get; set; } = "";
public string TextBox3 { get; set; } = "strSql";
public string Text3Title { get; set; } = "StringBuilder参数:";
public bool TextBox3Visiable { get; set; } = true;
public List<string> FuncList { get; set; }
public int funcIndex = 0;
public int FuncIndex
{
get
{
return funcIndex;
}
set
{
funcIndex = value;
SelectChanged();
NotifyPropertyChanged();
}
}
public bool RadioButton1 { get; set; } = true;
public bool RadioButton2 { get; set; } = false;
public bool RadioButton3 { get; set; } = false;
public string RadioButton1Text { get; set; } = "Java";
public string RadioButton2Text { get; set; } = "C#";
public string RadioButton3Text { get; set; } = "JS";
public bool RadioButton1Visiable { get; set; } = true;
public bool RadioButton2Visiable { get; set; } = true;
public bool RadioButton3Visiable { get; set; } = true;
public bool CheckBox1 { get; set; } = false;
public bool CheckBox3 { get; set; } = true;
public bool CheckBox2 { get; set; } = true;
public bool CheckBox1Visiable { get; set; } = true;
public bool CheckBox3Visiable { get; set; } = true;
public bool CheckBox2Visiable { get; set; } = true;
public DelegateCommand GenerateCmd { get; set; }
public DelegateCommand ClearCmd { get; set; }
public SQLStringBuilder封装ViewModel()
{
FuncList = new List<string>() {
"SQL转StringBuilder",
"XML格式化",
"SQL格式化",
"StringBuilder转SQL",
"大小写转换",
"JSON格式化"
};
FuncIndex = 0;
GenerateCmd = new DelegateCommand(GenerateCmdFunc);
ClearCmd = new DelegateCommand(ClearCmdFunc);
}
private void GenerateCmdFunc(object obj)
{
//SQL转StringBuilder
if (FuncIndex == 0)
{
if (CheckBox1)
{
string text2 = FormatStyle.Basic.Formatter.Format(TextBox1);
TextBox1 = text2;
}
List<string> first = GetFirstContext();
List<string> second = new List<string>();
if (first.Count == 0)
{
TextBox2 = string.Empty;
return;
}
int maxLength = GetMaxLength(GetNewList(first));
if (RadioButton3)
{
second.Add("var " + GetParmName() + " = \"\";");
}
else
{
second.Add("StringBuilder " + GetParmName() + " = new StringBuilder();");
}
//循环处理每一行
foreach (string str in first)
{
if (!CheckBox3)
{
if (str.Trim().StartsWith("--"))
{
second.Add(str.Trim().Replace("--", "//"));
continue;
}
if (str.Contains("--"))
{
//分割
int index = str.IndexOf("--");
string str1 = str.Substring(0, index).TrimEnd();
string str2 = str.Substring(index, str.Length - index).Trim();
if (!CheckBox2)
{
second.Add(GetString2(str1, 0, CheckBox3) + " " + str2.Replace("--", "//"));
}
else
{
string retStr = GetString(str1, maxLength - System.Text.Encoding.Default.GetByteCount(str1), CheckBox3) + " " + str2.Replace("--", "//");
second.Add(retStr);
}
continue;
}
}
if (!CheckBox2)
{
second.Add(GetString2(str, 0, CheckBox3));
}
else
{
second.Add(GetString(str, maxLength - System.Text.Encoding.Default.GetByteCount(str), CheckBox3));
}
}
TextBox2 = second.GetStrArray("\r\n");
}
//XML格式化
else if (FuncIndex == 1)
{
if (TextBox1.IsNullOrEmpty())
{
TextBox2 = string.Empty;
return;
}
TextBox2 = FormatXml(TextBox1);
}
//SQL格式化
else if (FuncIndex == 2)
{
if (TextBox1.IsNullOrEmpty())
{
TextBox2 = string.Empty;
return;
}
TextBox2 = FormatStyle.Basic.Formatter.Format(TextBox1);
}
//StringBuilder转SQL
else if (FuncIndex == 3)
{
List<string> first = GetFirstContext();
List<string> second = new List<string>();
if (first.Count == 0)
{
return;
}
//判断是否每一行是否以StringBuilder开头
string parmName = GetStringBuilderParmName(first[0]);
if (parmName.IsNullOrEmpty())
{
return;
}
for (int i = 1; i < first.Count; i++)
{
string str = first[i];
string handlerStr = HandlerString(str, parmName);
if (!String.Empty.Equals(handlerStr))
{
second.Add(handlerStr);
}
}
if (second.Count != 0)
{
int spaceNum = second[0].IndexOf(second[0].Trim());
for (int i = 0; i < second.Count; i++)
{
second[i] = QuSpace(second[i], spaceNum);
}
}
TextBox2 = second.GetStrArray("\r\n");
}
//大小写转换
else if (FuncIndex == 4)
{
if (TextBox1.IsNullOrEmpty())
{
TextBox2 = string.Empty;
return;
}
List<string> first = GetFirstContext();
List<string> second = new List<string>();
if (RadioButton1)
{
foreach (string str in first)
{
second.Add(str.ToUpper());
}
}
else if (RadioButton2)
{
foreach (string str in first)
{
second.Add(str.ToLower());
}
}
TextBox2 = second.GetStrArray("\r\n");
}
//JSON格式化
else if (FuncIndex == 5)
{
if (TextBox1.IsNullOrEmpty())
{
TextBox2 = string.Empty;
return;
}
TextBox2 = TextBox1.FormatJson();
}
}
private void ClearCmdFunc(object obj)
{
TextBox1 = string.Empty;
TextBox2 = string.Empty;
}
private void SelectChanged()
{
//SQL转StringBuilder
if (FuncIndex == 0)
{
RadioButton1Visiable = true;
RadioButton2Visiable = true;
RadioButton3Visiable = true;
RadioButton1Text = "Java";
RadioButton2Text = "C#";
RadioButton3Text = "JS";
CheckBox1Visiable = true;
CheckBox2Visiable = true;
CheckBox3Visiable = true;
TextBox3Visiable = true;
Button1Text = "生成";
Text3Title = "StringBuilder参数";
TextBox3 = "strSql";
}
//StringBuilder转SQL
else if (FuncIndex == 3)
{
RadioButton1Visiable = false;
RadioButton2Visiable = false;
RadioButton3Visiable = false;
TextBox3Visiable = false;
CheckBox1Visiable =false;
CheckBox2Visiable =false;
CheckBox3Visiable = false;
Button1Text = "生成";
}
//XML格式化
else if (FuncIndex == 1)
{
RadioButton1Visiable = false;
RadioButton2Visiable = false;
RadioButton3Visiable = false;
TextBox3Visiable = false;
CheckBox1Visiable = false;
CheckBox2Visiable = false;
CheckBox3Visiable = false;
Button1Text = "格式化";
}
//JSON格式化
else if (FuncIndex == 5)
{
RadioButton1Visiable = false;
RadioButton2Visiable = false;
RadioButton3Visiable = false;
TextBox3Visiable = false;
CheckBox1Visiable = false;
CheckBox2Visiable = false;
CheckBox3Visiable = false;
Button1Text = "格式化";
}
//SQL格式化
else if (FuncIndex == 2)
{
RadioButton1Visiable = false;
RadioButton2Visiable = false;
RadioButton3Visiable = false;
TextBox3Visiable = false;
CheckBox1Visiable =false;
CheckBox2Visiable =false;
CheckBox3Visiable = false;
Button1Text = "格式化";
}
//大小写转换
else if (FuncIndex == 4)
{
RadioButton1Visiable = true;
RadioButton2Visiable = true;
RadioButton3Visiable = false;
RadioButton1Text = "转大写";
RadioButton2Text = "转小写";
RadioButton1 = true;
TextBox3Visiable = false;
CheckBox1Visiable = false;
CheckBox2Visiable = false;
CheckBox3Visiable = false;
Button1Text = "转换";
}
}
private string FormatXml(string sUnformattedXml)
{
XmlDocument xd = new XmlDocument();
xd.LoadXml(sUnformattedXml);
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
XmlTextWriter xtw = null;
try
{
xtw = new XmlTextWriter(sw);
xtw.Formatting = Formatting.Indented;
xtw.Indentation = 1;
xtw.IndentChar = '\t';
xd.WriteTo(xtw);
}
finally
{
if (xtw != null)
xtw.Close();
}
return sb.ToString();
}
public string GetParmName()
{
string parm = TextBox3.Trim();
if (parm.IsNullOrEmpty())
{
return "strSql";
}
return parm;
}
#region
public List<string> GetNewList(List<string> list)
{
List<string> list2 = new List<string>();
foreach (string str in list)
{
//if (str.Trim().StartsWith("--"))
//{
// continue;
//}
//if (str.Contains("--"))
//{
// int index = str.IndexOf("--");
// list2.Add(str.Substring(0, index));
// continue;
//}
list2.Add(str.TrimEnd());
}
return list2;
}
#endregion
#region List得到其中最长的长度
public int GetMaxLength(List<string> list)
{
int maxLength = 0;
foreach (string str in list)
{
if (System.Text.Encoding.Default.GetByteCount(str) > maxLength)
{
maxLength = System.Text.Encoding.Default.GetByteCount(str);
}
}
return maxLength;
}
#endregion
#region
public string GetString(string strInfo, int spaceNum, bool appendLine)
{
string str = string.Empty;
if (RadioButton1)
{
if (appendLine)
{
str += GetParmName() + ".append(\" " + strInfo + GetSpace(spaceNum) + " \").append(\"\\n\");";
}
else
{
str += GetParmName() + ".append(\" " + strInfo + GetSpace(spaceNum) + " \");";
}
}
if (RadioButton2)
{
if (appendLine)
{
str += GetParmName() + ".Append(\" " + strInfo + GetSpace(spaceNum) + " \").AppendLine();";
}
else
{
str += GetParmName() + ".Append(\" " + strInfo + GetSpace(spaceNum) + " \");";
}
}
if (RadioButton3)
{
if (appendLine)
{
str += GetParmName() + " += \" " + strInfo + GetSpace(spaceNum) + " \\n\";";
}
else
{
str += GetParmName() + " += \" " + strInfo + GetSpace(spaceNum) + " \";";
}
}
return str;
}
public string GetString2(string strInfo, int spaceNum, bool appendLine)
{
string str = string.Empty;
if (RadioButton1)
{
if (appendLine)
{
str += GetParmName() + ".append(\" " + strInfo + GetSpace(spaceNum) + "\").append(\"\\n\");";
}
else
{
str += GetParmName() + ".append(\" " + strInfo + GetSpace(spaceNum) + "\");";
}
}
if (RadioButton2)
{
if (appendLine)
{
str += GetParmName() + ".Append(\" " + strInfo + GetSpace(spaceNum) + "\").AppendLine();";
}
else
{
str += GetParmName() + ".Append(\" " + strInfo + GetSpace(spaceNum) + "\");";
}
}
if (RadioButton3)
{
if (appendLine)
{
str += GetParmName() + " += \" " + strInfo + GetSpace(spaceNum) + "\\n\";";
}
else
{
str += GetParmName() + " += \" " + strInfo + GetSpace(spaceNum) + "\";";
}
}
return str;
}
#endregion
#region
public string GetSpace(int num)
{
string str = string.Empty;
for (int i = 0; i < num; i++)
{
str += " ";
}
return str;
}
#endregion
#region
public List<string> GetFirstContext()
{
List<string> list = new List<string>();
string content = TextBox1;
if (string.Empty.Equals(content.Trim()))
{
return list;
}
if (content.Contains("\t"))
{
content = content.Replace("\t", " ");
}
content = content.Replace("\r", "");
string[] str = content.Split('\n');
foreach (string strings in str)
{
if (!string.Empty.Equals(strings.Trim()))
{
list.Add(strings.TrimEnd());
}
}
return list;
}
#endregion
private string QuSpace(string str, int spaceNum)
{
string space = string.Empty;
for (int i = 0; i < spaceNum; i++)
{
space += " ";
}
if (!str.Contains(space))
{
return str;
}
return str.Substring(str.IndexOf(space) + spaceNum, str.Length - str.IndexOf(space) - spaceNum);
}
private string HandlerString(string str, string parmName)
{
if (str.Contains(parmName + ".Append"))
{
//得到StringBuilder中间的词
string sqlStr = GetStringBuilderText(str, parmName + ".Append");
//得到注释
string zhushi = GetZhuShi(str);
//拼接
if (string.Empty.Equals(zhushi))
{
return sqlStr.TrimEnd();
}
else
{
return sqlStr.TrimEnd() + " --" + zhushi;
}
}
if (str.Contains(parmName + ".append"))
{
//得到StringBuilder中间的词
string sqlStr = GetStringBuilderText(str, parmName + ".append");
//得到注释
string zhushi = GetZhuShi(str);
//拼接
if (string.Empty.Equals(zhushi))
{
return sqlStr.TrimEnd();
}
else
{
return sqlStr.TrimEnd() + " --" + zhushi;
}
}
return string.Empty;
}
private string GetStringBuilderText(string str, string startStr)
{
startStr = startStr + "(\"";
str = str.Substring(str.IndexOf(startStr), str.IndexOf("\")") - str.IndexOf(startStr));
str = str.Substring(startStr.Length, str.Length - startStr.Length);
return str;
}
private string GetZhuShi(string str)
{
string retStr = string.Empty;
if (str.Contains(@"//"))
{
retStr = str.Substring(str.IndexOf("//") + 2, str.Length - str.IndexOf("//") - 2);
}
return retStr;
}
private string GetStringBuilderParmName(string str)
{
string parmName = String.Empty;
if (!str.Contains("StringBuilder"))
{
return parmName;
}
str = str.Substring(str.IndexOf("StringBuilder"), str.IndexOf("=") - str.IndexOf("StringBuilder"));
str = str.Substring(str.IndexOf(" "), str.Length - str.IndexOf(" "));
parmName = str.Trim();
return parmName;
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using .Base;
namespace .ViewModel._05其他
{
public class ViewModel : ViewModelBase
{
}
}

View File

@@ -0,0 +1,199 @@
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Ursa.Controls;
using .Base;
namespace .ViewModel._05其他
{
public class ViewModel : ViewModelBase
{
public bool Enabled1 { get; set; } = true;
public bool Enabled2 { get; set; } = false;
//串口号下拉列表数据
public List<string> SerialList { get; set; }
public int SerialIndex { get; set; } = 0;
public string Data { get; set; } = "";
public DelegateCommand OpenCmd { get; set; }
public DelegateCommand CloseCmd { get; set; }
public DelegateCommand ReadCmd { get; set; }
public DelegateCommand WriteCmd { get; set; }
public DelegateCommand ClearCmd { get; set; }
private SerialPort sp1;
public ViewModel()
{
this.sp1 = new SerialPort();
//串口号
string[] portNames = SerialPort.GetPortNames();
if (portNames != null && portNames.Length > 0)
{
SerialList = portNames.ToList();
}
OpenCmd = new DelegateCommand(OpenCmdFunc);
CloseCmd = new DelegateCommand(CloseCmdFunc);
ReadCmd = new DelegateCommand(ReadCmdFunc);
WriteCmd = new DelegateCommand(WriteCmdFunc);
ClearCmd = new DelegateCommand(ClearCmdFunc);
}
private void OpenCmdFunc(object obj)
{
try
{
this.sp1.PortName = SerialList[SerialIndex];
this.sp1.BaudRate = 19200;
this.sp1.DataBits = 8;
this.sp1.StopBits = StopBits.One;
this.sp1.Parity = Parity.None;
if (this.sp1.IsOpen)
{
this.sp1.Close();
}
this.sp1.Open();
Enabled1 = false;
Enabled2 = true;
}
catch (Exception ex)
{
MessageBox.ShowAsync(ex.Message);
}
}
private void CloseCmdFunc(object obj)
{
if (this.sp1.IsOpen)
{
this.sp1.Close();
}
Enabled1 = true;
Enabled2 = false;
}
private void ReadCmdFunc(object obj)
{
List<byte> list = this.sendData(this.getReadData());
if ((list != null) && (list.Count >= 15))
{
int num = 0;
num = (((((((list[9] << 8) | list[10]) << 8) | list[11]) << 8) | list[12]) << 8) | list[13];
Data = Convert.ToString(num);
this.sendData(this.getBeatData());
}
}
private void WriteCmdFunc(object obj)
{
if (this.sp1.IsOpen)
{
string str = Data;
int num = 0;
bool flag = int.TryParse(str, out num);
if (!flag)
{
MessageBox.ShowAsync("请输入数字");
return;
}
if ((num < 0) || (num >= 999999999))
{
MessageBox.ShowAsync("数字只能在0~999999999之间");
return;
}
byte a = (byte)((num & 0xff00000000L) >> 32);
byte b = (byte)((num & 0xff000000L) >> 24);
byte c = (byte)((num & 0xff0000) >> 16);
byte d = (byte)((num & 0xff00) >> 8);
byte num8 = (byte)(num & 0xff);
this.sendData(this.getWriteData(a, b, c, d, num8));
this.sendData(this.getBeatData());
}
}
private void ClearCmdFunc(object obj)
{
Data = "";
}
private List<byte> getBeatData()
{
return new List<byte> { 0xAA, 0xBB, 0x05, 0x00, 0x00, 0x00, 0x06, 0x01, 0x07 };
}
private List<byte> getReadData()
{
return new List<byte> { 0xAA, 0xBB, 0x05, 0x00, 0x00, 0x00, 0x10, 0x20, 0x30 };
}
private List<byte> getWriteData(byte a, byte b, byte c, byte d, byte e)
{
List<byte> list = new List<byte>();
list.Add(0xAA);
list.Add(0xBB);
list.Add(0x0A);
list.Add(0x00);
list.Add(0x00);
list.Add(0x00);
list.Add(0x09);
list.Add(0x03);
list.Add(a);
list.Add(b);
list.Add(c);
list.Add(d);
list.Add(e);
byte item = list[6];
for (int i = 7; i < 13; i++)
{
item ^= list[i];
}
list.Add(item);
return list;
}
public List<byte> sendData(List<byte> sendData)
{
if (!this.sp1.IsOpen)
{
return null;
}
this.sp1.Write(sendData.ToArray(), 0, sendData.Count);
while (this.sp1.BytesToRead == 0)
{
Thread.Sleep(1);
}
Thread.Sleep(50);
byte[] buffer = new byte[this.sp1.BytesToRead];
this.sp1.Read(buffer, 0, buffer.Length);
return buffer.ToList<byte>();
}
private void Sp1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (this.sp1.IsOpen)
{
DateTime now = DateTime.Now;
try
{
byte[] buffer = new byte[this.sp1.BytesToRead];
this.sp1.Read(buffer, 0, buffer.Length);
}
catch (Exception exception)
{
MessageBox.ShowAsync(exception.Message, "出错提示!!!!!");
}
}
else
{
MessageBox.ShowAsync("请打开某个串口", "错误提示");
}
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using .Base;
namespace .ViewModel._05其他
{
public class ViewModel : ViewModelBase
{
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using .Base;
namespace .ViewModel._05其他
{
public class ASCII转换ViewModel : ViewModelBase
{
}
}