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;

namespace HRManagerSystem
{
    public partial class Staff_ADDKP : Form
    {
        public Staff_ADDKP()
        {
            InitializeComponent();
        }
        DataDataContext ddc = new DataDataContext();//实例化一个LINQ对象
        private void Staff_ADDKP_Load(object sender, EventArgs e)
        {
            KP_StaffDgv.Visible = false;//在窗体开始时，datagrateview控件不显示
         
        }

        #region 控件外观
        private void StaIDCB_Click(object sender, EventArgs e)
        {

            KP_StaffDgv.Visible = true;//点击控件，显现datagrateview控件
            KP_StaffDgv.Focus();//控件大小
            KP_StaffDgv.DataSource = ddc.V_KPStaff;//datagrateview控件与数据库视图联系
            KP_StaffDgv.Height = 18 + KP_StaffDgv.Rows.Count * 24;//控件大小

        } 
        #endregion
        #region 显示员工表

        private void KP_StaffDgv_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                string ID = Convert.ToString(KP_StaffDgv.Rows[e.RowIndex].Cells[0].Value);
                string name = Convert.ToString(KP_StaffDgv.Rows[e.RowIndex].Cells[1].Value);
                string depart = Convert.ToString(KP_StaffDgv.Rows[e.RowIndex].Cells[2].Value);
                KP_StaIDCB.Text = ID;
                KP_StaNameTB.Text = name;
                KP_DepartTB.Text = depart;
            }
            KP_StaffDgv.Visible = false;
        } 
        #endregion

        #region 增加员工考评
        private void UpDate_TSB_Click(object sender, EventArgs e)
        {
            //try
            //{
                T_KaoPing kp = new T_KaoPing();//获得所需要的表
                if (KP_StaIDCB.Text=="" )
                {
                    MessageBox.Show("员工不能为空！");
                    return;
                }
                else
                {
                    kp.Staff_ID = Convert.ToInt32(KP_StaIDCB.Text);//添加数据
                    kp.KP_Content = KP_ContartTB.Text;                 
                    try
                    {
                        kp.KP_Grade = Convert.ToInt32(KP_GradeTB.Text);
                    }              
                    catch
                    {
                        MessageBox.Show("评分必须是0-100之间的数字");
                        return;
                    }
                    try
                    {                        
                        kp.KP_Time = DateTime.Now;
                        kp.KP_Result = KP_RseultTB.Text;
                        ddc.T_KaoPing.InsertOnSubmit(kp);
                        ddc.SubmitChanges();
                        MessageBox.Show("添加成功！");
                        KP_GradeTB.Clear();
                        KP_RseultTB.Clear();
                        KP_ContartTB.Clear();
                    }
                    catch 
                    {
                         MessageBox.Show ("请录入详细信息，每一项都不能为空！");
                    }
                }            
          } 
        #endregion
        /// <summary>
        /// 重新增加数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region 重新增加员工考评
        private void ADD_TSB_Click(object sender, EventArgs e)
        {
            KP_ContartTB.Text = "";
            KP_DepartTB.Text = "";
            KP_GradeTB.Text = "";
            KP_RseultTB.Text = "";
            KP_StaIDCB.Text = "";
            KP_StaNameTB.Text = "";
        } 
        #endregion
        /// <summary>
        /// 窗体退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region 窗体退出
        private void Quit_TSB_Click(object sender, EventArgs e)
        {
            this.Close();
        } 
        #endregion

    }
}
