sc 2 months ago
parent
commit
8091b3dcc4
  1. 13
      UserClass/AsyncTcpClient.cs
  2. 4
      View/DispenseMachinesSet.xaml.cs
  3. 29
      View/MachinesSet.xaml
  4. 166
      View/MachinesSet.xaml.cs
  5. 30
      ViewModel/MainWindowViewModel.cs

13
UserClass/AsyncTcpClient.cs

@ -161,6 +161,19 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
}
}
else if (SYSAPI == "SC811")
{
try
{
DAT = DAT.Substring(DAT.IndexOf("]") + 1);
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Update("WorkOrder", new Dictionary<string, object> { { "State", 113 } },
"WorkOrder ='" + DAT + "'", null);
SQLiteHelpers.Close();
}
catch (Exception ex) { LogGing.LogGingDATA("[ERR='" + ex + "']=Exception"); MainWindowViewModel.ERR_c++; }
}
else if (SYSAPI == "SC812")
{
try
{

4
View/DispenseMachinesSet.xaml.cs

@ -34,11 +34,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
public DispenseMachinesSet()
{
InitializeComponent();
//
string[] Machine_ = { "252", "252RB", "252-2T", "252RDRM", "242W", "302", "303", "303PDW" };
TextMachineGroup.ItemsSource = Machine_;
TextMachineGroup.ItemsSource = Machine_;
}
private SQLiteHelper SQLiteHelpers = null; //定义数据库

29
View/MachinesSet.xaml

@ -65,25 +65,28 @@
<DataGridTextColumn Binding="{Binding Serial}" Width="0" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Baud}" Width="0" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding ID}" Width="0" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Type}" Width="0" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
<ComboBox HorizontalAlignment="Left" Height="30" Margin="150,10,0,0" x:Name="comboBoxMachine" VerticalAlignment="Top" Width="270" FontSize="20" IsEditable="True" />
<ComboBox HorizontalAlignment="Left" Height="40" Margin="150,10,0,0" x:Name="comboBoxMachine" VerticalAlignment="Top" Width="270" FontSize="20" IsEditable="True" />
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,10,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.Machine}" VerticalAlignment="Top" Width="120" FontSize="25"/>
<TextBox HorizontalAlignment="Left" Height="30" Margin="150,50,0,0" x:Name="TextMachineGroup" VerticalAlignment="Top" Width="270" FontSize="20" MaxLines="1"/>
<TextBox HorizontalAlignment="Left" Height="40" Margin="150,50,0,0" x:Name="TextMachineGroup" VerticalAlignment="Top" Width="270" FontSize="20" MaxLines="1"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,50,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.MachineGroup}" VerticalAlignment="Top" Width="120" FontSize="25"/>
<TextBox HorizontalAlignment="Left" Height="30" Margin="150,100,0,0" x:Name="IP" VerticalAlignment="Top" Width="200" FontSize="20" MaxLines="1"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="350,100,0,0" TextWrapping="Wrap" Text=":" VerticalAlignment="Top" Width="20" FontSize="25"/>
<TextBox HorizontalAlignment="Left" Height="30" Margin="360,100,0,0" x:Name="PORT" VerticalAlignment="Top" Width="60" FontSize="20" MaxLines="1" Text="7789"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,100,0,0" TextWrapping="Wrap" Text="IP/PORT" VerticalAlignment="Top" Width="120" FontSize="25"/>
<ComboBox HorizontalAlignment="Left" Height="30" Margin="150,150,0,0" x:Name="comboBoxCOM0" VerticalAlignment="Top" Width="200" FontSize="20" />
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,150,0,0" TextWrapping="Wrap" Text="COM" VerticalAlignment="Top" Width="120" FontSize="25"/>
<TextBox HorizontalAlignment="Left" Height="30" Margin="360,150,0,0" x:Name="BAUD" VerticalAlignment="Top" Width="60" FontSize="20" MaxLines="1" Text="57600"/>
<ComboBox HorizontalAlignment="Left" Height="40" Margin="150,100,0,0" x:Name="comboBoxtype" VerticalAlignment="Top" Width="270" FontSize="20" IsEditable="True" />
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,100,0,0" TextWrapping="Wrap" Text="{x:Static lang:Resources.Type}" VerticalAlignment="Top" Width="120" FontSize="25"/>
<TextBox HorizontalAlignment="Left" Height="40" Margin="150,150,0,0" x:Name="IP" VerticalAlignment="Top" Width="200" FontSize="20" MaxLines="1"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="350,150,0,0" TextWrapping="Wrap" Text=":" VerticalAlignment="Top" Width="20" FontSize="25"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,200,0,0" x:Name="textlog" TextWrapping="Wrap" Text="------------" VerticalAlignment="Top" Width="140" FontSize="20"/>
<Button Content="{x:Static lang:Resources.Save}" HorizontalAlignment="Left" Height="35" Margin="250,200,0,5" VerticalAlignment="Top" Width="80" Click="Save_Click"/>
<Button Content="{x:Static lang:Resources.Delete}" HorizontalAlignment="Left" Height="35" Margin="340,200,0,5" VerticalAlignment="Top" Width="80" Click="Delete_Click"/>
<Button Content="{x:Static lang:Resources.Test}" HorizontalAlignment="Left" Height="35" Margin="160,200,50,5" VerticalAlignment="Top" Width="80" Click="Test_Click"/>
<TextBox HorizontalAlignment="Left" Height="40" Margin="360,150,0,0" x:Name="PORT" VerticalAlignment="Top" Width="60" FontSize="20" MaxLines="1" Text="7789"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,150,0,0" TextWrapping="Wrap" Text="IP/PORT" VerticalAlignment="Top" Width="120" FontSize="25"/>
<ComboBox HorizontalAlignment="Left" Height="40" Margin="150,200,0,0" x:Name="comboBoxCOM0" VerticalAlignment="Top" Width="200" FontSize="20" />
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,200,0,0" TextWrapping="Wrap" Text="COM" VerticalAlignment="Top" Width="120" FontSize="25"/>
<TextBox HorizontalAlignment="Left" Height="40" Margin="360,200,0,0" x:Name="BAUD" VerticalAlignment="Top" Width="60" FontSize="20" MaxLines="1" Text="57600"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="350,200,0,0" TextWrapping="Wrap" Text=":" VerticalAlignment="Top" Width="20" FontSize="25"/>
<TextBlock HorizontalAlignment="Left" Height="40" Margin="10,250,0,0" x:Name="textlog" TextWrapping="Wrap" Text="------------" VerticalAlignment="Top" Width="140" FontSize="20"/>
<Button Content="{x:Static lang:Resources.Save}" HorizontalAlignment="Left" Height="35" Margin="250,250,0,5" VerticalAlignment="Top" Width="80" Click="Save_Click"/>
<Button Content="{x:Static lang:Resources.Delete}" HorizontalAlignment="Left" Height="35" Margin="340,250,0,5" VerticalAlignment="Top" Width="80" Click="Delete_Click"/>
<Button Content="{x:Static lang:Resources.Test}" HorizontalAlignment="Left" Height="35" Margin="160,250,50,5" VerticalAlignment="Top" Width="80" Click="Test_Click"/>

