frm_TaskInfo.cs 3.21 KB
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;
using HHWCS.Common;
using MySql.Data.MySqlClient;

namespace HHWCS.View
{
    public partial class Frm_TaskInfo : Form
    {
        public Frm_TaskInfo()
        {
            InitializeComponent();
            FormInit();
        }

        private void FormInit()
        {
            Dictionary<String,String> status = new Dictionary<string, string>();
            status.Add("0", "生成任务");
            status.Add("10", "下达任务");
            status.Add("20", "开始执行");
            status.Add("30", "到达站台");
            status.Add("40", "完成");
            cbx_Status.DataSource = status.ToList();
            cbx_Status.DisplayMember = "value";
            cbx_Status.ValueMember = "key";

        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataSet ds = MySqlHelper.ExecuteDataset(APP.ConnectionString, "select * from task");
            dgv_1.DataSource = ds.Tables[0];
            //using(MySqlConnection connection = new MySqlConnection("server=172.16.29.40;user id=root;password=hhsoftware;persistsecurityinfo=True;database=huaheng"))
            //{
            //    MySqlCommand command = new MySqlCommand("select * from task",connection);
            //    MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter();
            //    mySqlDataAdapter.SelectCommand = command;
            //    DataTable dt = new DataTable();
            //    mySqlDataAdapter.Fill(dt);
            //    dataGridView1.DataSource = dt;
            //    MessageBox.Show("ok");
            //}
        }

        private void btn_Query_Click(object sender, EventArgs e)
        {
            String sql = "select * from task where 1=1 ";
            String status = (String) cbx_Status.SelectedValue;
            if (!String.IsNullOrEmpty(status))
            {
                sql += " and status = '" + status + "'";
            }
            if (!String.IsNullOrEmpty(txt_Task.Text))
            {
                sql += " and id = " + txt_Task.Text;
            }
            if (!String.IsNullOrEmpty(txt_Pallete.Text))
            {
                sql += " and containerCode = '" + txt_Pallete.Text + "'";
            }

            DataSet ds = MySqlHelper.ExecuteDataset(APP.MysqlConnection, sql);
            if (ds == null||ds.Tables.Count==0)
            {
                MessageBox.Show("未找到数据");
            }
            dgv_1.DataSource = ds.Tables[0].AsEnumerable().Select(x => new {
                仓库 = x["warehouseCode"],
                任务号 = x["id"],
                托盘=x["containerCode"],
                状态 = x["status"],
                任务类型 = APP.GetTaskType(x["type"].ToString()),
                优先级 = x["priority"],
                站台 =x["station"],
                源库位=x["sourceLocation"],
                目标库位=x["destinationLocation"],
                创建者=x["createdBy"],
                创建时间=x["created"]

            }).ToList();
            APP.FormatDgv2(dgv_1);
        }
    }
}