using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CNAS_DBSync
{
    public delegate void InstumentCodeHanlder(SyncInstrumentItemInfo Instrumentitem);

    public partial class frmInstrumentCode : Form
    {
        public List<SyncInstrumentItemInfo> lstSyncInstrument = new List<SyncInstrumentItemInfo>();
        public InstumentCodeHanlder InstrumentDelegate;
        public string strOldCode = "";

        public frmInstrumentCode(List<SyncInstrumentItemInfo> lstSyncInstrument)
        {          
            InitializeComponent();

            this.lstSyncInstrument = lstSyncInstrument;
        }

        public frmInstrumentCode(List<SyncInstrumentItemInfo> lstSyncInstrument,string strOldCode=null)
        {
            InitializeComponent();

            this.lstSyncInstrument = lstSyncInstrument;
            this.strOldCode=this.txtCode.Text=strOldCode;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.txtCode.Text.Trim() == strOldCode) //此时没有修改任何内容
            {
                return;
            }

            int iMessage = new InstrumentCodeOperation().CheckInstrumentCode(this.txtCode.Text.Trim(),lstSyncInstrument);
            if (iMessage <= 0)
            {
                switch (iMessage)
                {
                    case 0:
                        MessageBox.Show("输入不允许为空！请重新输入！");                        
                        break;
                    case -1:
                        MessageBox.Show("输入含有特殊字符！请重新输入！");
                        break;
                    case -2:
                        MessageBox.Show("仪器编码不允许重复！请重新输入！");
                        break;

                }
                this.txtCode.Text = "";
                return;
            }

            //传输输入到父界面
            SyncInstrumentItemInfo syncinstrument = new SyncInstrumentItemInfo();
            syncinstrument.GUID = Guid.NewGuid().ToString();
            syncinstrument.Code = this.txtCode.Text.Trim();

            this.InstrumentDelegate(syncinstrument);


            //关闭界面
            this.Close();

        }
    }
}
