コード例 #1
0
        private void btnPolySave_Click(object sender, EventArgs e)
        {
            int  data   = 0;
            bool _excep = false;

            using (var uow = (AdoNetUnitOfWork)UnitOfWorkFactory.Create(UnitOfWorkFactory.ConnectionType.SQL, Connection.connectionString))
            {
                PolyclinicRepository pRepos = new PolyclinicRepository(uow);
                try
                {
                    Polyclinic polyclinic = new Polyclinic()
                    {
                        Name    = txtPolyclinicName.Text,
                        Address = txtPolyclinicAddress.Text
                    };
                    data = pRepos.AddPolyclinic(polyclinic);
                    uow.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    _excep = true;
                }
                if (_excep == false && data == 1)
                {
                    MessageBox.Show("The operation is successfull...");
                }
            }
        }
コード例 #2
0
        public int AddPolyclinic(Polyclinic polyclinic)
        {
            IDbCommand cmd = _unitOfWork.CreateCommand();

            cmd.CommandText = "INSERT INTO Polyclinic(name,address) VALUES (@name,@address)";
            cmd.Parameters.Add(new SqlParameter("@name", polyclinic.Name));
            cmd.Parameters.Add(new SqlParameter("@address", polyclinic.Address));

            int data = cmd.ExecuteNonQuery();

            return(data);
        }
コード例 #3
0
        public List <Polyclinic> FindPolyclinicL(string polyclinicName)
        {
            IDbCommand command = _unitOfWork.CreateCommand();

            polyclinicName      = "%" + polyclinicName + "%";
            command.CommandText = "SELECT * FROM Polyclinic WHERE name LIKE @name";
            command.Parameters.Add(new SqlParameter("@name", polyclinicName));
            IDataReader dataReader = command.ExecuteReader();

            List <Polyclinic> polyclinics = new List <Polyclinic>();

            while (dataReader.Read())
            {
                Polyclinic polyclinic = new Polyclinic()
                {
                    ID   = dataReader.GetInt32(0),
                    Name = dataReader.GetString(1),
                };
                polyclinics.Add(polyclinic);
            }
            dataReader.Close();
            return(polyclinics);
        }
コード例 #4
0
        public List <Polyclinic> GetAllPolyclinicsL()
        {
            IDbCommand command = _unitOfWork.CreateCommand();

            command.CommandText = "SELECT id AS 'Polyclinic No',name AS 'Polyclinic Name',address AS 'Polyclinic Adress' FROM Polyclinic";

            IDataReader dataReader = command.ExecuteReader();

            List <Polyclinic> polyclinics = new List <Polyclinic>();

            while (dataReader.Read())
            {
                Polyclinic polyclinic = new Polyclinic()
                {
                    ID      = dataReader.GetInt32(0),
                    Name    = dataReader.GetString(1),
                    Address = dataReader.GetString(2)
                };
                polyclinics.Add(polyclinic);
            }
            dataReader.Close();
            return(polyclinics);
        }