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_UpDateKP : Form
    {
        public Staff_UpDateKP()
        {
            InitializeComponent();
        }
        DataDataContext ddc = new DataDataContext();
        private void Staff_UpDateKP_Load(object sender, EventArgs e)
        {
            KP_StaffDgv.Visible = false;
        }
        
        private void KP_StaIDCB_Click(object sender, EventArgs e)
        {
            KP_StaffDgv.Visible = true;//点击控件，显现datagrateview控件
            KP_StaffDgv.Focus();//控件焦点
            KP_StaffDgv.DataSource = ddc .V_StaffKP  ;//datagrateview控件与数据库视图联系
            
        }
        string KPID;
        private void KP_StaffDgv_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                KPID = Convert.ToString(KP_StaffDgv.Rows[e.RowIndex].Cells[0].Value);
                string ID = Convert.ToString(KP_StaffDgv.Rows[e.RowIndex].Cells[1].Value);
                string name = Convert.ToString(KP_StaffDgv.Rows[e.RowIndex].Cells[2].Value);
                string depart = Convert.ToString(KP_StaffDgv.Rows[e.RowIndex].Cells[3].Value);
                KP_StaIDCB.Text = ID;
                KP_StaNameTB.Text = name;
                KP_DepartTB.Text = depart;
            }
            KP_StaffDgv.Visible = false;
        }
        T_KaoPing kp = new T_KaoPing();
        #region 修改考评信息
        private void Save_TSB_Click(object sender, EventArgs e)
        {

            if (KP_StaIDCB.Text == "")
            {
                MessageBox.Show("员工信息不能为空！");
            }
            else
            {
                var staffkp = ddc.T_KaoPing.Single(staffid => staffid.KP_ID == Convert.ToInt32(KPID));
                    try
                    {
                        staffkp.KP_Grade = Convert.ToDouble(KP_GradeTB.Text);
                    }
                    catch
                    {
                        MessageBox.Show("考评分必须在0—100之间的数字");
                        KP_GradeTB.Text = "";
                        return;
                    }
                    try
                    {                    
                    staffkp.KP_Content = KP_ContartTB.Text;
                    staffkp.KP_Result = KP_RseultTB.Text;                   
                    ddc.SubmitChanges();
                    MessageBox.Show("修改成功！");
                    KP_GradeTB.Clear();
                    KP_RseultTB.Clear();
                    KP_ContartTB.Clear();
                   // KP_StaIDCB.SelectedIndex = 0;

                   }
                    catch
                    {
                        MessageBox.Show("全为必填项！");
                    } 
            }
        } 
        #endregion

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


    }
}
