示例#1
0
        public List <ContractType> ContractTypeList()
        {
            List <ContractType> list = new List <ContractType>();

            string        query  = "SELECT * FROM Contract_type";
            SqlDataReader reader = Execute(query).ExecuteReader();

            try
            {
                while (reader.Read())
                {
                    var contractType = new ContractType()
                    {
                        Id   = int.Parse(reader["Id"].ToString()),
                        Name = reader["Contract_name"].ToString()
                    };
                    list.Add(contractType);
                }
            }
            finally
            {
                if (!reader.IsClosed)
                {
                    reader.Close();
                }
            }

            return(list);
        }
示例#2
0
        public int CreateOrUpdateContract(ContractType contract)
        {
            int returnId = -1;

            string query = "INSERT INTO Contract_type VALUES ('" + contract.Name + "')";


            ContractType con = GetContractType(contract.Id);

            if (con != null)
            {
                query    = " UPDATE Contract_type SET [Contract_name] = '" + contract.Name + "' WHERE id=" + contract.Id;
                returnId = contract.Id;
            }

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

            return(GetLastId("Contract_type"));
        }
示例#3
0
        public ContractType GetContractType(int id)
        {
            ContractType  contract = null;
            string        query    = "SELECT * FROM Contract_type WHERE id = " + id.ToString();
            SqlDataReader reader   = Execute(query).ExecuteReader();

            try
            {
                while (reader.Read())
                {
                    contract = new ContractType()
                    {
                        Id   = int.Parse(reader["id"].ToString()),
                        Name = reader["Contract_name"].ToString()
                    };
                }
            }
            finally
            {
                reader.Close();
            }

            return(contract);
        }