using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using Core.XgMes.Client.StorageBase;


namespace Core.XgMes.Client.JGKC.RollManager
{
    public partial class TurnoffSendQueryJB : Mes.ClientFrameWork.FrmBase
    {
        public TurnoffSendQueryJB()
        {
            InitializeComponent();
        }

        private void TurnoffSendQueryJB_Load(object sender, EventArgs e)
        {

        }

        private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
        {
             DialogResult result = DialogResult.No;
             switch (e.Tool.Key)
             {
                 case "btnQuery":
                     this.Cursor = Cursors.WaitCursor;
                     Query();
                     this.Cursor = Cursors.Default;
                     break;
                 case "btnExcel":
                     Export();
                     break;
                 case "btnExit":
                     this.Close();
                     break;
             }
        }
        private void Query()
        {
            try
            {
                
                string where = this.ucSendQueryJB1.WhereStr;
                System.Collections.ArrayList ps = new ArrayList();
                System.Collections.ArrayList pg = new ArrayList();
                System.Collections.ArrayList ps0 = this.ucSendStatJB1.SendSelectStr;
                System.Collections.ArrayList pg0 = this.ucSendStatJB1.SendGroupbyStr;
           
                //if (where.IndexOf("A.CLEARFLAG") < 0)
                //{
                //    ps.AddRange(ps0);
                //    ps.AddRange(ps1);
                //    pg.AddRange(pg0);
                //    pg.AddRange(pg1);
                //}
                //else if (where.IndexOf("A.CLEARFLAG='0'") >= 0)
                //{
                    ps.AddRange(ps0);
                    pg.AddRange(pg0);
                //}
                //else if (where.IndexOf("A.CLEARFLAG='1'") >= 0)
                //{
                //    ps.AddRange(ps1);
                //    pg.AddRange(pg1);
                //}
                string strerr = "";
                object obj = Core.Mes.ClientFrameWork.ClientCommon._RemotingHelp.ExecuteMethod("BJZWJBStuff", "Core.XgMes.Server.JGKC.RollManager.TurnoffSendCan",
                    "GetOutStorageData", new object[] { where, ps, pg }, out strerr);
                if (obj != null)
                {
                    this.ultraGrid1.DataSource = (System.Data.DataSet)obj;
                    foreach (System.Data.DataColumn col in this.dataSet1.Tables[0].Columns)
                    {
                        if (!((System.Data.DataSet)obj).Tables[0].Columns.Contains(col.ColumnName))
                        {
                            this.ultraGrid1.DisplayLayout.Bands[0].Columns[col.ColumnName].Hidden = true;
                        }
                        else
                        {
                            this.ultraGrid1.DisplayLayout.Bands[0].Columns[col.ColumnName].Hidden = false;
                        }
                    }
                }
                
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
               
            }
        }
        public void Export()
        {
            try
            {
                string filename = @"成品发运.xls";
                this.ultraGridExcelExporter1.Export(this.ultraGrid1, filename);
                System.Diagnostics.ProcessStartInfo st = new System.Diagnostics.ProcessStartInfo(filename);
                st.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
                System.Diagnostics.Process.Start(st);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }

        private void chk_Filter_CheckedChanged(object sender, EventArgs e)
        {
            if (this.chk_Filter.Checked)
            {
                this.ultraGrid1.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;

            }
            else
            {
                this.ultraGrid1.DisplayLayout.Bands[0].ColumnFilters.ClearAllFilters();
                this.ultraGrid1.DisplayLayout.Bands[1].ColumnFilters.ClearAllFilters();
                this.ultraGrid1.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.False;


            }
        }
    }
}