Exemple #1
0
        public int CreateOrUpdateMedical(Medical medical)
        {
            int returnId = -1;

            string query = "INSERT INTO Medical ([Expiration_date], [Number]) VALUES ('" + medical.ExpirationTime.ToShortDateString() + "'," +
                           medical.Number + ")";


            Medical med = GetMedical(medical.Id);

            if (med != null)
            {
                query = " UPDATE Medical SET [Expiration_date] = '" + medical.ExpirationTime.ToString("yyyy-MM-DD") +
                        "',[Number] = " + medical.Number + "WHERE id=" + medical.Id;
                returnId = medical.Id;
            }

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

            return(GetLastId("Medical"));
        }
Exemple #2
0
        public Medical GetMedical(int id)
        {
            Medical       medical = null;
            string        query   = "SELECT * FROM Medical WHERE id = " + id.ToString();
            SqlDataReader reader  = Execute(query).ExecuteReader();

            try
            {
                while (reader.Read())
                {
                    medical = new Medical()
                    {
                        Id             = int.Parse(reader["id"].ToString()),
                        ExpirationTime = DateTime.Parse(reader["Expiration_date"].ToString()),
                        Number         = int.Parse(reader["Number"].ToString())
                    };
                }
            }
            finally
            {
                reader.Close();
            }

            return(medical);
        }