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

namespace yinLouSys
{
    public partial class frmLogMan : Form
    {
        private frmMain _frmParent;

        public frmMain FrmParent
        {
            get { return _frmParent; }
            set { _frmParent = value; }
        }

        public frmLogMan()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmLogMan_Load(object sender, EventArgs e)
        {
            cbbFw.SelectedIndex = 0;
            LoadOper();
            SetFormSize();
        }

        private void SetFormSize()
        {
            this.Top = 30;
            this.Left = 0;
            this.Width = _frmParent.ClientSize.Width - 150;
            this.Height = _frmParent.ClientSize.Height - 130;

            //this.Size=_frmParent.ClientSize.Height;
        }

        private void LoadOper()
        {
            cbbType.Items.Clear();
            cbbType.Items.Add("请选择");
            DataTable db = code.SQLHelp.ExecuteDataTable("select l_operType from tab_log group by l_operType");
            foreach (DataRow r in db.Rows)
            {
                cbbType.Items.Add(r[0].ToString());
            }
            cbbType.SelectedIndex = 0;
        }

        private void cbbFw_SelectedIndexChanged(object sender, EventArgs e)
        {
            dtpStart.Enabled = cbbFw.SelectedIndex > 0;
            dtpEnd.Enabled = cbbFw.Text.StartsWith("介于");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = "select l_user as 操作员,l_ip as IP地址,l_time as 操作时间,l_operType as 操作类型,l_discrible as 操作描述 from tab_log where 1=1";
                if (cbbFw.SelectedIndex > 0)
                {
                    if (cbbFw.Text.StartsWith("介于"))
                    {
                        sql += " and l_time between '" + dtpStart.Value.ToString("yyyy-MM-dd") + "' and '" + dtpEnd.Value.ToString("yyyy-MM-dd") + "'";
                    }
                    else
                    {
                        sql += " and datediff(day,l_time,'" + dtpStart.Value.ToString("yyyy-MM-dd") + "')=0";
                    }
                }

                if ("请选择" != cbbType.Text)
                {
                    sql += " and l_operType='"+cbbType.Text+"'";
                }

                if ("" != txtOper.Text)
                {
                    sql += " and l_user like '%"+txtOper.Text+"%'";
                }

                dgList.DataSource = code.SQLHelp.ExecuteDataTable(sql);
                lblSum.Text = dgList.Rows.Count.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}