Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            salary sal;

            if (txtbasic.Text == "")
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Basic", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (txtempid.Text == "")
            {
                MetroFramework.MetroMessageBox.Show(this, "Insert Employee Id", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (dtpsal.Value == DateTime.Now)
            {
                MetroFramework.MetroMessageBox.Show(this, "Insert Date", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            // var d = context.salaries.FirstOrDefault(c => c.salId == id1);


            if (txtid.Text == "")
            {
                sal = new salary();
                context.salaries.Add(sal);
            }
            else
            {
                int id1 = Int32.Parse(txtid.Text);
                sal = context.salaries.FirstOrDefault(s => s.salId == id1);
                if (sal == null)
                {
                    this.init();
                    return;
                }
            }
            double b, c, h;

            if (!double.TryParse(txtbasic.Text, out b))
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Correct Basic", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!double.TryParse(txtca.Text, out c))
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Correct CA", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!double.TryParse(txtha.Text, out h))
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Correct Basic", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            sal.basic   = b;
            sal.ca      = c;
            sal.ha      = h;
            sal.empId   = Int32.Parse(txtempid.Text);
            sal.salDate = dtpsal.Value.ToShortDateString();
            if (rbvalid.Checked)
            {
                sal.isActive = "valid";
            }
            if (rbinvalid.Checked)
            {
                sal.isActive = "invalid";
            }


            context.SaveChanges();
            this.loadDetails(txtSearch.Text);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtName.Text))
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Name", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(dtpJoiningDate.Text))
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Date", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (rbtnMale.Checked == false && rbtnFemale.Checked == false)
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Gender", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (chkJava.Checked == false && chkCsharp.Checked == false && chkAlgo.Checked == false)
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Skills", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(txtEmail.Text))
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Email", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(txtPhone.Text))
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Phone", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(txtAddress.Text))
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Address", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (rbtnIsActiveYes.Checked == false && rbtnIsActiveNo.Checked == false)
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter IsActive", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(txtBasic.Text))
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter Basic Salary", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(txtCa.Text))
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter CA", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(txtHa.Text))
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter HA", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (rbtnInvalid.Checked == false && rbtnValid.Checked == false)
            {
                MetroFramework.MetroMessageBox.Show(this, "Enter IsActive", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            employee employee;

            if (string.IsNullOrEmpty(txtId.Text))
            {
                employee = new employee();
                context.employees.Add(employee);
            }
            else
            {
                int n = Int32.Parse(txtId.Text);
                employee = context.employees.FirstOrDefault(emp => emp.empId == n);
            }

            employee.empName     = txtName.Text;
            employee.joiningDate = Convert.ToDateTime(dtpJoiningDate.Text);
            employee.empGender   = rbtnMale.Checked == true ? "Male" : "Female";
            string skill = "";

            if (chkAlgo.Checked)
            {
                skill += string.IsNullOrEmpty(skill) ? "Algorithm" : ",Algorithm";
            }
            if (chkCsharp.Checked)
            {
                skill += string.IsNullOrEmpty(skill) ? "C#" : ",C#";
            }
            if (chkJava.Checked)
            {
                skill += string.IsNullOrEmpty(skill) ? "Java" : ",Java";
            }
            employee.empSkill    = skill;
            employee.empEmail    = txtEmail.Text;
            employee.empPhone    = txtPhone.Text;
            employee.empAddress  = txtAddress.Text;
            employee.empIsActive = rbtnIsActiveYes.Checked == true ? "Yes" : "No";
            context.SaveChanges();
            var u = context.usertypes.FirstOrDefault(ui => ui.utypeId == 3);

            u.employees.Add(employee);
            context.SaveChanges();
            salary sal;

            if (string.IsNullOrEmpty(txtId.Text))
            {
                sal = new salary();
                context.salaries.Add(sal);
                sal.empId = employee.empId;
                double b, h, c;
                if (!double.TryParse(txtBasic.Text, out b) || !double.TryParse(txtCa.Text, out c) || !double.TryParse(txtHa.Text, out h))
                {
                    MetroFramework.MetroMessageBox.Show(this, "Enter Correct Format of Basic,CA,HA", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                sal.basic    = b;
                sal.ca       = c;
                sal.ha       = h;
                sal.isActive = rbtnValid.Checked == true ? "valid" : "invalid";
                sal.salDate  = dtpJoiningDate.Text;
                context.SaveChanges();
            }
            fullrefresh();
            dgvDetails.ClearSelection();
            for (int i = 0; i < dgvDetails.Rows.Count; i++)
            {
                int n = Int32.Parse(dgvDetails.Rows[i].Cells[0].Value.ToString());
                if (n == employee.empId)
                {
                    dgvDetails.Rows[i].Selected = true;
                    loaddetail(n);
                }
            }
            salaryHide();
            MetroFramework.MetroMessageBox.Show(this, "Oparation inserted", "Successfull", MessageBoxButtons.OK, MessageBoxIcon.Question);
        }