Exemplo n.º 1
0
        public Customer GetByName(string name)
        {
            Customer _Customer = null;

            using (SqlConnection _Connection = RepositoryDBUtils.GetSqlConnection())
            {
                SqlCommand _Command = new SqlCommand
                {
                    Connection  = _Connection,
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "CRM_GetCustomerByName"
                };

                SqlParameter parameter = new SqlParameter("@Name", SqlDbType.NVarChar)
                {
                    Value = name
                };
                _Command.Parameters.Add(parameter);

                _Connection.Open();
                SqlDataReader _Reader = _Command.ExecuteReader(CommandBehavior.CloseConnection);
                while (_Reader.Read())
                {
                    _Customer = new Customer
                    {
                        ID      = int.Parse(_Reader["CustomerID"].ToString()),
                        Name    = _Reader["Name"].ToString(),
                        Address = _Reader["Address"].ToString()
                    };
                }
            }

            return(_Customer);
        }
        public void Add(PartInvoice invoice)
        {
            using (SqlConnection _Connection = RepositoryDBUtils.GetSqlConnection())
            {
                SqlCommand _Command = new SqlCommand
                {
                    Connection  = _Connection,
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "PMS_AddPartInvoice"
                };

                SqlParameter _StockCodeParameter = new SqlParameter("@StockCode", SqlDbType.VarChar, 50)
                {
                    Value = invoice.StockCode
                };
                _Command.Parameters.Add(_StockCodeParameter);
                SqlParameter QuantityParameter = new SqlParameter("@Quantity", SqlDbType.Int)
                {
                    Value = invoice.Quantity
                };
                _Command.Parameters.Add(QuantityParameter);
                SqlParameter CustomerIDParameter = new SqlParameter("@CustomerID", SqlDbType.Int)
                {
                    Value = invoice.CustomerID
                };
                _Command.Parameters.Add(CustomerIDParameter);

                _Connection.Open();
                _Command.ExecuteNonQuery();
            }
        }