WinHistory.xaml.cs 3.69 KB
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace XingYe_ACS.UI
{
    /// <summary>
    /// WinHistory.xaml 的交互逻辑
    /// </summary>
    public partial class WinHistory : Window
    {
        public WinHistory()
        {
            InitializeComponent();
        }

        private void BtnQuery_Click(object sender, RoutedEventArgs e)
        {
            Grid_History.ItemsSource = null;

            string CmSt =

            "SELECT strTaskNo as '任务号'" +
                ", taskType as '任务类型'" +
                ",strTaskAgv as '小车号'" +
                ",StartCharge as '小车开始电量'" +
                ",strStartTime as '任务开始时间'" +
                ",EndCharge as '小车结束电量'" +
                ",strEndTime as '任务结束时间'" +
                "FROM T_Charge_Record";

            string DataFilter = "";
            string CmString = CmSt;

          
            if (tBoxAgvNo.Text != "")
            {
                DataFilter += string.Format(" and strTaskAgv='{0}'", tBoxAgvNo.Text);
            }
            if (cBoxTaskType.Text != "")
            {
                DataFilter += string.Format(" and taskType='{0}'", cBoxTaskType.Text);
            }

            if (CalendarStart.ToString() != "" && CalendarEnd.ToString() == "")
            {
                DataFilter += string.Format(" and strStartTime>='{0}'", CalendarStart.ToString());

            }
            else if (CalendarStart.ToString() == "" && CalendarEnd.ToString() != "")
            {

                DataFilter += string.Format(" and strStartTime<='{0}'", CalendarEnd.ToString());

            }
            else if (CalendarStart.ToString() != "" && CalendarEnd.ToString() != "")
            {
                DataFilter += string.Format(" and strStartTime>='{0}' and strEndTime<='{1}'",
                    CalendarStart.ToString(), CalendarEnd.ToString());

            }

            if (DataFilter.IndexOf(" and") == 0)
            {
                DataFilter = DataFilter.Remove(0, 4);
            }
            if (DataFilter != "")
            {
                DataFilter = " where " + DataFilter;

                CmString += DataFilter;
            }

            DataSet ds = Common.DbHelperSQL.Query(CmString);


            if (ds != null) 
            {
                Grid_History.ItemsSource = ds.Tables[0].DefaultView;
                //DataTable dataTable = ds.Tables[0];
                //int rowNumber = dataTable.Rows.Count;
                //int columnNumber = dataTable.Columns.Count;
                ////建立Excel对象 
                //Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                //excel.Application.Workbooks.Add(true);
                //excel.Visible = true;//是否打开该Excel文件 

                ////填充数据 
                //for (int c = 0; c < rowNumber; c++)
                //{
                //    for (int j = 0; j < columnNumber; j++)
                //    {
                //        excel.Cells[c + 1, j + 1] = dataTable.Rows[c].ItemArray[j];
                //    }
                //}
            }
        }

        private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.DragMove();

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }
    }
}