using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Finisar.SQLite;
using EmployeeManagementSystem.DataAccessLayer1;
using EmployeeManagementSystem.Businesslayer1;




namespace Employee_Managemet_System
{
    public partial class EmpDetail : Form
    {
        private DataGrid Grid;
        private TextBox txtDesc;
        private Button btnDel;
        private Button btnAdd;
        private Button btnNew;
        private Label lblDesc;
        private Button btnEdit;

        private int i = 0;
        int Cnt1;
        int cnt3;
        int EmpID;

        EmployeeClass objEmployee = new EmployeeClass();
        DataSet dsEmployee = new DataSet();

        public EmpDetail()
        {
            InitializeComponent();

            lblOther1.Visible = false;
            txtSpecify1.Visible = false;
            lblOther2.Visible = false;
            txtSpecify2.Visible = false;
            lblOther3.Visible = false;
            txtSpecify3.Visible = false;
            lblOther4.Visible = false;
            txtSpecify4.Visible = false;

           

            // objEmployee.CreateEmployeeTable();
            txtFirstName.Text = "";
            txtMiddleName.Text = "";
            txtLastName.Text = "";
            comboDate.Text = "Select";
            comboMonth.Text = "Select";
            comboYear.Text = "Select";
            comboSex.Text = "Select";
            comboMaritualStatus.Text = "Select";
            comboBachelorsDegree.Text = "Select";
            comboBachelorsSpecialization.Text = "Select";
            comboMastersDegree.Text = "Select";
            comboMastersSpecialization.Text = "Select";
            txtAddress.Text = "";
            comboCity.Text = "Select";
            comboState.Text = "Select";
            comboCountry.Text = "Select";
            txtPincode.Text = "";
            dsEmployee = objEmployee.GetEmployeeList();
            Cnt1 = dsEmployee.Tables[0].Rows.Count;
            if (Cnt1 != 0)
            {
                datafill(0);

            }
            else
            {
                BtnSubmit.Enabled = true;
                btnUpdateEmployee.Enabled = false;
            }

            btnDeleteEmployee.Enabled = true;

            this.Hide();
            this.Hide();
        }

        private void Form1_Resize(object sender, System.EventArgs e)
        {
            if (FormWindowState.Minimized == WindowState)
                Hide();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }



