public static LTS.Employee GetEmployeeItemByID(int?EmployeeID) { LTS.Employee employee = new LTS.Employee(); try { using (LTS.LTSBase access = new LTS.LTSDC()) { employee = access.Employee.Where(o => o.EmpID == EmployeeID).FirstOrDefault(); } } catch (Exception ex) { } return(employee); }
public static int AddEmployee(LTS.Employee employee) { int?EmployeeID = -1; try { using (LTS.LTSBase access = new LTS.LTSDC()) { access.InsertEmployee(employee.Activated, employee.CellNo, employee.Email, employee.EmpAddress, employee.IDno, employee.IsAdmin, employee.Name, employee.Pass, employee.Salary, employee.Surname, employee.Username, ref EmployeeID); } } catch (Exception ex) { } return(EmployeeID.Value); }
public static bool UpdateEmployee(LTS.Employee employee) { bool completed = false; try { using (LTS.LTSBase access = new LTS.LTSDC()) { access.UpdateEmployee(employee.Activated, employee.CellNo, employee.Email, employee.EmpAddress, employee.IDno, employee.IsAdmin, employee.Name, employee.Pass, employee.Salary, employee.Surname, employee.Username, employee.EmpID); completed = true; } } catch (Exception ex) { completed = false; } return(completed); }
private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows == null) { } else { if (MessageBox.Show("Are You sure you want to remove this employee Item?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) { string empID; using (DataGridViewRow item = this.dataGridView1.SelectedRows[0]) { int i = item.Index; empID = dataGridView1.Rows[i].Cells[0].Value.ToString(); LTS.Employee employee = new LTS.Employee(); employee = DAT.DataAccess.GetEmployee().Where(it => it.EmpID == Convert.ToInt32(empID)).FirstOrDefault(); employee.Activated = false; bool updated = DAT.DataAccess.UpdateEmployee(employee); if (updated) { if (DialogResult.OK == MessageBox.Show("Employee item removed successfully!")) { ((Form1)this.Parent.Parent).ChangeView <Employee>(); } } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the employee item was not removed successfully!")) { ((Form1)this.Parent.Parent).ChangeView <Employee>(); } } } } else { } } }
private void button2_Click(object sender, EventArgs e) { error.Visible = false; richTextBox1.Visible = false; label22.Visible = false; IdentityNumber id = new IdentityNumber(txtID.Text); if (txtName.Text == "" || txtSur.Text == "" || txtID.Text == "" || txtCell.Text == "" || txtEmail.Text == "" || txtAddress.Text == "" || txtsalary.Text == "" || txtUsername.Text == "" || txtPassword.Text == "" || comboBoxActiv.SelectedItem.ToString() == "" || comboBoxAdmin.SelectedItem.ToString() == "" || !id.IsValid) { error.Visible = true; richTextBox1.Visible = true; } else { ///////////////////////CHECKS////////////////// bool isEmail = Regex.IsMatch(txtEmail.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase); bool isCell = Regex.IsMatch(txtCell.Text, @"^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$"); bool name = Regex.IsMatch(txtName.Text, @"^[a-zA-Z ]+$"); bool sName = Regex.IsMatch(txtSur.Text, @"^[a-zA-Z ]+$"); int exist; if (oldeID == txtID.Text) { exist = 0; } else { exist = DAT.DataAccess.GetEmployee().Where(i => i.IDno == txtID.Text).ToList().Count; } //////////////////////CHECKS////////////////// if (!isEmail || !isCell || !name || !sName || exist != 0) { if (exist != 0) { label22.Visible = true; } error.Visible = true; richTextBox1.Visible = true; } else { try { LTS.Employee newEmp = new LTS.Employee(); newEmp.EmpID = Convert.ToInt32(em.Text); newEmp.Name = txtName.Text; newEmp.Surname = txtSur.Text; newEmp.IDno = txtID.Text; newEmp.CellNo = txtCell.Text; newEmp.Email = txtEmail.Text; newEmp.EmpAddress = txtAddress.Text; newEmp.Salary = Convert.ToDecimal(txtsalary.Text); newEmp.IsAdmin = Convert.ToBoolean(comboBoxAdmin.SelectedItem); newEmp.Username = txtUsername.Text; newEmp.Pass = txtPassword.Text; newEmp.Activated = Convert.ToBoolean(comboBoxActiv.SelectedItem); bool updated = DAT.DataAccess.UpdateEmployee(newEmp); if (updated) { if (DialogResult.OK == MessageBox.Show("Employee item edited successfully!")) { ((Form1)this.Parent.Parent).ChangeView <Employee>(); } } else { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Employee item was not edited successfully!")) { ((Form1)this.Parent.Parent).ChangeView <Employee>(); } } } catch (Exception ex) { error.Visible = true; richTextBox1.Visible = true; } } } }