public bool searchEMP(Buisness_Logic.employee emp) { try { DataLayer.dbConnect dbemp_seach = new DataLayer.dbConnect(); dbemp_seach.openConnection(); bool temp = false; string query1 = "SELECT * FROM tbl_employee WHERE empID=@reg OR name=@name OR nic=@nic"; SqlCommand cmd1 = new SqlCommand(query1, dbemp_seach.getConnection()); cmd1.Parameters.AddWithValue("@reg", emp.empID); cmd1.Parameters.AddWithValue("@name", emp.name); cmd1.Parameters.AddWithValue("@nic", emp.nic); DataTable dtq = new DataTable(); SqlDataAdapter da1 = new SqlDataAdapter(cmd1); da1.Fill(dtq); if (dtq.Rows.Count > 0) { emp.empID = int.Parse(dtq.Rows[0]["empID"].ToString()); emp.name = dtq.Rows[0]["name"].ToString(); emp.nic = dtq.Rows[0]["nic"].ToString(); emp.dob = dtq.Rows[0]["dob"].ToString(); emp.gender = dtq.Rows[0]["gender"].ToString(); emp.address = dtq.Rows[0]["address"].ToString(); emp.phone = dtq.Rows[0]["phone"].ToString(); emp.email = dtq.Rows[0]["email"].ToString(); emp.position = dtq.Rows[0]["position"].ToString(); emp.profile = dtq.Rows[0]["profile"].ToString(); emp.photo = (byte[])dtq.Rows[0]["photo"]; emp.joinedDate = dtq.Rows[0]["joinedDate"].ToString(); temp = true; } if (temp == true) { return(true); } else { return(false); } } catch (Exception ert) { throw; } }
private void btnEMP2_search_Click(object sender, EventArgs e) { if (validate_search_employee()) { try { Buisness_Logic.employee emp = new Buisness_Logic.employee(); emp.empID = (string.IsNullOrEmpty(txtEmp2_empid.Text) ? 0 : int.Parse(txtEmp2_empid.Text)); emp.name = txtEmp2_name.Text; emp.nic = txtEmp2_nic.Text; Buisness_Logic.EmployeeRepository emprt = new Buisness_Logic.EmployeeRepository(); if (emprt.searchEMP(emp)) { txtEmp2_address.Text = emp.address; txtEmp2_dob.Text = emp.dob; txtEmp2_email.Text = emp.email; txtEmp2_empid.Text = emp.empID.ToString(); txtEmp2_jDate.Text = emp.joinedDate; txtEmp2_name.Text = emp.name; txtEmp2_nic.Text = emp.nic; txtEmp2_phone.Text = emp.phone.ToString(); txtEmp2_profile.Text = emp.profile; cmbEMP2_gender.SelectedItem = emp.gender; cmbEMP2_post.SelectedItem = emp.position; pictureBoxEmp2.SizeMode = PictureBoxSizeMode.StretchImage; MemoryStream ms2 = new MemoryStream(emp.photo); // ms1.ToArray(); ms2.Position = 0; ms2.Read(emp.photo, 0, emp.photo.Length); pictureBoxEmp2.Image = Image.FromStream(ms2); MessageBox.Show("Success", "Data Insertion", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Failed.", "Data Insertion", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception exy) { MessageBox.Show(exy.Message, "Data Insertion", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } } }
private void btnEmp1_save_Click(object sender, EventArgs e) { try { if (validateEmp()) { Buisness_Logic.employee emp = new Buisness_Logic.employee(); emp.name = txtEmp1_name.Text; emp.address = txtEmp1_address.Text; emp.dob = dateTimePickeremp.Value.ToShortDateString(); //initialize image MemoryStream memt1p1 = new MemoryStream(); picuturebox_emp1.Image.Save(memt1p1, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] photo_memt1 = memt1p1.ToArray(); emp.phone = txtEmp1_phone.Text; emp.photo = photo_memt1; emp.nic = txtEmp_nic.Text; emp.position = cmbEmp1_post.SelectedItem.ToString(); emp.joinedDate = txtEmp1_jdate.Text; emp.gender = cmbEmp1_gender.SelectedItem.ToString(); emp.email = txtEmp1_email.Text; emp.profile = txtEmp1_resume.Text; Buisness_Logic.EmployeeRepository empr = new Buisness_Logic.EmployeeRepository(); if (empr.addEmployee(emp)) { MessageBox.Show("Success", "Data Insertion", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Failed", "Data Insertion", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception exb) { MessageBox.Show(exb.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } }
private void btnPrSearch_Click(object sender, EventArgs e) { int monthInDigit = DateTime.ParseExact(cmbFin1_month.SelectedItem.ToString(), "MMMM", CultureInfo.InvariantCulture).Month; int year = int.Parse(metroTextBox1.Text); int eid = int.Parse(textPrEid.Text); Buisness_Logic.employee emp = new Buisness_Logic.employee(); Buisness_Logic.salary b = new Buisness_Logic.salary(); if (emp.calculate_salaryl(monthInDigit, year, eid, b)) { MessageBox.Show("Successfull"); textPrTotHrWrk.Text = b.tot_hours.ToString(); textPrTotExHrWrk.Text = b.extr_hours.ToString(); } else { } }
public bool addEmployee(Buisness_Logic.employee emp) { bool temp1 = false; try { DataLayer.dbConnect con1 = new DataLayer.dbConnect(); con1.openConnection(); string q1 = "insert into tbl_employee (name,dob,nic,address,gender,email,phone,position,profile,joinedDate,photo) values (@name,@dob,@nic,@address,@gender,@email,@phone,@position,@profile,@jdate,@photo)"; SqlCommand cmd1 = new SqlCommand(q1, con1.getConnection()); cmd1.Parameters.AddWithValue("@name", emp.name); cmd1.Parameters.AddWithValue("@dob", emp.dob); cmd1.Parameters.AddWithValue("@nic", emp.nic); cmd1.Parameters.AddWithValue("@address", emp.address); cmd1.Parameters.AddWithValue("@gender", emp.gender); cmd1.Parameters.AddWithValue("@email", emp.email); cmd1.Parameters.AddWithValue("@phone", emp.phone); cmd1.Parameters.AddWithValue("@position", emp.position); cmd1.Parameters.AddWithValue("@profile", emp.profile); cmd1.Parameters.AddWithValue("@photo", emp.photo); cmd1.Parameters.AddWithValue("@jdate", emp.joinedDate); cmd1.ExecuteNonQuery(); temp1 = true; } catch (Exception ew) { throw; } if (temp1 == true) { return(true); } else { return(false); } }
private void btnserch_Click(object sender, EventArgs e) { if (validate_search_employee()) { try { Buisness_Logic.employee emp = new Buisness_Logic.employee(); emp.empID = (string.IsNullOrEmpty(txtUSacnt_empid.Text) ? 0 : int.Parse(txtUSacnt_empid.Text)); emp.nic = txtUSacnt_nic.Text; emp.name = txtusre_name.Text; Buisness_Logic.EmployeeRepository emprt = new Buisness_Logic.EmployeeRepository(); if (emprt.searchEMP(emp)) { txtUSacnt_empid.Text = emp.empID.ToString(); txtUSacnt_username.Text = emp.name.Replace(" ", "_"); txtUSacnt_nic.Text = emp.nic; txtusre_name.Text = emp.name; MessageBox.Show("Success", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Failed.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception exy) { MessageBox.Show(exy.Message, "Data Insertion", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } } }
private void btnEMP2_update_Click(object sender, EventArgs e) { if (validateUpdate_employee()) { Buisness_Logic.employee gm = new Buisness_Logic.employee(); MemoryStream memt1p2 = new MemoryStream(); pictureBoxEmp2.SizeMode = PictureBoxSizeMode.StretchImage; pictureBoxEmp2.Image.Save(memt1p2, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] photo_memt2 = memt1p2.ToArray(); gm.empID = int.Parse(txtEmp2_empid.Text); gm.name = txtEmp2_name.Text; gm.nic = txtEmp2_nic.Text; gm.phone = txtEmp2_phone.Text; gm.address = txtEmp2_address.Text; gm.gender = cmbEMP2_gender.SelectedItem.ToString(); gm.position = cmbEMP2_post.SelectedItem.ToString(); gm.dob = txtEmp2_dob.Text; gm.joinedDate = txtEmp2_jDate.Text; gm.profile = txtEmp2_profile.Text; gm.photo = photo_memt2; gm.email = txtEmp2_email.Text; Buisness_Logic.EmployeeRepository grup = new Buisness_Logic.EmployeeRepository(); if (grup.update_employee(gm)) { MessageBox.Show("Employee detail updated.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); //datagridm3refresh(); } } }