        private void comboBachelorsDegree_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBachelorsDegree.Text == "Others")
            {
                lblOther1.Visible = true;
                txtSpecify1.Visible = true;

            }
            else
            {
                lblOther1.Visible = false;
                txtSpecify1.Visible = false;
            }
        }

        private void comboBachelorsSpecialization_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBachelorsSpecialization.Text == "Others")
            {
                lblOther2.Visible = true;
                txtSpecify2.Visible = true;
            }
            else
            {
                lblOther2.Visible = false;
                txtSpecify2.Visible = false;

            }
        }

        private void BtnSubmit_Click(object sender, EventArgs e)
        {
            EmployeeClass objEmployee = new EmployeeClass();
            DataSet dsEmployee = new DataSet();

            objEmployee.FirstName = txtFirstName.Text;
            objEmployee.MiddleName = txtMiddleName.Text;
            objEmployee.LastName = txtLastName.Text;
            if (comboDate.Text != "Select" && comboMonth.Text != "Select" && comboYear.Text != "Select")
                objEmployee.DateOfBirth = comboDate.Text + "-" + comboMonth.Text + "-" + comboYear.Text;
            if (comboSex.Text != "Select" && comboMaritualStatus.Text != "Select")
            {
                objEmployee.Sex = comboSex.Text;
                objEmployee.MaritualStatus = comboMaritualStatus.Text;
            }
            if (comboBachelorsDegree.Text != "Select")
            {
                if (comboBachelorsDegree.Text != "Others")
                {
                    objEmployee.BachelorDegree = comboBachelorsDegree.Text;
                }
                else
                {
                    objEmployee.BachelorDegree = txtSpecify1.Text;
                }
            }
            if (comboBachelorsSpecialization.Text != "Select")
            {
                if (comboBachelorsSpecialization.Text != "Others")
                {
                    objEmployee.BachelorDegreeSpecialization = comboBachelorsSpecialization.Text;
                }
                else
                {
                    objEmployee.BachelorDegreeSpecialization = txtSpecify2.Text;
                }
            }
            if (comboMastersDegree.Text != "Select")
            {
                if (comboMastersDegree.Text != "Others")
                {


                    objEmployee.MasterDegree = comboMastersDegree.Text;
                }
                else
                {
                    objEmployee.MasterDegree = txtSpecify3.Text;
                }
            }
            if (comboMastersSpecialization.Text != "Select")
            {
                if (comboMastersSpecialization.Text != "Others")
                {
                    objEmployee.MasterDegreeSpecialization = comboMastersSpecialization.Text;
                }
                else
                {
                    objEmployee.MasterDegreeSpecialization = txtSpecify4.Text;
                }
            }
            objEmployee.Address = txtAddress.Text;
            if (comboCity.Text != "Select" && comboState.Text != "Select" && comboCountry.Text != "Select")
            {
                objEmployee.City = comboCity.Text;
                objEmployee.State = comboState.Text;
                objEmployee.Country = comboCountry.Text;
            }
            objEmployee.Pincode = txtPincode.Text;
            bool bool1 = objEmployee.AddEmployeeDetail();
            if (bool1 == true)
            {
                txtFirstName.Text = "";
                txtMiddleName.Text = "";
                txtLastName.Text = "";
                comboDate.Text = "Select";
                comboMonth.Text = "Select";
                comboYear.Text = "Select";
                comboSex.Text = "Select";
                comboMaritualStatus.Text = "Select";
                comboBachelorsDegree.Text = "Select";
                comboBachelorsSpecialization.Text = "Select";
                comboMastersDegree.Text = "Select";
                comboMastersSpecialization.Text = "Select";
                txtAddress.Text = "";
                comboCity.Text = "Select";
                comboState.Text = "Select";
                comboCountry.Text = "Select";
                txtPincode.Text = "";
            }
        }

        private void comboMastersDegree_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboMastersDegree.Text == "Others")
            {
                lblOther3.Visible = true;
                txtSpecify3.Visible = true;

            }
            else
            {
                lblOther3.Visible = false;
                txtSpecify3.Visible = false;
            }
        }

        private void comboMastersSpecialization_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboMastersSpecialization.Text == "Others")
            {

                lblOther4.Visible = true;
                txtSpecify4.Visible = true;
            }
            else
            {
                lblOther4.Visible = false;
                txtSpecify4.Visible = false;
            }
        }

        private void btnNewEmployee_Click(object sender, EventArgs e)
        {
            btnUpdateEmployee.Enabled = false;
            BtnSubmit.Enabled = true;
            btnDeleteEmployee.Enabled = false;
            txtFirstName.Text = "";
            txtMiddleName.Text = "";
            txtLastName.Text = "";
            comboDate.Text = "Select";
            comboMonth.Text = "Select";
            comboYear.Text = "Select";
            comboSex.Text = "Select";
            comboMaritualStatus.Text = "Select";
            comboBachelorsDegree.Text = "Select";
            comboBachelorsSpecialization.Text = "Select";
            comboMastersDegree.Text = "Select";
            comboMastersSpecialization.Text = "Select";
            txtAddress.Text = "";
            comboCity.Text = "Select";
            comboState.Text = "Select";
            comboCountry.Text = "Select";
            txtPincode.Text = "";

        }

        //private void btnEditEmployee_Click(object sender, EventArgs e)
        //{
        //    BtnSubmit.Enabled = false;
        //}

        private void btnUpdateEmployee_Click(object sender, EventArgs e)
        {
            EmployeeClass objEmployee = new EmployeeClass();
            DataSet dsEmployee = new DataSet();
            objEmployee.EmployeeID = EmpID;
            objEmployee.FirstName = txtFirstName.Text;
            objEmployee.MiddleName = txtMiddleName.Text;
            objEmployee.LastName = txtLastName.Text;
            if (comboDate.Text != "Select" && comboMonth.Text != "Select" && comboYear.Text != "Select")
                objEmployee.DateOfBirth = comboDate.Text + "-" + comboMonth.Text + "-" + comboYear.Text;
            if (comboSex.Text != "Select" && comboMaritualStatus.Text != "Select")
            {
                objEmployee.Sex = comboSex.Text;
                objEmployee.MaritualStatus = comboMaritualStatus.Text;
            }
            if (comboBachelorsDegree.Text != "Select")
            {
                if (comboBachelorsDegree.Text != "Others")
                {
                    objEmployee.BachelorDegree = comboBachelorsDegree.Text;
                }
                else
                {
                    objEmployee.BachelorDegree = txtSpecify1.Text;
                }
            }
            if (comboBachelorsSpecialization.Text != "Select")
            {
                if (comboBachelorsSpecialization.Text != "Others")
                {
                    objEmployee.BachelorDegreeSpecialization = comboBachelorsSpecialization.Text;
                }
                else
                {
                    objEmployee.BachelorDegreeSpecialization = txtSpecify2.Text;
                }
            }
            if (comboMastersDegree.Text != "Select")
            {
                if (comboMastersDegree.Text != "Others")
                {


                    objEmployee.MasterDegree = comboMastersDegree.Text;
                }
                else
                {
                    objEmployee.MasterDegree = txtSpecify3.Text;
                }
            }
            if (comboMastersSpecialization.Text != "Select")
            {
                if (comboMastersSpecialization.Text != "Others")
                {
                    objEmployee.MasterDegreeSpecialization = comboMastersSpecialization.Text;
                }
                else
                {
                    objEmployee.MasterDegreeSpecialization = txtSpecify4.Text;
                }
            }
            objEmployee.Address = txtAddress.Text;
            if (comboCity.Text != "Select" && comboState.Text != "Select" && comboCountry.Text != "Select")
            {
                objEmployee.City = comboCity.Text;
                objEmployee.State = comboState.Text;
                objEmployee.Country = comboCountry.Text;
            }
            objEmployee.Pincode = txtPincode.Text;
            bool bool1 = objEmployee.UpdateEmployeeDetail();
            if (bool1 == true)
            {
                txtFirstName.Text = "";
                txtMiddleName.Text = "";
                txtLastName.Text = "";
                comboDate.Text = "Select";
                comboMonth.Text = "Select";
                comboYear.Text = "Select";
                comboSex.Text = "Select";
                comboMaritualStatus.Text = "Select";
                comboBachelorsDegree.Text = "Select";
                comboBachelorsSpecialization.Text = "Select";
                comboMastersDegree.Text = "Select";
                comboMastersSpecialization.Text = "Select";
                txtAddress.Text = "";
                comboCity.Text = "Select";
                comboState.Text = "Select";
                comboCountry.Text = "Select";
                txtPincode.Text = "";
            }
        }

        private void btnDeleteEmployee_Click(object sender, EventArgs e)
        {
            objEmployee.EmployeeID = EmpID;
            bool bool1 = objEmployee.DeleteEmployeeDetail();
        }

        private void btnFirst_Click(object sender, EventArgs e)
        {
            datafill(0);
        }

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            int cnt2;
            cnt2 = cnt3 - 1;
            if (cnt2 >= 0)
                datafill(cnt2);
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            int cnt2;
            cnt2 = cnt3 + 1;
            if (cnt2 < Cnt1)
                datafill(cnt2);
        }

        private void btnLast_Click(object sender, EventArgs e)
        {
            datafill(Cnt1 - 1);
        }
        public void datafill(int ID)
        {
            cnt3 = ID;
            EmpID = Convert.ToInt32(dsEmployee.Tables[0].Rows[ID]["EmployeeID"].ToString());
            txtFirstName.Text = dsEmployee.Tables[0].Rows[ID]["FirstName"].ToString();
            txtMiddleName.Text = dsEmployee.Tables[0].Rows[ID]["MiddleName"].ToString();
            txtLastName.Text = dsEmployee.Tables[0].Rows[ID]["LastName"].ToString();
            string dateOfBirth = dsEmployee.Tables[0].Rows[ID]["DateOfBirth"].ToString();
            string date = dateOfBirth.Substring(0, 2);
            string month = dateOfBirth.Substring(3, 3);
            string year = dateOfBirth.Substring(7, 4);
            comboDate.Text = date;
            comboMonth.Text = month;
            comboYear.Text = year;
            comboSex.Text = dsEmployee.Tables[0].Rows[ID]["Sex"].ToString();
            comboMaritualStatus.Text = dsEmployee.Tables[0].Rows[ID]["MaritalStatus"].ToString();
            try
            {
                comboBachelorsDegree.Text = dsEmployee.Tables[0].Rows[ID]["BachelorDegree"].ToString();
            }
            catch (Exception)
            {
                txtSpecify1.Text = dsEmployee.Tables[0].Rows[ID]["BachelorDegree"].ToString();
            }
            try
            {
                comboBachelorsSpecialization.Text = dsEmployee.Tables[0].Rows[ID]["BachelorSpecialization"].ToString();
            }
            catch
            {
                txtSpecify2.Text = dsEmployee.Tables[0].Rows[ID]["BachelorSpecialization"].ToString();
            }
            try
            {
                comboMastersDegree.Text = dsEmployee.Tables[0].Rows[ID]["MasterDegree"].ToString();
            }
            catch
            {
                txtSpecify3.Text = dsEmployee.Tables[0].Rows[ID]["MasterDegree"].ToString();

            }
            try
            {
                comboMastersSpecialization.Text = dsEmployee.Tables[0].Rows[ID]["MasterSpecialization"].ToString();
            }
            catch
            {
                txtSpecify4.Text = dsEmployee.Tables[0].Rows[ID]["MasterSpecialization"].ToString();
            }

            txtAddress.Text = dsEmployee.Tables[0].Rows[ID]["Address"].ToString();
            comboCity.Text = dsEmployee.Tables[0].Rows[ID]["City"].ToString();
            comboState.Text = dsEmployee.Tables[0].Rows[ID]["State"].ToString();
            comboCountry.Text = dsEmployee.Tables[0].Rows[ID]["Country"].ToString();
            txtPincode.Text = dsEmployee.Tables[0].Rows[ID]["Pincode"].ToString();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            BtnSubmit.Enabled = false;
            btnDeleteEmployee.Enabled = true;
            btnUpdateEmployee.Enabled = true;
            dsEmployee = objEmployee.GetEmployeeList();
            Cnt1 = dsEmployee.Tables[0].Rows.Count;
            datafill(0);

        }

        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Show();
                WindowState = FormWindowState.Normal;

            }
        }


    }
}