Example #1
0
        public Process(int id, int companyId)
        {
            /* CREATE PROCEDURE Get_ProcesosById
             * @Id int,
             * @CompanyId int */

            using (SqlCommand cmd = new SqlCommand("Get_ProcesosById"))
            {
                cmd.Connection  = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Id", SqlDbType.Int);
                cmd.Parameters.Add("@CompanyId", SqlDbType.Int);
                cmd.Parameters["@Id"].Value        = id;
                cmd.Parameters["@CompanyId"].Value = companyId;
                try
                {
                    cmd.Connection.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();
                    if (rdr.HasRows)
                    {
                        rdr.Read();
                        this.id          = id;
                        this.companyId   = companyId;
                        this.processType = (Type)rdr.GetInt32(2);
                        this.startDate   = rdr.GetString(3);
                        this.work        = rdr.GetString(4);
                        this.endDate     = rdr.GetString(5);
                        this.jobPosition = new JobPosition(Convert.ToInt32(rdr.GetInt64(7)), companyId);
                        this.modifiedBy  = new Employee(rdr.GetInt32(8));
                        this.modifiedOn  = rdr.GetDateTime(9);
                    }
                }
                finally
                {
                    if (cmd.Connection.State != ConnectionState.Closed)
                    {
                        cmd.Connection.Close();
                    }
                }
            }
        }
Example #2
0
        /// <summary>Gets a descriptive text with the differences between two job position objects</summary>
        /// <param name="jobPosition1">First job position object</param>
        /// <param name="jobPosition2">Second job position object</param>
        /// <returns>Descriptive text with the differences between two job position objects</returns>
        public static string Differences(JobPosition jobPosition1, JobPosition jobPosition2)
        {
            if (jobPosition1 == null || jobPosition2 == null)
            {
                return(string.Empty);
            }

            var  res   = new StringBuilder();
            bool first = true;

            if (jobPosition1.Description != jobPosition2.Description)
            {
                res.Append(string.Format(CultureInfo.InvariantCulture, "description:{0}", jobPosition2.Description));
                first = false;
            }

            if (jobPosition1.Responsible != null && jobPosition2.Responsible != null && jobPosition2.Responsible.Id != jobPosition1.Responsible.Id)
            {
                if (!first)
                {
                    res.Append(", ");
                }

                res.Append(string.Format(CultureInfo.InvariantCulture, "responsible{0}", jobPosition2.Responsible.Id));
                first = false;
            }

            if (jobPosition1.Responsible == null && jobPosition2.Responsible != null)
            {
                if (!first)
                {
                    res.Append(", ");
                }

                res.Append(string.Format(CultureInfo.InvariantCulture, "responsible{0}", jobPosition2.Responsible.Id));
                first = false;
            }

            if (jobPosition1.Responsible != null)
            {
                if (!first)
                {
                    res.Append(", ");
                }

                string resposibleId = "null";
                if (jobPosition2.Responsible != null)
                {
                    resposibleId = string.Format(CultureInfo.InvariantCulture, "{0}", jobPosition2.Responsible.Id);
                }

                res.Append(string.Format(CultureInfo.InvariantCulture, "responsible{0}", resposibleId));
                first = false;
            }

            if (jobPosition1.Department.Id != jobPosition2.Department.Id)
            {
                if (!first)
                {
                    res.Append(", ");
                }

                res.Append(string.Format(CultureInfo.GetCultureInfo("en-us"), "department:{0}", jobPosition2.Department.Id));
                first = false;
            }

            if (jobPosition1.Responsibilities != jobPosition2.Responsibilities)
            {
                if (!first)
                {
                    res.Append(", ");
                }

                res.Append(string.Format(CultureInfo.InvariantCulture, "responsibilities:{0}", jobPosition2.Responsibilities));
                first = false;
            }

            if (jobPosition1.Notes != jobPosition2.Notes)
            {
                if (!first)
                {
                    res.Append(", ");
                }

                res.Append(string.Format(CultureInfo.InvariantCulture, "notes:{0}", jobPosition2.Notes));
                first = false;
            }

            if (jobPosition1.AcademicSkills != jobPosition2.AcademicSkills)
            {
                if (!first)
                {
                    res.Append(", ");
                }

                res.Append(string.Format(CultureInfo.InvariantCulture, "academicSkills:{0}", jobPosition2.AcademicSkills));
                first = false;
            }

            if (jobPosition1.SpecificSkills != jobPosition2.SpecificSkills)
            {
                if (!first)
                {
                    res.Append(", ");
                }

                res.Append(string.Format(CultureInfo.InvariantCulture, "specificSkills:{0}", jobPosition2.SpecificSkills));
                first = false;
            }

            if (jobPosition1.Habilities != jobPosition2.Habilities)
            {
                if (!first)
                {
                    res.Append(", ");
                }

                res.Append(string.Format(CultureInfo.InvariantCulture, "Habilities:{0}", jobPosition2.Habilities));
                first = false;
            }

            if (jobPosition1.WorkExperience != jobPosition2.WorkExperience)
            {
                if (!first)
                {
                    res.Append(", ");
                }

                res.Append(string.Format(CultureInfo.InvariantCulture, "Experience:{0}", jobPosition2.WorkExperience));
            }

            return(res.ToString());
        }
