using Common;
using MeterPlugInLibrary;
using System;
using System.Collections;
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 com.hnshituo.core.webapp.vo;

namespace MeterModuleLibrary
{
    public partial class frmScaleQuery : Form
    {
        public frmScaleQuery()
        {
            InitializeComponent();
        }

        //语音播报
        //private VoicePlay vicPlayClass = new VoicePlay();//语音播放

        public List<PbModelDb> ht = new List<PbModelDb>();
        private void txtMETER_TYPE_NO_Enter(object sender, EventArgs e)
        {
            lbMsgInfo.Text = "";
            this.Visible = false;
            frmNumberKey2 fnk = new frmNumberKey2();
            if (fnk.ShowDialog() == DialogResult.OK)
            {
                this.Visible = true;

                txtMETER_TYPE_NO.Text = fnk.sValue;
                txtFORWARDING_UNIT_NAME.Text = "";
                txtMATTER_NAME.Text = "";
                txtRECEIVING_UINT_NAME.Text = "";

                ht.Clear();
                
                if (txtMETER_TYPE_NO.Text.Trim() != "" && txtMETER_TYPE_NO.Text.Trim().Length == 9) 
                {
                    string strM = txtMETER_TYPE_NO.Text.Trim();
                    string sql = @"select t1.load_point_no as id, t1.load_point_name text, t1.meter_code text2
                                  from meter_base_load_point t1
                                 where t1.meter_code = '" + strM.Substring(3, 3) + @"'
                                   and t1.valid_Flag = '1'
                                union all
                                select t1.load_point_no as id, t1.load_point_name text, t1.meter_code text2
                                  from meter_base_load_point t1
                                 where t1.meter_code = '" + strM.Substring(6, 3) + @"'
                                   and t1.valid_Flag = '1'
                                union all
                                select t2.matter_no as id, t2.matter_name text, t2.meter_code text2
                                  from meter_base_matter_info t2
                                 where t2.meter_code = '" + strM.Substring(0, 3) + @"'
                                   and t2.valid_Flag = '1'";

                    PbModelDbService<List<PbModelDb>> pb = new PbModelDbService<List<PbModelDb>>();
                    RESTfulResult<List<PbModelDb>> rm = pb.executeSqlDataWf(sql);
                    if (rm.Succeed && rm.Data != null && rm.Data.Count == 3)
                    {
                        txtMATTER_NAME.Text = rm.Data[2].text;
                        txtFORWARDING_UNIT_NAME.Text = rm.Data[0].text;
                        txtRECEIVING_UINT_NAME.Text = rm.Data[1].text;

                        //根据规则，将数据按3位数截取，然后作为条件查询基础表数据，然后绑定到界面上
                        ht = rm.Data;
                    }
                    else
                    {
                        //vicPlayClass.GetVoicePlay("信息输入有误", PbCache.collect.carno);
                        lbMsgInfo.Text = "*不存在该业务编码!";
                    }
                }
                else
                {
                    //vicPlayClass.GetVoicePlay("信息输入有误", PbCache.collect.carno);
                    lbMsgInfo.Text = "*不存在该业务编码!";
                }
                btnSubmit.Focus();
            }
            else
            {
                btnSubmit.Focus();
                this.Visible = true;
            }
        }

        public string strValue = "";
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            strValue = txtMETER_TYPE_NO.Text.Trim();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
