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 Microsoft.VisualBasic;
using System;
using System.Collections;
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 frmScaleLogSelect : Form
    {
        public frmScaleLogSelect()
        {
            InitializeComponent();
        }

        //菜单栏事件
        private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
        {
            switch (e.Tool.Key)
            {
                case "查询":
                    Query();
                    break;
              
                case "导出":
                    Export();
                    break;
               
            }
        }


        #region 自定义变量
        MeterBaseOperationLogService LogService = new MeterBaseOperationLogService();//日志服务
        private ComBaseInfoService comBaseInfoService = new ComBaseInfoService(); //基础数服务
        private CoreAppUser appUser = null;//登陆信息
        private string userId = "", userName = ""; //用户ID用户名
        #endregion


        #region 菜单栏方法
        //预报查询
        private void  Query() {
            try
            {
                if (DateTime.Compare(dtStartTime.Value, dtEndTime.Value) > 0)
                {
                    MessageBox.Show("开始时间不能大于结束时间");
                    return;
                }
                MeterBaseOperationLog log = new MeterBaseOperationLog();
                DataTable dtScaleTable = dataTable1.Clone();
                CommonPage<MeterBaseOperationLog> cp = new CommonPage<MeterBaseOperationLog>();
                if (checkDate.Checked)
                {
                    cp.startTime = dtStartTime.Text.ToString();
                    cp.endTime = dtEndTime.Text.ToString();
                }
                if (text1.Text.ToString().Trim() != "") {
                    log.operationPage = text1.Text.ToString();
                }
                
                if (text2.Text.ToString().Trim() != "" )
                {
                    log.operationFunction = text2.Text.ToString();
                }
                if (text3.Text.ToString().Trim() != "")
                {
                    log.operationId = text3.Text.ToString();
                }
                //if (ultraCombo1.Text.ToString().Trim() != "")
                //{
                //    log.logTypeCode = ultraCombo1.Value.ToString();
                //}
                log.logTypeCode = "001002005";
                log.createTime = DateTime.Now;
                cp.param = log;
                RESTfulResult<List<MeterBaseOperationLog>> rms = LogService.doQueryAndMultiple(cp);
                if (rms.Succeed)
                {
                    if (rms.Data != null && rms.Data.Count > 0)
                    {
                        dtScaleTable = rms.Data.ListToDataTable<MeterBaseOperationLog>();

                        ClsControlPack.CopyDataToDatatable(ref dtScaleTable, ref dataTable1, true);
                        ClsControlPack.RefreshAndAutoSize(ultraGridBeltPre);
                    }
                    else
                    {
                        dtScaleTable.Clear();
                        ClsControlPack.CopyDataToDatatable(ref dtScaleTable, ref dataTable1, true);
                        ClsControlPack.RefreshAndAutoSize(ultraGridBeltPre);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("查询失败，请联系技术中心！" + ex.Message);
                return;
            }
        }
      
        //导出预报数据
        private void Export() {
            string str = Interaction.InputBox("请输入要导出的文件名", "提示", "", 100, 100);
            string pqath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            this.ultraGridExcelExporter1.Export(this.ultraGridBeltPre, pqath + "\\" + str + ".xls");
            MessageBox.Show("导出成功，请查看桌面！是否有[" + str + ".xls]表格");
        }
       
        #endregion


        #region 公共方法区
        private void frmScalePredictionManage_Load(object sender, EventArgs e)
        {
            //设置grid除了选择列 其余不可编辑
            GridHelper.SetExcludeColumnsActive(ultraGridBeltPre.DisplayLayout.Bands[0], "UNCK");
            userId = ((ST_MainForm)(this.MdiParent)).UserID;
            userName = ((ST_MainForm)(this.MdiParent)).UserName;
            appUser = ((ST_MainForm)(this.MdiParent)).AppUser;
            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"));
            


            Query();

            RESTfulResult<List<ComBaseInfo>> rrComGradeName = comBaseInfoService.doQueryBaseList(new ComBaseInfo { validFlag = "1", pBaseCode = "001002" });
            if (rrComGradeName.Succeed && rrComGradeName.Data != null && rrComGradeName.Data.Count > 0)
            {
                rrComGradeName.Data.Sort((a, b) => a.baseName.CompareTo(b.baseName));
                ClsControlPack.SetUltraComboDataSource(ultraCombo1, rrComGradeName.Data.ListToDataTable<ComBaseInfo>(), "baseCode", "baseName");
            }
            else
            {
                MessageBox.Show("物料系数信息载入失败!");
                return;
            }
        }

        //时间控件开关
        private void checkDate_CheckedChanged(object sender, EventArgs e)
        {
            if (checkDate.Checked)
            {
                dtStartTime.Enabled = true;
                dtEndTime.Enabled = true;
            }
            else
            {
                dtStartTime.Enabled = false;
                dtEndTime.Enabled = false;
            }
        }

        #endregion
    }
}