using Newtonsoft.Json; using sunui.forms; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Web.UI.WebControls; using System.Windows.Forms; using System.Xml.Linq; using WMS.EnumDefine; using WMS.Model; using WMS.UI.Basic; using WMS.UI.SynthesizeQuery; using WMS.Untils; using Button = System.Windows.Forms.Button; using CheckBox = System.Windows.Forms.CheckBox; namespace WMS.UI.WORK { public partial class preview : Form { /// /// 选择的输送线编号 /// int check_convs_num = 0; //上线点库存数据 List UpStationInfo = new List(); Dictionary conveyorName = new Dictionary { {"2-39-1","Conveyor1"}, {"1-39-1","Conveyor2"}, {"1-0-1","Conveyor3"}, {"2-0-1","Conveyor4"}, }; string apiBase = "http://192.168.0.3"; // string apiBase = "http://localhost"; //已打开的窗口名集合 public static List newform = new List(); public preview() { InitializeComponent(); //dataGridView1.AutoGenerateColumns = false; Thread getStationTh = new Thread(getStation); getStationTh.Start(); } /// 解锁输送线状态和打开站点流水号 /// /// /// /// private void GTU1_Click(object sender, EventArgs e) { Button button = (Button)sender; //解锁输送线锁定状态 if (button.Name == "Conveyor1" || button.Name == "Conveyor2" || button.Name == "Conveyor3" || button.Name == "Conveyor4") { /* DialogResult dr = MessageBox.Show($"确认要解锁库位 {button.Text} 吗", "解锁库位确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { var res = FLogin.wcsWcf.unlockPosition(button.Text); WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(res.status == 200 ? 1 : 2, res.status == 200 ? "解锁成功" : "解锁失败"); ms.Show(); } //*/ //要求必须输入管理员密码才可以!!! FormManagerPassword fr = new FormManagerPassword(); fr.StartPosition = FormStartPosition.CenterScreen; fr.ShowDialog(); if (!fr.isValidateOk) { return; } var ret = FLogin.wcsWcf.findSinglePosition(button.Text); if (ret.status == 200) { var postion = ret.date.First(); var isLock = postion.isLock == true ? 1 : 0; var str_LastModifyTime = postion.LastModifyTime == null ? "" : ((DateTime)postion.LastModifyTime).ToString("yyyy-MM-dd HH:mm:ss"); placeEditForLock listView = new placeEditForLock(postion.positionId.ToString(), postion.positionName, isLock, postion.remark, postion.lastModifier, str_LastModifyTime ); listView.ShowDialog(); } else { WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "没有找到库位数据"); ms.Show(); } } else//打开上线点流水号 { if (!newform.Contains(button.Text)) { FrmPVClist listView = new FrmPVClist(button.Text, 1);//dataGridView1 listView.Show(); newform.Add(button.Text); } else { WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "此窗口已打开"); ms.Show(); } } } /// 获取输送线和上线点是状态 /// /// private void getStation() { while (true) { Thread.Sleep(2000); if (WMSFrmMain.isCurrentShowpreview == false) { continue; } try { List stations = FLogin.wcsWcf.stationStatus().date.ToList(); if (stations.Count > 0) { #region 判断输送线是否锁定 foreach (var item in stations) { var conv = stations.FirstOrDefault(x => x.positionName == item.positionName);//ControlText if (conv != null) { var name = conveyorName[item.positionName]; this.Controls.Find(name, true)[0].BackColor = conv.isLock == true ? Color.Red : Color.FromArgb(225, 225, 225); } } #endregion } #region 上线点是否有货 var res = FLogin.wcsWcf.UpStationInfo(); if (res.status == 200) { UpStationInfo = res.date.ToList(); foreach (var item in UpStationInfo) { this.Controls.Find(item.positionName, true)[0].BackColor = item.isfree == true ? Color.FromArgb(124, 205, 124) : Color.FromArgb(225, 225, 225); } } #endregion #region 获取AGV发送消息 string[] dataList = FLogin.wcsWcf.findAgvInfo(); if (dataList != null) { if (dataList.Length > 0) { label_agvGT.Text = dataList[0]; label_agvGG.Text = dataList[1]; } } #endregion } catch (Exception) { } } } /// 缸盖上线 /// /// /// /// private void button3_Click(object sender, EventArgs e) { try { HTTPService api = new HTTPService(apiBase + ":1025/pda/"); // HTTPService api = new HTTPService("http://localhost:1025/pda/"); string paprm = JsonConvert.SerializeObject(""); Guid guid = System.Guid.NewGuid(); string res = api.postContentForStringForAgv("GGoutStock/?materialCode=" + textBox3.Text.Trim() + "&station=" + comboBox8.SelectedItem.ToString(), paprm, guid); WMSCommon.SendToAGVResult(res); textBox2.Text = "缸盖上线叫料返回消息:" + DateTime.Now.ToLocalTime().ToShortTimeString() + res; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } /// 缸体上线 /// /// /// /// private void button12_Click(object sender, EventArgs e) { try { HTTPService api = new HTTPService(apiBase + ":1025/pda/"); string paprm = JsonConvert.SerializeObject(""); Guid guid = System.Guid.NewGuid(); string res = api.postContentForStringForAgv("GToutStock/?materialCode=" + textBox3.Text.Trim() + "&station=" + comboBox8.SelectedItem.ToString(), paprm, guid); WMSCommon.SendToAGVResult(res); textBox2.Text = "缸体上线叫料返回消息:" + DateTime.Now.ToLocalTime().ToShortTimeString() + res; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } /// 获取设备状态 /// /// private void getDeviceStatus_Srm() { while (true) { Thread.Sleep(1000); try { var srm = FLogin.wcsWcf.getSrmStatus(); if (srm != null) { label34.Text = "心跳:" + srm.handShake; label32.Text = "模式:" + srm.mode; label26.Text = "任务ID:" + srm.TaskID.ToString(); label25.Text = "状态:" + srm.state; label30.Text = "当前列:" + srm.posY; label27.Text = "当前层:" + srm.posZ; label28.Text = "报警信息:" + srm.Alarm_info; label53.Text = "是否完成:" + srm.taskFinish; label6.Text = "是否收到任务:" + srm.stb; label13.Text = "是否有货:" + srm.haveGoods; lbl_stateDetailName.Text = "详细状态:" + srm.stateDetailName; lbl_srmTaskExcuteName.Text = "任务执行:" + srm.srmTaskExcuteName; } } catch (Exception) { } } } private void getDeviceStatus_Convs() { while (true) { Thread.Sleep(1000); try { var convs = FLogin.wcsWcf.getConvStatus(); #region 输送线赋值 if (convs != null) { if (convs.Length == 4) { //int num = Convert.ToInt32(comboBox1.SelectedItem); int num = check_convs_num; if (num < 5 && num > 0) { label49.Text = "输送线编号:L0" + num; label50.Text = "心跳:" + convs[num - 1].handShake; label48.Text = "模式:" + convs[num - 1].mode; label43.Text = "任务id:" + convs[num - 1].taskId; if (convs[num - 1].position == "0") { label42.Text = "位置:无货"; } else { label42.Text = convs[num - 1].position == "1" ? "位置:外侧有货" : "位置:内测有货"; } label47.Text = "外形检测:" + convs[num - 1].check; label46.Text = "是否报警:" + convs[num - 1].isAlarm; lbl_GJJY.Text = "输送线外侧工件记忆:" + convs[num - 1].W_GJJY; lbl_LoadMaterialConfirm.Text = "放料完成信号:" + convs[num - 1].W_LoadMaterialConfirm; } else { label49.Text = "输送线编号:"; label50.Text = "心跳:"; label48.Text = "模式:"; label43.Text = "任务id:"; label42.Text = "位置:"; label47.Text = "外形检测:"; label46.Text = "是否报警:"; lbl_GJJY.Text = "输送线外侧工件记忆:"; lbl_LoadMaterialConfirm.Text = "放料完成信号:"; } } } #endregion } catch (Exception) { } } } private void preview_Load(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; Thread getinfo = new Thread(getDeviceStatus_Srm); getinfo.Start(); Thread getinfo2 = new Thread(getDeviceStatus_Convs); getinfo2.Start(); } /// 发送缸盖侧AGV任务 /// /// /// /// private void button17_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("本次任务将是AGV单机任务,仓储系统不会更改库存信息,请谨慎操作,确定要发送任务吗", "AGV任务", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { try {//postContent var newAgvTaskNo = ""; using (yunneiWCS.IyunneiWcfClient client = new yunneiWCS.IyunneiWcfClient()) { newAgvTaskNo = client.CreateTaskIdForAgvTaskByHand(); } tb_GG_AgvTaskNo.Text = newAgvTaskNo; var apiAddress = "http://192.168.0.3:6546/api/v2/"; var url = "orders"; HTTPService api = new HTTPService(apiAddress); //HTTPService api = new HTTPService(" http://localhost:1026/api/pp/"); var data = new { id = newAgvTaskNo, systemId = "WMS", type = "LoadingAndUnloading", source = comboBox2.SelectedItem, destination = comboBox3.SelectedItem }; string paprm = JsonConvert.SerializeObject(data); Guid guid = System.Guid.NewGuid(); string result = api.postContentForStringForAgv(url, paprm, guid); WMSCommon.SendToAGVResult(result); SuccessForHandToSendTaskToAgv(comboBox2.SelectedItem.ToString(), result); textBox8.Text = DateTime.Now.ToLocalTime().ToShortTimeString() + result; textBox8.Text = DateTimeHelper.ConvertToString(DateTime.Now) + "_____" + "返回结果:" + result + "。 请求参数:" + paprm + " 请求地址:" + apiAddress + url; } catch (Exception ex) { textBox8.Text = DateTimeHelper.ConvertToString(DateTime.Now) + "_____" + "出现异常:" + JsonConvert.SerializeObject(ex); } } } /// /// 手动给agv发送任务成功之后 /// /// /// private void SuccessForHandToSendTaskToAgv(string station, string agvRetResult) { if (!string.IsNullOrEmpty(agvRetResult)) { return; } int convDBValue = 0; if (station == "2-39-1") { convDBValue = 1; } else if (station == "1-39-1") { convDBValue = 2; } else if (station == "1-0-1") { convDBValue = 3; } else if (station == "2-0-1") { convDBValue = 4; } else { return; } var result = FLogin.wcsWcf.ClearGJJY(convDBValue - 1);//为啥减去1,因为减去1是为了匹配list的索引值 if (result.result) { //MessageBox.Show("给输送线" + num + "手动发送放料完成信号成功!"); } else { MessageBox.Show("给输送线" + convDBValue + "手动清除工件记忆信号失败!" + result.resMsg); } } /// 发送缸体侧AGV任务 /// /// /// /// private void button18_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("本次任务将是AGV单机任务,仓储系统不会更改库存信息,请谨慎操作,确定要发送任务吗", "AGV任务", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { try {//postContent var newAgvTaskNo = ""; using (yunneiWCS.IyunneiWcfClient client = new yunneiWCS.IyunneiWcfClient()) { newAgvTaskNo = client.CreateTaskIdForAgvTaskByHand(); } tb_GT_AgvTaskNo.Text = newAgvTaskNo; var apiAddress = "http://192.168.0.3:6546/api/v2/"; var url = "orders"; HTTPService api = new HTTPService(apiAddress); //HTTPService api = new HTTPService(" http://localhost:1026/api/pp/"); var data = new { id = newAgvTaskNo, systemId = "WMS", type = "LoadingAndUnloading", source = comboBox4.SelectedItem, destination = comboBox5.SelectedItem }; string paprm = JsonConvert.SerializeObject(data); Guid guid = System.Guid.NewGuid(); string result = api.postContentForStringForAgv(url, paprm, guid); WMSCommon.SendToAGVResult(result); SuccessForHandToSendTaskToAgv(comboBox4.SelectedItem.ToString(), result); textBox8.Text = DateTimeHelper.ConvertToString(DateTime.Now) + "_____" + "返回结果:" + result + "。 请求参数:" + paprm + " 请求地址:" + apiAddress + url; } catch (Exception ex) { textBox8.Text = DateTimeHelper.ConvertToString(DateTime.Now) + "_____" + "出现异常:" + JsonConvert.SerializeObject(ex); } } } /// 发送堆垛机任务 /// /// /// /// private void button6_Click(object sender, EventArgs e) { try { DialogResult dr = MessageBox.Show("本次任务将是堆垛机单机任务,仓储系统不会更改库存信息,请谨慎操作,确定要发送任务吗", "堆垛机任务", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { string sourcePlace = tb_SourcePlace.Text.Trim(); string toPlace = tb_ToPlace.Text.Trim(); long taskID = Convert.ToInt64(textBox4.Text.Trim()); string res = FLogin.wcsWcf.srmTaskReSend(taskID, sourcePlace, toPlace, 2, true); if (!string.IsNullOrEmpty(res)) { MessageBox.Show(res); } } } catch (Exception) { } } /// 堆垛机任务确认 /// /// /// /// private void button10_Click(object sender, EventArgs e) { try { FLogin.wcsWcf.srmConfirm(); } catch (Exception) { } } /// 堆垛机ACK确认 /// /// /// /// private void button15_Click(object sender, EventArgs e) { try { FLogin.wcsWcf.sendSrmACK(); } catch (Exception) { } } /// 堆垛机解除报警 /// /// /// /// private void button8_Click(object sender, EventArgs e) { try { FLogin.wcsWcf.srmAlarmReset(); } catch (Exception) { } } /// 模拟测试_空托盘回库测试 /// /// /// /// private void button2_Click(object sender, EventArgs e) { try { HTTPService api = new HTTPService(apiBase + ":1025/pda/"); List LIU = new List(); if (listBox1.Items.Count > 0) { foreach (var item in listBox1.Items) { serialNumbers liu = new serialNumbers(); liu.serialNumber = item.ToString(); LIU.Add(liu); } } var data = new { station = comboBox8.SelectedItem.ToString(), datalist = LIU }; string paprm = JsonConvert.SerializeObject(data); Guid guid = System.Guid.NewGuid(); string res = api.postContentForStringForAgv("EmptyBack", paprm, guid); WMSCommon.SendToAGVResult(res); textBox2.Text = "空托盘回库返回消息:" + DateTime.Now.ToLocalTime().ToShortTimeString() + res; } catch (Exception) { } } /// 模拟测试-添加流水号 /// /// /// /// private void button5_Click(object sender, EventArgs e) { listBox1.Items.Add(textBox1.Text.Trim()); } /// 模拟测试-清空流水号 /// /// /// /// private void button9_Click(object sender, EventArgs e) { listBox1.Items.Clear(); } private void button1_Click(object sender, EventArgs e) { } private void button4_Click(object sender, EventArgs e) { //int num = Convert.ToInt32(comboBox1.SelectedItem); int num = check_convs_num; if (num < 5 && num > 0) { } else { MessageBox.Show("请选择输送线设备号"); return; } DialogResult dr = MessageBox.Show("您确认要给输送线" + num + "手动发送放料完成信号吗", "输送线任务", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { try { var result = FLogin.wcsWcf.Trans_LoadMaterialConfirm(num - 1);//为啥减去1,因为减去1是为了匹配list的索引值 if (result.result) { //MessageBox.Show("给输送线" + num + "手动发送放料完成信号成功!"); } else { MessageBox.Show("给输送线" + num + "手动发送放料完成信号失败!" + result.resMsg); } } catch (Exception ex) { MessageBox.Show("给输送线" + num + "手动发送放料完成信号异常!" + ex.Message); } } } private void AGV_Click(object sender, EventArgs e) { } private void checkedChanged(object sender, EventArgs e) { if ((sender as CheckBox).Checked == true) { foreach (Control chk in (sender as CheckBox).Parent.Controls) { if (chk is CheckBox) { var _chk = chk as CheckBox; if (_chk != sender) { _chk.Checked = false; } } } } } private void ck_L01_CheckedChanged(object sender, EventArgs e) { checkedChanged(sender, e); check_convs_num = (sender as CheckBox).Checked == true ? 1 : 0; } private void checkBox1_CheckedChanged(object sender, EventArgs e) { checkedChanged(sender, e); check_convs_num = (sender as CheckBox).Checked == true ? 2 : 0; } private void checkBox2_CheckedChanged(object sender, EventArgs e) { checkedChanged(sender, e); check_convs_num = (sender as CheckBox).Checked == true ? 3 : 0; } private void checkBox3_CheckedChanged(object sender, EventArgs e) { checkedChanged(sender, e); check_convs_num = (sender as CheckBox).Checked == true ? 4 : 0; } private void button7_Click(object sender, EventArgs e) { } /// /// 堆垛机起点和目标点切换 /// /// /// private void button23_Click(object sender, EventArgs e) { var old_sourcePlace = this.tb_SourcePlace.Text; var old_toPlace = this.tb_ToPlace.Text; this.tb_SourcePlace.Text = old_toPlace; this.tb_ToPlace.Text = old_sourcePlace; } private void button24_Click(object sender, EventArgs e) { //int num = Convert.ToInt32(comboBox1.SelectedItem); int num = check_convs_num; if (num < 5 && num > 0) { } else { MessageBox.Show("请选择输送线设备号"); return; } DialogResult dr = MessageBox.Show("您确认要给输送线" + num + "手动清除外侧工件记忆吗", "输送线任务", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { try { var result = FLogin.wcsWcf.ClearGJJY(num - 1);//为啥减去1,因为减去1是为了匹配list的索引值 if (result.result) { //MessageBox.Show("给输送线" + num + "手动发送放料完成信号成功!"); } else { MessageBox.Show("给输送线" + num + "手动清除外侧工件记忆失败!" + result.resMsg); } } catch (Exception ex) { MessageBox.Show("给输送线" + num + "手动清除外侧工件记忆吗异常!" + ex.Message); } } } } public class serialNumbers { public string serialNumber { get; set; } } }