Esempio n. 1
0
        public EmployeeView Get(EmployeeEntity t)
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;

            try
            {
                conn = DALHelper.CreateSqlDbConnection();
                cmd = new SqlCommand("usp_GetEmployeeById", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Id", t.Id);

                SqlDataReader rdr = cmd.ExecuteReader();
                EmployeeView content = new EmployeeView();

                if (rdr.Read())
                {
                    content.Id = Convert.ToInt32(rdr["Id"]);
                    content.EmployeeNo = Convert.ToString(rdr["EmployeeNo"]);
                    content.Firstname = Convert.ToString(rdr["Firstname"]);
                    content.Middlename = Convert.ToString(rdr["Middlename"]);
                    content.Lastname = Convert.ToString(rdr["Lastname"]);
                    content.DateOfBirth = Convert.ToDateTime(rdr["DateOfBirth"]);
                    content.Nationality = Convert.ToString(rdr["Nationality"]);
                    content.Gender = (GenderEnum)Convert.ToInt32(rdr["Gender"]);
                    content.PersonalNumber = Convert.ToString(rdr["PersonalNumber"]);
                    content.Address = Convert.ToString(rdr["Address"]);
                    content.Country = Convert.ToString(rdr["Country"]);
                    content.City = Convert.ToString(rdr["City"]);
                    content.MobilePhone = Convert.ToString(rdr["MobilePhone"]);
                    content.WorkEmail = Convert.ToString(rdr["WorkEmail"]);
                    content.OtherEmail = Convert.ToString(rdr["OtherEmail"]);
                    content.Bank = Convert.ToString(rdr["Bank"]);
                    content.AccountNumber = Convert.ToString(rdr["AccountNumber"]);
                    content.Job = Convert.ToString(rdr["Job"]);
                    content.OrganizationalUnit = Convert.ToString(rdr["OrganizationalUnit"]);
                    content.MaritalStatus = (MaritalStatusEnum)Convert.ToInt32(rdr["MaritalStatus"]);
                    if (rdr["Image"] != DBNull.Value)
                    {
                        content.Image = (byte[])rdr["Image"];
                    }

                    content.Status = (StatusEnum)Convert.ToInt32(rdr["Status"]);
                }

                return content;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
                cmd.Dispose();
                conn.Dispose();
            }
        }
        public void InsertWithReminder(EmployeeEntity employeeEntity, ReminderEntity reminderEntity)
        {
            using (SqlConnection connection = DALHelper.CreateSqlDbConnection())
            {
                // Start a local transaction.
                SqlTransaction sqlTran = connection.BeginTransaction();

                // Enlist a command in the current transaction.

                try
                {
                    SqlCommand command = connection.CreateCommand();
                    command.Transaction = sqlTran;
                    new EmployeeMapper().Insert(employeeEntity, command);

                    command = connection.CreateCommand();
                    command.Transaction = sqlTran;

                    reminderEntity.EntityPK = employeeEntity.Id.ToString();

                    new ReminderMapper().Insert(reminderEntity, command);

                    // Commit the transaction.
                    sqlTran.Commit();
                }
                catch (Exception)
                {
                    // Handle the exception if the transaction fails to commit.

                    try
                    {
                        // Attempt to roll back the transaction.
                        sqlTran.Rollback();
                    }
                    catch (Exception)
                    {
                        // Throws an InvalidOperationException if the connection
                        // is closed or the transaction has already been rolled
                        // back on the server.
                    }
                }
            }
        }