166
View/MachinesSet.xaml.cs

@ -39,7 +39,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
comboBoxCOM0.ItemsSource = ports;
comboBoxCOM0.Text = Configini.IniReadvalue("SYS", "COM");
comboBoxMachine.ItemsSource = MainWindowViewModel.Machines.AsEnumerable().Select(rowdata => rowdata.Field<string>("name")).ToList();//转换机台
string[] type_ = { "828", "838" };
comboBoxtype.ItemsSource = type_;
}
private SQLiteHelper SQLiteHelpers = null; //定义数据库
@ -64,6 +65,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
PORT.Text = (Griddata.Columns[4].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列,
comboBoxCOM0.Text = (Griddata.Columns[5].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列,
BAUD.Text = (Griddata.Columns[6].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列,
comboBoxtype.Text = (Griddata.Columns[8].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;
}
}
@ -71,21 +73,31 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
{
if (!string.IsNullOrEmpty(comboBoxMachine.Text))
{
Dictionary<string, object> Machines_DAT = new Dictionary<string, object>();//缓存函数
Dictionary<string, object> dr_new = new Dictionary<string, object>();//缓存函数
dr_new.Add("Name", comboBoxMachine.Text);
dr_new.Add("Groups", TextMachineGroup.Text);
dr_new.Add("IP", IP.Text);
dr_new.Add("PORT", PORT.Text);
dr_new.Add("Serial", comboBoxCOM0.Text);
dr_new.Add("Baud", BAUD.Text);
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
if (SQLiteHelpers.ExecuteDataSet("select * from Machines where name ='" + comboBoxMachine.Text + "'", null).Tables[0].Rows.Count == 0)
{
MainWindowViewModel.Machines.Rows.Add(dr_new);
DatSteps(MainWindowViewModel.Machines);
{
DataRow dat_= MainWindowViewModel.Machines.NewRow();
dat_.BeginEdit();
dat_["Name"] = comboBoxMachine.Text;
dat_["Groups"] = TextMachineGroup.Text;
dat_["IP"] = IP.Text;
dat_["PORT"] = PORT.Text;
dat_["Serial"] = comboBoxCOM0.Text;
dat_["Type"] = comboBoxtype.Text;
dat_["Baud"] = BAUD.Text;
dat_["ID"] = 999;
dat_["ERR"] = false;
dat_["AUTO"] = false;
dat_["CALL"] = false;
dat_["LOCK"] = false;
if (comboBoxtype.Text == "838")
{ dat_["Desktop"] = true; }
else { dat_["Desktop"] = false; }
dat_.EndEdit();
MainWindowViewModel.Machines.Rows.Add(dat_);
DatSteps(MainWindowViewModel.Machines);
SQLiteHelpers.Delete("Machines", null, null);//
for (int x = 0; x < MainWindowViewModel.Machines.Rows.Count; x++)
{
@ -98,20 +110,21 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
Machines_DAT.Add("Groups", MainWindowViewModel.Machines.Rows[x]["Groups"]);
Machines_DAT.Add("Desktop", MainWindowViewModel.Machines.Rows[x]["Desktop"]);
Machines_DAT.Add("Dispense", MainWindowViewModel.Machines.Rows[x]["Dispense"]);
Machines_DAT.Add("LOCK", "FALSE");
Machines_DAT.Add("Type", MainWindowViewModel.Machines.Rows[x]["Type"]);
SQLiteHelpers.InsertData("Machines", Machines_DAT);//行插入
Machines_DAT.Clear();
}
}
else
else
{
DataRow dr = MainWindowViewModel.Machines.Rows[ID_-1];
DataRow dr = MainWindowViewModel.Machines.Rows[ID_];
dr.BeginEdit();
dr["Name"] = comboBoxMachine.Text;
dr["Groups"] = TextMachineGroup.Text;
dr["IP"] = IP.Text;
dr["PORT"] = PORT.Text;
dr["Serial"] = comboBoxCOM0.Text;
dr["Type"] = comboBoxtype.Text;
dr["Baud"] = BAUD.Text;
dr.EndEdit();
SQLiteHelpers.Delete("Machines", null, null);//
@ -126,11 +139,12 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
Machines_DAT.Add("Groups", MainWindowViewModel.Machines.Rows[x]["Groups"]);
Machines_DAT.Add("Desktop", MainWindowViewModel.Machines.Rows[x]["Desktop"]);
Machines_DAT.Add("Dispense", MainWindowViewModel.Machines.Rows[x]["Dispense"]);
Machines_DAT.Add("Type", MainWindowViewModel.Machines.Rows[x]["Type"]);
Machines_DAT.Add("LOCK", "FALSE");
SQLiteHelpers.InsertData("Machines", Machines_DAT);//行插入
Machines_DAT.Clear();
}
}
}
SQLiteHelpers.Close();
Griddata.ItemsSource = MainWindowViewModel.Machines.DefaultView;
comboBoxMachine.Text = null;
@ -153,14 +167,14 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
MessageBoxResult vr = System.Windows.MessageBox.Show(Properties.Resources.Delete + comboBoxMachine.Text, "SCCM", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (vr == MessageBoxResult.OK) // 如果是确定,就执行下面代码
{
MainWindowViewModel.Machines.Rows.RemoveAt(ID_-1);
MainWindowViewModel.Machines.Rows.RemoveAt(ID_ - 1);
DatSteps(MainWindowViewModel.Machines);
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
Dictionary<string, object> Machines_DAT = new Dictionary<string, object>();//缓存函数
SQLiteHelpers.Delete("Machines",null, null);//
SQLiteHelpers.Delete("Machines", null, null);//
for (int x = 0; x < MainWindowViewModel.Machines.Rows.Count; x++)
{
Machines_DAT.Add("ID", MainWindowViewModel.Machines.Rows[x]["ID"]);
@ -196,60 +210,108 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
{
DataRow dr = db.Rows[i];
dr.BeginEdit();
dr["ID"] = i ;
dr["ID"] = i;
dr.EndEdit();
}
}
private void Test_Click(object sender, RoutedEventArgs e)//测试按钮
{
if (!string.IsNullOrEmpty(IP.Text) && !string.IsNullOrEmpty(PORT.Text))
if (comboBoxtype.Text == "828")
{
if (!string.IsNullOrEmpty(comboBoxCOM0.Text) && !string.IsNullOrEmpty(BAUD.Text))
{
textlog.Text = "TEST";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 255));
//------------使用ping类------
string host = IP.Text;
Ping p1 = new Ping();
PingReply reply = p1.Send(host); //发送主机名或Ip地址
//StringBuilder sbuilder;
if (reply.Status == IPStatus.Success)
{
try
{
textlog.Text = "Link succeed";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0));
}
catch (Exception)
{
textlog.Text = "Link failed";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 0));
}
}
else
{
textlog.Text = "No links";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
}
}
else
{
textlog.Text = "Invalid";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
}
}
else if (comboBoxtype.Text == "838")
{
textlog.Text = "TEST";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 255));
//------------使用ping类------
string host = IP.Text;
Ping p1 = new Ping();
PingReply reply = p1.Send(host); //发送主机名或Ip地址
//StringBuilder sbuilder;
if (reply.Status == IPStatus.Success)
if (!string.IsNullOrEmpty(IP.Text) && !string.IsNullOrEmpty(PORT.Text))
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//连接服务器,绑定IP 与 端口
IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Parse(IP.Text), int.Parse(PORT.Text));
textlog.Text = "TEST";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(0, 0, 255));
//------------使用ping类------
string host = IP.Text;
try
{
socket.Connect(iPEndPoint);
socket.Close();//离线
textlog.Text = "Link succeed";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0));
Ping p1 = new Ping();
PingReply reply = p1.Send(host); //发送主机名或Ip地址
//StringBuilder sbuilder;
if (reply.Status == IPStatus.Success)
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//连接服务器,绑定IP 与 端口
IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Parse(IP.Text), int.Parse(PORT.Text));
try
{
socket.Connect(iPEndPoint);
socket.Close();//离线
textlog.Text = "Link succeed";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0));
}
catch (Exception)
{
textlog.Text = "Link failed";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 0));
}
}
else if (reply.Status == IPStatus.TimedOut)
{
textlog.Text = "Link timeout";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
}
else
{
textlog.Text = "No links";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
}
}
catch (Exception)
catch (Exception)
{
textlog.Text = "Link failed";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 0));
textlog.Text = "No links";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
}
}
else if (reply.Status == IPStatus.TimedOut)
else if (!string.IsNullOrEmpty(comboBoxCOM0.Text))
{
textlog.Text = "Link timeout";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
}
else
{
textlog.Text = "No links";
textlog.Text = "Invalid";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
}
}
else if (!string.IsNullOrEmpty(comboBoxCOM0.Text))
{
}
else
{
textlog.Text = "Invalid";
textlog.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
}
}
}
}

