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 WorkWidth : Form
    {
        public String selectValue;
        public WorkWidth(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.oldWidth.Text = modelWork.width_.ToString();
            this.newWidth.Text = modelWork.width_.ToString();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.newWidth.Text))
            {
                MessageBox.Show("请填入新的宽幅！");
            }
            else
            {
                Jpsoft.BLL.Work bllWork = new Jpsoft.BLL.Work();
                Jpsoft.Model.Work modelWork = bllWork.GetModel(this.workId.Text);
                modelWork.width_ = Convert.ToDouble(this.newWidth.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.newWidth.Text.Length <= 0)
                    e.Handled = true;   //小数点不能在第一位
                else
                {
                    float f;
                    float oldf;
                    bool b1 = false, b2 = false;
                    b1 = float.TryParse(this.newWidth.Text, out oldf);
                    b2 = float.TryParse(this.newWidth.Text + e.KeyChar.ToString(), out f);
                    if (b2 == false)
                    {
                        if (b1 == true)
                            e.Handled = true;
                        else
                            e.Handled = false;
                    }
                }
            }
        }
    }
}