Example #3
0
 public Process()
 {
     this.jobPosition = JobPosition.Empty;
     this.modifiedBy  = Employee.Empty;
     this.processType = Type.Undefined;
 }
Example #4
0
        /// <summary>Obtain the employess of department</summary>
        public void ObtainEmployees()
        {
            this.jobPositions = new List <JobPosition>();
            this.employees    = new List <Employee>();
            using (var cmd = new SqlCommand("Department_GetEmployess"))
            {
                using (var cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString))
                {
                    cmd.Connection  = cnn;
                    cmd.CommandType = CommandType.StoredProcedure;
                    try
                    {
                        cmd.Parameters.Add(DataParameter.Input("@DepartmentId", this.Id));
                        cmd.Parameters.Add(DataParameter.Input("@CompanyId", this.CompanyId));
                        cmd.Connection.Open();
                        using (var rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                var newJobPosition = new JobPosition
                                {
                                    Id          = rdr.GetInt32(0),
                                    CompanyId   = this.CompanyId,
                                    Description = rdr.GetString(1)
                                };

                                if (!rdr.IsDBNull(2))
                                {
                                    var responsible = new JobPosition
                                    {
                                        Id          = rdr.GetInt32(2),
                                        CompanyId   = this.CompanyId,
                                        Description = rdr.GetString(3)
                                    };
                                    newJobPosition.Responsible = responsible;
                                }

                                bool jobPositionExists = false;
                                foreach (var jobPosition in this.jobPositions)
                                {
                                    if (jobPosition.Id == newJobPosition.Id)
                                    {
                                        jobPositionExists = true;
                                        break;
                                    }
                                }

                                if (!jobPositionExists)
                                {
                                    this.jobPositions.Add(newJobPosition);
                                }

                                if (!rdr.IsDBNull(4))
                                {
                                    var newEmployee = new Employee
                                    {
                                        Id        = rdr.GetInt32(4),
                                        CompanyId = this.CompanyId,
                                        Name      = rdr.GetString(5),
                                        LastName  = rdr.GetString(6),
                                        Nif       = rdr.GetString(7),
                                        Email     = rdr.GetString(8),
                                        Phone     = rdr.GetString(9)
                                    };

                                    bool employeeExists = false;
                                    foreach (var employee in this.employees)
                                    {
                                        if (employee.Id == newEmployee.Id)
                                        {
                                            employeeExists = true;
                                            break;
                                        }
                                    }

                                    if (!employeeExists)
                                    {
                                        this.employees.Add(newEmployee);
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (cmd.Connection.State != ConnectionState.Closed)
                        {
                            cmd.Connection.Close();
                        }
                    }
                }
            }
        }