Esempio n. 3
0
        public void Update(EmployeeEntity t)
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;

            try
            {
                conn = DALHelper.CreateSqlDbConnection();
                cmd = new SqlCommand("usp_UpdateEmployee", conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Id", t.Id);
                cmd.Parameters.AddWithValue("@EmployeeNo", t.EmployeeNo);
                cmd.Parameters.AddWithValue("@Firstname", t.Firstname);
                cmd.Parameters.AddWithValue("@Middlename", t.Middlename);
                cmd.Parameters.AddWithValue("@Lastname", t.Lastname);
                cmd.Parameters.AddWithValue("@DateOfBirth", t.DateOfBirth);
                cmd.Parameters.AddWithValue("@NationalityId", t.NationalityId);
                cmd.Parameters.AddWithValue("@Gender", t.Gender);
                cmd.Parameters.AddWithValue("@PersonalNumber", t.PersonalNumber);
                cmd.Parameters.AddWithValue("@Address", t.Address);
                cmd.Parameters.AddWithValue("@CountryId", t.CountryId);
                cmd.Parameters.AddWithValue("@City", t.City);
                cmd.Parameters.AddWithValue("@MobilePhone", t.MobilePhone);
                cmd.Parameters.AddWithValue("@WorkEmail", t.WorkEmail);
                cmd.Parameters.AddWithValue("@OtherEmail", t.OtherEmail);
                cmd.Parameters.AddWithValue("@BankId", t.BankId);
                cmd.Parameters.AddWithValue("@AccountNumber", t.AccountNumber);
                cmd.Parameters.AddWithValue("@MaritalStatus", t.MaritalStatus);
                if (t.Image != null)
                {
                    cmd.Parameters.AddWithValue("@Image", t.Image);
                }

                cmd.ExecuteScalar();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
                cmd.Dispose();
                conn.Dispose();
            }
        }
Esempio n. 4
0
 public void Delete(EmployeeEntity t)
 {
     throw new NotImplementedException();
 }
        protected void ProceedButton_Click(object sender, EventArgs e)
        {
            EmployeeEntity entity = new EmployeeEntity();
            entity.EmployeeNo = EmployeeNoTextBox.Text;
            entity.Firstname = FirstnameTextBox.Text;
            entity.Middlename = "";
            entity.Middlename = MiddlenameTextBox.Text;
            entity.Lastname = LastnameTextBox.Text;

            DateTime dt;
            if (DateTime.TryParseExact(DateOfBirthTextBox.Text, ConfigurationManager.AppSettings["DateFormat"], null, System.Globalization.DateTimeStyles.None, out dt))
            {
                entity.DateOfBirth = dt;
            }

            entity.Gender = (GenderEnum)Convert.ToInt32(GenderDropDownList.SelectedValue);
            entity.NationalityId = Convert.ToInt32(NationalityDropDownList.SelectedValue);
            entity.CountryId = Convert.ToInt32(CountryDropDownList.SelectedValue);
            entity.Address = AddressTextBox.Text;
            entity.PersonalNumber = PersonalNumberTextBox.Text;
            entity.WorkEmail = WorkEmailTextBox.Text;
            entity.MobilePhone = MobilePhoneTextBox.Text;
            entity.OtherEmail = OtherEmailTextBox.Text;
            entity.City = CityTextBox.Text;
            entity.BankId = Convert.ToInt32(BankDropDownList.SelectedValue);
            entity.AccountNumber = AccountNumberTextBox.Text;
            entity.MaritalStatus = (MaritalStatusEnum)Convert.ToInt32(MaritalStatusDropDownList.SelectedValue);

            if (Session["fileContents_"] != null)
            {
                byte[] fileContents = (byte[])Session["fileContents_"];
                entity.Image = fileContents;
            }

            EmployeeMapper mapper = new EmployeeMapper();

            try
            {
                if (Request.QueryString["action"] == "update" && Request.QueryString["EmployeeId"] != null)
                {
                    entity.Id = Convert.ToInt32(Request.QueryString["EmployeeId"]);
                    mapper.Update(entity);
                    Response.Redirect("EducationAndExperience.aspx?action=update&EmployeeId=" + entity.Id);
                }
                else
                {
                    ReminderEntity reminder = new ReminderEntity();
                    reminder.EntityPK = entity.Id.ToString();
                    reminder.EntityPKType = typeof(int).ToString();
                    reminder.ReminderType = ReminderEnum.EmployeeNoContract;
                    reminder.Url = "/HRM/HR-Managment/Employee/EmployeesWithoutContract.aspx";
                    new EmployeeMapperTransaction().InsertWithReminder(entity, reminder);
                    Response.Redirect("EducationAndExperience.aspx?EmployeeId=" + entity.Id);
                }
            }
            catch (SqlException ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<script language='javascript'>displayNoty('The Employee No { " + EmployeeNoTextBox.Text + " } has been used, plase write another number');</script>");

                // if the script is not already registered
                if (!Page.ClientScript.IsClientScriptBlockRegistered(Page.GetType(), "HeyPopup"))
                    ClientScript.RegisterClientScriptBlock(Page.GetType(), "HeyPopup", sb.ToString());
            }
            finally
            {
            }
        }