using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HRManagerSystem.Bll;
namespace HRManagerSystem
{
    public partial class FuLiForm : Form
    {
        public FuLiForm()
        {
            InitializeComponent();
        }
        
        DataDataContext ddt = new DataDataContext();
        FuLi fu = new FuLi();
        public void FuLiForm_Load(object sender, EventArgs e)
        {
            
            //加载数据源
            fu.Reflush(dataGridView1);
            //显示状态栏中记录总数
            toolStripStatusLabel2.Text = ddt.T_FuLi.Count().ToString();
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        T_FuLi fuliinfo = new T_FuLi();
        T_StaffRecords staff = new T_StaffRecords();
        bool mark = false;
        int fuliid = 0;
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                fuliinfo = ddt.T_FuLi.Single(id => id.FL_ID == Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value));
                staff.Staff_Name = (dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString().ToString());
                fuliid = fuliinfo.FL_ID;

            }
            mark = true;
        }

        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (mark)
            {
                var fuliinfo = ddt.T_FuLi.Single(fuli => fuli.FL_ID == fuliid);
                if (DialogResult.Yes == MessageBox.Show("你确定要删除么？", "提示", MessageBoxButtons.YesNo))
                ddt.T_FuLi.DeleteOnSubmit(fuliinfo);//单个删除
                ddt.SubmitChanges();
                //加载数据源
                fu.Reflush(dataGridView1);
                //显示状态栏中记录总数
                toolStripStatusLabel2.Text = ddt.T_FuLi.Count().ToString();
            }
            else
            {
                MessageBox.Show("请先选择一行数据再进行删除操作！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            //show出添加页面窗体
            AddFuLiForm addfl = new AddFuLiForm();
            addfl.ShowDialog();
            //加载数据源
            fu.Reflush(dataGridView1);
            //显示状态栏中记录总数
            toolStripStatusLabel2.Text = ddt.T_FuLi.Count().ToString();
            
           
        }
        /// <summary>
        /// 修改福利信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (mark)
            {
                UpdateFuLiForm upfuli = new UpdateFuLiForm(fuliinfo,staff);
                upfuli.ShowDialog();
                ddt.SubmitChanges();
                //加载数据源
               fu.Reflush(dataGridView1);
            }
            else
            {
                MessageBox.Show("在修改之前请选择一列数据！");
            }



        }
       
        /// <summary>
        /// 查找操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            FuLiSearchForm search = new FuLiSearchForm();
            search.ShowDialog();
        }
        //刷新
        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            fu.Reflush(dataGridView1);
            //显示状态栏中记录总数
            toolStripStatusLabel2.Text = ddt.T_FuLi.Count().ToString();
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            FuLiSearchForm search = new FuLiSearchForm();
            search.ShowDialog();
        }
       
       

       


    }
}
