using HZH_Controls;
using HZH_Controls.Controls;
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 static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace WinForms
{
    public partial class WorkTag : Form
    {
        public String selectValue;
        public WorkTag(string workId)
        {
            InitializeComponent();
            this.workId.Text = workId;
            ShowInfo();
        }
        private void ShowInfo()
        {
            Jpsoft.BLL.Work bllWork = new Jpsoft.BLL.Work();
            Jpsoft.Model.Work modelWork = bllWork.GetModel(this.workId.Text);
            this.oldTagValue.Text = modelWork.tag_operator + " " + modelWork.tag_factor_save.ToString() + " " + modelWork.tag_unit;
            this.newTagValue.Text = modelWork.tag_factor_save.ToString();
            this.tagOperator.SelectedItem = modelWork.tag_operator;
            this.tagUnit.SelectedItem = modelWork.tag_unit;
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.newTagValue.Text))
            {
                MessageBox.Show("请填入新的加码！");
            }
            else
            {
                Jpsoft.BLL.Work bllWork = new Jpsoft.BLL.Work();
                Jpsoft.Model.Work modelWork = bllWork.GetModel(this.workId.Text);
                modelWork.tag_operator = this.tagOperator.SelectedText;
                modelWork.tag_unit = this.tagUnit.SelectedText;
                modelWork.colour_ = this.newTagValue.Text.Trim();
                bllWork.Update(modelWork);
                this.DialogResult = DialogResult.OK;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void newWidth_KeyPress(object sender, KeyPressEventArgs e)
        {
            //判断按键是不是要输入的类型。
            if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
                e.Handled = true;

            //小数点的处理。
            if ((int)e.KeyChar == 46)                           //小数点
            {
                if (this.newTagValue.Text.Length <= 0)
                    e.Handled = true;   //小数点不能在第一位
                else
                {
                    float f;
                    float oldf;
                    bool b1 = false, b2 = false;
                    b1 = float.TryParse(this.newTagValue.Text, out oldf);
                    b2 = float.TryParse(this.newTagValue.Text + e.KeyChar.ToString(), out f);
                    if (b2 == false)
                    {
                        if (b1 == true)
                            e.Handled = true;
                        else
                            e.Handled = false;
                    }
                }
            }
        }
    }
}
