コード例 #1
0
ファイル: SQLConnection.cs プロジェクト: Ewkaa/kadry
        public List <Employeer> GetAllEmployeers()
        {
            List <Employeer> listEmployeers = new List <Employeer>();
            string           query          = "SELECT * FROM Employeer";

            SqlDataReader reader = Execute(query).ExecuteReader();

            try
            {
                while (reader.Read())
                {
                    var employer = new Employeer()
                    {
                        Id              = int.Parse(reader["Id"].ToString()),
                        Firstname       = reader["First_name"].ToString(),
                        Surname         = reader["Surname"].ToString(),
                        MiddleName      = reader["Middle_name"].ToString(),
                        Pesel           = reader["Pesel"].ToString(),
                        Birthday        = DateTime.Parse(reader["Birth_date"].ToString()),
                        ContractDate    = DateTime.Parse(reader["Contract_date"].ToString()),
                        ContractEndDate = DateTime.Parse(reader["Contract_end_date"].ToString()),
                    };
                    listEmployeers.Add(employer);
                }
            }
            finally
            {
                if (!reader.IsClosed)
                {
                    reader.Close();
                }
            }

            return(listEmployeers);
        }
コード例 #2
0
ファイル: SQLConnection.cs プロジェクト: Ewkaa/kadry
        public Employeer GetEmployer(int id)
        {
            Employeer employer = null;
            string    query    = "SELECT * FROM Employeer WHERE id = " + id.ToString();
            //SELECT * FROM Employeer WHERE id=1
            SqlDataReader reader = Execute(query).ExecuteReader();

            try
            {
                if (reader.Read())
                {
                    employer = new Employeer()
                    {
                        Id              = int.Parse(reader["Id"].ToString()),
                        Firstname       = reader["First_name"].ToString(),
                        Surname         = reader["Surname"].ToString(),
                        MiddleName      = reader["Middle_name"].ToString(),
                        Pesel           = reader["Pesel"].ToString(),
                        Birthday        = DateTime.Parse(reader["Birth_date"].ToString()),
                        ContractDate    = DateTime.Parse(reader["Contract_date"].ToString()),
                        ContractEndDate = DateTime.Parse(reader["Contract_end_date"].ToString()),
                    };

                    var idContractType = int.Parse(reader["id_Contract_type"].ToString());
                    var idWorkplace    = int.Parse(reader["id_Workplace"].ToString());
                    var idHoliday      = int.Parse(reader["id_Holiday"].ToString());
                    var idMedical      = int.Parse(reader["id_Medical"].ToString());
                    var idSalary       = int.Parse(reader["id_Salary"].ToString());
                    var idHours        = int.Parse(reader["id_Hours"].ToString());
                    var idLogin        = int.Parse(reader["id_Login"].ToString());
                    var idSex          = int.Parse(reader["id_Sex"].ToString());

                    reader.Close();

                    employer.ContractType = GetContractType(idContractType);
                    employer.Workplace    = GetWorkplace(idWorkplace);
                    employer.Holiday      = GetHoliday(idHoliday);
                    employer.Medical      = GetMedical(idMedical);
                    employer.Salary       = GetSalary(idSalary);
                    employer.Hours        = GetHours(idHours);
                    employer.Login        = GetLogin(idLogin);
                    employer.Sex          = GetSex(idSex);
                }
            }
            finally
            {
                if (!reader.IsClosed)
                {
                    reader.Close();
                }
            }

            return(employer);
        }
コード例 #3
0
        public int CreateEmployer(Employeer employer)
        {
            int returnId = -1;

            string query =
                "INSERT INTO [dbo].[Employeer]" +
                "([Surname]" +
                ",[First_name]" +
                ",[Middle_name]" +
                ",[Pesel]" +
                ",[Birth_date]" +
                ",[Sex]" +
                ",[id_login]" +
                ",[id_Contract_type]" +
                ",[id_Hours]" +
                ",[id_Holiday]" +
                ",[id_Salary]" +
                ",[id_Medical]" +
                ",[id_Workplace]" +
                ",[Contract_date]" +
                ",[Contract_end_date])" +
                "VALUES(" +
                "'" + employer.Surname + "', " +
                "'" + employer.Firstname + "', " +
                "'" + employer.MiddleName + "', " +
                "'" + employer.Pesel + "', " +
                "'" + employer.Birthday.ToShortDateString() + "', " +
                "'" + employer.Sex + "', " +
                CreateLogin(employer.Login) + ", " +

                CreateOrUpdateContract(employer.ContractType).ToString() + ", " +
                CreateOrUpdateHours(employer.Hours).ToString() + ", " +
                CreateOrUpdateHoliday(employer.Holiday).ToString() + ", " +
                CreateOrUpdateSalary(employer.Salary).ToString() + ", " +
                CreateOrUpdateMedical(employer.Medical).ToString() + ", " +
                CreateOrUpdateWorkplace(employer.Workplace).ToString() + "," +
                "'" + employer.ContractDate.ToShortDateString() + "', " +
                "'" + employer.ContractEndDate.ToShortDateString() + "')";

            try
            {
                Execute(query).ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(returnId);
            }

            return(GetLastId("Employeer"));
        }