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.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using WMS.EnumDefine; using WMS.UI.SynthesizeQuery; using WMS.yunneiWCS; using WZ.Useful.Commons; using WMS.Untils; namespace WMS.UI.WORK { public partial class FormTaskList : Form { /// 每页数量 /// /// int pagesize = 20;// 每页数量 int taskID = 0; // 任务ID 搜索条件 int queryStatus = 0;//任务类型 搜索条件 string _taskTypeName = ""; string place = "";//起始位,目标位 搜索条件 /// /// 库位号 /// public FormTaskList() { InitializeComponent(); dataGridView1.AutoGenerateColumns = false; FormHelper.DataGridViewSelfAdaptionWidth(this.dataGridView1); CheckForIllegalCrossThreadCalls = false; LoadSelectData(); } /// /// 加载下拉数据 /// private void LoadSelectData() { //任务名称 var fr_taskType = FLogin.wcsWcf.GetEnumSelectList("taskType", true); var taskTypeNameList = fr_taskType.resData; this.uiComboBox_TaskName.Items.Clear(); var _list = taskTypeNameList.Select(x => x.Text).ToList(); this.uiComboBox_TaskName.Items.AddRange(_list.ToArray()); this.uiComboBox_TaskName.SelectedIndex = -1; //物料编码 var fr_materialCode = FLogin.wcsWcf.GetSelectList("materialCode"); var materialCodeList = fr_materialCode.resData; this.uiComboBox_materialCode.Items.Clear(); this.uiComboBox_materialCode.Items.AddRange(materialCodeList); //物料名称 var fr_materialName = FLogin.wcsWcf.GetSelectList("materialName"); var materialNameList = fr_materialName.resData; this.uiComboBox_materialName.Items.Clear(); this.uiComboBox_materialName.Items.AddRange(materialNameList); } private void FormTaskList_Load(object sender, EventArgs e) { this.toolStripComboBox1.SelectedIndex = 1; initData(); paging paga = new paging(); paga.pagenum = 1; paga.pagesize = pagesize; findData(paga, 0, 0, "", _taskTypeName); this.dataGridView1.ReadOnly = true; } private void initData() { //默认查询一周的 uiDatetimePicker_start.Value = DateTime.Now.AddDays(-7); uiDatetimePicker_end.Value = DateTime.Now.AddDays(1); //uiDatetimePicker_start.Text = "起始日期"; //uiDatetimePicker_end.Text = "截止日期"; } /// 查找任务列表 /// /// /// 分页 /// 任务ID /// 任务类型 private void findData(paging page, int taskId, int taskType, string place, string taskName) { try { page.startDateTime = uiDatetimePicker_start.Value; page.endDateTime = uiDatetimePicker_end.Value; var materialName = uiComboBox_materialName.Text.Trim() != "" ? uiComboBox_materialName.Text.Trim() : "";//物料名称 var materialCode = uiComboBox_materialCode.Text.Trim() != "" ? uiComboBox_materialCode.Text.Trim() : "";//物料编码 var aa = toolStripComboBox1.SelectedItem; var queryOrder = this.tb_Order.Text; if (taskName == "不筛选") { taskName = ""; } var res = FLogin.wcsWcf.findTask(page, taskId, taskType, place, queryOrder, taskName, materialCode, materialName); if (res.status == 200) { this.dataGridView1.DataSource = res.date; this.toolStripLabel5.Text = "/" + res.total; if (res.total == 1) { toolStripLabel2.Enabled = false; toolStripTextBox1.Enabled = false; toolStripLabel1.Enabled = false; toolStripLabel4.Enabled = false; toolStripLabel3.Enabled = false; } else { toolStripLabel3.Enabled = true; toolStripLabel2.Enabled = true; toolStripTextBox1.Enabled = true; toolStripLabel4.Enabled = page.pagenum == 1 ? false : true; } } else { this.toolStripLabel5.Text = "/" + 0; toolStripLabel2.Enabled = false; toolStripTextBox1.Enabled = false; toolStripLabel1.Enabled = false; toolStripLabel4.Enabled = false; toolStripLabel3.Enabled = false; this.dataGridView1.DataSource = null; WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "暂无数据"); ms.Show(); } } catch (Exception ex) { WZ.Useful.Commons.LogTextHelper.WriteLine("FormTaskList", "findData", ex.ToString()); } } private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { try { if (dataGridView1.DataSource != null) { DataGridView dgv = (DataGridView)sender; switch (dgv.Columns[e.ColumnIndex].Name) { case "taskStatus": e.Value = Enum.GetName(typeof(taskStatus), Convert.ToInt32(e.Value)); e.FormattingApplied = true; break; case "area": e.Value = (int)e.Value == 1 ? "缸体侧" : "缸盖侧"; e.FormattingApplied = true; break; default: break; } } } catch (Exception) { } } private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { try { if (dataGridView1.Columns[e.ColumnIndex].Name == "childTask") { int i = dataGridView1.CurrentRow.Index; string ss = dataGridView1.Rows[i].Cells["task_id"].Value.ToString(); taskChild listView = new taskChild(ss); listView.ShowDialog(); this.btnFind_Click(null, null); } else if (dataGridView1.Columns[e.ColumnIndex].Name == "pick") {//分拣 int i = dataGridView1.CurrentRow.Index; string ss = dataGridView1.Rows[i].Cells["task_id"].Value.ToString(); var postionName = dataGridView1.Rows[i].Cells["sourcePlace"].Value.ToString(); var taskStatus = dataGridView1.Rows[i].Cells["taskStatus"].Value.ToString(); if (taskStatus != "7") { WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "任务状态不是待分拣状态,不允许操作"); ms.Show(); return; } FrmPVClistForPick listView = new FrmPVClistForPick(postionName, Convert.ToInt64(ss)); listView.ShowDialog(); this.btnFind_Click(null, null); } else if (dataGridView1.Columns[e.ColumnIndex].Name == "delete") {//作废 int i = dataGridView1.CurrentRow.Index; string taskid = dataGridView1.Rows[i].Cells["task_id"].Value.ToString(); string createListCode = dataGridView1.Rows[i].Cells["createListCode"].Value.ToString(); string taskName = dataGridView1.Rows[i].Cells["taskName"].Value.ToString(); FrmTaskHandOperation frm = new FrmTaskHandOperation(taskid, createListCode, taskName); frm.ShowDialog(); this.btnFind_Click(null, null); } else if (dataGridView1.Columns[e.ColumnIndex].Name == "panglugongwei") {//旁路工位下发任务 int i = dataGridView1.CurrentRow.Index; string taskid = dataGridView1.Rows[i].Cells["task_id"].Value.ToString(); string createListCode = dataGridView1.Rows[i].Cells["createListCode"].Value.ToString(); string taskName = dataGridView1.Rows[i].Cells["taskName"].Value.ToString(); var postionName = dataGridView1.Rows[i].Cells["sourcePlace"].Value.ToString(); var taskStatus = dataGridView1.Rows[i].Cells["taskStatus"].Value.ToString(); if (taskStatus != "1") { WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "任务状态不是新建状态,不允许操作"); ms.Show(); return; } var taskType = dataGridView1.Rows[i].Cells["taskType"].Value.ToString(); if (taskType != "18" && taskType != "19") { WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "任务类型不是旁路工位缸体空托回库或旁路工位缸体余料回库,不允许操作"); ms.Show(); return; } string _materialCode = dataGridView1.Rows[i].Cells["materialCode"].Value.ToString(); string _materialName = dataGridView1.Rows[i].Cells["materialName"].Value.ToString(); FrmPangLuGongWei frm = new FrmPangLuGongWei(Convert.ToInt32(taskid), postionName, _materialCode, _materialName); frm.ShowDialog(); this.btnFind_Click(null, null); } else if (dataGridView1.Columns[e.ColumnIndex].Name == "tianyong") {//推送天永 int i = dataGridView1.CurrentRow.Index; string taskid = dataGridView1.Rows[i].Cells["task_id"].Value.ToString(); DialogResult dr = MessageBox.Show("确定要推送消息给天永机器人吗", "推送天永", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (dr == DialogResult.OK) { var res = FLogin.wcsWcf.safetySignalByPerson(Convert.ToInt32(taskid)); int statu = res.status == 200 ? 1 : 2; WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(statu, res.msg); ms.Show(); this.btnFind_Click(null, null); } } } catch (Exception ex) { } } private void btnFind_Click(object sender, EventArgs e) { paging page = new paging(); page.pagenum = 1; page.pagesize = pagesize; //param.materialName = uiComboBox_materialName.Text.Trim() != "" ? uiComboBox_materialName.Text.Trim() : "";//物料名称 //param.materialCode = uiComboBox_materialCode.Text.Trim() != "" ? uiComboBox_materialCode.Text.Trim() : "";//物料编码 if (textBox_taskID.Text.Trim() == "") { taskID = 0; } else { bool converOk = int.TryParse(textBox_taskID.Text.Trim(), out taskID); if (!converOk) { WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "任务id只能是数字,请正确输入"); ms.Show(); return; } } queryStatus = comboBox_status.SelectedIndex; if (uiComboBox_TaskName.SelectedIndex > -1) { _taskTypeName = uiComboBox_TaskName.SelectedItem.ToString(); } else { _taskTypeName = ""; } if (textBox_place.Text.Trim() != "") { place = textBox_place.Text.Trim(); } findData(page, taskID, queryStatus, place, _taskTypeName); toolStripTextBox1.Text = "1"; toolStripLabel1.Enabled = false;//上一页 toolStripLabel4.Enabled = false;//第一页 toolStripLabel2.Enabled = true;//下一页 toolStripLabel3.Enabled = true;//最后一页 //删除日志 WMS.Untils.LogTextHelper.BatchDeleteLog(); } private void btnReset_Click(object sender, EventArgs e) { uiComboBox_materialName.Text = ""; uiComboBox_materialCode.Text = ""; this.tb_Order.Text = ""; taskID = 0; textBox_taskID.Text = ""; queryStatus = comboBox_status.SelectedIndex = 0; uiComboBox_TaskName.SelectedIndex = -1; uiComboBox_TaskName.SelectedItem = ""; _taskTypeName = ""; place = textBox_place.Text = ""; initData(); paging paga = new paging(); paga.pagenum = 1; paga.pagesize = pagesize; findData(paga, 0, 0, "", _taskTypeName); } /// 每页数量改变 /// /// /// /// private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { pagesize = (toolStripComboBox1.SelectedIndex + 1) * 10; paging paga = new paging(); paga.pagenum = 1; paga.pagesize = pagesize; findData(paga, taskID, queryStatus, place, _taskTypeName); toolStripTextBox1.Text = "1"; } catch (Exception) { } } /// 第一页 /// /// /// /// private void toolStripLabel4_Click(object sender, EventArgs e) { try { paging paga = new paging(); paga.pagenum = 1; paga.pagesize = pagesize; findData(paga, taskID, queryStatus, place, _taskTypeName); toolStripLabel4.Enabled = false; toolStripLabel3.Enabled = true; toolStripTextBox1.Text = "1"; toolStripTextBox1.Enabled = true; toolStripLabel1.Enabled = false; toolStripLabel2.Enabled = true; } catch (Exception) { } } /// 上一页 /// /// /// /// private void toolStripLabel1_Click(object sender, EventArgs e) { try { int numPapg = 0; int.TryParse(toolStripTextBox1.Text.Trim(), out numPapg); numPapg--; toolStripTextBox1.Text = numPapg.ToString(); int sizetatol = 0; int a = this.toolStripLabel5.Text.Trim().Length; string size = this.toolStripLabel5.Text.Trim().Substring(1, a - 1); int.TryParse(size, out sizetatol); if (numPapg <= sizetatol) { paging paga = new paging(); paga.pagenum = numPapg; paga.pagesize = pagesize; findData(paga, taskID, queryStatus, place, _taskTypeName); toolStripLabel2.Enabled = true; toolStripLabel3.Enabled = true; if (numPapg == 1) { toolStripLabel1.Enabled = false; } } else { toolStripTextBox1.Text = "1"; WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "请输入数字,并大于1且不大于总页数"); ms.Show(); } } catch (Exception) { } } /// 下一页 /// /// /// /// private void toolStripLabel2_Click(object sender, EventArgs e) { try { int numPapg = 0; int.TryParse(toolStripTextBox1.Text.Trim(), out numPapg); numPapg++; this.toolStripTextBox1.Text = numPapg.ToString(); int sizetatol = 0; int a = this.toolStripLabel5.Text.Trim().Length; string size = this.toolStripLabel5.Text.Trim().Substring(1, a - 1); int.TryParse(size, out sizetatol); toolStripLabel4.Enabled = true; if (numPapg <= sizetatol) { paging paga = new paging(); paga.pagenum = numPapg; paga.pagesize = pagesize; findData(paga, taskID, queryStatus, place, _taskTypeName); toolStripLabel1.Enabled = true; if (numPapg == sizetatol) { toolStripLabel2.Enabled = false; toolStripLabel3.Enabled = false; } } else { toolStripTextBox1.Text = "1"; WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "请输入数字,并大于1且不大于总页数"); ms.Show(); } } catch (Exception) { } } /// 最后一页 /// /// /// /// private void toolStripLabel3_Click(object sender, EventArgs e) { try { int sizetatol = 0; int a = this.toolStripLabel5.Text.Trim().Length; string size = this.toolStripLabel5.Text.Trim().Substring(1, a - 1); int.TryParse(size, out sizetatol); paging paga = new paging(); paga.pagenum = sizetatol; paga.pagesize = pagesize; findData(paga, taskID, queryStatus, place, _taskTypeName); toolStripLabel3.Enabled = false; toolStripLabel4.Enabled = true; toolStripTextBox1.Text = sizetatol.ToString(); toolStripTextBox1.Enabled = true; toolStripLabel1.Enabled = true; toolStripLabel2.Enabled = false; } catch (Exception) { } } /// 第几页回车 /// /// /// /// private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { int numPapg = 0; int.TryParse(toolStripTextBox1.Text.Trim(), out numPapg); int sizetatol = 0; int a = this.toolStripLabel5.Text.Trim().Length; string size = this.toolStripLabel5.Text.Trim().Substring(1, a - 1); int.TryParse(size, out sizetatol); if (numPapg > 0 && numPapg <= sizetatol) { paging paga = new paging(); paga.pagenum = numPapg; paga.pagesize = pagesize; findData(paga, taskID, queryStatus, place, _taskTypeName); } else { toolStripTextBox1.Text = "1"; WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "请输入数字,并不大于总页数"); ms.Show(); } } } catch (Exception) { WMS.EnumDefine.messages ms = new WMS.EnumDefine.messages(2, "出错了"); ms.Show(); } } /// 加序号 /// /// /// /// private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { SolidBrush b = new SolidBrush(this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor); e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), this.dataGridView1.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4); // dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red; //注意:要读取taskType值,必须在列表中添加此列,并赋值name为taskType var value = dataGridView1.Rows[e.RowIndex].Cells["taskType"].Value; if (value != null && (value.ToString() == "18" || value.ToString() == "19" || value.ToString() == "16" || value.ToString() == "17")) {//缸体上线去旁路工位 缸体下线直接去旁路工位 旁路工位缸体空托回库 旁路工位缸体余料回库 dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Yellow; } } private void uiDatetimePicker_start_ValueChanged(object sender, DateTime value) { } private void uiDatetimePicker_end_ValueChanged(object sender, DateTime value) { } private void uiComboBox_materialCode_SelectedIndexChanged(object sender, EventArgs e) { btnFind_Click(null, null); } private void uiComboBox_materialName_SelectedIndexChanged(object sender, EventArgs e) { btnFind_Click(null, null); } } }