using com.hnshituo.core.webapp.vo;
using Common;
using Common.vo.pb;
using Infragistics.Win;
using Infragistics.Win.UltraWinEditors;
using Infragistics.Win.UltraWinGrid;
using JC_MeasuringSystem;
using MeterModuleLibrary;
using MeterPlugInLibrary;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Threading;
using System.Windows.Forms;

namespace BeltScaleSystem

{
    public partial class frmCheckWeightInfo : Form
    {
        private ComBaseInfoService comBaseInfoService = new ComBaseInfoService(); //基础数服务
        private MeterBaseMatterInfoService meterBaseMatterInfo = new MeterBaseMatterInfoService();//物料服务
        private MeterWorkBeltXiaopiService workBeltXiaopiService = new MeterWorkBeltXiaopiService();

        private DataTable dtPoint;//计量点数据源
        public frmCheckWeightInfo()
        {
            InitializeComponent();
        }
        //菜单栏事件
        private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
        {
            switch (e.Tool.Key)
            {
                case "查询":
                    Query();
                    break;
                
                case "导出":

                    break;
                
            }
        }
        //下拉框控件自定义option
        public static void valueToCombo(DataTable source, UltraComboEditor cbb)
        {
            cbb.DataSource = source;
            cbb.DisplayMember = "VALUE";
            cbb.ValueMember = "TEXT";
        }
        private void frmCheckWeightInfo_Load(object sender, EventArgs e)
        {
            GridHelper.SetExcludeColumnsActive(beltXiaoPilGrid.DisplayLayout.Bands[0], "");
            dtStartTime.Value = Convert.ToDateTime((DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"));
            dtEndTime.Value = Convert.ToDateTime((DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59"));
            DataTable dt3 = new DataTable();
            dt3.Columns.Add("TEXT");
            dt3.Columns.Add("VALUE");
            dt3.Rows.Add("0", "全部");
            dt3.Rows.Add("1", "A秤");
            dt3.Rows.Add("2", "B秤");
            valueToCombo(dt3, cmbScaleName);
            this.cmbScaleName.SelectedIndex = 0;

            MeterBaseSpotInfoService meterBaseSpotInfoService = new MeterBaseSpotInfoService();//计量点信息
            RESTfulResult<List<MeterBaseSpotInfo>> spo = meterBaseSpotInfoService.doQueryWf(new MeterBaseSpotInfo { validFlag = "1", spotTypeNo = "001002005" });
            if (spo.Succeed && spo.Data != null && spo.Data.Count > 0)
            {
                dtPoint = spo.Data.ListToDataTable<MeterBaseSpotInfo>();
            }
            if (dtPoint != null)
            {
                cmbPoint.DataSource = dtPoint;
                cmbPoint.DisplayMember = "baseSpotName";
                cmbPoint.ValueMember = "baseSpotNo";
            }
            cmbPoint.SelectedIndex = -1;


        }

        //查询
        private void  Query() {
            try
            {
                MeterWorkBeltXiaopi xiaopi = new MeterWorkBeltXiaopi();
                DataTable dtScaleTable = dataTable1.Clone();
                CommonPage<MeterWorkBeltXiaopi> cp = new CommonPage<MeterWorkBeltXiaopi>();
                if (checkDate.Checked)
                {
                    cp.startTime = dtStartTime.Text.ToString();
                    cp.endTime = dtEndTime.Text.ToString();
                }
                if (cmbScaleName.Text.ToString() != "全部")
                {
                    xiaopi.scaleName = cmbScaleName.Text.ToString().Substring(0,1);
                }
                if (cmbPoint.Text.ToString() != "")
                {
                    xiaopi.baseSpotNo = cmbPoint.Value.ToString();
                }
                cp.param = xiaopi;
                cp.memo1 = "1";//查所有数据
                RESTfulResult<List<MeterWorkBeltXiaopi>> rms = workBeltXiaopiService.doQueryWf(cp);
                if (rms.Succeed)
                {
                    if (rms.Data != null && rms.Data.Count > 0)
                    {

                        dtScaleTable = rms.Data.ListToDataTable<MeterWorkBeltXiaopi>();

                        ClsControlPack.CopyDataToDatatable(ref dtScaleTable, ref dataTable1, true);
                       
                        ClsControlPack.RefreshAndAutoSize(beltXiaoPilGrid);
                    }
                    else
                    {
                        dtScaleTable.Clear();
                        ClsControlPack.CopyDataToDatatable(ref dtScaleTable, ref dataTable1, true);
                        ClsControlPack.RefreshAndAutoSize(beltXiaoPilGrid);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("校皮数据查询失败，请联系技术中心！" + ex.Message);
                return;
            }
        }
    }
}