using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.ComponentModel.Design.ObjectSelectorEditor;

namespace WinForms
{
    public partial class Default : Form
    {
        public Default()
        {
            InitializeComponent();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            SelectWork selectWork = new SelectWork();
            DialogResult result = selectWork.ShowDialog();
            if (result == DialogResult.OK)
            {
                string workId = selectWork.selectValue;

                //基本信息
                ShowInfo(workId);

                //库存信息
                Jpsoft.BLL.Stock bllStock = new Jpsoft.BLL.Stock();
                List<Jpsoft.Model.Stock> listStock = bllStock.GetModelList(String.Format("del_flag=0 and work_id='{0}'", workId));
                this.dataGridView1.AutoGenerateColumns = false;
                this.dataGridView1.DataSource = listStock;
            }
        }

        private void ShowInfo(string workId)
        {
            Jpsoft.BLL.Work bllWork = new Jpsoft.BLL.Work();
            Jpsoft.Model.Work modelWork = bllWork.GetModel(workId);

            Jpsoft.BLL.Customer bllCustomer = new Jpsoft.BLL.Customer();
            Jpsoft.Model.Customer modelCustomer = bllCustomer.GetModel(modelWork.customer_id);

            this.workId.Text = modelWork.id_;
            this.labCustomer.Text = "客户：" + modelCustomer.name_;
            this.labName.Text = "品种及规格：" + modelWork.name_;
            this.labWidth.Text = "幅宽：" + modelWork.width_.ToString();
            this.labNumber.Text = "编号：" + modelWork.number_;
            this.labColour.Text = "色泽：" + modelWork.colour_;
            this.labTagFactorSave.Text = "加码：" + modelWork.tag_factor_save.ToString();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            WorkNumber workNumber = new WorkNumber(this.workId.Text);
            DialogResult result = workNumber.ShowDialog();
            if (result == DialogResult.OK)
            {
                ShowInfo(this.workId.Text);
            }
        }

        private void btnSetting_Click(object sender, EventArgs e)
        {
            Configure configureForm = new Configure();
            configureForm.ShowDialog();
        }

        private void workId_TextChanged(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.workId.Text))
            {
                this.button1.Enabled = false;
                this.button2.Enabled = false;
                this.button3.Enabled = false;
                this.button4.Enabled = false;
                this.button5.Enabled = false;
                this.button6.Enabled = false;
                this.button7.Enabled = false;
                this.button8.Enabled = false;
                this.button9.Enabled = false;
                this.button11.Enabled = false;
                this.button12.Enabled = false;
                this.button13.Enabled = false;
                this.button14.Enabled = false;
                this.button15.Enabled = false;
            }
            else
            {
                this.button1.Enabled = true;
                this.button2.Enabled = true;
                this.button3.Enabled = true;
                this.button4.Enabled = true;
                this.button5.Enabled = true;
                this.button6.Enabled = true;
                this.button7.Enabled = true;
                this.button8.Enabled = true;
                this.button9.Enabled = true;
                this.button11.Enabled = true;
                this.button12.Enabled = true;
                this.button13.Enabled = true;
                this.button14.Enabled = true;
                this.button15.Enabled = true;
            }
        }

        private void button15_Click(object sender, EventArgs e)
        {
            WorkWidth workWidth = new WorkWidth(this.workId.Text);
            DialogResult result = workWidth.ShowDialog();
            if (result == DialogResult.OK)
            {
                ShowInfo(this.workId.Text);
            }
        }

        private void button14_Click(object sender, EventArgs e)
        {
            WorkModel workModel = new WorkModel(this.workId.Text);
            DialogResult result = workModel.ShowDialog();
            if (result == DialogResult.OK)
            {
                ShowInfo(this.workId.Text);
            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            WorkColour workColour = new WorkColour(this.workId.Text);
            DialogResult result = workColour.ShowDialog();
            if (result == DialogResult.OK)
            {
                ShowInfo(this.workId.Text);
            }
        }

        private void button12_Click(object sender, EventArgs e)
        {
            WorkTag workTag = new WorkTag(this.workId.Text);
            DialogResult result = workTag.ShowDialog();
            if (result == DialogResult.OK)
            {
                ShowInfo(this.workId.Text);
            }
        }
    }
}