30
ViewModel/MainWindowViewModel.cs

@ -208,7 +208,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
void Tick_Main_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
{
int mid;
/*下传工单信息*/
SQLiteHelper WorkOrderSQL = new SQLiteHelper(DBAddress); //数据库连接路径
WorkOrderSQL.Open(); //打开数据库
@ -266,11 +265,34 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
"WorkOrder ='" + WorkOrderdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
}
}
/*下传工单设置*/
DataTable WorkOrderset_ = WorkOrderSQL.ExecuteDataSet("select * from WorkOrder where State='113'"+
"AND EndTime >'" + DateTime.Now.AddHours(-8).ToString("yyyy/MM/dd HH:mm:ss") + "'", null).Tables[0]; //读取表写入缓存
for (int k = 0; k < WorkOrderset_.Rows.Count; k++)
{
string WorkOrderset_m = WorkOrderset_.Select()[k].Field<object>("Machines").ToString();
string WorkOrderset_w = WorkOrderset_.Select()[k].Field<object>("WorkOrder").ToString();
int index = Convert.ToInt16(Selet_Machines(Machines, "ID", "Name='" + WorkOrderset_m + "'").ToString());
DataTable WorkOrder_set = WorkOrderSQL.ExecuteDataSet("select * from WorkOrderSet where WorkOrder='" +
WorkOrderset_w + "'", null).Tables[0]; //读取表写入缓存
if (WorkOrder_set.Rows.Count > 0)
{
stringQueue.Enqueue(new QueueString
{
ID = index,
DAT = "SC812" + Selet_Machines(Machines, "SYSKEY", "ID='" + index + "'") + DataTableToDictionary(WorkOrder_set).ToJsonString()
});
}
WorkOrderSQL.Update("WorkOrder", new Dictionary<string, object> { { "State", 110 } },
"WorkOrder ='" + WorkOrderdata.Select()[k].Field<object>("WorkOrder").ToString() + "'", null);
}
WorkOrderSQL.Close();
//系统时间
Sys_Time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
//更新机台状态与发送指令
//更新机台状态与发送指令
for (int i = 0; i < Machinesdata_Count; i++)
{
if (Selet_Machines(Machines, "State", "ID='" + i + "'").ToString() == "802")
@ -299,9 +321,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
Updata_Machines(Machines, "State", "ID='" + i + "'", "101");
}
}
for (int i = 0; i < Machinesdata_Count; i++)
{
int m_run = (int)Selet_Machines(Machines, "WORK_RUN", "ID='" + i + "'");
if (m_run==0)
{
@ -665,6 +684,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
dataRow["ERR"] = false;
dataRow["LOCK"] = false;
dataRow["AUTO"] = false;
dataRow["CALL"] = false;
dataRow["UserInfoStart"] = 900;
dataRow.EndEdit();
dataRow.AcceptChanges();

Loading…
Cancel
Save