using SYNC_SAP_MES;
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;

namespace SYNC_SAP_MES
{
    /// <summary>
    /// 
    /// </summary>
    public partial class D_Update_FlowNo : Form
    {
        /// <summary>
        /// 
        /// </summary>
        public string FlowNo = "";
        /// <summary>
        /// 
        /// </summary>
        public D_Update_FlowNo()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="from_Opera"></param>
        public D_Update_FlowNo(string flowNo)
        {
            InitializeComponent();
            txt_FlowNo.Text = flowNo;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Sure_Click(object sender, EventArgs e)
        {
            if (!ifIntValue(txt_FlowNo.Text.Trim()))
            {
                MessageBox.Show("流水号不能为空，且必须为整数！");
                return;
            }
            else 
            {
                Sql_Biz_SAP.GetFlowNo_CurrMax(out string flowNo_CurrMax);
                var setFlowNo = txt_FlowNo.Text;
                if (Convert.ToInt32(setFlowNo) < Convert.ToInt32(flowNo_CurrMax))
                {
                    //允许设置 >= 的流水号
                    MessageBox.Show("不允许设置小于当前生产的流水号！");
                    return;
                }
            }
            if (string.IsNullOrEmpty(txt_Sure.Text))
            {
                MessageBox.Show("为了防止错误操作，请填写在文本框填入 确认 ！");
                return;
            }

            FlowNo = txt_FlowNo.Text;
            DialogResult = DialogResult.OK;
        }
        private bool ifIntValue(string inputValue)
        {
            try
            {
                var k = Convert.ToInt32(inputValue);
                return true;
            }
            catch
            {
                return false;
            }
        }
        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void btn_Query_Click(object sender, EventArgs e)
        {
            Sql_Biz_SAP.GetFlowNo_CurrMax(out string FlowNo);
            txt_FlowNo_CurrMax.Text = FlowNo;
        }

      
    }
}
