using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Data.SqlClient;
using System.IO;

namespace VR2ManagerClient
{
    public partial class SearchReport : Form
    {
        public VR2.DBServerSetting db_set;
        public string sCaller;
        public string sCallee;
        public DateTime dtBegin;
        public DateTime dtEnd;

        public SearchReport()
        {
            InitializeComponent();
        }

        private void SearchReport_Load(object sender, EventArgs e)
        {
            DateTime dtNow = DateTime.Now;
            dtPicker1.Value = dtNow.AddDays(-5);

            dtNow = DateTime.Now;
            dtPicker2.Value = dtNow.AddDays(1);

            this.reportViewer1.RefreshReport();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            sCaller = tbCaller.Text;
            sCallee = tbCallee.Text;
            dtBegin = dtPicker1.Value;
            dtEnd = dtPicker2.Value;
            //SearchData(sCaller, sCallee, dtBegin, dtEnd);
        }
/*
        public void SearchData(string caller, string callee, DateTime dt1, DateTime dt2)
        {
            string commandStr = "SELECT CallerID, CalleeID, TimeInit, TimeBegin, TimeEnd, Duration, RecordPath FROM " + db_set.CallLogTableName + " WHERE ";

            commandStr += "TimeInit >= '" + DateTimeToStr(dt1) + "' AND TimeInit <= '" + DateTimeToStr(dt2) + "' ";
            if (caller.Length > 0)
            {
                commandStr += "AND CallerID = '" + caller + "' ";
            }
            if (callee.Length > 0)
            {
                commandStr += "AND CalleeID = '" + callee + "' ";
            }

            if (db_set.ConnectDB())
            {
                string strCon = db_set.GetConnStr();
                string strSQL = commandStr;
                SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strCon);
                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
                BindingSource dbBindSource = new BindingSource();

                // Populate a new data table and bind it to the BindingSource.
                DataTable table = new DataTable();
                table.Locale = System.Globalization.CultureInfo.InvariantCulture;
                dataAdapter.Fill(table);

                dbBindSource.DataSource = table;

                reportViewer1.Visible = true;

                ReportDataSource datasource = new
                  ReportDataSource("DataSetProducts_ShowProductByCategory",
                  table);

                reportViewer1.LocalReport.DataSources.Clear();
                reportViewer1.LocalReport.DataSources.Add(datasource);

                reportViewer1.LocalReport.Refresh();


                // Resize the DataGridView columns to fit the newly loaded content.
                dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);

                // you can make it grid readonly.
                dataGridView1.ReadOnly = true;

                // finally bind the data to the grid
                dataGridView1.DataSource = dbBindSource;

                db_set.DisconnectDB();
            }

        }*/
    }
}